OpenTelemetry provides support for Ktor with the KtorClientTelemetry
and KtorServerTelemetry
plugins for the Ktor client and server respectively. For the source code, see
the repository on GitHub.
This project contains examples of how to use the KtorClientTelemetry
and KtorServerTelemetry
plugins.
You can find examples for the client plugin KtorClientTelemetry
in
the extractions folder.
And you can find examples for the server plugin KtorServerTelemetry
in
the extractions folder.
Note: You need to have Docker installed and running to run the sample.
To run this sample, execute the following command from the opentelemetry
directory::
./gradlew :runWithDocker
It will start a Grafana
, Grafana Tempo
and Prometheus
in the docker container and
then it will start a server
on http://localhost:8080/.
Then, to run the client, which will send requests to a server, you can execute the following command in
an opentelemetry
directory:
./gradlew :client:run
Note: In this example, we use an Autoconfiguration OpenTelemetry instance, we set environment variables in build.gradle.kts file. You can find more information about these environment variables in the OpenTelemetry documentation.
Let's check what we will see in the Grafana
after running the server (with Docker) and the client:
- Go to http://localhost:3000, login with admin/admin.
- Check created metrics either in explore section by selecting prometheus datasource or in one preconfigured dashboard with http traffic stats
- Check created traces in explore section by selecting Tempo datasource and switching to search tab
- Check profiles in Drilldown/profiles
Note: OTEL agent is in the separate branch otel-agent