tencent cloud

Automatic Connecting Java Application for the K8s Environment (Recommended)
Last updated:2026-01-29 10:45:57
Automatic Connecting Java Application for the K8s Environment (Recommended)
Last updated: 2026-01-29 10:45:57
For Java applications deployed on Kubernetes, APM offers automatic connection schemes that enable agent auto-injection to facilitate quick application integration.
Java applications that are automatically connected in the K8s environment will be automatically injected with the Tencent Cloud OpenTelemetry Java Agent Enhanced Edition (TencentCloud-OTel Java Agent). The Tencent Cloud OpenTelemetry Java Agent Enhanced Edition is based on the secondary development of OpenTelemetry-java-instrumentation from the open-source community, adhering to the Apache License 2.0 protocol. The OpenTelemetry License is cited within the agent package. Building upon the open-source agent, the Tencent Cloud OpenTelemetry Java Agent Enhanced Edition has improved significantly in Event Tracking density, advanced diagnosis, performance protection, and enterprise-level capabilities.

Prerequisites

See Supported Java Versions and Frameworks by the OTel Java Agent Enhanced Edition to ensure that the Java version and application server are within the supported range by the agent. For the dependency libraries and frameworks supported by automatic tracing, data reporting can be completed upon successful connection without modifying the code. In addition, the Tencent Cloud OpenTelemetry Java Agent Enhanced Edition adheres to the OpenTelemetry protocol standard. if automatic Event Tracking does not meet your scenario, or you need to add business layer Event Tracking, use OpenTelemetry API for Custom Metrics Definition.

Step 1: Install Operator.

Install Operator in the K8s cluster, it's recommended to install Operator with one click on the APM console, for details see installing tencent-opentelemetry-operator.

Step 2: Add annotation to workload.

Take Tencent Kubernetes Engine (TKE) as an example. You can add annotation in the workload through the following procedure. For common K8s clusters, use tools such as kubectl to add annotation.
1. Log in to TKE console.
2. Click Cluster to enter the corresponding TKE cluster.
3. In Workload, you can find the application that needs to connect APM, click More, then click Edit YAML.
4. Add the following content in the Pod annotation, then click Complete to finish the connection.
cloud.tencent.com/inject-java: "true"
cloud.tencent.com/otel-service-name: my-app # Application name. Processes of connecting with the same application name are displayed as multiple instances under the same application in APM.
# The application name can be up to 63 characters and can only contain lowercase letters, digits, and the separator (-), and it must start with a lowercase letter and end with a digit or lowercase letter.
Note that this content needs to be added to spec.template.metadata.annotations, affecting the Pod's annotation, not the workload's annotation. You can see the following code snippet:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
k8s-app: my-app
name: my-app
namespace: default
spec:
selector:
matchLabels:
k8s-app: my-app
template:
metadata:
labels:
k8s-app: my-app
annotations:
cloud.tencent.com/inject-java: "true" # Add it here.
cloud.tencent.com/otel-service-name: my-app
spec:
containers:
image: my-app:0.1
name: my-app

Connection Verification

After annotations are added to the workload, based on different publish policies, you can trigger a restart of the application pod. The newly launched pod will automatically inject the agent and connect to the APM server to report monitoring data, with the reported business system being the default business system of the Operator. Under normal traffic conditions, the connected application will be displayed in Application Performance Management > Application list. Click Application name/ID to go to the application details page. Select Instance Analysis to view the connected application instances. Since there is a certain latency in the processing of observable data, if the application or instance does not appear in the console after connecting, wait for about 30 seconds.

Custom Event Tracking

When automatic instrumentation does not meet your scenario, or you need to add business layer instrumentation, see Custom Event Tracking and use the OpenTelemetry API to add custom instrumentation.

More Connection Configuration Items (Optional)

At the Workload level, you can add more annotations to adjust the connect behaviors:
Configuration Item
Description
cloud.tencent.com/apm-token
Specify the Token for the APM business system. If this configuration item is not added, the Operator's configuration is used (corresponding to the Operator's env.APM_TOKEN field).
cloud.tencent.com/java-instr-version
Specify the Java agent version. If this configuration item is not added, the configuration of the Operator is used (corresponding to the Operator's env.JAVA_INSTR_VERSION field). The value can be latest (default) or a specific version number. For a list of specific version numbers, see Agent Version Information. It is not recommended to fill in this field unless necessary.
cloud.tencent.com/container-names
Specify the container for agent injection. This configuration item supports injecting probes into multiple containers. Just fill in the names of multiple containers in the value of this configuration item and separate them with commas. If this configuration item is not added, the probe will be default injected into the first container. This configuration item is supported in Operator 0.88 and above versions.

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback