public interface Tracer
Tracer abstraction.
Tracer is the central point that collects tracing spans, and (probably) pushes them to backend.
-
Method Summary
Modifier and TypeMethodDescriptionboolean
enabled()
Whether this tracer is enabled or not.extract
(HeaderProvider headersProvider) Extract parent span context from inbound request, such as from HTTP headers.static Tracer
global()
Get the currently registered global tracer.static void
Register a global tracer, behavior depends on implementation.void
inject
(SpanContext spanContext, HeaderProvider inboundHeadersProvider, HeaderConsumer outboundHeadersConsumer) Inject current span as a parent for outbound request, such as when invoking HTTP request from a client.static Tracer
noOp()
Create a no-op tracer.Span.Builder<?>
spanBuilder
(String name) A new span builder to constructSpan
.default <T> T
Access the underlying tracer by specific type.
-
Method Details
-
noOp
Create a no-op tracer. All spans created from this tracer are not doing anything.- Returns:
- no-op tracer
-
global
Get the currently registered global tracer.- Returns:
- global tracer
-
global
Register a global tracer, behavior depends on implementation.- Parameters:
tracer
- tracer to use as a global tracer
-
enabled
boolean enabled()Whether this tracer is enabled or not. A no op tracer is disabled.- Returns:
true
if this tracer is enabled
-
spanBuilder
A new span builder to constructSpan
.- Parameters:
name
- name of the operation- Returns:
- a new span builder
-
extract
Extract parent span context from inbound request, such as from HTTP headers.- Parameters:
headersProvider
- provider of headers- Returns:
- span context of inbound parent span, or empty optional if no span context can be found
-
inject
void inject(SpanContext spanContext, HeaderProvider inboundHeadersProvider, HeaderConsumer outboundHeadersConsumer) Inject current span as a parent for outbound request, such as when invoking HTTP request from a client.- Parameters:
spanContext
- current span contextinboundHeadersProvider
- provider of inbound headers, may beHeaderProvider.empty()
or headers from original request (if any)outboundHeadersConsumer
- consumer of headers that should be propagated to remote endpoint
-
unwrap
Access the underlying tracer by specific type. This is a dangerous operation that will succeed only if the tracer is of expected type. This practically removes abstraction capabilities of this API.- Type Parameters:
T
- type of the tracer- Parameters:
tracerClass
- type to access- Returns:
- instance of the tracer
- Throws:
IllegalArgumentException
- in case the tracer cannot provide the expected type
-