public class ThreadLocalActiveSpan extends Object implements ActiveSpan
ThreadLocalActiveSpan is a simple ActiveSpan implementation that relies on Java's
thread-local storage primitive.ActiveSpanSource,
ActiveSpanSource.activeSpan()| Modifier and Type | Method and Description |
|---|---|
io.opentracing.v_030.util.ThreadLocalActiveSpan.Continuation |
capture()
"Capture" a new
ActiveSpan.Continuation associated with this ActiveSpan and Span, as well as any
3rd-party execution context of interest. |
void |
close()
A synonym for
ActiveSpan.deactivate() that can be used in try-with-resources blocks. |
SpanContext |
context()
Retrieve the associated SpanContext.
|
void |
deactivate()
Mark the end of the active period for the current thread and
ActiveSpan. |
String |
getBaggageItem(String key) |
ThreadLocalActiveSpan |
log(long timestampMicroseconds,
Map<String,?> fields)
Like log(Map<String, Object>), but with an explicit timestamp.
|
ThreadLocalActiveSpan |
log(long timestampMicroseconds,
String event)
Record an event at a specific timestamp.
|
ThreadLocalActiveSpan |
log(Map<String,?> fields)
Log key:value pairs to the Span with the current walltime timestamp.
|
ThreadLocalActiveSpan |
log(String event)
Record an event at the current walltime timestamp.
|
ThreadLocalActiveSpan |
setBaggageItem(String key,
String value)
Sets a baggage item in the Span (and its SpanContext) as a key/value pair.
|
ThreadLocalActiveSpan |
setOperationName(String operationName)
Sets the string name for the logical operation this span represents.
|
ThreadLocalActiveSpan |
setTag(String key,
boolean value)
Same as
BaseSpan.setTag(String, String), but for boolean values. |
ThreadLocalActiveSpan |
setTag(String key,
Number value)
Same as
BaseSpan.setTag(String, String), but for numeric values. |
ThreadLocalActiveSpan |
setTag(String key,
String value)
Set a key:value tag on the Span.
|
String |
toString() |
public void deactivate()
ActiveSpanActiveSpan. When the last
ActiveSpan is deactivated for a given Span, it is automatically Span.finish()ed.
NOTE: Calling ActiveSpan.deactivate() more than once on a single ActiveSpan instance leads to undefined
behavior.
deactivate in interface ActiveSpan{@link ActiveSpan}s are auto-closeable and may be used in try-with-resources blockspublic io.opentracing.v_030.util.ThreadLocalActiveSpan.Continuation capture()
ActiveSpanActiveSpan.Continuation associated with this ActiveSpan and Span, as well as any
3rd-party execution context of interest. The ActiveSpan.Continuation may be used as data in a closure or callback
function where the ActiveSpan may be resumed and reactivated.
IMPORTANT: the caller MUST ActiveSpan.Continuation.activate() and ActiveSpan.deactivate() the
returned ActiveSpan.Continuation or the associated Span will never automatically Span.finish().
That is, calling ActiveSpan.capture() increments a refcount that must be decremented somewhere else.
The associated Span will not Span.finish() while a ActiveSpan.Continuation is outstanding; in
this way, it provides a reference/pin just like an ActiveSpan does.
capture in interface ActiveSpanActiveSpan.Continuation to ActiveSpan.Continuation.activate() at the appropriate time.public SpanContext context()
BaseSpancontext in interface BaseSpan<ActiveSpan>public ThreadLocalActiveSpan setTag(String key, String value)
BaseSpansetTag in interface BaseSpan<ActiveSpan>public ThreadLocalActiveSpan setTag(String key, boolean value)
BaseSpanBaseSpan.setTag(String, String), but for boolean values.setTag in interface BaseSpan<ActiveSpan>public ThreadLocalActiveSpan setTag(String key, Number value)
BaseSpanBaseSpan.setTag(String, String), but for numeric values.setTag in interface BaseSpan<ActiveSpan>public ThreadLocalActiveSpan log(Map<String,?> fields)
BaseSpanCAUTIONARY NOTE: not all Tracer implementations support key:value log fields end-to-end. Caveat emptor.
A contrived example (using Guava, which is not required):
span.log(
ImmutableMap.Builder()
.put("event", "soft error")
.put("type", "cache timeout")
.put("waited.millis", 1500)
.build());
log in interface BaseSpan<ActiveSpan>fields - key:value log fields. Tracer implementations should support String, numeric, and boolean values;
some may also support arbitrary Objects.BaseSpan.log(String)public ThreadLocalActiveSpan log(long timestampMicroseconds, Map<String,?> fields)
BaseSpanCAUTIONARY NOTE: not all Tracer implementations support key:value log fields end-to-end. Caveat emptor.
log in interface BaseSpan<ActiveSpan>timestampMicroseconds - The explicit timestamp for the log record. Must be greater than or equal to the
Span's start timestamp.fields - key:value log fields. Tracer implementations should support String, numeric, and boolean values;
some may also support arbitrary Objects.BaseSpan.log(long, String)public ThreadLocalActiveSpan log(String event)
BaseSpan
span.log(Collections.singletonMap("event", event));
log in interface BaseSpan<ActiveSpan>event - the event value; often a stable identifier for a moment in the Span lifecyclepublic ThreadLocalActiveSpan log(long timestampMicroseconds, String event)
BaseSpan
span.log(timestampMicroseconds, Collections.singletonMap("event", event));
log in interface BaseSpan<ActiveSpan>timestampMicroseconds - The explicit timestamp for the log record. Must be greater than or equal to the
Span's start timestamp.event - the event value; often a stable identifier for a moment in the Span lifecyclepublic ThreadLocalActiveSpan setBaggageItem(String key, String value)
BaseSpansetBaggageItem in interface BaseSpan<ActiveSpan>public String getBaggageItem(String key)
getBaggageItem in interface BaseSpan<ActiveSpan>public ThreadLocalActiveSpan setOperationName(String operationName)
BaseSpansetOperationName in interface BaseSpan<ActiveSpan>public void close()
ActiveSpanActiveSpan.deactivate() that can be used in try-with-resources blocks.close in interface ActiveSpanclose in interface Closeableclose in interface AutoCloseableCopyright © 2016–2018 OpenTracing. All rights reserved.