Class SimpleSpanProcessor
- java.lang.Object
-
- io.opentelemetry.sdk.trace.export.SimpleSpanProcessor
-
- All Implemented Interfaces:
SpanProcessor
,java.io.Closeable
,java.lang.AutoCloseable
public final class SimpleSpanProcessor extends java.lang.Object implements SpanProcessor
An implementation of theSpanProcessor
that converts theReadableSpan
toSpanData
and passes it directly to the configured exporter.This processor will cause all spans to be exported directly as they finish, meaning each export request will have a single span. Most backends will not perform well with a single span per request so unless you know what you're doing, strongly consider using
BatchSpanProcessor
instead, including in special environments such as serverless runtimes.SimpleSpanProcessor
is generally meant to for logging exporters only.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
exportUnsampledSpans
private java.util.concurrent.atomic.AtomicBoolean
isShutdown
private static java.util.logging.Logger
logger
private java.util.Set<CompletableResultCode>
pendingExports
private SpanExporter
spanExporter
-
Constructor Summary
Constructors Constructor Description SimpleSpanProcessor(SpanExporter spanExporter, boolean exportUnsampledSpans)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SimpleSpanProcessorBuilder
builder(SpanExporter exporter)
Returns a new Builder forSimpleSpanProcessor
.static SpanProcessor
create(SpanExporter exporter)
Returns a newSimpleSpanProcessor
which exports spans to theSpanExporter
synchronously.CompletableResultCode
forceFlush()
Processes all span events that have not yet been processed.SpanExporter
getSpanExporter()
Return the processor's configuredSpanExporter
.boolean
isEndRequired()
Returnstrue
if thisSpanProcessor
requires end events.boolean
isStartRequired()
Returnstrue
if thisSpanProcessor
requires start events.void
onEnd(ReadableSpan span)
Called when aSpan
is ended, if theSpan.isRecording()
returns true.void
onStart(Context parentContext, ReadWriteSpan span)
Called when aSpan
is started, if theSpan.isRecording()
returns true.CompletableResultCode
shutdown()
Processes all span events that have not yet been processed and closes used resources.java.lang.String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.opentelemetry.sdk.trace.SpanProcessor
close
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
spanExporter
private final SpanExporter spanExporter
-
exportUnsampledSpans
private final boolean exportUnsampledSpans
-
pendingExports
private final java.util.Set<CompletableResultCode> pendingExports
-
isShutdown
private final java.util.concurrent.atomic.AtomicBoolean isShutdown
-
-
Constructor Detail
-
SimpleSpanProcessor
SimpleSpanProcessor(SpanExporter spanExporter, boolean exportUnsampledSpans)
-
-
Method Detail
-
create
public static SpanProcessor create(SpanExporter exporter)
Returns a newSimpleSpanProcessor
which exports spans to theSpanExporter
synchronously.This processor will cause all spans to be exported directly as they finish, meaning each export request will have a single span. Most backends will not perform well with a single span per request so unless you know what you're doing, strongly consider using
BatchSpanProcessor
instead, including in special environments such as serverless runtimes.SimpleSpanProcessor
is generally meant to for logging exporters only.
-
builder
public static SimpleSpanProcessorBuilder builder(SpanExporter exporter)
Returns a new Builder forSimpleSpanProcessor
.- Since:
- 1.34.0
-
onStart
public void onStart(Context parentContext, ReadWriteSpan span)
Description copied from interface:SpanProcessor
Called when aSpan
is started, if theSpan.isRecording()
returns true.This method is called synchronously on the execution thread, should not throw or block the execution thread.
- Specified by:
onStart
in interfaceSpanProcessor
- Parameters:
parentContext
- the parentContext
of the span that just started.span
- theSpan
that just started.
-
isStartRequired
public boolean isStartRequired()
Description copied from interface:SpanProcessor
Returnstrue
if thisSpanProcessor
requires start events.- Specified by:
isStartRequired
in interfaceSpanProcessor
- Returns:
true
if thisSpanProcessor
requires start events.
-
onEnd
public void onEnd(ReadableSpan span)
Description copied from interface:SpanProcessor
Called when aSpan
is ended, if theSpan.isRecording()
returns true.This method is called synchronously on the execution thread, should not throw or block the execution thread.
- Specified by:
onEnd
in interfaceSpanProcessor
- Parameters:
span
- theSpan
that just ended.
-
isEndRequired
public boolean isEndRequired()
Description copied from interface:SpanProcessor
Returnstrue
if thisSpanProcessor
requires end events.- Specified by:
isEndRequired
in interfaceSpanProcessor
- Returns:
true
if thisSpanProcessor
requires end events.
-
shutdown
public CompletableResultCode shutdown()
Description copied from interface:SpanProcessor
Processes all span events that have not yet been processed and closes used resources.- Specified by:
shutdown
in interfaceSpanProcessor
- Returns:
- a
CompletableResultCode
which completes when shutdown is finished.
-
forceFlush
public CompletableResultCode forceFlush()
Description copied from interface:SpanProcessor
Processes all span events that have not yet been processed.- Specified by:
forceFlush
in interfaceSpanProcessor
- Returns:
- a
CompletableResultCode
which completes when currently queued spans are finished processing.
-
getSpanExporter
public SpanExporter getSpanExporter()
Return the processor's configuredSpanExporter
.- Since:
- 1.37.0
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-