All Products
Search
Document Center

Container Service for Kubernetes:Use an AlbConfig to enable Xtrace for Tracing Analysis

Last Updated:Mar 26, 2026

Managed Service for OpenTelemetry gives you end-to-end visibility into requests flowing through your microservices. By enabling Xtrace in AlbConfig, ALB attaches trace IDs to every request at the ingress layer — so you can correlate access logs with distributed traces without instrumenting each service individually.

Prerequisites

Before you begin, ensure that you have:

How it works

When a request enters the ALB listener, ALB generates a trace ID and injects it into the request headers using the Zipkin sampling algorithm. The request, together with its trace ID, is forwarded to the backend service. Access logs for each request — including the trace ID — are written to a Simple Log Service (SLS) Logstore. Managed Service for OpenTelemetry reads these logs and reconstructs the full trace, which you can then view in the OpenTelemetry console.

Xtrace is configured at the listener level in AlbConfig. The sampling rate applies uniformly to all traffic on that listener.

Enable Xtrace for ALB Ingress

Step 1: Enable Simple Log Service for the cluster

Enable Simple Log Service for your cluster. After enabling, the cluster automatically creates an SLS project. For instructions, see Collect logs from ACK cluster containers.

Step 2: Get the SLS project ID

  1. Log on to the ACK console and click Clusters in the left navigation pane.

  2. Click the name of your cluster, then click Cluster Information in the left navigation pane.

  3. On the Basic Information tab, copy the value from the Simple Log Service Project field. You will use this ID in the next step.

Step 3: Create an AlbConfig

The AlbConfig creates an ALB instance with Simple Log Service access logs enabled and Xtrace configured on the listener.

  1. Create alb-test.yaml with the following content:

    You can only modify Xtrace settings after Simple Log Service access logs are enabled on the ALB instance. If you are reusing an existing ALB instance, set forceOverride: true under spec.config to overwrite its existing properties. See Reuse an existing ALB instance.
    For instructions on creating a vSwitch, see Create and manage vSwitches.

    Xtrace parameter reference

    Parameter Description Default Range
    tracingEnabled Enables Xtrace on the listener false true / false
    tracingSample Sampling rate. 10000 = 100%, 5000 = 50%, 1 = 0.01% 1–10000
    tracingType Sampling algorithm Zipkin
    apiVersion: alibabacloud.com/v1
    kind: AlbConfig
    metadata:
      name: alb-demo
    spec:
      config:
        name: alb-test
        addressType: Intranet
        zoneMappings: # The vSwitch must be in an ALB-supported zone and the same VPC as the cluster. Select at least two vSwitches in different zones for high availability.
        - vSwitchId: vsw-2vc82nndnoo**********  # Replace with your vSwitch ID.
        - vSwitchId: vsw-2vc30f5mlhs**********
        accessLogConfig:
          logProject: "k8s-log-xz92lvykqj1siwvif****"  # Replace with your SLS project ID from Step 2.
          logStore: alb_xz92lvykqj1siwvif****           # Must start with "alb_". Created automatically if it does not exist.
      listeners:
      - port: 80
        protocol: HTTP
        logConfig:
          accessLogRecordCustomizedHeadersEnabled: false
          accessLogTracingConfig:
            tracingEnabled: true    # Set to true to enable Xtrace. Default: false.
            tracingSample: 9999     # Sampling rate. Range: 1-10000, where 10000 = 100%. Example: 9999 = 99.99%.
            tracingType: Zipkin     # Sampling algorithm. Only takes effect when tracingEnabled is true.
  2. Apply the AlbConfig:

    kubectl apply -f alb-test.yaml

    Expected output:

    albconfig.alibabacloud.com/alb-demo created

Step 4: Create an IngressClass

  1. Create alb.yaml with the following content:

    apiVersion: networking.k8s.io/v1
    kind: IngressClass
    metadata:
      name: alb
    spec:
      controller: ingress.k8s.alibabacloud/alb
      parameters:
        apiGroup: alibabacloud.com
        kind: AlbConfig
        name: alb-demo
  2. Apply the IngressClass:

    kubectl apply -f alb.yaml

    Expected output:

    ingressclass.networking.k8s.io/alb created

Step 5: Deploy a service and configure Ingress routing

  1. Create cafe-service.yaml with the following content to deploy a coffee Deployment and coffee-svc Service:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: coffee
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: coffee
      template:
        metadata:
          labels:
            app: coffee
        spec:
          containers:
          - name: coffee
            image: registry.cn-hangzhou.aliyuncs.com/acs-sample/nginxdemos:latest
            ports:
            - containerPort: 80
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: coffee-svc
    spec:
      ports:
      - port: 80
        targetPort: 80
        protocol: TCP
      selector:
        app: coffee
      type: NodePort
  2. Deploy the Deployment and Service:

    kubectl apply -f cafe-service.yaml

    Expected output:

    deployment.apps/coffee created
    service/coffee-svc created
  3. Create cafe-ingress.yaml to configure Ingress routing rules:

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: cafe-ingress
    spec:
      ingressClassName: alb
      rules:
       - host: demo.domain.ingress.top
         http:
          paths:
          - path: /coffee
            pathType: ImplementationSpecific
            backend:
              service:
                name: coffee-svc
                port:
                  number: 80
  4. Apply the Ingress:

    kubectl apply -f cafe-ingress.yaml

    Expected output:

    ingress.networking.k8s.io/cafe-ingress created

Step 6: Configure domain name resolution

If you set a custom domain in spec.rules.host, add a CNAME record for that domain pointing to the ALB DNS name. For instructions, see Create and use an ALB Ingress to expose Services to external traffic.

Step 7: Send requests to generate trace data

  1. Get the ALB instance address:

    kubectl get ing

    Expected output:

    NAME           CLASS   HOSTS                     ADDRESS                                              PORTS   AGE
    cafe-ingress   alb     demo.domain.ingress.top   alb-u53i28ewt580*****.cn-<Region>.alb.aliyuncs.com   80      16m
  2. Send a request to the service:

    The number of requests needed before traces appear in the console depends on your sampling rate. With tracingSample: 9999 (99.99%), a single request is enough. With a lower rate — for example, tracingSample: 100 (1%) — send at least 100 requests to ensure a trace is captured: ``bash for i in $(seq 1 100); do curl -s -o /dev/null -H Host:demo.domain.ingress.top http://alb-u53i28ewt580*****.cn-<Region>.alb.aliyuncs.com/coffee; done ``
    curl -H Host:demo.domain.ingress.top http://alb-u53i28ewt580*****.cn-<Region>.alb.aliyuncs.com/coffee

    The response is an HTML page with the title Hello World.

Verify tracing

Check SLS access logs

  1. Log on to the ACK console and click Clusters.

  2. Click your cluster name, then click Cluster Information.

  3. On the Basic Information tab, click the link in the Simple Log Service Project field to open the SLS console. In the left navigation pane, click the Logstore whose name starts with alb_ (for example, alb_xz92lvykqj1siwvif****). Search for xtrace to confirm that requests contain Xtrace data.

    image

View traces in the OpenTelemetry console

  1. Log on to the Managed Service for OpenTelemetry console.

  2. On the Applications page, select the region from the top navigation bar and click your application name.

  3. In the left navigation pane, click API Calls, then click the Trace tab to view trace data. The tab shows up to 100 traces with the longest duration. For more information, see Interface Calls.

What's next