Repository navigation
Reuse no-op scopes in the OTel bridge - #1646
Merged
Merged
Conversation
Return the existing facade no-op scope for redundant and empty native scopes, and reuse a stateless SpanInScope when no attachment is needed. Preserve clearing, restoration and publisher behavior. Assert scope behavior without casting to private wrappers. Cover clearing native baggage without a span and closing a redundant scope while another span is current. Benchmark escaping, inlined and real scope operations. Signed-off-by: Tommy Ludwig <8924140+shakuzen@users.noreply.github.com>
jonatan-ivanov
approved these changes
Nov 4, 2026
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.
Redundant span scopes and clearing an already empty context currently allocate wrappers even though closing them does nothing. Reuse
CurrentTraceContext.Scope.NOOPand a privateSpanInScopesingleton, while preserving actual context clearing, restoration and publisher behavior.Replace the existing scope test's private-wrapper casts with current-context/restoration assertions. Add coverage for clearing native baggage/data without an active span and closing a redundant scope while another span is current.
Validation
git diff --checkpass.Local benchmarks against main
Returned-scope cases let the result escape;
inlinedTracerScopecovers ordinary fully inlined usage, where HotSpot already eliminates allocation.realTracerScopeis the control for an actual attachment/restoration. The change removes the escaping no-op wrappers without a measured change in that control.JMH 1.37, OTel 1.67.0, Java 25.0.4.1, Apple M5 Pro/macOS arm64; valid non-recording native spans. One worker, fixed 512 MiB G1 heap, three independent forks/version with alternating order; three 500 ms warmups and five 500 ms measurements. Values are means of fork means.