@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(Event event)
Adds an event to the
Span. |
void |
addEvent(Event event,
long timestamp)
Adds an event to the
Span. |
void |
addEvent(String name)
Adds an event to the
Span. |
void |
addEvent(String name,
Attributes attributes)
Adds an event to the
Span. |
void |
addEvent(String name,
Attributes attributes,
long timestamp)
Adds an event to the
Span. |
void |
addEvent(String name,
long timestamp)
Adds an event to the
Span. |
static DefaultSpan |
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 DefaultSpan |
getInvalid()
Returns a
DefaultSpan with an invalid SpanContext. |
boolean |
isRecording()
Returns
true if this Span records tracing events (e.g. |
void |
setAttribute(String key,
AttributeValue 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(Status status)
Sets the
Status to the Span. |
String |
toString() |
void |
updateName(String name)
Updates the
Span name. |
public static DefaultSpan getInvalid()
DefaultSpan with an invalid SpanContext.DefaultSpan with an invalid SpanContext.public static DefaultSpan 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 attribute will be silently
dropped. Note: this behavior could change in the future.
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.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.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.setAttribute in interface Spankey - the key for this attribute.value - the value for this attribute.public void setAttribute(String key, AttributeValue value)
SpanSpan. If the Span previously contained a mapping for
the key, the old value is replaced by the specified value.setAttribute in interface Spankey - the key for this attribute.value - the value for this attribute.public void addEvent(String name)
SpanSpan.public void addEvent(String name, long timestamp)
SpanSpan.
Use this method to specify an explicit event timestamp. If not called, the implementation will use the current timestamp value, which should be the default case.
Important: this is NOT equivalent with System.nanoTime().
public void addEvent(String name, Attributes attributes)
SpanSpan.public void addEvent(String name, Attributes attributes, long timestamp)
SpanSpan.
Use this method to specify an explicit event timestamp. If not called, the implementation will use the current timestamp value, which should be the default case.
Important: this is NOT equivalent with System.nanoTime().
public void addEvent(Event event)
SpanSpan.public void addEvent(Event event, long timestamp)
SpanSpan.
Use this method to specify an explicit event timestamp. If not called, the implementation will use the current timestamp value, which should be the default case.
Important: this is NOT equivalent with System.nanoTime().
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.