Package ai.acolite.agentsdk.core.tracing
Class TraceProvider
java.lang.Object
ai.acolite.agentsdk.core.tracing.TraceProvider
TraceProvider
Global singleton for trace/span creation and processor management.
Features: - Environment variable support: OPENAI_AGENTS_DISABLE_TRACING=1 or true - Returns NoopTrace/NoopSpan when disabled (no performance overhead) - Manages multiple processors via MultiTracingProcessor - Automatic shutdown on JVM exit
Usage:
// Get global instance
TraceProvider provider = TraceProvider.getGlobalTraceProvider();
// Register processors
provider.registerProcessor(new ConsoleTraceProcessor());
// Create traces
Trace trace = provider.createTrace(Trace.builder().name("My workflow").build());
Environment Variables: - OPENAI_AGENTS_DISABLE_TRACING=1 or true - Disables all tracing
Ported from TypeScript OpenAI Agents SDK Source: tracing/provider.ts
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateSpan(Span<TData> span) Create a new span.createTrace(Trace trace) Create a new trace.Force flush all pending traces/spans immediately.Get the current span from ThreadLocal context.Get the current trace from ThreadLocal context.static TraceProviderGet the global TraceProvider singleton.static voidInitialize the global provider with default cloud tracing setup.booleanCheck if tracing is currently disabled.voidregisterProcessor(TraceProcessor processor) Add a processor to the list of processors.voidsetDisabled(boolean disabled) Enable or disable tracing at runtime.voidsetProcessors(List<TraceProcessor> processors) Set the list of processors.shutdown()Shutdown with default timeout (5 seconds).shutdown(long timeoutMs) Shutdown all processors.
-
Constructor Details
-
TraceProvider
public TraceProvider()Create a new TraceProvider. Checks OPENAI_AGENTS_DISABLE_TRACING environment variable.
-
-
Method Details
-
registerProcessor
Add a processor to the list of processors. Each processor will receive all traces/spans. -
setProcessors
Set the list of processors. This will replace any existing processors. -
getCurrentTrace
Get the current trace from ThreadLocal context. -
getCurrentSpan
Get the current span from ThreadLocal context. -
setDisabled
public void setDisabled(boolean disabled) Enable or disable tracing at runtime. -
isDisabled
public boolean isDisabled()Check if tracing is currently disabled. -
createTrace
Create a new trace. Returns NoopTrace if tracing is disabled. -
createSpan
Create a new span. Returns NoopSpan if tracing is disabled or no active trace. -
shutdown
Shutdown all processors. Waits up to timeout for export to complete. -
shutdown
Shutdown with default timeout (5 seconds). -
forceFlush
Force flush all pending traces/spans immediately. -
getGlobalTraceProvider
Get the global TraceProvider singleton. Thread-safe lazy initialization. -
initializeWithDefaultCloudTracing
public static void initializeWithDefaultCloudTracing()Initialize the global provider with default cloud tracing setup. Sets up BatchTraceProcessor + OpenAITraceExporter.This should be called once at application startup if you want automatic cloud tracing with OpenAI.
-