Skip to content

Java

Download the OpenTelemetry Java agent next to your app. Nothing changes in your build.

Terminal window
curl -L -O https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar

Set these where your app runs. Replace YOUR_INGEST_KEY with your key and checkout with your service name.

Terminal window
export OTEL_SERVICE_NAME=checkout
export OTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=production
export OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp.siteqwality.com
export OTEL_EXPORTER_OTLP_HEADERS=Authorization=YOUR_INGEST_KEY
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf

Add the -javaagent flag to the command that starts your app:

Terminal window
java -javaagent:opentelemetry-javaagent.jar -jar app.jar

Spring, servlet containers, JDBC, HTTP clients, Kafka and many more are now traced automatically.

Keep logging the way you do. The agent sends Logback and Log4j records, linked to the trace of the request that wrote them:

private static final Logger logger = LoggerFactory.getLogger(App.class);
logger.info("order placed, orderId={}", 42);

Add io.opentelemetry:opentelemetry-api to your dependencies, then:

private static final LongCounter orders =
GlobalOpenTelemetry.getMeter("checkout").counterBuilder("orders.placed").build();
orders.add(1);

The agent also sends JVM and HTTP server metrics on its own.

Open Logs, Traces or Metrics. New data usually shows up within a minute, and a page that says it is waiting for data switches to your data on its own.

The code on this page comes from a runnable example that is checked against our ingest rules every month.

Nothing arriving? Check that the key is an ingest key for this account, that your account has early access, and the status codes in Ingest routes and limits.