This example demonstrates simple usage of the OpenTelemetry Java Agent published by opentelemetry-java-instrumentation.
It consists of a spring boot application with:
- A gradle task for downloading the OpenTelemetry Java Agent.
- A simple web API available at
GET http://localhost:8080/ping
. When called, auto instrumentation from the OpenTelemetry Java Agent records spans and metrics. Additionally, there is manual trace and metric instrumentation, as well as application logging performed in the context of traces using the log4j API. - A docker compose setup configured to run the application and export to the collector via OTLP.
- The collector is configured with the OTLP receiver and export it to standard out with the logging exporter
- Java 1.8
- Docker compose
Build the application jar
../gradlew bootJar
Run the application and the collector with docker compose
docker-compose up --build
In a separate shell, exercise the application by calling its endpoint
curl http://localhost:8080/ping
Watch for spans, metrics, and logs in the collector log output
By default, this example uses the environment variable configuration schema to configure the SDK. However, it also includes sdk-config.yaml which demonstrates how the file configuration scheme can be used instead. sdk-config.yaml
demonstrates view configuration to disable a metric, something which is not available in the environment variable configuration scheme.
To use file configuration instead of the environment variable scheme, add the following before starting the application and collector:
export OTEL_CONFIG_FILE=/sdk-config.yaml
Note that toggling file configuration causes the environment variable configuration scheme to be ignored completely. However, there is support for environment variable substitution within configuration files.