Skip to main content

OpenTelemetry Exporter

Because the 6.x iOS SDK is built on OpenTelemetry, it has the ability to export OpenTelemetry signals directly from the mobile code level, without any of the telemetry hitting our backend.

To send traces and logs from the SDK to your collector or vendor of choice, you will need to configure the SDK with an exporter capable of sending OTel signals to that destination. This will be done in the creation of the Embrace.Options, by adding an OpenTelemetryExport.

Direct Exporters

Some collectors have built or presently support direct export of traces or logs in Swift. In theory, any implementation of SpanExporter or LogRecordExporter that can point to the location of the collector should be able to send, respectively, spans and logs.

The OpenTelemetry-Swift repository lists publicly-available exporters that can be added directly to your Embrace configuration. For example, here is an SDK configuration that adds a Jaeger exporter for traces:

    try? Embrace
.setup(
options: Embrace.Options(
appId: "AppID",
logLevel: .debug,
export: OpenTelemetryExport(
spanExporter: JaegerSpanExporter(
serviceName: "jaegerServiceName",
collectorAddress: "jaegerCollectorAddress"
)
)
)
)
.start()

Otlp Export through HTTP or gRPC

The OpenTelemetry-Swift list also has OTLP HTTP and gRPC exporters for logs and spans. These can be used more flexibly than the single-service exporters like Jaeger, because vendors can provide some important keys or headers that allow you to use the protocol to export to an HTTP or gRPC address.

For example, Grafana Cloud allows you to generate a token that you can use with their OTLP traces and spans gateway. On the SDK side, you can add an OtlpHttpTraceExporter to send your spans to that Grafana account via the Grafana Cloud traces endpoint, and similarly use an OtlpHttpLogExporter to send your logs to the same account via the GC log endpoint:

    let grafanaCloudTokenString = //String generated from your account
let urlConfig = URLSessionConfiguration.default
urlConfig.httpAdditionalHeaders = ["Authorization": "Basic \(grafanaCloudTokenString)"]

try? Embrace
.setup(
options: Embrace.Options(
appId: "AppID",
logLevel: .debug,
export: OpenTelemetryExport(
spanExporter: OtlpHttpTraceExporter(
endpoint: URL(string: "https://otlp-gateway-prod-us-west-0.grafana.net/otlp/v1/traces")!,
useSession: URLSession(configuration: urlConfig)
),
logExporter: OtlpHttpLogExporter(
endpoint: URL(string: "https://otlp-gateway-prod-us-west-0.grafana.net/otlp/v1/logs")!,
useSession: URLSession(configuration: urlConfig)
)
)
)
)
.start()