Class OpenAITraceExporter

java.lang.Object
ai.acolite.agentsdk.core.tracing.OpenAITraceExporter
All Implemented Interfaces:
TraceExporter

public class OpenAITraceExporter extends Object implements TraceExporter
OpenAITraceExporter

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

  • Constructor Details

    • OpenAITraceExporter

      public OpenAITraceExporter()
      Create exporter with default API key from environment
    • OpenAITraceExporter

      public OpenAITraceExporter(String apiKey)
      Create exporter with specific API key
    • OpenAITraceExporter

      public OpenAITraceExporter(String apiKey, OpenAITraceExporter.RetryConfig retryConfig)
      Create exporter with custom configuration
    • OpenAITraceExporter

      public OpenAITraceExporter(String apiKey, String endpoint, OpenAITraceExporter.RetryConfig retryConfig)
      Create exporter with full configuration
  • Method Details

    • export

      public CompletableFuture<Void> export(List<Object> items)
      Description copied from interface: TraceExporter
      Export 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:
      export in interface TraceExporter
      Parameters:
      items - List of Trace and Span objects to export
      Returns:
      CompletableFuture that completes when export finishes (or fails)
    • shutdown

      public CompletableFuture<Void> shutdown(long timeoutMs)
      Description copied from interface: TraceExporter
      Shutdown the exporter gracefully. Should flush any pending data and release resources.
      Specified by:
      shutdown in interface TraceExporter
      Parameters:
      timeoutMs - Maximum time to wait for shutdown
      Returns:
      CompletableFuture that completes when shutdown finishes