To run OpenTelemetry (OTEL) collector for local and also one to send logs to Context for a Java (Spring Boot) application.
Check Spring Boot app/ directory for more details on the demo app.
There are different ways to collect observability data out of your java applicaion. Refer : https://opentelemetry.io/docs/languages/java/#repositories
We are using the https://github.com/open-telemetry/opentelemetry-java-instrumentation java agent method.
- docker-compose.yaml : To run everything(including grafana stack) in local docker environment. Idea is that, this will help you to understand and set up and everything in local correctly before preparing to send it to Context.
First, download the OpenTelemetry Java agent:
## get latest when possible (test it first, ofcourse)
cd examples/java/spring-boot/etc/
wget -q -O ./opentelemetry-javaagent.jar https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v2.4.0/opentelemetry-javaagent.jar
# Pre-req: you need to have `sdk`: https://sdkman.io/install.
# Again this is upto you. If you have the correct java runtime already, feel free to move to the build part.
sdk use java 17.0.9-tem # to select correct java runtime
## Build the jar using gradle. You can use maven if you want, then the path to the jar needs to be updated in the Dockerfile
./gradlew bootJar
Next, run the Docker Compose file with the following commands:
docker compose up --remove-orphans
# pre-requisite: needs the context token to be updated in the `etc/otel-collector/config-context.yaml`
docker compose -f docker-compose-context.yaml up --remove-orphans
docker logs otel-collector -f
Loki: See Logs
Tempo: See Traces
Prometheus: See Metrics
docker-compose down --remove-orphans
docker volume rm otel_grafana-storage otel_loki-storage otel_mimir-storage otel_minio-data otel_prometheus-data otel_tempo-storage