Java OpenTelemetry Instrumentation

This document contains instructions on how to set up OpenTelemetry instrumentation in your Java applications and view your application traces in SigNoz.

OpenTelemetry Java is the language-specific implementation of OpenTelemetry in Java.

Requirements

Java 8 or higher

Send Traces to SigNoz Cloud

OpenTelemetry provides a handy Java JAR agent that can be attached to any Java 8+ application and dynamically injects bytecode to capture telemetry from a number of popular libraries and frameworks.

Based on your application environment, you can choose the setup below to send traces to SigNoz Cloud.

From VMs, there are two ways to send data to SigNoz Cloud.

Send traces directly to SigNoz Cloud

OpenTelemetry Java agent can send traces directly to SigNoz Cloud.

Step 1. Download otel java binary agent

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

Step 2. Run your application

OTEL_RESOURCE_ATTRIBUTES=service.name=<service_name> \
OTEL_EXPORTER_OTLP_HEADERS="signoz-ingestion-key=<your-ingestion-key>" \
OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.<region>.signoz.cloud:443 \
java -javaagent:$PWD/opentelemetry-javaagent.jar -jar <my-app>.jar
  • Set the <region> to match your SigNoz Cloud region
  • Replace <your-ingestion-key> with your SigNoz ingestion key.
  • <service_name> is name of your service

In case you encounter an issue where all applications do not get listed in the services section then please refer to the troubleshooting section.


Send traces via OTel Collector binary

Step 1. Download OTel java binary agent

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

Step 2. Run your application

java -javaagent:$PWD/opentelemetry-javaagent.jar -jar <myapp>.jar
  • <myapp> is the name of your application jar file
  • In case you download opentelemetry-javaagent.jar file in different directory than that of the project, replace $PWD with the path of the otel jar file.

In case you encounter an issue where all applications do not get listed in the services section then please refer to the troubleshooting section.

Validating instrumentation by checking for traces

With your application running, you can verify that you’ve instrumented your application with OpenTelemetry correctly by confirming that tracing data is being reported to SigNoz.

To do this, you need to ensure that your application generates some data. Applications will not produce traces unless they are being interacted with, and OpenTelemetry will often buffer data before sending. So you need to interact with your application and wait for some time to see your tracing data in SigNoz.

Validate your traces in SigNoz:

  1. Trigger an action in your app that generates a web request. Hit the endpoint a number of times to generate some data. Then, wait for some time.
  2. In SigNoz, open the Services tab. Hit the Refresh button on the top right corner, and your application should appear in the list of Applications. Ensure that you're checking data for the time range filter applied in the top right corner.
  3. Go to the Traces tab, and apply relevant filters to see your application’s traces.

You might see other dummy applications if you’re using self-hosted SigNoz for the first time. You can remove it by following the docs here.

If you don't see your application reported in the list of services, try our troubleshooting guide.

Configuring the agent

The agent is highly configurable. You can check out all the configuration options available here.

Disabled instrumentations

Some instrumentations can produce too many spans and make traces very noisy. For this reason, the following instrumentations are disabled by default:

  • jdbc-datasource which creates spans whenever the java.sql.DataSource#getConnection method is called.
  • dropwizard-metrics, which might create very low-quality metrics data because of the lack of label/attribute support in the Dropwizard metrics API.

To enable them, add the otel.instrumentation.<name>.enabled system property: -Dotel.instrumentation.jdbc-datasource.enabled=true

Manual Instrumentation

For manual instrumentation of Java application, refer to the docs here.

Sample Java Application

Was this page helpful?