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 defaultSpanthat is used when noSpanimplementation is available. All operations are no-op except context propagation.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static PropagatedSpanINVALIDprivate SpanContextspanContext
-
Constructor Summary
Constructors Modifier Constructor Description privatePropagatedSpan(SpanContext spanContext)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SpanaddEvent(java.lang.String name)Adds an event to theSpan.SpanaddEvent(java.lang.String name, long timestamp, java.util.concurrent.TimeUnit unit)Adds an event to theSpanwith the giventimestamp, as nanos since epoch.SpanaddEvent(java.lang.String name, Attributes attributes)Adds an event to theSpanwith the givenAttributes.SpanaddEvent(java.lang.String name, Attributes attributes, long timestamp, java.util.concurrent.TimeUnit unit)(package private) static Spancreate(SpanContext spanContext)voidend()Marks the end ofSpanexecution.voidend(long timestamp, java.util.concurrent.TimeUnit unit)Marks the end ofSpanexecution with the specified timestamp.SpanContextgetSpanContext()Returns theSpanContextassociated with thisSpan.booleanisRecording()Returnstrueif thisSpanrecords tracing events (e.g.SpanrecordException(java.lang.Throwable exception)Records information about theThrowableto theSpan.SpanrecordException(java.lang.Throwable exception, Attributes additionalAttributes)Records information about theThrowableto theSpan.SpansetAllAttributes(Attributes attributes)Sets attributes to theSpan.<T> SpansetAttribute(AttributeKey<T> key, T value)Sets an attribute to theSpan.SpansetAttribute(java.lang.String key, boolean value)Sets an attribute to theSpan.SpansetAttribute(java.lang.String key, double value)Sets an attribute to theSpan.SpansetAttribute(java.lang.String key, long value)Sets an attribute to theSpan.SpansetAttribute(java.lang.String key, java.lang.String value)Sets an attribute to theSpan.SpansetStatus(StatusCode statusCode)Sets the status to theSpan.SpansetStatus(StatusCode statusCode, java.lang.String description)Sets the status to theSpan.java.lang.StringtoString()SpanupdateName(java.lang.String name)Updates theSpanname.-
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:SpanSets an attribute to theSpan. If theSpanpreviously 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:
setAttributein 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:SpanSets an attribute to theSpan. If theSpanpreviously 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:
setAttributein 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:SpanSets an attribute to theSpan. If theSpanpreviously 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:
setAttributein 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:SpanSets an attribute to theSpan. If theSpanpreviously 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:
setAttributein 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:SpanSets an attribute to theSpan. If theSpanpreviously 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:
setAttributein 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:SpanSets attributes to theSpan. If theSpanpreviously contained a mapping for any of the keys, the old values are replaced by the specified values.- Specified by:
setAllAttributesin interfaceSpan- Parameters:
attributes- the attributes- Returns:
- this.
-
addEvent
public Span addEvent(java.lang.String name)
Description copied from interface:SpanAdds 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:SpanAdds an event to theSpanwith the giventimestamp, as nanos since epoch. Note, thistimestampis 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:SpanAdds an event to theSpanwith 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:SpanAdds an event to theSpanwith the givenAttributesandtimestamp. Note, thistimestampis 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:
addEventin interfaceSpan- Parameters:
name- the name of the event.attributes- the attributes that will be added; these are associated with this event, not theSpanas 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:SpanSets the status to theSpan.If used, this will override the default
Spanstatus. 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:
setStatusin interfaceSpan- Parameters:
statusCode- theStatusCodeto set.- Returns:
- this.
-
setStatus
public Span setStatus(StatusCode statusCode, java.lang.String description)
Description copied from interface:SpanSets the status to theSpan.If used, this will override the default
Spanstatus. 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:
setStatusin interfaceSpan- Parameters:
statusCode- theStatusCodeto set.description- the description of theStatus.- Returns:
- this.
-
recordException
public Span recordException(java.lang.Throwable exception)
Description copied from interface:SpanRecords information about theThrowableto 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:
recordExceptionin interfaceSpan- Parameters:
exception- theThrowableto record.- Returns:
- this.
-
recordException
public Span recordException(java.lang.Throwable exception, Attributes additionalAttributes)
Description copied from interface:SpanRecords information about theThrowableto theSpan.- Specified by:
recordExceptionin interfaceSpan- Parameters:
exception- theThrowableto record.additionalAttributes- the additionalAttributesto record.- Returns:
- this.
-
updateName
public Span updateName(java.lang.String name)
Description copied from interface:SpanUpdates theSpanname.If used, this will override the name provided via
Span.Builder.Upon this update, any sampling behavior based on
Spanname will depend on the implementation.- Specified by:
updateNamein interfaceSpan- Parameters:
name- theSpanname.- Returns:
- this.
-
end
public void end()
Description copied from interface:SpanMarks the end ofSpanexecution.Only the timing of the first end call for a given
Spanwill 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:SpanMarks the end ofSpanexecution with the specified timestamp.Only the timing of the first end call for a given
Spanwill 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:SpanReturns theSpanContextassociated with thisSpan.- Specified by:
getSpanContextin interfaceSpan- Returns:
- the
SpanContextassociated with thisSpan.
-
isRecording
public boolean isRecording()
Description copied from interface:SpanReturnstrueif thisSpanrecords tracing events (e.g.Span.addEvent(String),Span.setAttribute(String, long)).- Specified by:
isRecordingin interfaceSpan- Returns:
trueif thisSpanrecords tracing events.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-