-
Notifications
You must be signed in to change notification settings - Fork 590
[API] reduce allocation in no span case #4254
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3336902
perf: reduce allocation
proost ead2aa8
doc: update change log
proost 5bb2e06
Merge branch 'main' of github.com:open-telemetry/opentelemetry-cpp in…
proost cec5e30
Merge branch 'main' into perf-get-span-context
marcalff e4cfad2
Merge branch 'main' into perf-get-span-context
marcalff 7d7b79a
fix: null shared ptr
proost ab3d8b0
Merge branch 'main' of github.com:open-telemetry/opentelemetry-cpp in…
proost 8b3642d
Merge branch 'perf-get-span-context' of github.com:proost/opentelemet…
proost 479e552
Merge branch 'main' into perf-get-span-context
marcalff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,7 +41,7 @@ class HttpTraceContext : public context::propagation::TextMapPropagator | |
| void Inject(context::propagation::TextMapCarrier &carrier, | ||
| const context::Context &context) noexcept override | ||
| { | ||
| SpanContext span_context = trace::GetSpan(context)->GetContext(); | ||
| SpanContext span_context = trace::GetSpanContext(context); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not an ABI break. No observable behavior change. |
||
| if (!span_context.IsValid()) | ||
| { | ||
| return; | ||
|
|
||
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
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
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
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
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
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
Oops, something went wrong.
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.
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.
Could the active variant alternative contain an empty
nostd::shared_ptr<Span>here?nostd::get_ifwould still return a non-null pointer to the storedshared_ptr, so this condition would succeed even though*maybe_spanis null, and the next line would dereference it.The same issue applies to
maybe_span_contextbelow. Should both branches also check that the storedshared_ptris non-null and returnSpanContext::GetInvalid()otherwise?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.
You are right, Thank you!
7d7b79a
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.
On one hand, I am not sure if it is possible to add an empty
nostd::shared_ptr<Span>into a context, so this extra check might not be needed.On the other hand, now that this logic is in the API, being defensive and extra cautious is better ... especially because it needs to be robust to any version of the API/SDK.
So, this is a good change.
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.
It is possible for the context to contain a span key and null span ptr value by passing a null span to SetSpan or when constructing a Scope object (neither check). Given the
trace::GetSpan(context)->GetContext()pattern used before it seems it has not been a problem in practice but adding a check here shouldn't hurt.