public interface Tracer extends SpanAccessor
A 'span' represents a length of time. It has many other attributes such as a name, ID, and even potentially a set of key/value strings attached to it.
Each thread in your application has a single currently active currentSpan associated with it. When this is non-null, it represents the current operation that the thread is doing. spans are NOT thread-safe, and must never be used by multiple threads at once. With care, it is possible to safely pass a span object between threads, but in most cases this is not necessary.
Most crucial methods in terms of span lifecycle are:
| Modifier and Type | Method and Description |
|---|---|
void |
addTag(String key,
String value)
Adds a tag to the current span if tracing is currently on.
|
Span |
close(Span span)
Remove this span from the current thread, stop it and send it for collection.
|
Span |
continueSpan(Span span)
Contributes to a span started in another thread.
|
Span |
createSpan(String name)
Creates a new Span.
|
Span |
createSpan(String name,
Sampler sampler)
Start a new span if the sampler allows it or if we are already tracing in this
thread.
|
Span |
createSpan(String name,
Span parent)
Creates a new Span with a specific parent.
|
Span |
detach(Span span)
Remove this span from the current thread, but don't stop it yet or send it for
collection.
|
<V> Callable<V> |
wrap(Callable<V> callable)
Returns a wrapped
Callable which will be recorded as a span
in the current trace. |
Runnable |
wrap(Runnable runnable)
Returns a wrapped
Runnable which will be recorded as a span
in the current trace. |
getCurrentSpan, isTracingSpan createSpan(String name)
name - The name field for the new span to create.Span createSpan(String name, Span parent)
name - The name field for the new span to create.Span createSpan(String name, Sampler sampler)
name - the name of the spansampler - a sampler to decide whether to create the span or notSpan continueSpan(Span span)
void addTag(String key, String value)
Every span may also have zero or more key/value Tags, which do not have
timestamps and simply annotate the spans.
Check TraceKeys for examples of most common tag keys
Span detach(Span span)
continueSpan(Span).
Example of usage:
// Span "A" was present in thread "X". Let's assume that we're in thread "Y" to which span "A" got passed
Span continuedSpan = tracer.continueSpan(spanA);
// Now span "A" got continued in thread "Y".
... // Some work is done... state of span "A" could get mutated
Span previouslyStoredSpan = tracer.detach(continuedSpan);
// Span "A" got removed from the thread Y but it wasn't yet sent for collection.
// Additional work can be done on span "A" in thread "X" and finally it can get closed and sent for collection
tracer.close(spanA);
Span close(Span span)
span - the span to close<V> Callable<V> wrap(Callable<V> callable)
Callable which will be recorded as a span
in the current trace.Copyright © 2017 Pivotal Software, Inc.. All rights reserved.