public final class BatchSpanProcessor extends Object implements SpanProcessor
SpanProcessor 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 are maxExportBatchSize pending spans or scheduleDelayMillis has passed
since the last export finished.
This batch SpanProcessor can cause high contention in a very high traffic service.
TODO: Add a link to the SpanProcessor that uses Disruptor as alternative with low contention.
Configuration options for BatchSpanProcessor can be read from system properties,
environment variables, or Properties objects.
For system properties and Properties objects, BatchSpanProcessor
will look for the following names:
otel.bsp.schedule.delay: sets the delay interval between two consecutive exports.
otel.bsp.max.queue: sets the maximum queue size.
otel.bsp.max.export.batch: sets the maximum batch size.
otel.bsp.export.timeout: sets the maximum allowed time to export data.
otel.bsp.export.sampled: sets whether only sampled spans should be exported.
For environment variables, BatchSpanProcessor will look for the following names:
OTEL_BSP_SCHEDULE_DELAY: sets the delay interval between two consecutive exports.
OTEL_BSP_MAX_QUEUE: sets the maximum queue size.
OTEL_BSP_MAX_EXPORT_BATCH: sets the maximum batch size.
OTEL_BSP_EXPORT_TIMEOUT: sets the maximum allowed time to export data.
OTEL_BSP_EXPORT_SAMPLED: sets whether only sampled spans should be exported.
| Modifier and Type | Class and Description |
|---|---|
static class |
BatchSpanProcessor.Builder
Builder class for
BatchSpanProcessor. |
| Modifier and Type | Method and Description |
|---|---|
io.opentelemetry.sdk.common.CompletableResultCode |
forceFlush()
Processes all span events that have not yet been processed.
|
boolean |
isEndRequired()
Returns
true if this SpanProcessor requires end events. |
boolean |
isStartRequired()
Returns
true if this SpanProcessor requires start events. |
static BatchSpanProcessor.Builder |
newBuilder(SpanExporter spanExporter)
Returns a new Builder for
BatchSpanProcessor. |
void |
onEnd(ReadableSpan span)
Called when a
Span is ended, if the Span.isRecording()
returns true. |
void |
onStart(ReadWriteSpan span)
Called when a
Span is started, if the Span.isRecording()
returns true. |
io.opentelemetry.sdk.common.CompletableResultCode |
shutdown()
Processes all span events that have not yet been processed and closes used resources.
|
public void onStart(ReadWriteSpan span)
SpanProcessorSpan is started, if the Span.isRecording()
returns true.
This method is called synchronously on the execution thread, should not throw or block the execution thread.
onStart in interface SpanProcessorspan - the ReadableSpan that just started.public boolean isStartRequired()
SpanProcessortrue if this SpanProcessor requires start events.isStartRequired in interface SpanProcessortrue if this SpanProcessor requires start events.public void onEnd(ReadableSpan span)
SpanProcessorSpan is ended, if the Span.isRecording()
returns true.
This method is called synchronously on the execution thread, should not throw or block the execution thread.
onEnd in interface SpanProcessorspan - the ReadableSpan that just ended.public boolean isEndRequired()
SpanProcessortrue if this SpanProcessor requires end events.isEndRequired in interface SpanProcessortrue if this SpanProcessor requires end events.public io.opentelemetry.sdk.common.CompletableResultCode shutdown()
SpanProcessorshutdown in interface SpanProcessorCompletableResultCode which completes when shutdown is finished.public io.opentelemetry.sdk.common.CompletableResultCode forceFlush()
SpanProcessorforceFlush in interface SpanProcessorCompletableResultCode which completes when currently queued spans are
finished processing.public static BatchSpanProcessor.Builder newBuilder(SpanExporter spanExporter)
BatchSpanProcessor.spanExporter - the SpanExporter to where the Spans are pushed.BatchSpanProcessor.NullPointerException - if the spanExporter is null.