Monitoring Java applications with OpenTelemetry and Instana
You can automatically instrument a Java application with the OpenTelemetry Java agent and send metrics and traces to Instana with the Instana agent. You can view the metrics on the Instana UI. Instrumenting a Spring Boot application ('petclinic') with the OpenTelemetry collector Java agent is shown in the following example.
To get started with the OpenTelemetry integration quickly, see the following sample steps:
Prerequisites
- Make sure that the Instana host agent is connected with the Instana backend.
- Make sure that JDK 17 or later is installed and that the
JAVA_HOME
andPATH
environment variables are configured so that Java 17 works optimally.
Sample integration steps
-
Configure the Instana agent configuration file to enable OpenTelemetry data ingestion as follows:
com.instana.plugin.opentelemetry: grpc: enabled: true http: enabled: true
-
Run the
stop
andstart
commands to restart your Instana agent, and ensure that the ports 4317 and 4318 are listened. Check the ports by running the following command:netstat -an | grep 4317
netstat -an | grep 4318
-
Download the Spring Boot demo application by running the following command:
git clone https://github.com/spring-projects/spring-petclinic.git
-
Build the demo application by running the following command:
cd spring-petclinic ./mvnw clean package -Dmaven.test.skip=true
-
Download the OpenTelemetry Java agent by running the following command:
wget https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar
-
Run the application with the OpenTelemetry Java agent as follows:
export OTEL_SERVICE_NAME=my-service export OTEL_TRACES_EXPORTER=otlp export OTEL_METRICS_EXPORTER=otlp export OTEL_LOGS_EXPORTER=otlp export OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4317" export OTEL_EXPORTER_OTLP_PROTOCOL=grpc export OTEL_RESOURCE_ATTRIBUTES="service.instance.id=petclinic,INSTANA_PLUGIN=jvm" export OTEL_EXPORTER_OTLP_HEADERS="x-instana-key=instanalocal" java -javaagent:./opentelemetry-javaagent.jar -jar target/*.jar --server.port=28080
-
Open a browser, and go to
http://localhost:28080
or change to the IP address of the host that is running the demo application. Click the Find Owners menu and Find Owners button, and take whatever actions you like to generate the OpenTelemetry data. -
Find the OpenTelemetry entity and its metrics.
-
Open the Instana UI, and click Infrastructure. Then, click Analyze Infrastructure.
-
Select OpenTelemetry from the list of types of the entities. Click the entity instance that is named
petclinic@my-service
to open the associated dashboard and lists all its metadata and metrics. You can also use this OpenTelemetry entity in a custom dashboard.
-
-
Find the traces or calls of the OpenTelemetry entity.
Open the Instana UI, click Analytics, and then input the following filter:
You can see a list of calls that you made. Click one of them to display the trace view of the OpenTelemetry call.