-
Notifications
You must be signed in to change notification settings - Fork 485
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
fix: Allow overlapping context scopes #2378
base: main
Are you sure you want to change the base?
fix: Allow overlapping context scopes #2378
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2378 +/- ##
=====================================
Coverage 79.0% 79.0%
=====================================
Files 120 120
Lines 22512 22580 +68
=====================================
+ Hits 17791 17857 +66
- Misses 4721 4723 +2 ☔ View full report in Codecov by Sentry. |
b64d904
to
dd46520
Compare
ab2f259
to
4502611
Compare
828ba76
to
ea537b8
Compare
@bantonsson Can you add some details on how this fixes the issue of contexts being dropped out-of-order? Perhaps some code comments will help future readers. |
@cijothomas I'll clean this up a bit more and add comments describing the |
ea537b8
to
ecb0279
Compare
ecb0279
to
94ddd7e
Compare
@cijothomas Do you know if the integration tests are flaky? The previous run failed but now it succeeded without any functional changes to the code. |
You can ignore it for now. Integration tests are not marked required for merging PRs. It does has some instability due to spinning up OTel Collector in a docker and multiple tests using the same instance etc. That will be addressed separately. |
Interesting. I too am curious to know a bit more about What is the expected behavior of the context stack if new contexts are pushed during out-of-order pops? |
Fixes #1887
This PR is fully functional, but not complete with edge case checks, tests and comments. It's ment as a basis for discussions.
Changes
This PR changes the single current
Context
to a more robust stack that is resilient to out of order and overlappingContext
scopes. This robustness is needed to be able to support better interop with tokio-rs/tracing.There are some
context_attach
benchmarks added, and this implementation performs the same or between 3-17% faster than the old one (while maintaining a working context state).As for the
context
benchmarks inopentelemetry-sdk
, this implementation performs the same except for thecontext/is_sampled/?/alt
variants where it is 6-7% slower. I haven't dug into this too much at this point.Update 2025-02-04
Two things:
context
benchmark into separate functions that are not inlined into the iterator loop, and there are now no differences in thecontext
benchmark between the old way, and the new context stack.Context
, that increases the throughput ofcontext_attach
60-80% forempty_cx
, 230-330% forsingle_value_cx
and 50-80% forspan_cx
. The optimization also increases the throughput of thespec
versions of thecontext
benchmark between 20-50%.Merge requirement checklist
CHANGELOG.md
files updated for non-trivial, user-facing changes