CurrentTraceContext.Default
, StrictCurrentTraceContext
public class ThreadLocalCurrentTraceContext extends CurrentTraceContext
A static thread local ensures we have one context per thread, as opposed to one per thread- tracer. This means all tracer instances will be able to see any tracer's contexts.
The trade-off of this (instance-based reference) vs the reverse: trace contexts are not separated by tracer by default. For example, to make a trace invisible to another tracer, you have to use a non-default implementation.
Sometimes people make different instances of the tracer just to change configuration like
the local service name. If we used a thread-instance approach, none of these would be able to see
eachother's scopes. This would break Tracing.currentTracer()
scope visibility in a way
few would want to debug. It might be phrased as "MySQL always starts a new trace and I don't know
why."
If you want a different behavior, use a different subtype of CurrentTraceContext
,
possibly your own, or raise an issue and explain what your use case is.
CurrentTraceContext.Default, CurrentTraceContext.Scope, CurrentTraceContext.ScopeDecorator
Modifier and Type | Method | Description |
---|---|---|
static CurrentTraceContext |
create() |
|
TraceContext |
get() |
Returns the current span in scope or null if there isn't one.
|
static CurrentTraceContext.Builder |
newBuilder() |
|
CurrentTraceContext.Scope |
newScope(TraceContext currentSpan) |
Sets the current span in scope until the returned object is closed.
|
decorateScope, executor, executorService, maybeScope, wrap, wrap
public static CurrentTraceContext create()
public static CurrentTraceContext.Builder newBuilder()
public TraceContext get()
CurrentTraceContext
get
in class CurrentTraceContext
public CurrentTraceContext.Scope newScope(@Nullable TraceContext currentSpan)
CurrentTraceContext
newScope
in class CurrentTraceContext
currentSpan
- span to place into scope or null to clear the scopeCopyright © 2018 OpenZipkin. All rights reserved.