CompositeSpanProcessor implements SpanProcessor
Read onlyYes
FinalYes
Forwards spans to multiple processors.
This is useful when you need to:
- Send spans to multiple backends (e.g., both console and OTLP)
- Combine batching with memory storage for testing
- Add custom processing alongside export
Example usage:
$processor = new CompositeSpanProcessor([
new BatchingSpanProcessor($otlpExporter),
new MemorySpanProcessor(),
]);
Interfaces
- SpanProcessor
- Interface for processing spans when they start and end.
Methods
- __construct() : mixed
- exporter() : SpanExporter
- Get the exporter used by this processor.
- flush() : bool
- Export all pending spans and return success status.
- onEnd() : void
- Called when a span ends.
- onStart() : void
- Called when a span starts.
- processors() : array<string|int, SpanProcessor>
- Get all processors in this composite.
Methods
__construct()
public
__construct(array<string|int, SpanProcessor> $processors) : mixed
Parameters
- $processors : array<string|int, SpanProcessor>
exporter()
Get the exporter used by this processor.
public
exporter() : SpanExporter
Return values
SpanExporterflush()
Export all pending spans and return success status.
public
flush() : bool
Forces immediate export of any buffered spans. Returns true if all spans were successfully exported.
Return values
boolonEnd()
Called when a span ends.
public
onEnd(Span $span) : void
This is invoked synchronously when the span completes. The span is fully populated at this point (end time, status, all attributes).
Parameters
- $span : Span
onStart()
Called when a span starts.
public
onStart(Span $span) : void
This is invoked synchronously when the span begins. Implementations should avoid blocking operations in this method.
Parameters
- $span : Span
processors()
Get all processors in this composite.
public
processors() : array<string|int, SpanProcessor>