public interface Tracer extends ActiveSpanSource
Modifier and Type | Interface and Description |
---|---|
static interface |
Tracer.SpanBuilder |
Modifier and Type | Method and Description |
---|---|
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.
|
activeSpan, makeActive
Tracer.SpanBuilder buildSpan(String operationName)
You can override the operationName later via BaseSpan.setOperationName(String)
.
A contrived example:
Tracer tracer = ...
// Note: if there is a `tracer.activeSpan()`, it will be used as the target of an implicit CHILD_OF
// Reference for "workSpan" when `startActive()` is invoked.
try (ActiveSpan workSpan = tracer.buildSpan("DoWork").startActive()) {
workSpan.setTag("...", "...");
// etc, etc
}
// It's also possible to create Spans manually, bypassing the ActiveSpanSource 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.