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 declarative configuration scheme can be used to configure the SDK based on a YAML configuration file instead.
sdk-config.yaml
extends the opentelemetry-configuration sdk-config.yaml template, demonstrating:
- Configuration of instrumentation (see
.instrumentation.java
) - Configuration of rule based routing sampler (see
.tracer_provider.sampler.parent_based.root
)
To use declarative configuration instead of the environment variable scheme, add the following before starting the application and collector:
export OTEL_EXPERIMENTAL_CONFIG_FILE=/sdk-config.yaml
Note: toggling declarative configuration causes the env var configuration scheme to be ignored completely. However, there is support for env var substitution within configuration files.