Class BatchSpanProcessor
- java.lang.Object
-
- io.opentelemetry.sdk.trace.export.BatchSpanProcessor
-
- All Implemented Interfaces:
SpanProcessor
,java.io.Closeable
,java.lang.AutoCloseable
public final class BatchSpanProcessor extends java.lang.Object implements SpanProcessor
Implementation of theSpanProcessor
that batches spans exported by the SDK then pushes them to the exporter pipeline.All spans reported by the SDK implementation are first added to a synchronized queue (with a
maxQueueSize
maximum size, if queue is full spans are dropped). Spans are exported either when there aremaxExportBatchSize
pending spans orscheduleDelayNanos
has passed since the last export finished.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
BatchSpanProcessor.Worker
-
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 static AttributeKey<java.lang.Boolean>
SPAN_PROCESSOR_DROPPED_LABEL
private static AttributeKey<java.lang.String>
SPAN_PROCESSOR_TYPE_LABEL
private static java.lang.String
SPAN_PROCESSOR_TYPE_VALUE
private BatchSpanProcessor.Worker
worker
private static java.lang.String
WORKER_THREAD_NAME
-
Constructor Summary
Constructors Constructor Description BatchSpanProcessor(SpanExporter spanExporter, boolean exportUnsampledSpans, MeterProvider meterProvider, long scheduleDelayNanos, int maxQueueSize, int maxExportBatchSize, long exporterTimeoutNanos)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static BatchSpanProcessorBuilder
builder(SpanExporter spanExporter)
Returns a new Builder forBatchSpanProcessor
.CompletableResultCode
forceFlush()
Processes all span events that have not yet been processed.(package private) java.util.List<SpanData>
getBatch()
(package private) java.util.Queue<ReadableSpan>
getQueue()
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
-
WORKER_THREAD_NAME
private static final java.lang.String WORKER_THREAD_NAME
-
SPAN_PROCESSOR_TYPE_LABEL
private static final AttributeKey<java.lang.String> SPAN_PROCESSOR_TYPE_LABEL
-
SPAN_PROCESSOR_DROPPED_LABEL
private static final AttributeKey<java.lang.Boolean> SPAN_PROCESSOR_DROPPED_LABEL
-
SPAN_PROCESSOR_TYPE_VALUE
private static final java.lang.String SPAN_PROCESSOR_TYPE_VALUE
-
exportUnsampledSpans
private final boolean exportUnsampledSpans
-
worker
private final BatchSpanProcessor.Worker worker
-
isShutdown
private final java.util.concurrent.atomic.AtomicBoolean isShutdown
-
-
Constructor Detail
-
BatchSpanProcessor
BatchSpanProcessor(SpanExporter spanExporter, boolean exportUnsampledSpans, MeterProvider meterProvider, long scheduleDelayNanos, int maxQueueSize, int maxExportBatchSize, long exporterTimeoutNanos)
-
-
Method Detail
-
builder
public static BatchSpanProcessorBuilder builder(SpanExporter spanExporter)
Returns a new Builder forBatchSpanProcessor
.- Parameters:
spanExporter
- theSpanExporter
to which the Spans are pushed.- Returns:
- a new
BatchSpanProcessorBuilder
. - Throws:
java.lang.NullPointerException
- if thespanExporter
isnull
.
-
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
-
getBatch
java.util.List<SpanData> getBatch()
-
getQueue
java.util.Queue<ReadableSpan> getQueue()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-