@Immutable public final class DefaultSpan extends Object implements Span
DefaultSpan is the default Span that is used when no Span
implementation is available. All operations are no-op except context propagation.
Used also to stop tracing, see Tracer.withSpan(io.opentelemetry.trace.Span).
Span.Builder, Span.Kind| Modifier and Type | Method and Description |
|---|---|
void |
addEvent(String name)
Adds an event to the
Span. |
void |
addEvent(String name,
Attributes attributes)
Adds an event to the
Span with the given Attributes. |
void |
addEvent(String name,
Attributes attributes,
long timestamp)
|
void |
addEvent(String name,
long timestamp)
Adds an event to the
Span with the given timestamp, as nanos since epoch. |
static Span |
create(SpanContext spanContext)
Creates an instance of this class with the
SpanContext. |
void |
end()
Marks the end of
Span execution. |
void |
end(EndSpanOptions endOptions)
Marks the end of
Span execution with the specified EndSpanOptions. |
SpanContext |
getContext()
Returns the
SpanContext associated with this Span. |
static Span |
getInvalid()
Returns a
DefaultSpan with an invalid SpanContext. |
boolean |
isRecording()
Returns
true if this Span records tracing events (e.g. |
void |
recordException(Throwable exception)
|
void |
recordException(Throwable exception,
Attributes additionalAttributes)
|
<T> void |
setAttribute(AttributeKey<T> key,
T value)
Sets an attribute to the
Span. |
void |
setAttribute(String key,
boolean value)
Sets an attribute to the
Span. |
void |
setAttribute(String key,
double value)
Sets an attribute to the
Span. |
void |
setAttribute(String key,
long value)
Sets an attribute to the
Span. |
void |
setAttribute(String key,
String value)
Sets an attribute to the
Span. |
void |
setStatus(StatusCanonicalCode canonicalCode)
Sets the status to the
Span. |
void |
setStatus(StatusCanonicalCode canonicalCode,
String description)
Sets the status to the
Span. |
String |
toString() |
void |
updateName(String name)
Updates the
Span name. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitsetAttributepublic static Span getInvalid()
DefaultSpan with an invalid SpanContext.DefaultSpan with an invalid SpanContext.public static Span create(SpanContext spanContext)
SpanContext.spanContext - the SpanContext.DefaultSpan.public void setAttribute(String key, String value)
SpanSpan. If the Span previously contained a mapping for
the key, the old value is replaced by the specified value.
If a null or empty String value is passed in, the behavior is undefined, and hence
strongly discouraged.
Note: It is strongly recommended to use Span.setAttribute(AttributeKey, Object), and
pre-allocate your keys, if possible.
setAttribute in interface Spankey - the key for this attribute.value - the value for this attribute.public void setAttribute(String key, long value)
SpanSpan. If the Span previously contained a mapping for
the key, the old value is replaced by the specified value.
Note: It is strongly recommended to use Span.setAttribute(AttributeKey, Object), and
pre-allocate your keys, if possible.
setAttribute in interface Spankey - the key for this attribute.value - the value for this attribute.public void setAttribute(String key, double value)
SpanSpan. If the Span previously contained a mapping for
the key, the old value is replaced by the specified value.
Note: It is strongly recommended to use Span.setAttribute(AttributeKey, Object), and
pre-allocate your keys, if possible.
setAttribute in interface Spankey - the key for this attribute.value - the value for this attribute.public void setAttribute(String key, boolean value)
SpanSpan. If the Span previously contained a mapping for
the key, the old value is replaced by the specified value.
Note: It is strongly recommended to use Span.setAttribute(AttributeKey, Object), and
pre-allocate your keys, if possible.
setAttribute in interface Spankey - the key for this attribute.value - the value for this attribute.public <T> void setAttribute(AttributeKey<T> key, T value)
SpanSpan. If the Span previously contained a mapping for
the key, the old value is replaced by the specified value.
Note: the behavior of null values is undefined, and hence strongly discouraged.
setAttribute in interface Spankey - the key for this attribute.value - the value for this attribute.public void addEvent(String name)
SpanSpan. The timestamp of the event will be the current time.public void addEvent(String name, long timestamp)
SpanSpan with the given timestamp, as nanos since epoch. Note,
this timestamp is not the same as System.nanoTime() but may be computed using
it, for example, by taking a difference of readings from System.nanoTime() and adding
to the span start time.
When possible, it is preferred to use Span.addEvent(String) at the time the event
occurred.
public void addEvent(String name, Attributes attributes)
SpanSpan with the given Attributes. The timestamp of the event
will be the current time.public void addEvent(String name, Attributes attributes, long timestamp)
SpanSpan with the given Attributes and timestamp.
Note, this timestamp is not the same as System.nanoTime() but may be computed
using it, for example, by taking a difference of readings from System.nanoTime() and
adding to the span start time.
When possible, it is preferred to use Span.addEvent(String) at the time the event
occurred.
public void setStatus(StatusCanonicalCode canonicalCode)
SpanSpan.
If used, this will override the default Span status. Default status code is StatusCanonicalCode.UNSET.
Only the value of the last call will be recorded, and implementations are free to ignore previous calls.
setStatus in interface SpancanonicalCode - the StatusCanonicalCode to set.public void setStatus(StatusCanonicalCode canonicalCode, String description)
SpanSpan.
If used, this will override the default Span status. Default status code is StatusCanonicalCode.UNSET.
Only the value of the last call will be recorded, and implementations are free to ignore previous calls.
setStatus in interface SpancanonicalCode - the StatusCanonicalCode to set.description - the description of the Status.public void recordException(Throwable exception)
SpanThrowable to the Span.
Note that SemanticAttributes.EXCEPTION_ESCAPED
cannot be determined by this function. You should record this attribute manually using Span.recordException(Throwable, Attributes) if you know that an exception is escaping.
recordException in interface Spanexception - the Throwable to record.public void recordException(Throwable exception, Attributes additionalAttributes)
SpanrecordException in interface Spanexception - the Throwable to record.additionalAttributes - the additional Attributes to record.public void updateName(String name)
SpanSpan name.
If used, this will override the name provided via Span.Builder.
Upon this update, any sampling behavior based on Span name will depend on the
implementation.
updateName in interface Spanname - the Span name.public void end()
SpanSpan execution.
Only the timing of the first end call for a given Span will be recorded, and
implementations are free to ignore all further calls.
public void end(EndSpanOptions endOptions)
SpanSpan execution with the specified EndSpanOptions.
Only the timing of the first end call for a given Span will be recorded, and
implementations are free to ignore all further calls.
Use this method for specifying explicit end options, such as end Timestamp. When no
explicit values are required, use Span.end().
end in interface SpanendOptions - the explicit EndSpanOptions for this Span.public SpanContext getContext()
SpanSpanContext associated with this Span.getContext in interface SpanSpanContext associated with this Span.public boolean isRecording()
Spantrue if this Span records tracing events (e.g. Span.addEvent(String), Span.setAttribute(String, long)).isRecording in interface Spantrue if this Span records tracing events.