public final class GlobalTracer extends Object implements Tracer
register
.
The register method should only be called once
during the application initialization phase.
If the registerIfAbsent(Tracer) register} method is never called,
the default NoopTracer
is used.
Where possible, use some form of dependency injection (of which there are many) to access the `Tracer` instance. For vanilla application code, this is often reasonable and cleaner for all of the usual DI reasons.
That said, instrumentation for packages that are themselves statically
configured (e.g., JDBC drivers) may be unable to make use of said DI
mechanisms for Tracer
access, and as such they should fall back on
GlobalTracer
. By and large, OpenTracing instrumentation should
always allow the programmer to specify a Tracer
instance to use for
instrumentation, though the GlobalTracer
is a reasonable fallback or
default value.
Tracer.SpanBuilder
Modifier and Type | Method and Description |
---|---|
Scope |
activateSpan(Span span) |
Span |
activeSpan() |
Tracer.SpanBuilder |
buildSpan(String operationName) |
void |
close() |
<C> SpanContext |
extract(Format<C> format,
C carrier) |
static Tracer |
get()
Returns the constant GlobalTracer.
|
<C> void |
inject(SpanContext spanContext,
Format<C> format,
C carrier) |
static boolean |
isRegistered()
Identify whether a
Tracer has previously been registered. |
static void |
register(Tracer tracer)
Deprecated.
Please use
registerIfAbsent(Tracer) or registerIfAbsent(Callable) instead. |
static boolean |
registerIfAbsent(Callable<Tracer> provider)
|
static boolean |
registerIfAbsent(Tracer tracer)
|
ScopeManager |
scopeManager() |
String |
toString() |
public static Tracer get()
All methods are forwarded to the currently configured tracer.
Until a tracer is explicitly configured
,
the NoopTracer
is used.
and {@link #registerIfAbsent(Callable)}
public static boolean isRegistered()
Tracer
has previously been registered.
This check is useful in scenarios where more than one component may be responsible for registering a tracer. For example, when using a Java Agent, it will need to determine if the application has already registered a tracer, and if not attempt to resolve and register one itself.
public static boolean registerIfAbsent(Callable<Tracer> provider)
Tracer
to back the behaviour of the get()
.
The tracer is provided through a Callable that will only be called if the global tracer is absent.
Registration is a one-time operation. Once a tracer has been registered, all attempts at re-registering
will return false
.
Every application intending to use the global tracer is responsible for registering it once during its initialization.
provider
- Provider for the tracer to use as global tracer.true
if the provided tracer was registered as a result of this call,
false
otherwise.NullPointerException
- if the tracer provider is null
or provides a null
Tracer.RuntimeException
- any exception thrown by the provider gets rethrown,
checked exceptions will be wrapped into appropriate runtime exceptions.public static boolean registerIfAbsent(Tracer tracer)
Tracer
to back the behaviour of the get()
.
Registration is a one-time operation. Once a tracer has been registered, all attempts at re-registering
will return false
. Use registerIfAbsent(Callable)
for lazy initiation to avoid multiple
instantiations of tracer.
Every application intending to use the global tracer is responsible for registering it once during its initialization.
tracer
- tracer to be registered.true
if the provided tracer was registered as a result of this call,
false
otherwise.NullPointerException
- if the tracer null
.RuntimeException
- any exception thrown by the provider gets rethrown,
checked exceptions will be wrapped into appropriate runtime exceptions.registerIfAbsent(Callable)
@Deprecated public static void register(Tracer tracer)
registerIfAbsent(Tracer)
or registerIfAbsent(Callable)
instead.Tracer
to back the behaviour of the global tracer
.
Registration is a one-time operation, attempting to call it more often will result in a runtime exception.
Every application intending to use the global tracer is responsible for registering it once during its initialization.
tracer
- Tracer to use as global tracer.RuntimeException
- if there is already a current tracer registeredregisterIfAbsent(Callable)
public ScopeManager scopeManager()
scopeManager
in interface Tracer
public Tracer.SpanBuilder buildSpan(String operationName)
public <C> void inject(SpanContext spanContext, Format<C> format, C carrier)
public <C> SpanContext extract(Format<C> format, C carrier)
public Span activeSpan()
activeSpan
in interface Tracer
public Scope activateSpan(Span span)
activateSpan
in interface Tracer
public void close()
Copyright © 2016–2019 OpenTracing. All rights reserved.