If you want to add OpenTelemetry to the services in an existing docker-compose.yml you can use a
docker-compose.override.yml
to do so without touching your existing file.
Imagine you have three services listed called frontend, processing and backend in your compose file.
Two of them are written in Java, one of them in Node.JS. Create the following docker-compose.override.yml
file alongside your docker-compose.yml to inject the Java agent and the @opentelemetry/auto-instrumentations-node
package into them:
services:
frontend:
environment:
- JAVA_TOOL_OPTIONS=-javaagent:/mnt/opentelemetry-javaagent.jar
- OTEL_RESOURCE_ATTRIBUTES=service.name=frontend
- OTEL_EXPORTER=otlp
- OTEL_EXPORTER_OTLP_ENDPOINT=http://jaeger:4318
volumes:
- ./opentelemetry-javaagent.jar:/mnt/opentelemetry-javaagent.jar
processing:
environment:
- JAVA_TOOL_OPTIONS=-javaagent:/mnt/opentelemetry-javaagent.jar
- OTEL_RESOURCE_ATTRIBUTES=service.name=processing
- OTEL_EXPORTER=otlp
- OTEL_EXPORTER_OTLP_ENDPOINT=http://jaeger:4318
volumes:
- ./opentelemetry-javaagent.jar:/mnt/opentelemetry-javaagent.jar
backend:
environment:
- NODE_PATH=/mnt/node_modules
- NODE_OPTIONS=-r "@opentelemetry/auto-instrumentations-node/register"
- OTEL_RESOURCE_ATTRIBUTES=service.name=backend
- OTEL_EXPORTER=otlp
- OTEL_EXPORTER_OTLP_ENDPOINT=http://jaeger:4318
volumes:
- ./node_modules:/mnt/node_modules
# If you want to add jaeger for visualization as well, uncomment the following
# jaeger:
# image: jaegertracing/all-in-one
# ports:
# - "16686:16686"
# - "4317:4317"
# - "4318:4318"Next, download the Java agent and the Node.JS module using the following commands:
curl -L -O https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar
echo {} > package.json
npm install @opentelemetry/auto-instrumentations-nodeIn your folder you should now have the following:
- file
docker-compose.yml - file
docker-compose.override.yml - file
opentelemetry-javaagent.jar - directory
node_modules
With this setup ready, run your application:
docker compose up
Your services are now emitting logs, metrics and traces!