> ## Documentation Index
> Fetch the complete documentation index at: https://docs.appsignal.com/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenTelemetry Java Installation

Please follow the [installation guide](/guides/new-application) first, when adding a new application to AppSignal.

Then make sure to [install the AppSignal collector](/collector/installation) before proceeding.

To install and configure OpenTelemetry for your Java application, we recommend using the OpenTelemetry Java agent to export data to the AppSignal collector. This agent will automatically instrument your application.

## Download the OpenTelemetry Java agent

Download the OpenTelemetry Java agent from the [latest release on Github](https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar). When running your application, the OpenTelemetry Java agent will need to be present.

## Run your application with the agent

When running your application, you will need to configure the Java runtime to load the OpenTelemetry Java agent. Change how you start your application to load the OpenTelemetry Java agent with your application:

<CodeGroup>
  ```shell Shell theme={null}
  java -javaagent:/path/to/opentelemetry-javaagent.jar -jar your-application.jar
  ```
</CodeGroup>

Replace `/path/to/opentelemetry-javaagent.jar` with the path to the downloaded agent and `your-application.jar` with the path to your application's JAR file.

### Gradle

When using Gradle, you can add the agent to the task that starts your application in the `build.gradle` file:

<CodeGroup>
  ```groovy title="build.gradle.kts" theme={null}
  tasks.bootRun {
      jvmArgs = listOf("-javaagent:/path/to/opentelemetry-javaagent.jar")
      // With any other configuration after
  }
  ```
</CodeGroup>

## Configure the agent

The agent may be configured using Java properties or environment variables. We recommend using environment variables for configuration. First, configure the agent to export traces and logs to the AppSignal collector:

<CodeGroup>
  ```shell Shell theme={null}
  # Export traces and metrics to the AppSignal collector using the OTLP protocol.
  # Replace `http://localhost:8099` with the address of your AppSignal collector
  # if it's running on another host.
  export OTEL_TRACES_EXPORTER=otlp
  export OTEL_METRICS_EXPORTER=otlp
  export OTEL_LOGS_EXPORTER=otlp
  export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
  export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:8099
  ```
</CodeGroup>

Then, configure the OpenTelemetry resource attributes required by AppSignal:

<CodeGroup>
  ```shell Shell theme={null}
  # Replace these values with your AppSignal application name, environment
  # and push API key. These are used by the resource attributes configuration below.
  APPSIGNAL_APP_NAME=your-app-name
  APPSIGNAL_APP_ENV=production
  APPSIGNAL_PUSH_API_KEY=your-push-api-key

  # Optionally, set a custom revision and hostname. If not set, the resource attributes
  # configuration below will use the current Git revision and system hostname.
  # REVISION=your-custom-revision
  # HOSTNAME=your-custom-hostname

  # Set the name of the service that is being monitored. A common choice is the
  # name of the framework used. This is used to group traces and metrics in AppSignal.
  export OTEL_SERVICE_NAME=my-service-name

  export OTEL_RESOURCE_ATTRIBUTES="\
  appsignal.config.name=$APPSIGNAL_APP_NAME,\
  appsignal.config.environment=$APPSIGNAL_APP_ENV,\
  appsignal.config.push_api_key=$APPSIGNAL_PUSH_API_KEY,\
  appsignal.config.revision=${REVISION:-$(git rev-parse --short HEAD 2>/dev/null || echo unknown)},\
  appsignal.config.language_integration=java,\
  appsignal.config.app_path=$PWD,\
  host.name=${HOSTNAME:-$(hostname)}\
  "
  ```
</CodeGroup>

## Test the app!

Now that all the components are connected, start your app with the required environment variables and test if you see data arrive in AppSignal. Check the ["Errors > Issue list"](https://appsignal.com/redirect-to/app?to=exceptions) and ["Performance > Traces"](https://appsignal.com/redirect-to/app?to=performance/traces) page specifically.

If after following our installation instructions you still don't see data in AppSignal, [let us know](mailto:support@appsignal.com?subject=OpenTelemetry%20beta%20issue) and we'll help you finalize your OpenTelemetry installation!
