Skip to content

ProcessingTracer

ProcessingTracer is the production Tracer. It creates spans as ProcessedSpan values that forward every lifecycle event to a SpanProcessor synchronously, preserving arrival order without blocking the caller.

For local development without export see OSLogTracer.

public struct ProcessingTracer: Tracer {
// Full control — bring your own SpanProcessor:
public init(processor: any SpanProcessor)
// Convenience — wires BatchSpanProcessor around an exporter:
public init(
exporter: any TraceExporter,
batchSize: Int = 64,
redaction: any Redactor = Redaction.default
)
}

The convenience init is the normal path. It creates a BatchSpanProcessor internally and is equivalent to:

ProcessingTracer(
processor: BatchSpanProcessor(
exporter: exporter,
batchSize: batchSize,
redaction: redaction
)
)

Use the processor: init when you need a custom batching strategy, fan-out to multiple exporters, or sampling — see Custom Tracing.

The most common setup: wire an OTLPExporter directly through the convenience init.

let tracer = ProcessingTracer(
exporter: OTLPExporter(
endpoint: URL(string: "https://collector.example.com/v1/traces")!,
headers: ["Authorization": "Basic <token>"]
)
)
let orchestrator = MultiAgentOrchestrator(
config: OrchestratorConfig(tracer: tracer)
)

ProcessingTracer delegates flush and shutdown to the underlying processor. Call them explicitly — nothing drains automatically.

// In your SceneDelegate / AppDelegate:
func sceneWillResignActive(_ scene: UIScene) {
Task { try await tracer.flush() }
}
func applicationWillTerminate(_ application: UIApplication) {
Task { await tracer.shutdown() }
}

The convenience init accepts a Redactor that is applied by BatchSpanProcessor before every export. The built-in Redaction hashes user ids and clips long strings:

// Custom clip limit, clear user ids:
let tracer = ProcessingTracer(
exporter: myExporter,
redaction: Redaction(hashUserIds: false, maxStringLength: 8192)
)

See Custom Tracing for a full Redactor conformance example.

  • Tracing Overview — all protocols and the full pipeline diagram.
  • BatchSpanProcessor — the default SpanProcessor wired by the convenience init.
  • OTLPExporter — OTLP/HTTP JSON export, Langfuse/Datadog/Grafana/Honeycomb compatible.
  • Custom Tracing — custom SpanProcessor, Tracer, and Redactor conformances.