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
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: