Class OpenAITraceExporter
- All Implemented Interfaces:
TraceExporter
Exports traces and spans to the OpenAI tracing platform via HTTP. Handles serialization, HTTP requests, retries, and error handling.
Key Features: - HTTP POST to OpenAI tracing API - Groups items by API key for multi-tenant support - Exponential backoff with jitter for retries - Respects 5xx for retry, 4xx for log-and-continue - Thread-safe HTTP client
API Endpoint: POST https://api.openai.com/v1/traces/ingest Authorization: Bearer YOUR_API_KEY Content-Type: application/json OpenAI-Beta: traces=v1
Payload Format: { "data": [ { "type": "trace", "trace_id": "...", ... }, { "type": "span", "span_id": "...", ... } ] }
Source: https://github.com/openai/openai-agents-js/blob/main/packages/agents-core/src/tracing/exporter.ts
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classException indicating a retriable errorstatic classRetry configuration -
Constructor Summary
ConstructorsConstructorDescriptionCreate exporter with default API key from environmentOpenAITraceExporter(String apiKey) Create exporter with specific API keyOpenAITraceExporter(String apiKey, OpenAITraceExporter.RetryConfig retryConfig) Create exporter with custom configurationOpenAITraceExporter(String apiKey, String endpoint, OpenAITraceExporter.RetryConfig retryConfig) Create exporter with full configuration -
Method Summary
Modifier and TypeMethodDescriptionExport a batch of trace items (Trace and Span objects).shutdown(long timeoutMs) Shutdown the exporter gracefully.
-
Constructor Details
-
OpenAITraceExporter
public OpenAITraceExporter()Create exporter with default API key from environment -
OpenAITraceExporter
Create exporter with specific API key -
OpenAITraceExporter
Create exporter with custom configuration -
OpenAITraceExporter
public OpenAITraceExporter(String apiKey, String endpoint, OpenAITraceExporter.RetryConfig retryConfig) Create exporter with full configuration
-
-
Method Details
-
export
Description copied from interface:TraceExporterExport a batch of trace items (Trace and Span objects).The implementation should: 1. Serialize items to target format 2. Send to external system 3. Handle errors appropriately (log or retry)
- Specified by:
exportin interfaceTraceExporter- Parameters:
items- List of Trace and Span objects to export- Returns:
- CompletableFuture that completes when export finishes (or fails)
-
shutdown
Description copied from interface:TraceExporterShutdown the exporter gracefully. Should flush any pending data and release resources.- Specified by:
shutdownin interfaceTraceExporter- Parameters:
timeoutMs- Maximum time to wait for shutdown- Returns:
- CompletableFuture that completes when shutdown finishes
-