Commit ec9b17f
feat(otel-thread-ctx): Node.js OTEP-4947 thread-context writer (#9210)
Mirrors the active trace ID, span ID, local root span ID and current endpoint
into a thread-local OTEP-4947 record, so an out-of-process eBPF reader can
attribute samples without going through the tracer. The record is discovered via
the otel_thread_ctx_nodejs_v1 TLS symbol exported by the @datadog/pprof addon,
and decoded using an OTEP-4719 process context published through libdatadog's
process discovery (threadlocal.* attribute key map, schema version, and the V8
layout constants a reader needs to walk into the record).
Off by default, behind DD_TRACE_OTEL_CTX_ENABLED. Requires Linux and an active
AsyncContextFrame (default from Node 24, opt-in on 22/23), and refuses to start
unless the installed @datadog/pprof exposes every API member the writer calls
and a context can actually be installed in this process — an unusable pprof
costs a log line rather than an exception thrown from a hot-path diagnostic
channel subscriber.
One ThreadContext is built per span on first activation and cached on the span,
so re-entry in another async-context frame re-installs the same reference rather
than allocating. On span finish the record is invalidated in place, which drops
it out of scope for every frame that inherited it — sibling frames and
continuations the span scheduled before finishing — since no later storage event
reaches those.
The endpoint is held back until its value settles: plugins publish interim
routing tags, and datadog-plugin-next seeds resource.name with the bare request
method, so publishing early would leave a reader attributing samples to "GET".
Once a request's endpoint resolves it is appended to every record built under
that request, the request span's own and each descendant's.1 parent 4feb07b commit ec9b17f
19 files changed
Lines changed: 1854 additions & 107 deletions
File tree
- .github
- workflows
- packages/dd-trace
- src
- config
- profiling
- profilers
- test
- profiling/profilers
- scripts/docker
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
369 | 369 | | |
370 | 370 | | |
371 | 371 | | |
| 372 | + | |
372 | 373 | | |
| 374 | + | |
| 375 | + | |
373 | 376 | | |
| 377 | + | |
| 378 | + | |
374 | 379 | | |
375 | 380 | | |
376 | 381 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
| 64 | + | |
63 | 65 | | |
64 | 66 | | |
65 | 67 | | |
| |||
118 | 120 | | |
119 | 121 | | |
120 | 122 | | |
| 123 | + | |
121 | 124 | | |
122 | 125 | | |
123 | 126 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
| 75 | + | |
74 | 76 | | |
75 | 77 | | |
76 | 78 | | |
| |||
180 | 182 | | |
181 | 183 | | |
182 | 184 | | |
183 | | - | |
| 185 | + | |
184 | 186 | | |
185 | 187 | | |
186 | 188 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
340 | 340 | | |
341 | 341 | | |
342 | 342 | | |
| 343 | + | |
343 | 344 | | |
344 | 345 | | |
345 | 346 | | |
| |||
1040 | 1041 | | |
1041 | 1042 | | |
1042 | 1043 | | |
| 1044 | + | |
1043 | 1045 | | |
1044 | 1046 | | |
1045 | 1047 | | |
| |||
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3518 | 3518 | | |
3519 | 3519 | | |
3520 | 3520 | | |
| 3521 | + | |
| 3522 | + | |
| 3523 | + | |
| 3524 | + | |
| 3525 | + | |
| 3526 | + | |
| 3527 | + | |
3521 | 3528 | | |
3522 | 3529 | | |
3523 | 3530 | | |
| |||
0 commit comments