public interface Tracer
Modifier and Type | Interface and Description |
---|---|
static interface |
Tracer.SpanBuilder |
Modifier and Type | Method and Description |
---|---|
Span |
activeSpan() |
Tracer.SpanBuilder |
buildSpan(String operationName)
Return a new SpanBuilder for a Span with the given `operationName`.
|
<C> SpanContext |
extract(Format<C> format,
C carrier)
Extract a SpanContext from a `carrier` of a given type, presumably after propagation across a process boundary.
|
<C> void |
inject(SpanContext spanContext,
Format<C> format,
C carrier)
Inject a SpanContext into a `carrier` of a given type, presumably for propagation across process boundaries.
|
ScopeManager |
scopeManager() |
ScopeManager scopeManager()
ScopeManager
, which may be a noop but may not be null.Span activeSpan()
Span
. This is a shorthand for Tracer.scopeManager().active().span(),
and null will be returned if Scope#active()
is null.Tracer.SpanBuilder buildSpan(String operationName)
You can override the operationName later via Span.setOperationName(String)
.
A contrived example:
Tracer tracer = ...
// Note: if there is a `tracer.active()` Scope, its `span()` will be used as the target
// of an implicit CHILD_OF Reference for "workScope.span()" when `startActive()` is invoked.
try (Scope workScope = tracer.buildSpan("DoWork").startActive()) {
workScope.span().setTag("...", "...");
// etc, etc
}
// It's also possible to create Spans manually, bypassing the ScopeManager activation.
Span http = tracer.buildSpan("HandleHTTPRequest")
.asChildOf(rpcSpanContext) // an explicit parent
.withTag("user_agent", req.UserAgent)
.withTag("lucky_number", 42)
.startManual();
<C> void inject(SpanContext spanContext, Format<C> format, C carrier)
Example:
Tracer tracer = ...
Span clientSpan = ...
TextMap httpHeadersCarrier = new AnHttpHeaderCarrier(httpRequest);
tracer.inject(span.context(), Format.Builtin.HTTP_HEADERS, httpHeadersCarrier);
C
- the carrier type, which also parametrizes the Format.spanContext
- the SpanContext instance to inject into the carrierformat
- the Format of the carriercarrier
- the carrier for the SpanContext state. All Tracer.inject() implementations must support
io.opentracing.propagation.TextMap and java.nio.ByteBuffer.Format
,
Format.Builtin
<C> SpanContext extract(Format<C> format, C carrier)
Example:
Tracer tracer = ...
TextMap httpHeadersCarrier = new AnHttpHeaderCarrier(httpRequest);
SpanContext spanCtx = tracer.extract(Format.Builtin.HTTP_HEADERS, httpHeadersCarrier);
... = tracer.buildSpan('...').asChildOf(spanCtx).startActive();
If the span serialized state is invalid (corrupt, wrong version, etc) inside the carrier this will result in an
IllegalArgumentException.C
- the carrier type, which also parametrizes the Format.format
- the Format of the carriercarrier
- the carrier for the SpanContext state. All Tracer.extract() implementations must support
io.opentracing.propagation.TextMap and java.nio.ByteBuffer.Format
,
Format.Builtin
Copyright © 2016–2017 OpenTracing. All rights reserved.