This example shows how to use OTLP HTTP Exporter to instrument a simple Swift application.
This example will export spans data using OTLP HTTP Exporter . It will use proto format.
-
Run docker: This will start otel-collector, Zipkin and Prometheus
# from this directory docker-compose up
-
Run app
# from this directory swift run OTLPHTTPExporter
-
Teardown the docker images
# from this directory docker-compose down
-
Open page at http://localhost:9411/zipkin/ - you should be able to see the spans in zipkin
The prometheus client will be available at http://localhost:9090.
Note: It may take some time for the application metrics to appear on the Prometheus dashboard.
-
If you don't set service.name as per https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/sdk-environment-variables.md the default name of the service and spans generate by the OTLP Exporter is
unknown_service:otlpexporter
You can either set the service.name by editing the schema in Xcode and the set the environment variable for OTEL_RESOURCE_ATTRIBUTES, or set it via command line:# from this directory OTEL_RESOURCE_ATTRIBUTES="service.name=my-swift-app,service.version=v1.2.3" swift run OTLPExporter
This will create a service and spans with the name my-swift-app
- For more information on OpenTelemetry, visit: https://opentelemetry.io/
- For more information on trace, visit: https://github.com/open-telemetry/opentelemetry-swift/tree/main/Sources/OpenTelemetrySdk/Trace
- For more information on metrics, visit: https://github.com/open-telemetry/opentelemetry-swift/tree/main/Sources/OpenTelemetrySdk/Metrics
Apache License 2.0