-
Notifications
You must be signed in to change notification settings - Fork 598
refactor: avoid span_data and instrumentation_scope clone for every single span processor #3267
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
base: main
Are you sure you want to change the base?
Conversation
1c0d427 to
a9868b0
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3267 +/- ##
=====================================
Coverage 80.8% 80.8%
=====================================
Files 129 129
Lines 23203 23238 +35
=====================================
+ Hits 18750 18793 +43
+ Misses 4453 4445 -8 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks for the PR @taisho6339. Could you check if we can use a pattern similar to the one in the Logs SDK? In that implementation, the |
…nData` and `&InstrumentationScope` by reference This eliminates unnecessary `SpanData` clones when multiple `SpanProcessor`s are configured. Performance improvement scales with the number of processors. Processors that need to store the data asynchronously should clone it explicitly.
e2ecd0c to
98c3b24
Compare
|
@lalitb thank you for your feedback, that makes sense. I reflected it and I also changed SpanData to reference and pass it to SpanProcessors to align with the Log implementation. |
| } | ||
| } | ||
| // Build export data once to avoid cloning for multiple processors | ||
| let export_data = build_export_data(data, self.span_context.clone(), &self.tracer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
build_export_data still clones the scope unnecessarily?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, build_export_data() still clones InstrumentationScope once, but this is a deliberate trade-off to maintain SpanData's public API compatibility. The real performance gain comes from eliminating (N-1) clones of the entire SpanData (~120+ bytes plus variable-length fields) in Span::end() when multiple processors are configured. Removing the instrumentation_scope field from SpanData or passing the reference entirely would be a larger breaking change that could be considered in a future PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are okay to make breaking changes to Span/Tracing given its not marked stable. However, let's have a full analysis to this area before making the changes. There are few discussions in #2962 to be considered here.
(In general, yes, passing immutable ref to on_end makes total sense- just want to make sure we have the desired end state in mind before the implementation)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#2726 related issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please take a look at #2962 @taisho6339 and come with input there.
Fixes #1125
Changes
Changed
SpanProcessor::on_end()signature to accept&SpanDataand&InstrumentationScopeby reference. This eliminates unnecessarySpanDataclones when multipleSpanProcessors are configured. Performance improvement scales with the number of processors. Processors that need to store the data asynchronously should clone it explicitly.Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial, user-facing changes