Use ALB Tracing to Analyze End-to-End Business Transactions

更新时间:
复制 MD 格式

ALB supports tracing. After you enable this feature, ALB automatically injects trace headers when forwarding requests, which helps you obtain complete request tracing data, including the request source, the nodes traversed, and the response time. This lets you quickly locate and resolve performance bottlenecks in distributed architectures.

Background information

Tracing analysis provides developers of distributed applications with tools such as full call chain reconstruction, request volume statistics, topology visualization, and application dependency analysis. These tools help you quickly analyze and diagnose performance bottlenecks in distributed application architectures.

A trace record corresponds to a call chain (Trace). Broadly, a call chain represents the execution path of a transaction or workflow through a distributed system. It is a directed acyclic graph (DAG) composed of multiple spans, where each span represents a named, timed segment of continuous execution within the call chain.

After you enable ALB tracing, ALB automatically injects or updates HTTP trace headers when forwarding requests, and reports the trace data to Alibaba Cloud Managed Service for OpenTelemetry. ALB tracing supports both the OpenTelemetry and Zipkin tracing methods.

Tracing methods

OpenTelemetry

When ALB tracing is enabled and the OpenTelemetry type is selected, ALB adds or updates the traceparent field in the HTTP header before forwarding a request to a backend server. The format of the traceparent field is {version}-{traceid}-{parentid}-{traceflags}. The following table describes each part.

Field

Description

Format

version

The OpenTelemetry version used.

Always 00.

traceid

The ID that identifies this trace.

A 32-digit hexadecimal number.

parentid

The ID that identifies the current node on the trace chain.

A 16-digit hexadecimal number.

traceflags

Indicates whether this request is sampled.

00 (not sampled) or 01 (sampled), determined by the configured sample rate.

Scenario 1: The request does not carry traceparent

When the request header sent by the client does not carry the traceparent field, ALB generates a complete traceparent field and inserts it into the HTTP header.

image

Scenario 2: The request already carries traceparent

When an upstream service already carries the traceparent field in the request header, ALB inherits the version, traceid, and traceflags, and generates only a new parentid.

image

The following table compares the field values:

Part

Upstream request value

ALB forwarded value

Processing

version

00

00

Inherited

traceid

7a3f91c4d8e26b5f9f3a7c1d6b4e8a25

7a3f91c4d8e26b5f9f3a7c1d6b4e8a25

Inherited

parentid

1d9b4e70a6cf3288

c8e14b7a2d95f360

Newly generated

traceflags

00

00

Inherited

Zipkin

When ALB tracing is enabled and the Zipkin type is selected, ALB adds or updates the X-B3-* fields in the HTTP header before forwarding a request to a backend server. The following table describes each field.

Field

Description

Format

X-B3-TraceId

The ID that identifies this trace.

A 16-digit hexadecimal number.

X-B3-SpanId

The ID that identifies the current node on the trace chain.

A 16-digit hexadecimal number.

X-B3-ParentSpanId

The ID that identifies the previous node on the trace chain.

A 16-digit hexadecimal number.

X-B3-Sampled

Indicates whether this request is sampled.

0 (not sampled) or 1 (sampled), determined by the configured sample rate.

Scenario 1: The request does not carry trace headers

When the request header sent by the client does not carry the X-B3-* fields, ALB acts as the origin node of the trace chain and generates the X-B3-TraceId, X-B3-SpanId, and X-B3-Sampled fields and inserts them into the HTTP header. Because there is no upstream node on the chain, the forwarded request does not contain the X-B3-ParentSpanId field.

image

Scenario 2: The request already carries trace headers

When an upstream service already carries the complete X-B3-* fields in the request header, ALB inherits the values of X-B3-TraceId and X-B3-Sampled, generates a new X-B3-SpanId, and passes the X-B3-SpanId from the upstream request to the backend server as the X-B3-ParentSpanId.

image

The following table compares the field values:

Field

Upstream request value

ALB forwarded value

Processing

X-B3-TraceId

7a3f91c4d8e26b5f

7a3f91c4d8e26b5f

Inherited

X-B3-SpanId

1d9b4e70a6cf3288

9f3a7c1d6b4e8a25

Newly generated

X-B3-ParentSpanId

e45c2a9f7b10d36e

1d9b4e70a6cf3288

Uses the upstream SpanId

X-B3-Sampled

1

1

Inherited

Applicable scope

Step 1: Enable tracing

  1. Log on to the ALB console, select the region where your instance is located, find the target instance, and click its instance ID.

  2. Click the Listener tab, find the target listener, and click its listener ID.

  3. In the Tracing section of the Listener Details tab, turn on the Tracing switch.

  4. In the Enable Tracing dialog box, complete the following configurations and click Save.

    • Activate Service

      • Activate Managed Service for OpenTelemetry: If this is your first time using the service, select the service agreement to confirm activation.

    • Create Access Log (if not already created for the target ALB instance)

      • Project: A resource management unit in Simple Log Service used for resource isolation and control.

        • Select Project: Select an existing project from the drop-down list.

        • Create Project: Enter a project name in the field.

      • Logstore: A unit in Simple Log Service for log data collection, storage, and query.

        • Select Logstore: Select an existing Logstore from the drop-down list.

        • Create Logstore: Enter a Logstore name in the field. If you select Create Project, you must also select Create Logstore.

    • Enable Tracing Analysis

      • Tracing Type: You can select OpenTelemetry(W3C) or Zipkin(B3).

      • Sampling Rate: Valid values: 1 to 100. Default value: 100. Adjust the sample rate to control the volume of trace data reported.

    • Notes on Creating Service-linked Role: When you perform this operation, the system automatically creates a service-linked role.

Step 2: View trace data

  1. Log on to a client terminal and test connectivity with the backend server. For more information, see Quickly implement IPv4 load balancing with ALB.

  2. Log on to the ALB console, select the region where your instance is located, find the target instance, and click its instance ID.

  3. Click the Listener tab, find the target listener, and click its listener ID.

  4. In the Tracing section of the Listener Details tab, click View next to Trace Analysis and go to the Managed Service for OpenTelemetry console to view trace data.

    The query bar at the top of the page automatically includes the attributes.app_lb_id and attributes.slb_vport filters. The quick filter panel on the left lets you filter by status, duration range, and application name.

More information

Disable tracing

  • Tracing depends on access logs. Disabling access logs makes tracing unavailable, so proceed with caution. After you disable tracing, access logs remain enabled. If you no longer need them, disable them manually.

  • When tracing is disabled for all listeners under an ALB instance, ALB stops shipping trace data to Managed Service for OpenTelemetry.

Billing

When you use tracing, Alibaba Cloud automatically activates Managed Service for OpenTelemetry and the access log service. After activation, you incur charges for data reporting, trace storage, and log services.

Supported regions for ALB tracing

Public cloud regions

Area

Region

China

China (Hangzhou), China (Shanghai), China (Shenzhen), China (Chengdu), China (Qingdao), China (Beijing), China (Zhangjiakou), China (Ulanqab), China (Hong Kong), China (Guangzhou), and China (Heyuan)

Asia-Pacific

Singapore, Malaysia (Kuala Lumpur), Japan (Tokyo), Indonesia (Jakarta)

Europe and Americas

UK (London), Germany (Frankfurt), US (Virginia), and US (Silicon Valley)

Finance Cloud regions

Area

Region

China

China East 2 Finance (Shanghai)