Using OpenTelemetry to Provide Traceability for Non-Containerized Java Services
TOC
Overview
This solution will guide you on how to modify non-containerized Java services deployed on virtual machines or physical machines to view their invocation chains with containerized services on the platform. Please note that this solution only provides traceability functionality and does not support viewing logs.
Prerequisites
- Your Java service is deployed on virtual or physical machines and requires traceability functionality.
- A service mesh has been created on the cluster.
- You have access to the control nodes of the Kubernetes cluster, and the
kubectltool is installed.
Steps
1. Download and Configure the OpenTelemetry Java Agent
First, you need to copy the OpenTelemetry Java Agent jar file to the ./agent directory on the control node of the cluster where the service mesh was created.
Select and execute the appropriate script based on the cluster's runtime component
-
Containerd Runtime Component
-
Install the
nerdctltool on the control node. Download it, extract the package, grant execution permission, and copy it to the/usr/local/bindirectory: -
Log in to the image repository used by the cluster, replacing
<image_registry_address>with the actual address: -
Run the following script to copy the Java Agent jar file from the image to the local system:
-
-
Docker Runtime Component
-
Log in to the image repository used by the cluster:
-
Run the following script to copy the Java Agent jar file from the image to the local system:
-
2. Distribute the Java Agent to Java Service Nodes
Copy the opentelemetry-javaagent-ext.jar obtained in step 1 to the ./agent directory on all nodes running Java services.
3. Set Environment Variables
Configure the following environment variables on all Java service nodes:
4. Modify the Java Service Startup Script
In the startup script of the Java service, add the following parameter:
5. Create a ConfigMap
In the namespace where you want to enable the traceability feature, create a ConfigMap to store the mapping between the addresses and names of non-containerized Java services. Example:
- The
host,port, andserviceNamemust correspond to the access address, port, and service name of the non-containerized services. TheserviceNamemust match theservice.namedefined in theOTEL_RESOURCE_ATTRIBUTESenvironment variable.
6. Restart the Java Service
After applying the above configurations, restart the Java service to make the changes take effect.