feat(sdk): support OTEL_ATTRIBUTE_COUNT_LIMIT env var#3568
Conversation
OTEL_ATTRIBUTE_COUNT_LIMIT is the spec-defined general fallback for the maximum span attribute count. Previously only the span-specific OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT was read, so the general variable had no effect. Read OTEL_ATTRIBUTE_COUNT_LIMIT in Config::default() and apply it to max_attributes_per_span, then let OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT override it when both are set, matching the precedence in the configuration spec. The general limit deliberately does not touch the per-event / per-link attribute limits, which have their own defaults per the spec. Part of open-telemetry#3374
516613c to
ef52166
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3568 +/- ##
=====================================
Coverage 82.9% 83.0%
=====================================
Files 130 130
Lines 27768 27809 +41
=====================================
+ Hits 23040 23082 +42
+ Misses 4728 4727 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| //! | ||
| //! | Variable | Description | Default | | ||
| //! |---|---|---| | ||
| //! | `OTEL_ATTRIBUTE_COUNT_LIMIT` | Maximum number of attributes allowed on a span. Acts as the fallback for `OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT`, which takes precedence when both are set. | `128` | |
There was a problem hiding this comment.
OTEL_ATTRIBUTE_COUNT_LIMIT -> is this supposed to affect spans and logs too?
There was a problem hiding this comment.
I think we should do this only after Logs also support this, else this may misled users to believing that setting this ENV variable will enforce limits, but in reality - Logs don't enforce it.
cijothomas
left a comment
There was a problem hiding this comment.
Thanks for your contribution. Please see https://github.com/open-telemetry/opentelemetry-rust/pull/3568/changes#r3471676694
This is better done after Logging fixes.
|
Good point — thanks. The logs SDK doesn't enforce any attribute limit today, so I've opened #3571 to add that first ( Once #3571 lands, I'll update this PR so |
Part of #3374
Problem
OTEL_ATTRIBUTE_COUNT_LIMITis the spec-defined general fallback for the maximum span attribute count (SDK configuration spec). The SDK only read the span-specificOTEL_SPAN_ATTRIBUTE_COUNT_LIMIT, so setting the general variable had no effect. This is one of the gaps tracked in #3374.Change
In
Config::default(), readOTEL_ATTRIBUTE_COUNT_LIMITand apply it tomax_attributes_per_span, then letOTEL_SPAN_ATTRIBUTE_COUNT_LIMIToverride it when both are set (per the spec's precedence). Code-based configuration (e.g.with_max_attributes_per_span) continues to take precedence over both, since the builder starts fromConfig::default().The general limit deliberately does not touch the per-event / per-link attribute count limits — those have their own spec defaults (128) and are not governed by
OTEL_ATTRIBUTE_COUNT_LIMIT.Tests
otel_attribute_count_limit_sets_span_attribute_limit— general var applies to span attributes and leaves per-event / per-link limits at their defaults.span_attribute_count_limit_overrides_general_limit— span-specific var wins when both are set.default_span_attribute_limit_when_unset— default of 128 when neither is set.Also documented the variable and its precedence in the crate-level env-var table and added a CHANGELOG entry.
cargo test -p opentelemetry_sdk --all-features --lib trace::config,cargo clippy --all-targets --all-features -- -Dwarnings, andcargo fmt --all -- --checkall pass.