public class OpenTelemetrySpan extends Object implements Span
Span
implementation that uses OpenTelemetry's Span
to provide tracing
capabilities to an application.
These traces should always be created using the OpenTelemetrySpanFactory
since this will make sure the proper
parent context is extracted before creating the Span
.
Constructor and Description |
---|
OpenTelemetrySpan(io.opentelemetry.api.trace.SpanBuilder spanBuilder)
Creates the span, based on the
SpanBuilder provided. |
Modifier and Type | Method and Description |
---|---|
Span |
addAttribute(String key,
String value)
Adds an attribute to the span.
|
void |
end()
Ends the span.
|
SpanScope |
makeCurrent()
Sets the Span as the current for the current thread.
|
Span |
recordException(Throwable t)
Records an exception to the span.
|
Span |
start()
Starts the Span.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
run, runCallable, runConsumer, runSupplier, wrapCallable, wrapConsumer, wrapRunnable, wrapSupplier
public OpenTelemetrySpan(io.opentelemetry.api.trace.SpanBuilder spanBuilder)
SpanBuilder
provided. This SpanBuilder
will supply the
Span
when the start()
method is invoked.spanBuilder
- The provider of the Span
.public Span start()
Span
Span.makeCurrent()
in
order to do so.public SpanScope makeCurrent()
Span
SpanScope
must be closed before ending
the Span, on the same thread, or through a try-with-resources statement in the same thread as this method was
called.
You can make a span current on as many threads as you like, but you have to close every SpanScope
, or
context will leak into the current thread. Note that if this is neglected, the Span.end()
method should warn
the user in order to report this back to the framework.
makeCurrent
in interface Span
public void end()
Span
If scopes are still open when this method is called, either an exception should be thrown or an error log should be produced to warn the user of the leak. This information can then be reported back to the developers of the framework for a fix.
public Span recordException(Throwable t)
Span
recordException
in interface Span
t
- The exception to recordpublic Span addAttribute(String key, String value)
Span
addAttribute
in interface Span
key
- The key of the attribute.value
- The value of the attribute.Copyright © 2010–2024. All rights reserved.