OpenTelemetry for Swift

OpenTelemetry provides libraries for instrumenting Swift applications, including iOS apps, server-side Swift (like Vapor), and cross-platform services.

Installation

Install OpenTelemetry Swift via Swift Package Manager:

.package(url: "https://github.com/open-telemetry/opentelemetry-swift", from: "1.0.0")

Add it to your dependencies in your Package.swift file.

Full installation instructions:
👉 OpenTelemetry Swift Getting Started

Auto-Instrumentation

Auto-instrumentation lets you automatically trace common libraries such as HTTP clients, database drivers, and more without needing to modify your code. OpenTelemetry provides auto-instrumentation libraries for many popular languages, making it fast to get started with tracing.

Currently, Swift requires manual setup for most telemetry.
There’s no full auto-instrumentation for iOS or server-side Swift yet.

Manual Instrumentation

Manual instrumentation gives you full control over your traces, allowing you to create spans wherever needed. You can customize span names, attributes, and relationships to capture the most important parts of your application’s flow.

Manually create spans in Swift:

let tracer = OpenTelemetry.instance.tracerProvider.get(instrumentationName: "my-service")
let span = tracer.spanBuilder(spanName: "my-operation").startSpan() span.end()

Learn more:
👉 Swift Manual Instrumentation

Exporters

Once your application is instrumented, you need to export telemetry data. PlayerZero supports the OpenTelemetry Protocol (OTLP) over HTTP. You can configure your OpenTelemetry SDK to export traces, logs, and metrics to PlayerZero’s endpoint by setting the endpoint URL and API token.

You typically configure an OTLP HTTP exporter for Swift projects.

Set:

OTEL_EXPORTER_OTLP_ENDPOINT=https://sdk.playerzero.app/otlp 
OTEL_EXPORTER_OTLP_HEADERS=Authorization=Bearer <your-playerzero-token> 
OTEL_TRACES_EXPORTER=otlp 
OTEL_METRICS_EXPORTER=otlp

Official reference:
👉 Swift SDK Configuration

Optional: Using a Collector

Using an OpenTelemetry Collector is optional for most setups. A collector can help route telemetry to multiple destinations, perform transformations, or batch data efficiently. You might use a collector if you want to forward telemetry to both PlayerZero and another observability platform simultaneously.

You can forward Swift telemetry through a collector before sending it to PlayerZero.

For detailed language-specific instrumentation examples and full OpenTelemetry documentation, refer to the links below.