Trace Sampling 2.0: Code Knowledge Enhanced Span-level Sampling for Distributed Tracing

Yulun Wu, Guangba Yu, Zhihan Jiang, Yichen Li, Michael R. LyuarXiv 2025 · DOI

Abstract

Modern microservice architectures rely on distributed tracing for observability, yet the sheer volume of trace data—often exceeding petabytes daily—necessitates aggressive sampling. Traditional "Trace Sampling 1.0" employs a coarse-grained, all-or-nothing approach at the trace level, which frequently results in either excessive storage costs or the loss of critical diagnostic context. We propose Autoscope, a framework representing "Trace Sampling 2.0." Autoscope utilizes static code analysis to perform surgical, span-level sampling. By identifying "Dominant Span Sets" within a Call Site Control Flow Graph (CSCFG), the system discards redundant spans while preserving the structural integrity of the trace. Experimental results demonstrate that Autoscope reduces storage overhead by over 80% and improves root cause analysis accuracy by 8.3% compared to state-of-the-art methods.

Introduction

Distributed tracing provides an "X-ray" view of request propagation through complex microservice webs. However, the scale of modern systems makes storing every trace impossible; for instance, Alibaba generates over 20 petabytes of trace data every day. To manage this, industry-standard systems use trace-level sampling, where entire execution paths are either saved or deleted. This "Trace Sampling 1.0" paradigm suffers from two major flaws: the "Query Miss" problem, where normal traces needed for baseline comparison are missing, and extreme redundancy, as approximately 90% of spans within a trace often provide negligible diagnostic value.

The Shift to Trace Sampling 2.0

The core limitation of 1.0 is its binary nature. Researchers from The Chinese University of Hong Kong advocate for a transition to Trace Sampling 2.0, which operates at the granularity of individual spans. Instead of discarding a whole trace because it appears "normal," a span-level approach keeps only the essential "marker" spans that define the execution logic.

Comparison of Trace-level (a) and Span-level (b) sampling strategies.

As shown in the figure above, trace-level sampling (a) often leads to failed queries for discarded traces. In contrast, span-level sampling (b) reserves critical spans across all traces, ensuring that SREs can always query the basic structure of any request while significantly reducing the backend storage footprint.

Methodology: Autoscope and Code Knowledge

Autoscope achieves this surgical precision by integrating "code knowledge" into the sampling decision. The workflow is built upon three technical pillars:

  1. Call Site Control Flow Graph (CSCFG): Autoscope uses static analysis to map the application's logical structure. To account for dynamic behaviors like gRPC calls or reflection that static tools might miss, it incorporates a Runtime Patch based on actual execution data.
  2. Dominant Span Sets (DSS): By analyzing the CSCFG, Autoscope identifies spans that are "mutually dominant"—meaning if one occurs, the others must also occur. It only needs to store one representative span from such a set to reconstruct the entire branch later.
  3. Anomaly-Aware Selection: Within these sets, Autoscope uses a robust Z-score based on Median Absolute Deviation (MAD) to prioritize spans with unusual latencies, ensuring that even in noisy environments, the most relevant performance data is preserved.
Transformation from a standard Control Flow Graph (CFG) to a Call Site Control Flow Graph (CSCFG) to identify dominant logic paths.

The transformation to CSCFG (illustrated above) allows the system to understand which basic blocks are tied to specific call sites, enabling the identification of redundant spans that do not add unique structural information.

Evaluation and Results

Autoscope was evaluated using the TrainTicket and Social Network microservice benchmarks, with failures injected via ChaosBlade. The system demonstrated superior performance across several metrics:

  • Storage Efficiency: Average storage reduction of 81.2%, outperforming existing methods like Perch and TraceMesh.
  • Diagnostic Fidelity: Maintained 98.1% coverage of faulty spans, ensuring that critical error data is rarely lost.
  • Improved RCA: Traces processed by Autoscope led to an 8.3% increase in Root Cause Analysis (RCA) accuracy, as the preserved spans maintain the structural integrity required by automated diagnostic tools.
  • Operational Overhead: With a processing time of approximately 4.4ms per trace, Autoscope is suitable for high-throughput production environments.

Conclusion

Trace Sampling 2.0 represents a fundamental shift from volume-based to value-based data retention. By leveraging code-level insights, Autoscope proves that it is possible to discard the vast majority of trace data without sacrificing the visibility required for complex debugging. This "surgical" approach paves the way for more sustainable and effective observability in the era of massive-scale microservices.

Paper Citation: Wu, Y., Yu, G., Jiang, Z., Li, Y., & Lyu, M. R. (2025). Trace Sampling 2.0: Code Knowledge Enhanced Span-level Sampling for Distributed Tracing. arXiv:2509.13852v1 [cs.SE].

Summary updated

BibTeX
@misc{wu2025trace,
  author = {Yulun Wu and Guangba Yu and Zhihan Jiang and Yichen Li and Michael R. Lyu},
  title = {{Trace Sampling 2.0: Code Knowledge Enhanced Span-level Sampling for Distributed Tracing}},
  year = {2025},
  eprint = {2509.13852},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2509.13852},
}
Figure