import * as core from '@opentelemetry/core' ; import * as api from '@opentelemetry/api' ; import * as proto from './common' ; const MAX_INTEGER_VALUE = 2147483647 ; const MIN_INTEGER_VALUE = - 2147483648 ; export type protoAnyValueType = string | number | boolean | Array < null | undefined | string > | Array < null | undefined | number > | Array < null | undefined | boolean > ; export function toProtoArrayValue ( values ) { return { values : values . map ( toProtoAnyValue ) , } ; } export function fromProtoArrayValue ( protoArrayValue ) { return protoArrayValue . values . map ( fromProtoAnyValue ) as protoAnyValueType ; } export function toProtoAnyValue ( sdkValue ) { switch ( typeof sdkValue ) { case 'string' : return { stringValue : sdkValue , } ; case 'boolean' : return { boolValue : sdkValue , } ; case 'number' : { if ( Number . isInteger ( sdkValue ) && sdkValue <= MAX_INTEGER_VALUE && sdkValue >= MIN_INTEGER_VALUE ) { return { intValue : sdkValue , } ; } else { return { doubleValue : sdkValue , } ; } } } if ( Array . isArray ( sdkValue ) ) { return { arrayValue : toProtoArrayValue ( sdkValue ) , } ; } return { } ; } export function fromProtoAnyValue ( protoAnyValue ) { if ( protoAnyValue . stringValue ) { return protoAnyValue . stringValue ; } else if ( protoAnyValue . boolValue ) { return protoAnyValue . boolValue ; } else if ( protoAnyValue . intValue ) { return protoAnyValue . intValue ; } else if ( protoAnyValue . doubleValue ) { return protoAnyValue . doubleValue ; } else if ( protoAnyValue . arrayValue ) { return fromProtoArrayValue ( protoAnyValue . arrayValue ) ; } } export function toProtoKeyValue ( k , v ) { return { key : k , value : toProtoAnyValue ( v ) , } ; } export function fromProtoKeyValue ( protoKeyValue ) { return [ protoKeyValue . key , fromProtoAnyValue ( protoKeyValue . value ) ] ; } export function toProtoSpanAttributes ( sdkSpanAttributes ) { return Object . entries ( sdkSpanAttributes ) . map ( ( [ sdkAttributeKey , sdkAttributeValue ] ) => toProtoKeyValue ( sdkAttributeKey , sdkAttributeValue ) ) ; } export function fromProtoSpanAttributes ( protoSpanAttributes ) { return Object . fromEntries ( protoSpanAttributes . map ( fromProtoKeyValue ) ) ; } export function toInstrumentationLibrary ( sdkInstrumentationLibrary ) { return { name : sdkInstrumentationLibrary . name , version : sdkInstrumentationLibrary . version , } ; } export function fromInstrumentationLibrary ( protoInstrumentationLibrary ) { return { name : protoInstrumentationLibrary . name , version : protoInstrumentationLibrary . version , } ; }