Skip to content

Assert span in scope can't be null and add tests to verify#917

Merged
tylerbenson merged 2 commits intomasterfrom
tyler/null-span-in-scope
Jul 18, 2019
Merged

Assert span in scope can't be null and add tests to verify#917
tylerbenson merged 2 commits intomasterfrom
tyler/null-span-in-scope

Conversation

@tylerbenson
Copy link
Contributor

@tylerbenson tylerbenson commented Jul 16, 2019

We want to be able to use NoopSpan to 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.

This is useful to temporarily remove a trace from scope for a defined period.
@mar-kolya
Copy link
Contributor

$git grep 'scope\.span()' | wc -l
157

Wouldn't it be risky to assume scope without span could exist considering number of places this is used without checks?

@tylerbenson
Copy link
Contributor Author

@mar-kolya I understand the concern. Would you prefer we use NoopSpan to indicate this instead? Semantically, I'm not sure which I like better.

@mar-kolya
Copy link
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.

@tylerbenson tylerbenson changed the title Allow null to be set in Scope for Span Assert span in scope can't be null and add tests to verify Jul 18, 2019
@tylerbenson tylerbenson merged commit 13b794c into master Jul 18, 2019
@tylerbenson tylerbenson deleted the tyler/null-span-in-scope branch July 18, 2019 20:43
@tylerbenson tylerbenson added this to the 0.31.0 milestone Jul 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: core Tracer core tag: breaking change Breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants