Select a trace sampling policy

Updated at:

Application Real-Time Monitoring Service (ARMS) provides multiple trace sampling policies that help you capture failed, timeout, and abnormal traces from large volumes of business data while minimizing resource costs.

Common sampling policies in distributed tracing

In distributed tracing, three sampling policies are available based on the time when a sampling decision is made.

image
  • Head-based sampling: The sampling decision is made at the root span of an ingress service, such as a gateway service, proxy service, or core upstream service. If the root span of the ingress service is sampled, the trace data of subsequent services is also sampled. This ensures the coherence of the entire trace. Head-based sampling effectively reduces trace overhead and data costs. However, because sampling decisions are made on the client side, failed, slow, or abnormal traces may be less likely to be sampled.

  • Tail-based sampling: The sampling decision is made at the server after all traces are available. If a trace needs to be sampled, its data is stored. Otherwise, the data is discarded. This ensures data consistency. Tail-based sampling accurately samples failed, slow, or abnormal traces for troubleshooting and diagnostics at any time. However, it also increases trace overhead and data costs.

  • Unitary sampling: Unitary sampling is a non-coherent sampling policy. For a trace, the service to which each span belongs determines whether to sample and report data. Because each service determines the trace sampling, the reported trace data is not complete.

For information about ARMS trace sampling rules, see Select a trace sampling mode (agent versions earlier than 3.2.8).

Sampling policies provided by ARMS

ARMS typically employs head-based sampling to minimize costs associated with reported observable data. For information about the billing of observable data, see Billing for Application Monitoring.

  • Fixed-rate sampling: Traces are sampled based on a specified sampling rate at the ingress service. For example, if the fixed rate is 10%, one out of every 10 pieces of trace data is recorded.

  • Adaptive sampling: A variant of the Least Frequently Used (LFU) algorithm is used for operation-level Top N sampling to sample a limited number of requests for each API operation per unit of time. This is a cost-effective head-based sampling policy developed by ARMS.

Select a sampling policy by scenario

The following sections help you balance monitoring coverage and costs for different scenarios.

Note

In ARMS, you can copy the trace sampling settings of one application to another in batches to meet your business requirements in varied scenarios. For more information, see Copying configurations.

Cost control: fixed-rate sampling

In general, you can set a low fixed sampling rate for your applications, such as changing the default rate of 10% to 5%.

Halving the sampling rate halves the cost, but does not proportionally reduce the useful trace data. Most exceptions that appear in one trace also appear in other traces of the same application, especially under high request volumes, unless the exception is an occasional spike. A low fixed sampling rate still captures most anomalies while significantly reducing your costs.

The following figure shows the settings for fixed-rate sampling. For information about how to set the sampling rate, see Fixed-rate sampling.

image.png

ARMS also allows you to customize sampling rates globally. ARMS uses agents to identify the root spans of each application. On the server side, ARMS identifies ingress applications based on the number of root spans and ranks them by trace data volume. You can then use the page to quickly adjust the sampling rates for the top N ingress applications together.

Core business: fixed-rate sampling and operation-specific full collection

For critical business workflows, set a high fixed sampling rate on your core applications and enable full collection for specific operations to capture all their traces.

For example, in an e-commerce system, focus on operations such as product querying and purchasing rather than querying and editing user information. Increase the sampling rate above the default 10% for core applications and enable full collection for the operations that require it.

Important

Full collection may result in a surge of the collected data. Make sure that full collection is enabled only for the key operations, or when necessary.

The following figure shows the settings for collecting all trace data of specific operations, or operations with certain prefixes or suffixes. For information about how to set the full collection, see Fixed-rate sampling.

image.png

Major O&M events: fixed-rate sampling

During major O&M events, such as large-scale promotions or performance testing on new releases, you can set a fixed 100% sampling rate for data with certain tags or even for all applications. This facilitates troubleshooting, auditing, and accountability.

After the major events, we recommend that you lower the sampling rate to prevent performance loss and unnecessary costs.

Traffic fluctuation: adaptive sampling

When traffic fluctuates with changing business logic, use the adaptive sampling policy for your applications.

Applications with complex business logic often involve many operations. Adaptive sampling prevents data volume from growing linearly with traffic by selecting entries based on the LFU algorithm. The built-in minimum sampling policy supplements this by ensuring that trace data is recorded for every operation, regardless of traffic level.

Note

Minimum sampling for all API operations: The traces of each API operation are automatically sampled within one minute. By default, ARMS enables this sampling policy.

By contrast:

  • If you set a fixed sampling rate for the applications, the operations with many requests will be over-sampled, whereas the operations that are not sampled due to low traffic or zero calls, such as scheduling, may affect the tracing result if exceptions occur.

  • If you manually enable full collection for specific operations individually, this will result in a large O&M workload and potential oversights.

Nevertheless, you can still configure full collection for specific operations that are critical to the application performance. You can use custom operation names, prefixes, or suffixes to mark API operations that require 100% sampling. Requests received by these operations trigger 100% sampling of the entire trace.

The following figure shows the settings for adaptive sampling. For information about how to configure the settings, see Adaptive sampling.

image.png

Related steps

After traces are sampled, configure filter conditions and aggregation dimensions to analyze trace data in real time. For more information, see Trace Explorer.