AutoScope: Code Knowledge Enhanced Span-level Sampling for Distributed Tracing
Distributed tracing is essential for observing microservices but incurs prohibitive storage costs. Existing solutions primarily rely on trace-level sampling, which indiscriminately discards entire traces based on probability or tail latency. This coarse-grained approach often loses critical off-the-path anomalies and fails to retain normal baselines required for comparative diagnosis. To address these limitations, we introduce the concept of span-level sampling, a fine-grained paradigm that retains only essential spans rather than full traces. However, we identify a critical challenge in this new approach where naive span retention leads to structural ambiguity, as the removal of intermediate spans disrupts the graph topology and renders the remaining data useless for analysis. To resolve this, we propose AutoScope , a novel framework that leverages static code knowledge to enable structurally safe span-level sampling. AutoScope constructs a Bridged Call Site Control Flow Graph (CSCFG) to map runtime spans to static execution logic. By identifying Dominant Span Sets (DSS), it exploits the “Sample One, Infer All” property to enable aggressive compression while preserving the structural skeleton of every request. Extensive evaluations on two benchmark microservice systems demonstrate that AutoScope achieves an 80.2% storage reduction while maintaining a state-of-the-art faulty span coverage of 98.1%. Furthermore, the reconstructed traces enhance downstream Root Cause Analysis (RCA) tasks, improving the Mean Reciprocal Rank (MRR) by an average of 8.3%.