-
Notifications
You must be signed in to change notification settings - Fork 839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs(api): clarify TextMapPropagator
API requirements
#5370
Open
chancancode
wants to merge
2
commits into
open-telemetry:main
Choose a base branch
from
tildeio:fix-propagator-generic-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains 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
chancancode
force-pushed
the
fix-propagator-generic-2
branch
from
January 24, 2025 17:46
916e2f3
to
3e66c66
Compare
8 tasks
The current interface places the generic paramter on the interface itself. This implies that the implementors of `TextMapPropagator` can specify what carrier types it accepts (and that each implementor only work with one specific type of carrier). ```ts interface TextMapPropagator<Carrier> { inject(context: Context, carrier: Carrier, setter: TextMapSetter<Carrier>): void; extract(context: Context, carrier: Carrier, getter: TextMapGetter<Carrier>): void; } ``` In reality, this is not the case. The propagator API is designed to be called by participating code around the various transport layers (such as the `fetch` inst on the browser, or integration with the HTTP server library on the backend), and it is these callers that ultimately controls what carrier type the currently configured propagator is called with. Therefore, a correct implementation of this interface must treat the carrier as an opaque value, and only work with it using the provided getter/setter. Ideally, the interface should look like this instead: ```ts interface TextMapPropagator { inject<Carrier>(context: Context, carrier: Carrier, setter: TextMapSetter<Carrier>): void; extract<Carrier>(context: Context, carrier: Carrier, getter: TextMapGetter<Carrier>): void; } ``` This communicates and enforces the contract. Unfortunately, that would be a breking change we are not currently prepared to make. Instead, this commit updates the documentation to explicitly document the discrapancy and advice implemntors the correct way forward. It also updates our own implementations to follow the recommended pattern, as well as updating the tests to be more well-behaved around this, as some of them are written to rely on this exact behavior that would be problematic in the real world. Ref open-telemetry#5365 Ref open-telemetry#5368
chancancode
force-pushed
the
fix-propagator-generic-2
branch
from
January 24, 2025 19:08
3e66c66
to
82d8f73
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #5370 +/- ##
==========================================
+ Coverage 94.63% 94.71% +0.07%
==========================================
Files 318 318
Lines 8036 8036
Branches 1685 1685
==========================================
+ Hits 7605 7611 +6
+ Misses 431 425 -6
|
25 tasks
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.
Non-breaking parts from #5368
Which problem is this PR solving?
The current interface places the generic paramter on the interface itself. This implies that the implementors of
TextMapPropagator
can specify what carrier types it accepts (and that each implementor only work with one specific type of carrier).In reality, this is not the case.
The propagator API is designed to be called by participating code around the various transport layers (such as the
fetch
inst on the browser, or integration with the HTTP server library on the backend), and it is these callers that ultimately controls what carrier type the currently configured propagator is called with.Therefore, a correct implementation of this interface must treat the carrier as an opaque value, and only work with it using the provided getter/setter.
Ideally, the interface should look like this instead:
This communicates and enforces the contract. Unfortunately, that would be a breking change we are not currently prepared to make (see #5368).
Short description of the changes
Instead, this commit updates the documentation to explicitly document the discrapancy and advice implemntors the correct way forward.
It also updates our own implementations to follow the recommended pattern, as well as updating the tests to be more well-behaved around this, as some of them are written to rely on this exact behavior that would be problematic in the real world.
Ref #5365
Ref #5368
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Checklist:
addedupdated