Non-Intrusive Integration of Tracing in Java Applications
Feature Overview
Tracing is a core capability of observability in distributed systems, which can fully record the call paths and performance data of requests within the system. This article describes how to achieve non-intrusive integration of tracing in Java applications using the automatic injection of the OpenTelemetry Java Agent.
Use Cases
Java applications can be integrated for the following scenarios:
- Quickly adding tracing capabilities to Java applications
- Avoiding modifications to the application source code
- Deploying services with Kubernetes
- Visualizing service inter-call relationships and analyzing performance bottlenecks
Prerequisites
Before using this feature, ensure that:
- The target service is deployed on the Alauda Container Platform
- The service is using JDK version Java 8 or higher
- You have editing permissions for the Deployment in the target namespace
- The platform has completed tracing deployment
Steps to Operate
For a Java application that needs to be integrated into the Alauda Container Platform tracing, the following adaptations are required:
- Configure automatic injection annotations for the Java Deployment.
- Set the
SERVICE_NAME
environment variable.
- Set the
SERVICE_NAMESPACE
environment variable.
Example of Deployment adaptation:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-java-deploy
spec:
template:
metadata:
annotations:
instrumentation.opentelemetry.io/inject-java: cpaas-system/acp-common-java
labels:
app.kubernetes.io/name: my-java-app
spec:
containers:
- env:
- name: SERVICE_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.labels['app.kubernetes.io/name']
- name: SERVICE_NAMESPACE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
- Choose
cpaas-system/acp-common-java
Instrumentation as the configuration for injecting the Java Agent.
- Configure the
SERVICE_NAME
environment variable, which can be associated through labels or fixed values.
- Configure the
SERVICE_NAMESPACE
environment variable, with its value as metadata.namespace
.
Operation Results
After adapting the Java application:
- If the newly started Java application pod contains the
opentelemetry-auto-instrumentation-java
init container, it indicates that the injection was successful.
- Send test requests to the Java application.
- In the Container Platform view, select the project, cluster, and namespace where the Java application resides.
- Navigate to the Observability -> Tracing page to view the tracing data and timeline waterfall diagram of the Java application.