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 theSpanProcessorthat 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
maxQueueSizemaximum size, if queue is full spans are dropped). Spans are exported either when there aremaxExportBatchSizepending spans orscheduleDelayNanoshas passed since the last export finished.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classBatchSpanProcessor.Worker
-
Field Summary
Fields Modifier and Type Field Description private booleanexportUnsampledSpansprivate java.util.concurrent.atomic.AtomicBooleanisShutdownprivate static java.util.logging.Loggerloggerprivate static AttributeKey<java.lang.Boolean>SPAN_PROCESSOR_DROPPED_LABELprivate static AttributeKey<java.lang.String>SPAN_PROCESSOR_TYPE_LABELprivate static java.lang.StringSPAN_PROCESSOR_TYPE_VALUEprivate BatchSpanProcessor.Workerworkerprivate static java.lang.StringWORKER_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 BatchSpanProcessorBuilderbuilder(SpanExporter spanExporter)Returns a new Builder forBatchSpanProcessor.CompletableResultCodeforceFlush()Processes all span events that have not yet been processed.(package private) java.util.List<SpanData>getBatch()(package private) java.util.Queue<ReadableSpan>getQueue()SpanExportergetSpanExporter()Return the processor's configuredSpanExporter.booleanisEndRequired()Returnstrueif thisSpanProcessorrequires end events.booleanisStartRequired()Returnstrueif thisSpanProcessorrequires start events.voidonEnd(ReadableSpan span)Called when aSpanis ended, if theSpan.isRecording()returns true.voidonStart(Context parentContext, ReadWriteSpan span)Called when aSpanis started, if theSpan.isRecording()returns true.CompletableResultCodeshutdown()Processes all span events that have not yet been processed and closes used resources.java.lang.StringtoString()-
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- theSpanExporterto which the Spans are pushed.- Returns:
- a new
BatchSpanProcessorBuilder. - Throws:
java.lang.NullPointerException- if thespanExporterisnull.
-
onStart
public void onStart(Context parentContext, ReadWriteSpan span)
Description copied from interface:SpanProcessorCalled when aSpanis 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:
onStartin interfaceSpanProcessor- Parameters:
parentContext- the parentContextof the span that just started.span- theSpanthat just started.
-
isStartRequired
public boolean isStartRequired()
Description copied from interface:SpanProcessorReturnstrueif thisSpanProcessorrequires start events.- Specified by:
isStartRequiredin interfaceSpanProcessor- Returns:
trueif thisSpanProcessorrequires start events.
-
onEnd
public void onEnd(ReadableSpan span)
Description copied from interface:SpanProcessorCalled when aSpanis 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:
onEndin interfaceSpanProcessor- Parameters:
span- theSpanthat just ended.
-
isEndRequired
public boolean isEndRequired()
Description copied from interface:SpanProcessorReturnstrueif thisSpanProcessorrequires end events.- Specified by:
isEndRequiredin interfaceSpanProcessor- Returns:
trueif thisSpanProcessorrequires end events.
-
shutdown
public CompletableResultCode shutdown()
Description copied from interface:SpanProcessorProcesses all span events that have not yet been processed and closes used resources.- Specified by:
shutdownin interfaceSpanProcessor- Returns:
- a
CompletableResultCodewhich completes when shutdown is finished.
-
forceFlush
public CompletableResultCode forceFlush()
Description copied from interface:SpanProcessorProcesses all span events that have not yet been processed.- Specified by:
forceFlushin interfaceSpanProcessor- Returns:
- a
CompletableResultCodewhich 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:
toStringin classjava.lang.Object
-
-