Class PropagatedSpan
- java.lang.Object
-
- io.opentelemetry.api.trace.PropagatedSpan
-
- All Implemented Interfaces:
Span
,ImplicitContextKeyed
@Immutable final class PropagatedSpan extends java.lang.Object implements Span
The defaultSpan
that is used when noSpan
implementation is available. All operations are no-op except context propagation.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static PropagatedSpan
INVALID
private SpanContext
spanContext
-
Constructor Summary
Constructors Modifier Constructor Description private
PropagatedSpan(SpanContext spanContext)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Span
addEvent(java.lang.String name)
Adds an event to theSpan
.Span
addEvent(java.lang.String name, long timestamp, java.util.concurrent.TimeUnit unit)
Adds an event to theSpan
with the giventimestamp
, as nanos since epoch.Span
addEvent(java.lang.String name, Attributes attributes)
Adds an event to theSpan
with the givenAttributes
.Span
addEvent(java.lang.String name, Attributes attributes, long timestamp, java.util.concurrent.TimeUnit unit)
(package private) static Span
create(SpanContext spanContext)
void
end()
Marks the end ofSpan
execution.void
end(long timestamp, java.util.concurrent.TimeUnit unit)
Marks the end ofSpan
execution with the specified timestamp.SpanContext
getSpanContext()
Returns theSpanContext
associated with thisSpan
.boolean
isRecording()
Returnstrue
if thisSpan
records tracing events (e.g.Span
recordException(java.lang.Throwable exception)
Records information about theThrowable
to theSpan
.Span
recordException(java.lang.Throwable exception, Attributes additionalAttributes)
Records information about theThrowable
to theSpan
.Span
setAllAttributes(Attributes attributes)
Sets attributes to theSpan
.<T> Span
setAttribute(AttributeKey<T> key, T value)
Sets an attribute to theSpan
.Span
setAttribute(java.lang.String key, boolean value)
Sets an attribute to theSpan
.Span
setAttribute(java.lang.String key, double value)
Sets an attribute to theSpan
.Span
setAttribute(java.lang.String key, long value)
Sets an attribute to theSpan
.Span
setAttribute(java.lang.String key, java.lang.String value)
Sets an attribute to theSpan
.Span
setStatus(StatusCode statusCode)
Sets the status to theSpan
.Span
setStatus(StatusCode statusCode, java.lang.String description)
Sets the status to theSpan
.java.lang.String
toString()
Span
updateName(java.lang.String name)
Updates theSpan
name.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.opentelemetry.context.ImplicitContextKeyed
makeCurrent
-
Methods inherited from interface io.opentelemetry.api.trace.Span
addEvent, addEvent, addLink, addLink, end, setAttribute, storeInContext
-
-
-
-
Field Detail
-
INVALID
static final PropagatedSpan INVALID
-
spanContext
private final SpanContext spanContext
-
-
Constructor Detail
-
PropagatedSpan
private PropagatedSpan(SpanContext spanContext)
-
-
Method Detail
-
create
static Span create(SpanContext spanContext)
-
setAttribute
public Span setAttribute(java.lang.String key, java.lang.String value)
Description copied from interface:Span
Sets an attribute to theSpan
. If theSpan
previously contained a mapping for the key, the old value is replaced by the specified value.Empty String "" and null are valid attribute
value
, but not valid keys.Note: It is strongly recommended to use
Span.setAttribute(AttributeKey, Object)
, and pre-allocate your keys, if possible.- Specified by:
setAttribute
in interfaceSpan
- Parameters:
key
- the key for this attribute.value
- the value for this attribute.- Returns:
- this.
-
setAttribute
public Span setAttribute(java.lang.String key, long value)
Description copied from interface:Span
Sets an attribute to theSpan
. If theSpan
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.- Specified by:
setAttribute
in interfaceSpan
- Parameters:
key
- the key for this attribute.value
- the value for this attribute.- Returns:
- this.
-
setAttribute
public Span setAttribute(java.lang.String key, double value)
Description copied from interface:Span
Sets an attribute to theSpan
. If theSpan
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.- Specified by:
setAttribute
in interfaceSpan
- Parameters:
key
- the key for this attribute.value
- the value for this attribute.- Returns:
- this.
-
setAttribute
public Span setAttribute(java.lang.String key, boolean value)
Description copied from interface:Span
Sets an attribute to theSpan
. If theSpan
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.- Specified by:
setAttribute
in interfaceSpan
- Parameters:
key
- the key for this attribute.value
- the value for this attribute.- Returns:
- this.
-
setAttribute
public <T> Span setAttribute(AttributeKey<T> key, T value)
Description copied from interface:Span
Sets an attribute to theSpan
. If theSpan
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.
- Specified by:
setAttribute
in interfaceSpan
- Parameters:
key
- the key for this attribute.value
- the value for this attribute.- Returns:
- this.
-
setAllAttributes
public Span setAllAttributes(Attributes attributes)
Description copied from interface:Span
Sets attributes to theSpan
. If theSpan
previously contained a mapping for any of the keys, the old values are replaced by the specified values.- Specified by:
setAllAttributes
in interfaceSpan
- Parameters:
attributes
- the attributes- Returns:
- this.
-
addEvent
public Span addEvent(java.lang.String name)
Description copied from interface:Span
Adds an event to theSpan
. The timestamp of the event will be the current time.
-
addEvent
public Span addEvent(java.lang.String name, long timestamp, java.util.concurrent.TimeUnit unit)
Description copied from interface:Span
Adds an event to theSpan
with the giventimestamp
, as nanos since epoch. Note, thistimestamp
is not the same asSystem.nanoTime()
but may be computed using it, for example, by taking a difference of readings fromSystem.nanoTime()
and adding to the span start time.When possible, it is preferred to use
Span.addEvent(String)
at the time the event occurred.
-
addEvent
public Span addEvent(java.lang.String name, Attributes attributes)
Description copied from interface:Span
Adds an event to theSpan
with the givenAttributes
. The timestamp of the event will be the current time.
-
addEvent
public Span addEvent(java.lang.String name, Attributes attributes, long timestamp, java.util.concurrent.TimeUnit unit)
Description copied from interface:Span
Adds an event to theSpan
with the givenAttributes
andtimestamp
. Note, thistimestamp
is not the same asSystem.nanoTime()
but may be computed using it, for example, by taking a difference of readings fromSystem.nanoTime()
and adding to the span start time.When possible, it is preferred to use
Span.addEvent(String)
at the time the event occurred.- Specified by:
addEvent
in interfaceSpan
- Parameters:
name
- the name of the event.attributes
- the attributes that will be added; these are associated with this event, not theSpan
as forsetAttribute()
.timestamp
- the explicit event timestamp since epoch.unit
- the unit of the timestamp- Returns:
- this.
-
setStatus
public Span setStatus(StatusCode statusCode)
Description copied from interface:Span
Sets the status to theSpan
.If used, this will override the default
Span
status. Default status code isStatusCode.UNSET
.Only the value of the last call will be recorded, and implementations are free to ignore previous calls.
- Specified by:
setStatus
in interfaceSpan
- Parameters:
statusCode
- theStatusCode
to set.- Returns:
- this.
-
setStatus
public Span setStatus(StatusCode statusCode, java.lang.String description)
Description copied from interface:Span
Sets the status to theSpan
.If used, this will override the default
Span
status. Default status code isStatusCode.UNSET
.Only the value of the last call will be recorded, and implementations are free to ignore previous calls.
- Specified by:
setStatus
in interfaceSpan
- Parameters:
statusCode
- theStatusCode
to set.description
- the description of theStatus
.- Returns:
- this.
-
recordException
public Span recordException(java.lang.Throwable exception)
Description copied from interface:Span
Records information about theThrowable
to theSpan
.Note that the EXCEPTION_ESCAPED value from the Semantic Conventions 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.- Specified by:
recordException
in interfaceSpan
- Parameters:
exception
- theThrowable
to record.- Returns:
- this.
-
recordException
public Span recordException(java.lang.Throwable exception, Attributes additionalAttributes)
Description copied from interface:Span
Records information about theThrowable
to theSpan
.- Specified by:
recordException
in interfaceSpan
- Parameters:
exception
- theThrowable
to record.additionalAttributes
- the additionalAttributes
to record.- Returns:
- this.
-
updateName
public Span updateName(java.lang.String name)
Description copied from interface:Span
Updates theSpan
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.- Specified by:
updateName
in interfaceSpan
- Parameters:
name
- theSpan
name.- Returns:
- this.
-
end
public void end()
Description copied from interface:Span
Marks the end ofSpan
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.
-
end
public void end(long timestamp, java.util.concurrent.TimeUnit unit)
Description copied from interface:Span
Marks the end ofSpan
execution with the specified timestamp.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, useSpan.end()
.
-
getSpanContext
public SpanContext getSpanContext()
Description copied from interface:Span
Returns theSpanContext
associated with thisSpan
.- Specified by:
getSpanContext
in interfaceSpan
- Returns:
- the
SpanContext
associated with thisSpan
.
-
isRecording
public boolean isRecording()
Description copied from interface:Span
Returnstrue
if thisSpan
records tracing events (e.g.Span.addEvent(String)
,Span.setAttribute(String, long)
).- Specified by:
isRecording
in interfaceSpan
- Returns:
true
if thisSpan
records tracing events.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-