Enabling Telemetry in Java Services (Spring Boot)
To capture telemetry in our services deployed on Kubernetes (logs, metrics, and traces), you must add annotations to application deployments. These annotations allow the Grafana Alloy collector to automatically detect services and collect the information needed to feed traces, logs, and metrics into Grafana Cloud.
Setup
- Modify the Service Deployment
For Java (Spring Boot) services, edit the file: deploy/gke/deployment.yaml.erb
Add the following annotations within the spec.template.annotations block:
spec:
template:
annotations:
instrumentation.opentelemetry.io/container-names: "app"
instrumentation.opentelemetry.io/inject-java: alloy/auto-instrumentation
These annotations enable automatic injection of the OpenTelemetry agent into the app container, enabling
export of telemetry signals to Grafana Alloy.
- Update the ESP Container
In the same deployment.yaml.erb file, locate the ESP container definition and make the following adjustments:
- In all versions greater than or equal to 2 (2.x.x) of the ESP container, you must add the
--disable_tracingargument within theargsblock to avoid conflicts with OpenTelemetry auto-instrumentation.
Add the --disable_tracing parameter within the args block:
- name: esp
image: gcr.io/endpoints-release/endpoints-runtime:2.53.0
args: [..., "--disable_tracing"]
This ensures tracing is managed exclusively by OpenTelemetry, avoiding conflicts between ESP and the Alloy agent.