Skip to content
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

Exposes Tracer.currentSpanCustomizer() and Span.customizer() for safety #650

Merged
merged 5 commits into from
Mar 12, 2018

Conversation

codefromthecrypt
Copy link
Member

Eventhough we made a safe user type SpanCustomizer, we didn't provide
a safe alternative to Tracer.currentSpan(). This led to routine
leaking of brave.Span to users (even if they need to cast to discover
this). While we did have CurrentSpanCustomizer, that relied on current
context to work. Particularly the new servlet instrumentation uses
explicit references, which are cheaper.

This adds a couple utilities and uses them:
Tracer.currentSpanCustomizer() - safer than currentSpan()
Span.customizer() - safely masks lifecycle methods from parsers

These are safer as they don't have the ability to abend the span, and
have a chance of holding less state (ex NoopSpanCustomizer is constant).

Future work will introduce UnsafeSpan, which can rely on these methods
to ensure higher performance in single-threaded scenarios such as
synchronous calls.

Eventhough we made a safe user type `SpanCustomizer`, we didn't provide
a safe alternative to `Tracer.currentSpan()`. This led to routine
leaking of `brave.Span` to users (even if they need to cast to discover
this). While we did have `CurrentSpanCustomizer`, that relied on current
context to work. Particularly the new servlet instrumentation uses
explicit references, which are cheaper.

This adds a couple utilities and uses them:
`Tracer.currentSpanCustomizer()` - safer than `currentSpan()`
`Span.customizer()` - safely masks lifecycle methods from parsers

These are safer as they don't have the ability to abend the span, and
have a chance of holding less state (ex NoopSpanCustomizer is constant).

Future work will introduce `UnsafeSpan`, which can rely on these methods
to ensure higher performance in single-threaded scenarios such as
synchronous calls.
@codefromthecrypt
Copy link
Member Author

cc @shakuzen @zeagord @anuraaga @yschimke @wu-sheng @jonathan-lo @marcingrzejszczak
this is mainly bulletproofing. Later cheaper instrumentation will layer over this.

@yschimke
Copy link

In a number of cases you get a SpanCustomizer (potentially a NoopSpanCustomizer) and pass it down through other methods. Is checking instanceof NoopSpanCustomizer the preferred way to avoid any additional work ala Log4j, isDebugEnabled?

@yschimke
Copy link

Looks good, I'll adopt it once it lands.

@codefromthecrypt
Copy link
Member Author

@yschimke I don't mind making NoopSpanCustomizer public type. sadly we can't add an isNoop() method to customizer because it is an interface and we have a lot of <java8 code still

@codefromthecrypt
Copy link
Member Author

codefromthecrypt commented Mar 12, 2018

I will make a note for brave5 about customizer should have isNoop regardless

@yschimke
Copy link

TIOLI, not a blocking issue in any way for me

@codefromthecrypt
Copy link
Member Author

@yschimke I suspect you won't be the only to ask this, made a javadoc about it.

@codefromthecrypt codefromthecrypt mentioned this pull request Mar 12, 2018
@codefromthecrypt
Copy link
Member Author

not sure timeline on follow-up for unsafe.. might be next release but anyway here's the description #651

@codefromthecrypt codefromthecrypt merged commit 0c42e4a into master Mar 12, 2018
@codefromthecrypt codefromthecrypt deleted the current-span-customizer branch March 12, 2018 22:57
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.

3 participants