Docs » Collect application spans and traces » Instrument Java applications for Splunk Observability Cloud » Instrument a Java application for Splunk Observability Cloud

Instrument a Java application for Splunk Observability Cloud 🔗

The Java agent from the Splunk Distribution of OpenTelemetry Java can automatically instrument your Java application by injecting instrumentation to Java classes.


To generate all the basic install commands for your environment and application, open the Observability Cloud wizard in Data Setup > APM Instrumentation > Java > Add Connection.

Install and enable the Java agent 🔗

Follow these steps to automatically instrument your application using the Java agent:

  1. Check that you meet the requirements. See Java agent compatibility and requirements.

  2. Make sure that the collector you set up to receive trace data is installed and configured.

  3. Download the JAR file for the latest version of the agent:

    curl -L \
    -o splunk-otel-javaagent.jar
  4. Set the OTEL_SERVICE_NAME environment variable:

    export OTEL_SERVICE_NAME=<yourServiceName>
  5. Set the -javaagent argument to the path of the Java agent:

    java -javaagent:./splunk-otel-javaagent.jar \
    -jar <myapp>.jar


    If your application runs on a supported Java server, see Define agent paths for Java application servers for Splunk Observability Cloud.

By default, tracing uses the Splunk OTel connector to send trace data to Observability Cloud. If no data appears in Observability > APM, see Troubleshoot Java instrumentation for Splunk Observability Cloud.


If you need to add custom attributes to spans or want to manually generate spans, you need to manually instrument your Java application or service. See Manually instrument Java applications for Splunk Observability Cloud.

Deploy the Java agent in Kubernetes 🔗

To deploy the Java agent in Kubernetes, configure the Kubernetes Downward API to expose environment variables to Kubernetes resources.

The following example shows how to update a deployment to inject environment variables by adding the agent configuration under the .spec.template.spec.containers.env section:

      - env:
      - name: SPLUNK_OTEL_AGENT
            fieldPath: status.hostIP
         value: "http://$(SPLUNK_OTEL_AGENT):4317"
      - name: OTEL_SERVICE_NAME
         value: "<serviceName>"
         value: 'deployment.environment=<environmentName>'
      image: my-image
      name: myapp

Configure the Java agent 🔗

You can configure the agent using environment variables or by setting system properties as runtime arguments. For more details about both methods, see Configuration methods.

In most cases, the only configuration setting you need to enter is the service name. You can also define other basic settings, like the deployment environment, the service version, and the endpoint, among others.

  • To set the deployment environment, provide a value for the deployment.environment attribute by entering the following command:

    export OTEL_RESOURCE_ATTRIBUTES='deployment.environment=<envtype>'
  • To set the service version, provide a value for the service.version attribute by entering the following command:

    export OTEL_RESOURCE_ATTRIBUTES='deployment.environment=<envtype>,service.version=<version>'
  • To use an exporter endpoint different than the default value, set the endpoint environment variable for the exporter:

    export OTEL_EXPORTER_OTLP_ENDPOINT='http://<host>:<port>'
  • To enable automatic metric collection, enable the metrics feature using a system property argument. You can also use the SPLUNK_METRICS_ENABLED environment variable.


For advanced configuration of the JVM agent, like changing trace propagation formats, correlating traces and logs, or enabling custom sampling, see Configure the Java agent for Splunk Observability Cloud.

Send data directly to Observability Cloud 🔗

If you need to send data directly to Observability Cloud, set the following environment variables:

export SPLUNK_ACCESS_TOKEN=<access_token>
export OTEL_TRACES_EXPORTER=jaeger-thrift-splunk
export OTEL_EXPORTER_JAEGER_ENDPOINT=https://ingest.<realm>

To obtain an access token, see Create and manage user API access tokens.

In the ingest endpoint URL, realm is the O11y realm. For example, us0. To find the realm of your account, open the main menu in Observability Cloud, hover over your user name, and then select Accounts Settings.

Instrument Lambda functions 🔗

You can also instrument AWS Lambda functions. See the Splunk OpenTelemetry Java Lambda Wrapper on GitHub.