sdk/trace: add trace.WithAllowKeyDuplication - #8488
Conversation
Add TestSpanAttributeCapacity_WithAllowKeyDuplication to cover the addOverCapAttrsNoDup code path that is exercised when WithAllowKeyDuplication is enabled and attributes exceed AttributeCountLimit. Test cases cover: under/at/over capacity, split calls that cross the limit, invalid attributes, and a mix of valid-at-capacity followed by invalid attrs.
|
03674ce to
2084182
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8488 +/- ##
======================================
Coverage 84.0% 84.1%
======================================
Files 329 331 +2
Lines 26068 26506 +438
======================================
+ Hits 21919 22312 +393
- Misses 3768 3788 +20
- Partials 381 406 +25
🚀 New features to boost your workflow:
|
|
Marking as draft. Please make it "ready for review" once feedback is addressed. Please also avoid using force-push as described in |
pellared
left a comment
There was a problem hiding this comment.
I made a quick review.
Can you compare benchmarks results with main using benchstat for the go.opentelemetry.io/otel/sdk/trace package and add the results in the PR description?
Done! Added benchstat results comparing base (7128e65) to this branch in the PR description — no regression on the default path, and WithAllowKeyDuplication speedups are shown as a table. |
|
Please update the PR description after the changes. |
Done i have updated the PR discription. |
8ec3b0b to
75ba388
Compare
|
@Dipanshusinghh please merge |
will do this by today |
…uplication # Conflicts: # CHANGELOG.md # sdk/trace/provider.go # sdk/trace/span.go
|
@MrAlias PTAL ! |
@Dipanshusinghh are the unresolved threads still works in progress? Do you have permissions to resolve the threads? |
sorry just forgot to click the resolve button! done now thnx |
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Closes #8480
Adds
WithAllowKeyDuplication()tosdk/traceas aTracerProviderOptionto opt out of the attribute map key deduplication introduced in #8471.Instead of checking a boolean flag on every span operation (the approach reverted in 5fa1035), this swaps a function pointer once at
TracerProviderconstruction — keeping the hot path completely branch-free with no per-operation overhead.Benchmarks
goos: windows
goarch: amd64
pkg: go.opentelemetry.io/otel/sdk/trace
cpu: AMD Ryzen 5 5500U with Radeon Graphics
1. Baseline Comparison (vs
main)benchstatcomparing base commit7128e65to this branch — verifying no regression in the default (deduplication enabled) path.
│ sec/op vs base │ StartEndSpan/AlwaysSample-12 1018.0n ~ (p=0.841 n=5) StartEndSpan/NeverSample-12 542.9n ~ (p=0.548 n=5) SpanWithAttributes_4/AlwaysSample-12 1.876µ +7.26% (p=0.008 n=5) SpanWithAttributes_4/NeverSample-12 842.9n ~ (p=0.310 n=5) SpanWithEvents_4/AlwaysSample-12 2.154µ ~ (p=0.079 n=5) SpanWithEvents_4/NeverSample-12 571.5n ~ (p=0.310 n=5) geomean 1.608µ +5.45% B/op and allocs/op: no change across all benchmarks.
The
+5.45%geomean is driven entirely by the one marginalSpanWithAttributes_4result; all other benchmarks are within noise.2. WithAllowKeyDuplication Speedup
Benchmarks comparing deduplication enabled vs. disabled, with and without duplicate keys.
With duplicate keys (opt-in benefit):
ns/op: −10% (SetAttributes), −35% (AddEvent)
B/op: −16% (SetAttributes), −37% (AddEvent)
allocs/op: −40% (SetAttributes), −33% (AddEvent)
Without duplicate keys (default path):
No change — fast path is completely unaffected.