Class BatchSpanProcessor

java.lang.Object
io.opentelemetry.sdk.trace.export.BatchSpanProcessor
All Implemented Interfaces:
SpanProcessor, Closeable, AutoCloseable

public final class BatchSpanProcessor extends Object implements SpanProcessor
Implementation of the 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 scheduleDelayNanos has passed since the last export finished.

  • Method Details

    • builder

      public static BatchSpanProcessorBuilder builder(SpanExporter spanExporter)
      Returns a new Builder for BatchSpanProcessor.
      Parameters:
      spanExporter - the SpanExporter to which the Spans are pushed.
      Returns:
      a new BatchSpanProcessorBuilder.
      Throws:
      NullPointerException - if the spanExporter is null.
    • onStart

      public void onStart(io.opentelemetry.context.Context parentContext, ReadWriteSpan span)
      Description copied from interface: SpanProcessor
      Called when a Span 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.

      Specified by:
      onStart in interface SpanProcessor
      Parameters:
      parentContext - the parent Context of the span that just started.
      span - the Span that just started.
    • isStartRequired

      public boolean isStartRequired()
      Description copied from interface: SpanProcessor
      Returns true if this SpanProcessor requires start events.
      Specified by:
      isStartRequired in interface SpanProcessor
      Returns:
      true if this SpanProcessor requires start events.
    • onEnd

      public void onEnd(ReadableSpan span)
      Description copied from interface: SpanProcessor
      Called when a Span 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.

      Specified by:
      onEnd in interface SpanProcessor
      Parameters:
      span - the Span that just ended.
    • isEndRequired

      public boolean isEndRequired()
      Description copied from interface: SpanProcessor
      Returns true if this SpanProcessor requires end events.
      Specified by:
      isEndRequired in interface SpanProcessor
      Returns:
      true if this SpanProcessor 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 interface SpanProcessor
      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 interface SpanProcessor
      Returns:
      a CompletableResultCode which completes when currently queued spans are finished processing.
    • toString

      public String toString()
      Overrides:
      toString in class Object