You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Calling this DatadogSpanContext.toTraceId() method on what appears to be a valid span can sometimes error out with an undefined inner this._traceId value:
traceID is either a valid Trace ID from the current span or undefined in which case we default to 'n/a/ based on the code above
Actual result
We regularly encounter an error whereby we seem to have a defined span (i.e. not null or undefined) with an empty or missing DatadogSpanContext._traceID property such that when we call toTraceId() on it we get the following error:
.../my_app/node_modules/dd-trace/packages/dd-trace/src/opentracing/span_context.js:39
return this._traceId.toString(10)
^
TypeError: Cannot read properties of undefined (reading 'toString')
at DatadogSpanContext.toTraceId (.../my_app/packages/dd-trace/src/opentracing/span_context.js:39:26)
Unit Tests
Here is a failing test we can add to packages/dd-trace/test/opentracing/span_context.spec.js to demonstrate the issue
This set of libraries is honestly disappointingly unstable. I feel like every time we upgrade another random issue like this appears. We had it pinned since May 2024 to circumvent another bug, but yesterday I was forced to unpin to fix another problem, and now I wake up to several reports of this error reported here.
You seriously need to invest in better integration tests.
We're using serverless-plugin-datadog and getting this library through the layer that is published in datadog-lambda-js, the dd-trace version there is not even v5 yet for some reason, but it also has this same problem here.
I've downgraded the layer to 112, which for us is the LKGC.
Calling this
DatadogSpanContext.toTraceId()
method on what appears to be a valid span can sometimes error out with an undefined innerthis._traceId
value:dd-trace-js/packages/dd-trace/src/opentracing/span_context.js
Lines 33 to 40 in 497c0b0
Suggested Solution
While I am not sure what might cause this scenario, a quick fix would be to make the dot property access of
this._traceId
a bit more defensive:Replication Steps
Using:
Initialize the tracer on startup:
Try to defensively get the active span's
traceID
at runtimeExpected result
traceID
is either a valid Trace ID from the current span orundefined
in which case we default to'n/a/
based on the code aboveActual result
We regularly encounter an error whereby we seem to have a defined
span
(i.e. notnull
orundefined
) with an empty or missingDatadogSpanContext._traceID
property such that when we calltoTraceId()
on it we get the following error:Unit Tests
Here is a failing test we can add to
packages/dd-trace/test/opentracing/span_context.spec.js
to demonstrate the issueThe text was updated successfully, but these errors were encountered: