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 |
| The OpenTelemetry version used. | Always |
| The ID that identifies this trace. | A 32-digit hexadecimal number. |
| The ID that identifies the current node on the trace chain. | A 16-digit hexadecimal number. |
| Indicates whether this request is sampled. |
|
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.
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.
The following table compares the field values:
Part | Upstream request value | ALB forwarded value | Processing |
|
|
| Inherited |
|
|
| Inherited |
|
|
| Newly generated |
|
|
| 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 |
| The ID that identifies this trace. | A 16-digit hexadecimal number. |
| The ID that identifies the current node on the trace chain. | A 16-digit hexadecimal number. |
| The ID that identifies the previous node on the trace chain. | A 16-digit hexadecimal number. |
| Indicates whether this request is sampled. |
|
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.
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.
The following table compares the field values:
Field | Upstream request value | ALB forwarded value | Processing |
|
|
| Inherited |
|
|
| Newly generated |
|
|
| Uses the upstream SpanId |
|
|
| Inherited |
Applicable scope
Only Standard Edition and WAF Enhanced Edition ALB instances support tracing. Basic Edition ALB instances do not support this feature.
You have created an ALB instance and created a server group.
You have configured a listener for the instance and associated it with a server group.
You have created an ECS instance as a backend server, deployed the Nginx service on the ECS instance, and added the ECS instance to the server group.
Step 1: Enable tracing
Log on to the ALB console, select the region where your instance is located, find the target instance, and click its instance ID.
Click the Listener tab, find the target listener, and click its listener ID.
In the Tracing section of the Listener Details tab, turn on the Tracing switch.
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
Log on to a client terminal and test connectivity with the backend server. For more information, see Quickly implement IPv4 load balancing with ALB.
Log on to the ALB console, select the region where your instance is located, find the target instance, and click its instance ID.
Click the Listener tab, find the target listener, and click its listener ID.
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_idandattributes.slb_vportfilters. 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) |