id | title |
---|---|
opentelemetry-example |
OpenTelemetry Example |
You can find the source code here.
For an explanation in more detail, check the OpenTracing Example.
We're going to show an example of how to pass contextual information using Baggage and collect traces, metrics, and logs.
By default the example code uses OTLP Logging Exporters to print all signals to stdout in OTLP JSON encoding. This means that you can run the application immediately and observe the results.
For this, you need to run proxy and backend parts of application in different terminals via sbt.
Run proxy:
sbt "opentelemetryExample/runMain zio.telemetry.opentelemetry.example.ProxyApp"
Run backend:
sbt "opentelemetryExample/runMain zio.telemetry.opentelemetry.example.BackendApp"
Now perform the following request to see the results immediately:
curl -X GET http://localhost:8080/statuses
In case you want to try different observability platforms such as Jaeger, Fluentbit, Seq, DataDog, Honeycomb or others, please change the OtelSdk.scala file by choosing from the available tracer, meter, and logger providers or by implementing your own.
We chose Jaeger for distributed traces and Seq to store logs to demonstrate how the library works with available open-source observability platforms.
Start Jaeger by running the following command:
docker run --rm -it \
-d \
-e COLLECTOR_OTLP_ENABLED=true \
-p 4317:4317 \
-p 16686:16686 \
jaegertracing/all-in-one:1.47
To run Seq, you also need to specify an admin password (user is admin
):
PH=$(echo 'admin123' | docker run --rm -i datalust/seq config hash)
docker run \
-d \
--restart unless-stopped \
-e ACCEPT_EULA=Y \
-e SEQ_FIRSTRUN_ADMINPASSWORDHASH="$PH" \
-p 80:80 \
-p 5341:5341 \
datalust/seq
You must also switch the Tracing and Logging providers to Jaeger and Seq. For this, you need to swap the stdout
providers we use by default in OtelSdk.scala to TracerProvider.jaeger and LoggerProvider.seq
Run the application and fire a curl request as shown above. Head over to Jaeger UI and Seq UI to see the result.