public interface Tracer
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.
|
Tracer.SpanBuilder buildSpan(String operationName)
You can override the operationName later via Span.setOperationName(String)
.
A contrived example:
Tracer tracer = ...
Span parentSpan = tracer.buildSpan("DoWork")
.start();
Span http = tracer.buildSpan("HandleHTTPRequest")
.asChildOf(parentSpan.context())
.withTag("user_agent", req.UserAgent)
.withTag("lucky_number", 42)
.start();
<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).start();
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.