Skip to main content

Instrumentation

Java Instrumentation with OpenTelemetry (OTLP Collector) - Virex Docs

Instrument Java applications using OpenTelemetry and export telemetry via OTLP.

Java Instrumentation with OpenTelemetry (OTLP Collector)

This guide explains how to instrument Java applications using OpenTelemetry and export metrics, traces, and logs to an OpenTelemetry Collector using OTLP.

Architecture Overview

Java App → OpenTelemetry Java Agent → OTLP → OpenTelemetry Collector → Grafana Stack

Step 1: Download Java Agent

curl -LO https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar

Step 2: Configure Environment Variables

export OTEL_SERVICE_NAME=orders-service export OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317 export OTEL_EXPORTER_OTLP_PROTOCOL=grpc

Step 3: Start Application

java -javaagent:/path/opentelemetry-javaagent.jar -jar app.jar

Step 4: Collector Configuration (Minimal)

receivers: otlp: protocols: grpc: http:

processors: batch:

exporters: prometheus: endpoint: 0.0.0.0:8889

service: pipelines: metrics: receivers: [otlp] processors: [batch] exporters: [prometheus]

Best Practices

  • Use consistent service names
  • Start with sampling
  • Prefer SLO-based alerting