OpenTelemetry Java for Uptrace

Getting started

You can instrument Java applications without changing any code by simply attaching a Java agent JAR provided by OpenTelemetry.

Step 1. Download the latest pre-compiled Java agent JAR:

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

Step 2. Configure the agent to export data to Uptrace using environment variables:

export OTEL_TRACES_EXPORTER=otlp
export OTEL_METRICS_EXPORTER=otlp
export OTEL_LOGS_EXPORTER=otlp
export OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp.uptrace.dev:4317
export OTEL_EXPORTER_OTLP_HEADERS="uptrace-dsn=https://<token>@uptrace.dev/<project_id>"
export OTEL_RESOURCE_ATTRIBUTES=service.name=myservice,service.version=1.0.0

Step 3. Enable the agent by providing the -javaagent flag when starting your app:

java -javaagent:path/to/opentelemetry-javaagent.jar \
     -jar myapp.jar

That's it! The agent supports huge number of libraries and frameworksopen in new window and a majority of the most popular application serversopen in new window.

Configuration

The agent can be configuredopen in new window using environment variables, system properties, or a configuration file.

For example, instead of using env variables, you can create uptrace.properties file that contains Java properties:

otel.traces.exporter=otlp
otel.metrics.exporter=otlp
otel.logs.exporter=otlp
otel.exporter.otlp.endpoint=https://otlp.uptrace.dev:4317
otel.exporter.otlp.headers=uptrace-dsn={{ dsn }}
otel.resource.attributes=service.name=myservice,service.version=1.0.0

And pass that file to the agent using the otel.javaagent.configuration-file system property:

java -javaagent:path/to/opentelemetry-javaagent.jar \
     -Dotel.javaagent.configuration-file=path/to/uptrace.properties \
     -jar myapp.jar

Disabling the agent

To disable the agent, pass -Dotel.javaagent.enabled=false or use OTEL_JAVAAGENT_ENABLED=false environment variable.

You can also suppress specific instrumentations by passing -Dotel.instrumentation.[name].enabled=false or using OTEL_INSTRUMENTATION_[NAME]_ENABLED=false environment variable. See documentationopen in new window for the list of instrumentation names.

What's next?

From the blog:

Last Updated: