Package ai.acolite.agentsdk.core.tracing
Class BatchTraceProcessor
java.lang.Object
ai.acolite.agentsdk.core.tracing.BatchTraceProcessor
- All Implemented Interfaces:
TraceProcessor,AutoCloseable
BatchTraceProcessor
Buffers traces and spans in memory and exports them in batches. Provides configurable batching behavior with automatic and manual flush.
Key Features: - In-memory buffering with bounded queue - Periodic batch export (every N seconds) - Threshold-based export (when queue is 80% full) - Graceful shutdown with final flush - Thread-safe operations
Thread Safety: - BlockingQueue handles concurrent enqueue from multiple threads - Synchronized exportBatch() ensures only one export runs at a time - ScheduledExecutorService provides periodic exports on single thread
Usage:
BatchTraceProcessor processor = new BatchTraceProcessor(
exporter,
BatchTraceProcessor.Config.builder()
.maxBatchSize(100)
.scheduleDelayMs(5000)
.build()
);
Source:
https://github.com/openai/openai-agents-js/blob/main/packages/agents-core/src/tracing/batcher.ts-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classConfiguration for BatchTraceProcessor -
Constructor Summary
ConstructorsConstructorDescriptionBatchTraceProcessor(TraceExporter exporter, BatchTraceProcessor.Config config) -
Method Summary
Modifier and TypeMethodDescriptionFlush all pending traces/spans.voidCalled when a span ends.voidonSpanStart(Span<?> span) Called when a span starts.voidonTraceEnd(Trace trace) Called when a trace ends.voidonTraceStart(Trace trace) Called when a trace starts.shutdown(long timeoutMs) Shutdown the processor gracefully.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ai.acolite.agentsdk.core.tracing.TraceProcessor
close, shutdown
-
Constructor Details
-
BatchTraceProcessor
-
-
Method Details
-
onTraceStart
Description copied from interface:TraceProcessorCalled when a trace starts. Processors can export the trace immediately or buffer it.- Specified by:
onTraceStartin interfaceTraceProcessor
-
onTraceEnd
Description copied from interface:TraceProcessorCalled when a trace ends.- Specified by:
onTraceEndin interfaceTraceProcessor
-
onSpanStart
Description copied from interface:TraceProcessorCalled when a span starts.- Specified by:
onSpanStartin interfaceTraceProcessor
-
onSpanEnd
Description copied from interface:TraceProcessorCalled when a span ends. Most processors export spans on end to capture complete data.- Specified by:
onSpanEndin interfaceTraceProcessor
-
forceFlush
Description copied from interface:TraceProcessorFlush all pending traces/spans. Blocks until all data is exported.- Specified by:
forceFlushin interfaceTraceProcessor
-
shutdown
Description copied from interface:TraceProcessorShutdown the processor gracefully. Flushes pending data and releases resources.- Specified by:
shutdownin interfaceTraceProcessor- Parameters:
timeoutMs- Maximum time to wait for shutdown (milliseconds)
-