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.
kubectl
tool is installed.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 nerdctl
tool on the control node. Download it, extract the package, grant execution permission, and copy it to the /usr/local/bin
directory:
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:
Copy the opentelemetry-javaagent-ext.jar
obtained in step 1 to the ./agent
directory on all nodes running Java services.
Configure the following environment variables on all Java service nodes:
Environment Variable | Description |
---|---|
OTEL_PROPAGATORS | The propagation format for trace data. Available values: b3 , b3multi . Multiple values can be separated by commas. |
OTEL_TRACES_EXPORTER | Trace data exporter. The value must be otlp . |
OTEL_EXPORTER_OTLP_ENDPOINT | The OTLP data reporting address in the format http://<ASM_OTEL_COLLECTOR_IP>:4317 , where ASM_OTEL_COLLECTOR_IP is the IP accessible to the service mesh component. |
OTEL_RESOURCE_ATTRIBUTES | Custom tags. Required fields: service.name , vm.name . For example: service.name=myservice.ns,vm.name=vm-test . vm.name refers to the name of the virtual machine where the service is hosted, and service.name specifies the name displayed in the invocation chain. You may add other custom tags, and it is recommended to use the vm prefix to identify VM services. Multiple key-value pairs can be separated by commas. |
In the startup script of the Java service, add the following parameter:
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:
host
, port
, and serviceName
must correspond to the access address, port, and service name of the non-containerized services. The serviceName
must match the service.name
defined in the OTEL_RESOURCE_ATTRIBUTES
environment variable.After applying the above configurations, restart the Java service to make the changes take effect.