epok
View as Markdown

Trace a Java app

One JVM flag installs the official OpenTelemetry Java agent. It instruments Spring, Servlet, JDBC, Kafka and many other libraries with no code changes. Agent 2.x uses HTTP by default, but 1.x agents use gRPC, so set the protocol below either way. There is no gRPC endpoint.

Time to first span: about 5 min. API key: app.epok.cloud, then Settings, then API Keys.

1. Set the OTLP endpoint and key

Set these in the environment that starts the JVM. Use the base URL; the agent appends /v1/traces. The header name must be x-api-key.

bash
export OTEL_EXPORTER_OTLP_ENDPOINT="https://ingest.epok.cloud"
export OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf"   # 1.x agents default to gRPC
export OTEL_EXPORTER_OTLP_HEADERS="x-api-key=YOUR_API_KEY"
export OTEL_EXPORTER_OTLP_COMPRESSION="gzip"
export OTEL_SERVICE_NAME="checkout-service"          # becomes service.name

2. Download and attach the agent

Download the latest agent and add it as a JVM argument. Keep the agent file next to the app or give an absolute path.

bash
curl -L -o opentelemetry-javaagent.jar \
  https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar

# Start your app with the agent. The agent instruments Spring, Servlet,
# JDBC, Kafka and many other libraries without code changes.
java -javaagent:./opentelemetry-javaagent.jar -jar your-app.jar

3. Set service.name

OTEL_SERVICE_NAME becomes the service.name resource attribute. Use one stable name per service. Without it the agent reports unknown_service:java.

4. Verify traces in Epok

  1. Send a request through your app.
  2. Open Traces in the app and filter by service name checkout-service.
  3. A span tree appears within a few seconds. The service summary fills in after a few minutes of traffic.

Logs

The Java agent captures java.util.logging, Logback and Log4j2 records as OpenTelemetry logs. Agent 2.x sends them over OTLP by default, to the same endpoint and with the same header as above. No appender change is needed.

Troubleshooting

  1. No spans arrive. The agent is not on the JVM command line, or it is exporting over gRPC. Check the -javaagent flag and set OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf.
  2. Spans show as unknown_service:java. OTEL_SERVICE_NAME did not reach the JVM. Set it in the same environment that starts the app.
  3. 401 or 403. 401 means no key was found; check the header is exactly x-api-key in OTEL_EXPORTER_OTLP_HEADERS. 403 means the key was read and rejected; check its scope and whether it was rotated.

Next