feat: prototype context attach/detach#6387
Draft
pichlermarc wants to merge 4 commits intoopen-telemetry:mainfrom
Draft
feat: prototype context attach/detach#6387pichlermarc wants to merge 4 commits intoopen-telemetry:mainfrom
pichlermarc wants to merge 4 commits intoopen-telemetry:mainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6387 +/- ##
==========================================
- Coverage 95.50% 95.47% -0.03%
==========================================
Files 365 365
Lines 11606 11627 +21
Branches 2676 2683 +7
==========================================
+ Hits 11084 11101 +17
- Misses 522 526 +4
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Important
While this PR is intended to show possible use of attach/detach functionality for
tracingChannelinstrumentation, as an alternative to proposal #6088, It does not feature a production ready implementation of itIt's intended as a means to demonstrate how I expect this could be used to accomplish that use case.
Which problem is this PR solving?
Proposal #6088 is to allow accessing the internal
AsyncLocalStoragefrom the outside, for the purpose of binding it to aTracingChannel, so that context propagation works properly. While this is works in practice it has a few downsides:AsyncLocalStorageis internal to avoid tampering, misuse can lead to catastrophic effects and can be hard to debugContextManageris aAsyncLocalStorageContextManager, so many do not have anAsyncLocalStorage. As such, we also cannot add it to the@opentelemetry/apipackage. FurtherAsyncLocalStorageis a Node.js type, and the@opentelemetry/apiand its types must remain compatible with the BrowserMy counter-proposal is implementing the spec-defined
attach()anddetach()operations to achieve a similar effect. This works by manually attaching context when theTracingChannelemits its events, storing the state on the message, and detaching the context once the end message is received.This implementation:
ContextManager)The downsides:
AsyncLocalStorage, context attach/detach can have potentially catastrophic effects (however, I think it's easier to document that than with exposingAsyncLocalStorageand other language SIGs have been managing fine with this operation available)You can find an example how tracing channel instrumentation would work at
examples/tracing-channels.Previous work on context attach/detach