Skip to content

feat(tracing): allow span processor to keep span reference#3350

Open
samugi wants to merge 1 commit intoopen-telemetry:mainfrom
samugi:samugi/span-ref-in-processors-fixes-602
Open

feat(tracing): allow span processor to keep span reference#3350
samugi wants to merge 1 commit intoopen-telemetry:mainfrom
samugi:samugi/span-ref-in-processors-fixes-602

Conversation

@samugi
Copy link

@samugi samugi commented Feb 14, 2026

Fixes #602

Changes

Adds a get_handle method to Span that allows obtaining an instance of SpanHandle: a structure that shares the same fields as the span, where the SpanData is protected by a Mutex.

This allows holding a reference to a Span, which enables use cases such as span processors keeping track of active spans, as mentioned in the spec.

Example:

impl SpanProcessor for MyProcessor {
    fn on_start(&self, span: &mut Span, _cx: &Context) {
        let handle = span.get_handle();
        // Store handle for later use
    }
}

Notes

First contribution here. The change ended up being a bit more invasive than I would've hoped, if there's a cleaner or more idiomatic way to achieve the goal, I'm very happy to adjust the approach and keep iterating on it. Thanks!

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • Unit tests added/updated (if applicable)
  • Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • Changes in public API reviewed (if applicable)

Adds a get_handle method to `Span` that allows obtaining an instance of
`SpanHandle`: a structure that shares the same fields as the span, where
the SpanData is protected by a Mutex.

This allows holding a reference to a span, which enables use cases such
as span processors keeping track of active spans, as mentioned in
[the spec](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md#onstart).

fixes: 602
@samugi samugi requested a review from a team as a code owner February 14, 2026 09:47
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Feb 14, 2026

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: samugi / name: Samuele (c22aa5e)

@codecov
Copy link

codecov bot commented Feb 14, 2026

Codecov Report

❌ Patch coverage is 96.40449% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.4%. Comparing base (0948c61) to head (c22aa5e).

Files with missing lines Patch % Lines
opentelemetry-sdk/src/trace/span.rs 96.1% 15 Missing ⚠️
opentelemetry-sdk/src/trace/span_processor.rs 98.1% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main   #3350     +/-   ##
=======================================
+ Coverage   82.2%   82.4%   +0.2%     
=======================================
  Files        128     128             
  Lines      24510   24875    +365     
=======================================
+ Hits       20154   20511    +357     
- Misses      4356    4364      +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@scottgerring
Copy link
Member

Hey @samugi thanks for contributing!

This is a pretty chunky change, and I note a SHOULD in the spec; out of curiosity, is there an external driver you'd like to share - e.g. something downstream that needs this to be implemented?

I haven't looked at it in detail yet, but I'd suggest we likely want a reasonably detailed design discussion here. Paging @cijothomas and @bantonsson who almost certainly have useful input :)

@samugi
Copy link
Author

samugi commented Feb 17, 2026

hey @scottgerring , thanks for the feedback!

out of curiosity, is there an external driver you'd like to share - e.g. something downstream that needs this to be implemented?

Not really, I picked the issue from the Tracing SDK Stable milestone. Is the milestone up to date and a good source of contributions or would you recommend focusing elsewhere? Thank you!

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.

Allow span processor to keep reference of spans

2 participants