Assert span in scope can't be null and add tests to verify#917
Merged
tylerbenson merged 2 commits intomasterfrom Jul 18, 2019
Merged
Assert span in scope can't be null and add tests to verify#917tylerbenson merged 2 commits intomasterfrom
tylerbenson merged 2 commits intomasterfrom
Conversation
This is useful to temporarily remove a trace from scope for a defined period.
Contributor
Wouldn't it be risky to assume scope without span could exist considering number of places this is used without checks? |
Contributor
Author
|
@mar-kolya I understand the concern. Would you prefer we use |
Contributor
|
I think semantically there should be no scope without a span - i.e. scope must have a span. NoopSpan might work, or client span (which we guaranteed to have) if there is no parent might work too. I feel that using null span creates potential to NPE far away from actual bug site which will make debugging harder. In fact I would be in a favour of adding assert to place where scope is created to make sure that span is not null. |
mar-kolya
approved these changes
Jul 18, 2019
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.
We want to be able to use
NoopSpanto temporarily remove the current trace from scope for a period.In our instrumentation, we sometimes capture the parent span on one thread to restore as the parent on a different thread. If that parent is null, we should be able to indicate that state. We will do so with a
NoopSpan.For example:
We have an async http client request that starts in one thread and finishes in another thread. We want the callback to have the correct trace context, but not necessarily be a child of the client span, so the best option is to provide the parent span as the scope for the callback. If there is no parent, we need to identify such even if there's an existing trace for some reason where the callback is being executed.