Commit 171d78e
authored
feat(tailsamplingprocessor): Add tracing for ConsumeTraces and samplingTick (#45646)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
# Description
This PR adds distributed tracing instrumentation to the
tailsamplingprocessor to provide visibility into trace processing
behavior and policy evaluation.
## What's Changed
- Trace spans for key operations:
- `tailsampling.ConsumeTraces`: Tracks incoming traces/spans count
- `tailsampling.samplingPolicyOnTick`: Records batch processing metrics
and policy evaluation results
- Optimized for minimal allocations:
- Pre-allocated policy name attributes to reduce per-decision
allocations
- Added String() method to samplingpolicy.Decision enum
## Why This Matters
Tracing provides critical insights into the async nature of tail
sampling decisions, making it significantly easier to debug issues like:
- Which policies are making sampling decisions
- Policy evaluation latency and errors
- Trace batching and decision timing
<!-- Issue number (e.g. #1234) or full URL to issue, if applicable. -->
## Link to tracking issue
Fixes #43931
<!--Describe what testing was performed and which tests were added.-->
# Testing
I have run my own collector with 17 policies, and a testing app sending
data to try to match some of them. [See my config
here](https://gist.github.com/jdvr/740b8a4d83d5fdcc9219601e8a2ad31f)
## Resulting traces
### `tailsampling.ConsumeTraces` shows full data journey, from receiver.
<img width="1678" height="454" alt="image"
src="https://github.com/user-attachments/assets/01f54409-17fb-422a-8fb4-5a29e8582871"
/>
### `tailsampling.samplingPolicyOnTick` shows executed policies and
sampling decision information
<img width="1676" height="545" alt="image"
src="https://github.com/user-attachments/assets/1783b0a6-14a8-4718-93a6-fdc6fb9ff112"
/>
<img width="1680" height="367" alt="image"
src="https://github.com/user-attachments/assets/608bec00-69a5-47e5-bda6-dddb05969bd7"
/>
# Benchmarks
I have run benchmark test and the new code doesn't produce any
significant change
<details>
<summary>bench_before.txt</summary>
```shell
goos: darwin
goarch: arm64
pkg: github.com/open-telemetry/opentelemetry-collector-contrib/processor/tailsamplingprocessor
cpu: Apple M1
BenchmarkSampling-8 55839 19188 ns/op 0 B/op 0 allocs/op
BenchmarkSampling-8 64318 18691 ns/op 0 B/op 0 allocs/op
BenchmarkSampling-8 63302 18951 ns/op 0 B/op 0 allocs/op
BenchmarkSampling-8 63372 18894 ns/op 0 B/op 0 allocs/op
BenchmarkSampling-8 64154 18808 ns/op 0 B/op 0 allocs/op
BenchmarkSampling-8 64200 18687 ns/op 0 B/op 0 allocs/op
BenchmarkSampling-8 63379 18854 ns/op 0 B/op 0 allocs/op
BenchmarkSampling-8 63357 18933 ns/op 0 B/op 0 allocs/op
BenchmarkSampling-8 64212 18686 ns/op 0 B/op 0 allocs/op
BenchmarkSampling-8 63412 18927 ns/op 0 B/op 0 allocs/op
BenchmarkProcessorThroughput-8 866 1210287 ns/op 231.94 MB/s 4688599 B/op 36616 allocs/op
BenchmarkProcessorThroughput-8 897 1211507 ns/op 231.71 MB/s 4687953 B/op 36606 allocs/op
BenchmarkProcessorThroughput-8 916 1217058 ns/op 230.65 MB/s 4687569 B/op 36602 allocs/op
BenchmarkProcessorThroughput-8 927 1219294 ns/op 230.23 MB/s 4689993 B/op 36638 allocs/op
BenchmarkProcessorThroughput-8 926 1212671 ns/op 231.49 MB/s 4687731 B/op 36603 allocs/op
BenchmarkProcessorThroughput-8 853 1215764 ns/op 230.90 MB/s 4687635 B/op 36602 allocs/op
BenchmarkProcessorThroughput-8 874 1267715 ns/op 221.43 MB/s 4689856 B/op 36638 allocs/op
BenchmarkProcessorThroughput-8 885 1228161 ns/op 228.57 MB/s 4688816 B/op 36624 allocs/op
BenchmarkProcessorThroughput-8 854 1214659 ns/op 231.11 MB/s 4689043 B/op 36625 allocs/op
BenchmarkProcessorThroughput-8 894 1226793 ns/op 228.82 MB/s 4687590 B/op 36605 allocs/op
PASS
ok github.com/open-telemetry/opentelemetry-collector-contrib/processor/tailsamplingprocessor 46.393s
```
</details>
<details>
<summary>bench_after.txt</summary>
```shell
```
</details>
Comparation using [benchstat](golang.org/x/perf/cmd/benchstat)
```
❯ benchstat bench_before.txt bench_after.txt
goos: darwin
goarch: arm64
pkg: github.com/open-telemetry/opentelemetry-collector-contrib/processor/tailsamplingprocessor
cpu: Apple M1
│ bench_before.txt │ bench_after.txt │
│ sec/op │ sec/op vs base │
Sampling-8 18.87µ ± 1% 18.84µ ± 3% ~ (p=0.838 n=10)
ProcessorThroughput-8 1.216m ± 1% 1.314m ± 1% +8.02% (p=0.000 n=10)
geomean 151.5µ 157.3µ +3.83%
│ bench_before.txt │ bench_after.txt │
│ B/op │ B/op vs base │
Sampling-8 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
ProcessorThroughput-8 4.471Mi ± 0% 4.471Mi ± 0% ~ (p=0.315 n=10)
geomean ² +0.00% ²
¹ all samples are equal
² summaries must be >0 to compute geomean
│ bench_before.txt │ bench_after.txt │
│ allocs/op │ allocs/op vs base │
Sampling-8 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹
ProcessorThroughput-8 36.61k ± 0% 36.61k ± 0% ~ (p=0.305 n=10)
geomean ² +0.00% ²
¹ all samples are equal
² summaries must be >0 to compute geomean
│ bench_before.txt │ bench_after.txt │
│ B/s │ B/s vs base │
ProcessorThroughput-8 220.1Mi ± 1% 203.7Mi ± 1% -7.42% (p=0.000 n=10)
```
# Benchmark Results
### BenchmarkProcessorThroughput
| Metric | Before | After | Change |
|--------|--------|-------|--------|
| **Latency** | 1.216ms | 1.314ms | +8.02% |
| **Memory** | 4.471 MiB | 4.471 MiB | ~0% |
| **Allocations** | 36.61k | 36.61k | ~0% |
| **Throughput** | 220.1 MB/s | 203.7 MB/s | -7.42% |
### BenchmarkSampling
| Metric | Before | After | Change |
|--------|--------|-------|--------|
| **Latency** | 18.87µs | 18.84µs | -0.16% |
| **Memory** | 0 KB | 0 KB | ~0% |
| **Allocations** | 0 | 0 | ~0% |
<!--Describe the documentation added.-->
#### Documentation
<!--Please delete paragraphs that you did not use before submitting.-->1 parent 3ad470c commit 171d78e
6 files changed
Lines changed: 358 additions & 10 deletions
File tree
- .chloggen
- processor/tailsamplingprocessor
- internal/telemetry
- pkg/samplingpolicy
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
Lines changed: 61 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
Lines changed: 192 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
Lines changed: 24 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
54 | 78 | | |
55 | 79 | | |
56 | 80 | | |
| |||
0 commit comments