OpenTelemetry Java Installation
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.
Make sure to install the AppSignal collector before proceeding with these instructions.
Download the OpenTelemetry Java agent
Download the OpenTelemetry Java agent from the latest release on Github. 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 OpenTelmetry Java agent with your application:
java -javaagent:/path/to/opentelemetry-javaagent.jar -jar your-application.jar
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:
bootRun { jvmArgs = ["-javaagent:/path/to/opentelemetry-javaagent.jar"] }
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:
# 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_EXPORTER_OTLP_PROTOCOL=http/protobuf export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:8099 # The AppSignal collector does not currently support logging. # Disable the logging exporter to silence export errors. export OTEL_LOGS_EXPORTER=none
Then, configure the OpenTelemetry resource attributes required by AppSignal:
# 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)},\ appsignal.config.language_integration=java,\ appsignal.config.app_path=$PWD,\ host.name=${HOSTNAME:-$(hostname)}\ "
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" and "Performance > Traces" page specifically.
If after following our installation instructions you still don't see data in AppSignal, let us know and we'll help you finalize your OpenTelemetry installation!