Skip to content

feat(sdk): support OTEL_ATTRIBUTE_COUNT_LIMIT env var#3568

Closed
Wassbdr wants to merge 1 commit into
open-telemetry:mainfrom
Wassbdr:feat/3374-otel-attribute-count-limit
Closed

feat(sdk): support OTEL_ATTRIBUTE_COUNT_LIMIT env var#3568
Wassbdr wants to merge 1 commit into
open-telemetry:mainfrom
Wassbdr:feat/3374-otel-attribute-count-limit

Conversation

@Wassbdr

@Wassbdr Wassbdr commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Part of #3374

Problem

OTEL_ATTRIBUTE_COUNT_LIMIT is the spec-defined general fallback for the maximum span attribute count (SDK configuration spec). The SDK only read the span-specific OTEL_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(), read OTEL_ATTRIBUTE_COUNT_LIMIT and apply it to max_attributes_per_span, then let OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT override 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 from Config::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, and cargo fmt --all -- --check all pass.

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
@Wassbdr
Wassbdr force-pushed the feat/3374-otel-attribute-count-limit branch from 516613c to ef52166 Compare June 24, 2026 10:52
@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.0%. Comparing base (1b3846c) to head (ef52166).
⚠️ Report is 15 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

//!
//! | 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` |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OTEL_ATTRIBUTE_COUNT_LIMIT -> is this supposed to affect spans and logs too?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 cijothomas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution. Please see https://github.com/open-telemetry/opentelemetry-rust/pull/3568/changes#r3471676694

This is better done after Logging fixes.

@Wassbdr

Wassbdr commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

Good point — thanks. The logs SDK doesn't enforce any attribute limit today, so I've opened #3571 to add that first (OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT + with_max_attributes_per_log, with OTEL_ATTRIBUTE_COUNT_LIMIT as fallback, enforced in SdkLogger::emit).

Once #3571 lands, I'll update this PR so OTEL_ATTRIBUTE_COUNT_LIMIT consistently acts as the general fallback for both spans and logs. Happy to keep this one open and rebase on top of #3571, or close it and fold the general-fallback wording into a follow-up — whichever you prefer.

@github-actions

Copy link
Copy Markdown

Thank you for your contribution! This PR has been automatically marked as stale because it has not had activity in the last 14 days. This may be due to a delay in review on our side or awaiting a response from you; either is fine, and we appreciate your patience.

It will be closed in 14 days if no further activity occurs. Pushing a new commit or leaving a comment will remove the stale label and keep the PR open.

@github-actions github-actions Bot added the Stale label Jul 10, 2026
@github-actions

Copy link
Copy Markdown

Closed as inactive. Thank you again for the contribution; please feel free to reopen this PR (or open a new one) if you'd like to continue the work.

@github-actions github-actions Bot closed this Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants