Skip to content

Conversation

@szegedi
Copy link

@szegedi szegedi commented Jan 15, 2026

What does this PR do?:

  • Discards the CPED approach where we replace the AsyncContextFrame (ACF) object in the CPED with a proxy that has an internal field for our sample context.
  • Instead, adopts an approach where the sample context is stored directly in the ACF map under an arbitrary key.
  • It is possible to pass in a key externally. Passing in an AsyncLocalStorage as the key will allow the sampling context object to be retrieved from JavaScript using storage.getStore() on that object. This opens the possibility of implementing custom contexts in dd-trace-js.

Motivation:
Simplification and performance. Storing the sampling context directly in the ACF reduces the complexity of having a proxy object. We also no longer need to ensure that the proxy object is updated every time a new async context is created, thus dd-trace-js no longer needs to instrument AsyncLocalStorage.enterWith, eliminating the need to do any work on context creation or switches.

Additional Notes:
While storing the sampling context is now simpler, retrieving it from the signal handler actually got more complex, but that's a tradeoff we should make. Namely, in the signal handler now we need to chase pointers from current isolate to the hash table backing the ACF storage, and then also implement the hash table lookup-by-key. None of these data structures are published by V8, so we're doing raw memory interpretation. They would also need to be updated if V8 internally changes them. (I will probably rewrite the current code to instead declare structs that mirror the memory layout and use that.)

How to test the change?:
TBD

@github-actions
Copy link

Overall package size

Self size: 1.77 MB
Deduped: 2.15 MB
No deduping: 2.15 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | source-map | 0.7.6 | 185.63 kB | 185.63 kB | | pprof-format | 2.2.1 | 163.06 kB | 163.06 kB | | p-limit | 3.1.0 | 7.75 kB | 13.78 kB | | delay | 5.0.0 | 11.17 kB | 11.17 kB | | node-gyp-build | 3.9.0 | 8.81 kB | 8.81 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants