sdk/trace: apply AttributeValueLengthLimit to event and link attributes #9523
All Vouch review confidence checks passed
Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #9523"
general
weight: 0.35
MrAlias
Fixes #9514
Summary
SpanLimits.AttributeValueLengthLimitpreviously applied only to span attributes (SetAttributesvianormAttr), whileaddEvent(AddEvent,RecordError) andAddLink(trace.WithLinks,span.AddLink) normalized nested maps and attribute depth without truncating attribute values.Add
normAttrsandnormalizeLimitedAttrsinsdk/traceso event and link attributes apply per-event/per-link count limits first and then run only retained attributes throughnormAttrwhenAttributeValueLengthLimit >= 0:0truncates to empty,< 0remains unlimited viaKeyValuesDedupLimitDepth);AttributePerEventCountLimit/AttributePerLinkCountLimitbefore value normalization, recordingDroppedAttributeCountfrom the original length and avoiding truncation work on discarded attributes (preserving negative unlimited counts and caller-slice immutability);SpanLimits.AttributeValueLengthLimitdocumentation andCHANGELOG.md.Benchmarks
Base:
34915e1(semconv: adopt v1.45.0) +sdk/trace/attr_limit_bench_test.goonly.Head:
18a920f7(cd sdk && go test -bench=BenchmarkAttributeLimitNormalization -benchmem -count=6 -run='^$' ./trace/, Go 1.27.1, darwin/arm64, Apple M4 Max).Performance impact
AttributeValueLengthLimitand a retained 1,024-element string slice of oversized strings,AddLinknow actually truncates the slice (54.25 KiB / 4 allocs/op, 9.14 µs) andAddEventadds the same truncation cost on top ofEventConfig's 296 B / 3 allocs copy. Base skipped value-length truncation on events and links altogether. With unlimitedAttributeValueLengthLimit(-1), retainedAddEventandAddLinkremain flat (0 B / 0 allocs/op forAddLink, unchanged 296 B / 3 allocs/op forAddEvent).AttributePerEventCountLimit/AttributePerLinkCountLimitbefore normalization avoids walking or allocating discarded attributes. Whencount=0,AddLinkstays at 0 B / 0 allocs/op and drops from 38.8 ns to 14.5 ns across both finite and unlimited length limits;AddEventdrops from 138 ns to 106 ns with no extra allocations aboveEventConfig. Indiscard-suffix(keeping 1 oversized string and dropping the 1,024-element slice),AddLinkpays only 64 B / 1 alloc/op (45.4 ns) for the retained string instead of copying the discarded 54 KiB slice.SetAttributes(deferred and eager deduplication): Allocations and bytes/op are identical across all four cases (finite/unlimited×deferred/eager), with timing flat within noise.Verification
cd sdk && go test -race -count=1 ./trace/... ./internal/attrnorm/... ./log/...make golangci-lint/./sdk golangci-lint/./sdk/log misspellcd sdk && go test -bench=BenchmarkAttributeLimitNormalization -benchmem -count=6 -run='^$' ./trace/