0

I am attempting to correlate traces originating in DataDog's RUM SDK, which are hitting by BE instrumented with OpenTelemetry. Essentially trying to implement the reverse of DD's documentation on Connect OpenTelemetry Traces And Logs

OpenTelemetry TraceId and SpanId properties differ from Datadog conventions. Therefore it’s necessary to translate TraceId and SpanId from their OpenTelemetry formats (a 128bit unsigned int and 64bit unsigned int represented as a 32-hex-character and 16-hex-character lowercase string, respectively) into their Datadog Formats(a 64bit unsigned int).

The context is being set in my BE in the following way;

(event:any) => {
      if(event.headers) {
        const traceId = event.headers['x-datadog-trace-id']
        const spanId = event.headers['x-datadog-parent-id']
        if(traceId && spanId) {
          const convertedTraceId = convertToOtelId(traceId, 32);
          const convertedSpanId = convertToOtelId(spanId, 16);
          const spanContext: SpanContext = {
            traceId: convertedTraceId,
            spanId: convertedSpanId,
            traceFlags: 1,
            isRemote: true,
          };
    
          return propagation.extract(context.active(), spanContext);
        }
      }
      return ROOT_CONTEXT;
    }

convertToOtelId is producing these results;

trace id - In: 2245099779221068633, Out: 00000000000000001f28325aa9c79b59

span id - In: 4011377516575614177, Out: 37ab46991f7a64e1

Obviously the 128-bit uint for the trace_id does not look correct with its leading zeros. Am I understanding this conversion correctly?

coderdude123
  • 311
  • 2
  • 7

1 Answers1

1

Yes, you are doing it correct. The extra leading zeros indicate the remaining unused bits. Here is simple cross check in python.

>>>
>>> format(2245099779221068633, "032x")  # The trace ID as 32-byte hexadecimal string
'00000000000000001f28325aa9c79b59'
>>>
>>> format(4011377516575614177, "016x")  # The span ID as 16-byte hexadecimal string
'37ab46991f7a64e1'
Srikanth Chekuri
  • 1,944
  • 1
  • 9
  • 19