Class BatchSpanProcessor
- java.lang.Object
-
- io.opentelemetry.sdk.trace.export.BatchSpanProcessor
-
- All Implemented Interfaces:
SpanProcessor
public final class BatchSpanProcessor extends 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 orscheduleDelayMillis
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, orProperties
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.
-
-
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
.io.opentelemetry.sdk.common.CompletableResultCode
forceFlush()
Processes all span events that have not yet been processed.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(io.opentelemetry.context.Context parentContext, ReadWriteSpan span)
Called when aSpan
is started, if theSpan.isRecording()
returns true.io.opentelemetry.sdk.common.CompletableResultCode
shutdown()
Processes all span events that have not yet been processed and closes used resources.
-
-
-
Method Detail
-
builder
public static BatchSpanProcessorBuilder builder(SpanExporter spanExporter)
Returns a new Builder forBatchSpanProcessor
.- Parameters:
spanExporter
- theSpanExporter
to where the Spans are pushed.- Returns:
- a new
BatchSpanProcessor
. - Throws:
NullPointerException
- if thespanExporter
isnull
.
-
onStart
public void onStart(io.opentelemetry.context.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
- theReadableSpan
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
- theReadableSpan
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 io.opentelemetry.sdk.common.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 io.opentelemetry.sdk.common.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.
-
-