Interface ReadableSpan
- All Known Subinterfaces:
ReadWriteSpan
Span that can be read.-
Method Summary
Modifier and TypeMethodDescription<T> TgetAttribute(io.opentelemetry.api.common.AttributeKey<T> key) Returns the value for the givenAttributeKey, ornullif not found.default io.opentelemetry.api.common.AttributesReturns the Span attributes.io.opentelemetry.sdk.common.InstrumentationLibraryInfoDeprecated.default io.opentelemetry.sdk.common.InstrumentationScopeInfoReturns the instrumentation scope specified when creating the tracer which produced this span.io.opentelemetry.api.trace.SpanKindgetKind()Returns the kind of the span.longReturns the latency of theSpanin nanos.getName()Returns the name of theSpan.io.opentelemetry.api.trace.SpanContextReturns the parentSpanContextof theSpan, orSpanContext.getInvalid()if this is a root span.io.opentelemetry.api.trace.SpanContextReturns theSpanContextof theSpan.booleanhasEnded()Returns whether this Span has already been ended.This converts this instance into an immutable SpanData instance, for use in export.
-
Method Details
-
getSpanContext
io.opentelemetry.api.trace.SpanContext getSpanContext()Returns theSpanContextof theSpan.Equivalent with
Span.getSpanContext().- Returns:
- the
SpanContextof theSpan.
-
getParentSpanContext
io.opentelemetry.api.trace.SpanContext getParentSpanContext()Returns the parentSpanContextof theSpan, orSpanContext.getInvalid()if this is a root span.- Returns:
- the parent
SpanContextof theSpan
-
getName
String getName()Returns the name of theSpan.The name can be changed during the lifetime of the Span by using the
Span.updateName(String)so this value cannot be cached.Note: the implementation of this method performs locking to ensure thread-safe behavior.
- Returns:
- the name of the
Span.
-
toSpanData
SpanData toSpanData()This converts this instance into an immutable SpanData instance, for use in export.- Returns:
- an immutable
SpanDatainstance.
-
getInstrumentationLibraryInfo
Deprecated.Returns the instrumentation library specified when creating the tracer which produced this span.- Returns:
- an instance of
InstrumentationLibraryInfodescribing the instrumentation library
-
getInstrumentationScopeInfo
default io.opentelemetry.sdk.common.InstrumentationScopeInfo getInstrumentationScopeInfo()Returns the instrumentation scope specified when creating the tracer which produced this span.- Returns:
- an instance of
InstrumentationScopeInfodescribing the instrumentation scope
-
hasEnded
boolean hasEnded()Returns whether this Span has already been ended.Note: the implementation of this method performs locking to ensure thread-safe behavior.
- Returns:
trueif the span has already been ended,falseif not.
-
getLatencyNanos
long getLatencyNanos()Returns the latency of theSpanin nanos. If still active then returns now() - start time.Note: the implementation of this method performs locking to ensure thread-safe behavior.
- Returns:
- the latency of the
Spanin nanos.
-
getKind
io.opentelemetry.api.trace.SpanKind getKind()Returns the kind of the span.- Returns:
- the kind of the span.
-
getAttribute
Returns the value for the givenAttributeKey, ornullif not found.The attribute values can be changed during the lifetime of the Span by using
Span.setAttribute(java.lang.String, java.lang.String)} so this value cannot be cached.Note: the implementation of this method performs locking to ensure thread-safe behavior.
- Returns:
- the value for the given
AttributeKey, ornullif not found.
-
getAttributes
default io.opentelemetry.api.common.Attributes getAttributes()Returns the Span attributes.Attributes can be changed during the lifetime of the Span by using
Span.setAttribute(java.lang.String, java.lang.String)} so this value cannot be cached.Note: the implementation of this method performs locking and returns an immutable copy to ensure thread-safe behavior. If you only need a single attribute it is better to call
getAttribute(AttributeKey).- Returns:
- the Span attributes, or
Attributes.empty()if the span has no attributes. - Since:
- 1.38.0
-
getInstrumentationScopeInfo().