tencent cloud

Feedback

Automatic Connecting Node.js Applications for TKE Environment (Recommended)

Last updated: 2024-06-19 16:31:30
    For Node.js applications deployed on TKE, APM provides an automatic connect scheme. This allows for the automatic injection of agents after the application is deployed to TKE, facilitating quick connection.
    TKE environment automatically connected Node.js applications will use the community OpenTelemetry-JavaScript scheme for agent injection. For more information about OpenTelemetry-JavaScript, see the community OpenTelemetry-Javascript project.

    Prerequisites

    See OpenTelemetry-JavaScript scheme supported components and frameworks to ensure that the Node.js version, dependency libraries, and frameworks are within the supported range of the agent. For dependency libraries and frameworks supported by automatic Event Tracking, data reporting can be completed after a successful connection without modifying the code. If automatic Event Tracking does not meet your needs, or you need to add business layer instrumentation, use OpenTelemetry API for custom metrics.

    Step 1: Install Operator.

    Install Operator in the TKE 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.

    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. Apply the following content in the Pod annotation, then click Complete to finish the connection.
    cloud.tencent.com/inject-nodejs: "true"
    cloud.tencent.com/otel-service-name: my-app # Application name, processes that connect using the same application name are displayed in APM as multiple instances under the same application.
    # 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-nodejs: "true" # Add here
    cloud.tencent.com/otel-service-name: my-app
    spec:
    containers:
    image: my-app:0.1
    name: my-app

    Connection Verification

    After an annotation is added to the workload, based on different publish policies, it triggers the restart of the application Pod. The newly started Pod will automatically inject an agent and connect to the APM server to report monitoring data, with the business system reported being the default for Operator. Under normal traffic conditions, the connected applications will be displayed in APM > Application monitoring > Application list , and the connected application instances will be displayed in APM > Application monitoring > App details > Instance monitoring. Due to a certain delay in processing observable data, if the application or instance is not found in the console immediately after connection, wait for about 30 seconds.

    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 configuration of the Operator is used (corresponding to the Operator's env.APM_TOKEN field).
    cloud.tencent.com/nodejs-instr-version
    Specify the Node.js agent version. If this configuration item is not added, the Operator's configuration is used (corresponding to the Operator'snullenv.NODEJS_INSTR_VERSION field). The values 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.
    
    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 avaliable.

    7x24 Phone Support