tencent cloud

All product documents
Tencent Cloud Observability Platform
Customize Application Instance Attributes
Last updated: 2025-03-12 11:43:26
Customize Application Instance Attributes
Last updated: 2025-03-12 11:43:26
When an application is integrated with APM, for each application instance, users can customize a series of instance attributes to achieve query filtering and data aggregation based on instance attributes. In the observable data generated by the application instance, the corresponding instance attribute information will be attached. For example, in the application details feature provided by APM, users can filter target instances based on instance attributes and analyze the performance under specific K8s clusters, K8s workloads, and application image versions. In container monitoring, CVM monitoring and other features provided by APM, it is necessary to associate other cloud products through instance attributes to achieve integrated observability.

APM-Supported Instance Attributes

Attribute Name
Key
Required
Scenarios Where Automatic Injection Is Possible
Instance name
host.name
Yes
Connect via Tencent Cloud Enhanced Java Agent
Connect via Skywalking Solution
TKE environment can be integrated with one click via tencent-opentelemetry-operator
CVM region
cvm.region
No
Connecting via Tencent Cloud OpenTelemetry Java Agent Enhanced Edition
CVM instance ID
cvm.instance.id
No
Connecting via Tencent Cloud OpenTelemetry Java Agent Enhanced Edition
TKE region
k8s.region
No
One-click integration of TKE environment via Tencent OpenTelemetry Operator
TKE cluster ID
k8s.cluster.id
No
One-click integration of TKE environment via Tencent OpenTelemetry Operator
K8s node IP
k8s.node.ip
No
One - click connection of TKE environment through Tencent OpenTelemetry Operator.
K8s namespace.
k8s.namespace.name
No
One-click integration of TKE environment via Tencent OpenTelemetry Operator
Name of K8s Deployment.
k8s.deployment.name
No
One-click integration of TKE environment via Tencent OpenTelemetry Operator
Name of K8s Pod.
k8s.pod.name
No
One-click integration of TKE environment via Tencent OpenTelemetry Operator
K8s Pod IP
k8s.pod.ip
No
One-click integration of TKE environment via Tencent OpenTelemetry Operator
Application version.
service.version
No
One-click integration of TKE environment via Tencent OpenTelemetry Operator
Custom field 1
custom_key_1
No
-
Custom field 2
custom_key_2
No
-
Custom Field 3
custom_key_3
No
-

Manually Set Instance Attributes

Note:
Only applications connected through the OpenTelemetry scheme are supported.
In scenarios where instance attributes can be automatically injected, do not override them by manual settings.
When connecting an application, instance attributes need to be filled in the Resource Attributes along with token and service.name. In the OpenTelemetry standard, Resource Attributes reflect the basic information of an application instance in the form of key-value pairs. Users can set instance attributes through environment variables or in the access code. The specific setting method is consistent with the way token and service.name are set when connecting the application.

Method 1: Set Instance Attributes Through Environment Variables

Add instance attributes to the environment variable OTEL_RESOURCE_ATTRIBUTES. Eventually, OTEL_RESOURCE_ATTRIBUTES will be displayed in a format similar to key1=value1,key2=value2,key3=value3.
Refer to the following code to set two instance attributes: k8s.region and k8s.cluster.id.
export OTEL_RESOURCE_ATTRIBUTES="service.name=myService,token=myToken"
export OTEL_RESOURCE_ATTRIBUTES="$OTEL_RESOURCE_ATTRIBUTES,k8s.region=ap-guangzhou,k8s.cluster.id=cls-7i2n4axx"
For applications deployed in Kubernetes (without one-click integration via tencent-opentelemetry-operator), instance attributes can also be set in the workload YAML file through OTEL_RESOURCE_ATTRIBUTES environment variable, refer to the following code snippet:
spec:
containers:
- env:
- name: OTEL_RESOURCE_ATTRIBUTES
value: "service.name=myService,token=myToken,k8s.region=ap-guangzhou,k8s.cluster.id=cls-7i2n4axx"
For applications in TKE environment integrated with one click via tencent-opentelemetry-operator, instance attributes that have not been automatically injected can be set in the workload YAML file, refer to the following code snippet:
spec:
containers:
- env:
- name: OTEL_RESOURCE_ATTRIBUTES
value: "custom_key_1=value1,custom_key_2=value_2,cvm.region=ap-guangzhou,cvm.instance.id=ins-3flvdptq"
Note:
For applications in the TKE environment that are connected with one click through tencent-opentelemetry-operator, besides the instance attributes that can be automatically injected, token and service.name have also been automatically injected. Do not overwrite them in the Yaml file through the OTEL_RESOURCE_ATTRIBUTES environment variable.

Method 2: Set Instance Attributes In the Access Code

If integrating an application through code, you can directly set instance attributes in the integration code. For example, in a Go application:
import (
"context"
"errors"
"os"
"go.opentelemetry.io/otel/sdk/resource"
)
r, err := resource.New(ctx, []resource.Option{
resource.WithAttributes(
attribute.KeyValue{Key: "token", Value: attribute.StringValue("my-token")},
attribute.KeyValue{Key: "service.name", Value: attribute.StringValue("my-service")},
attribute.KeyValue{Key: "host.name", Value: attribute.StringValue("10.10.0.1")},
attribute.KeyValue{Key: "k8s.region", Value: attribute.StringValue("ap-guangzhou")},
attribute.KeyValue{Key: "k8s.cluster.id", Value: attribute.StringValue("cls-7i2n4ace")},
),
}...)

How To Dynamically Obtain Pod Names

Since information such as Pod name, Pod IP, and node IP can only be determined after the Pod is created, during the deployment of workloads, you can dynamically obtain this information through Kubernetes Downward API and write it into environment variables for future reference, making it convenient to manually set instance attributes.
spec:
containers:
- env:
- name: POD_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
- name: POD_IP
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.podIP
- name: NODE_IP
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.hostIP
After saving to environment variables, they can be directly referenced, for example:
spec:
containers:
- env:
- name: OTEL_RESOURCE_ATTRIBUTES
value: "service.name=myService,token=myToken,k8s.pod.ip=$(POD_IP),k8s.pod.name=$(POD_NAME)"
Note:
For applications in the TKE environment that are connected with one click through tencent-opentelemetry-operator, instance attributes such as Pod name, Pod IP and node IP have all been automatically injected. Do not overwrite them in the Yaml file through the OTEL_RESOURCE_ATTRIBUTES environment variable.




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

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 available.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon