DataDog / dd-opentelemetry-exporter-js

OpenTelemetry JS Datadog Exporter
Apache License 2.0
13 stars 10 forks source link

Injected `trace_id` and `span_id` in DatadogPropagator seems wrong #16

Open seanyu4296 opened 3 years ago

seanyu4296 commented 3 years ago

Describe the bug The code for inject in propagator is wrong if you compare it to the implementation here

https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/f1e8331be111a4a8bf65670dfaff359714edef85/exporter/datadogexporter/translate_traces.go#L465-L470

https://github.com/DataDog/dd-opentelemetry-exporter-js/blob/7682aabe492f4d1c2d7d0d8acbfc013eeae1ea53/src/datadogPropagator.ts#L48-L50

Correct implementation seems to be + substring it if necessary

spanContext.traceId && id(spanContext.traceId.length > 16 ? spanContext.traceId.substr(16): spanContextTraceId), 'hex')

cc @ericmustin

seanyu4296 commented 3 years ago

if we want to respect "opentelemtery specification" i think extract should also be modified to.

    const traceId = id(traceIdHeaderValue, 10).toString('hex').padStart(32, '0'); // pad this for opentelemetry
    const spanId = id(spanIdHeaderValue, 10).toString('hex');
seanyu4296 commented 3 years ago

I made a sample repo to show

https://github.com/seanyu4296/node-dd-otel-poc/blob/b2c6dc262cae9e52f828c798f24ffb9e4c21f962/custom-datadog/datadog-propagator.ts#L116