Skip to content

[SDK] Read span limits from environment variables#4258

Open
HrMathematiker wants to merge 4 commits into
open-telemetry:mainfrom
HrMathematiker:span-limits-env
Open

[SDK] Read span limits from environment variables#4258
HrMathematiker wants to merge 4 commits into
open-telemetry:mainfrom
HrMathematiker:span-limits-env

Conversation

@HrMathematiker

Copy link
Copy Markdown

Fixes #4257

Changes

Adds span_limits_env::GetSpanLimitsFromEnv(), which builds a SpanLimits from the environment variables defined in the specification, and uses it as the default in the TracerProviderFactory::Create overloads that previously defaulted to SpanLimits::NoLimits(). The implementation mirrors the existing batch_span_processor_options_env pattern (OTEL_BSP_*).

Semantics, chosen to preserve the backward-compatible default established in #4232:

  • A field whose environment variable is unset keeps its SpanLimits::NoLimits() value — with no variables set, GetSpanLimitsFromEnv() == SpanLimits::NoLimits() and SDK behavior is unchanged.
  • Supported variables: OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT, OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT, OTEL_SPAN_EVENT_COUNT_LIMIT, OTEL_SPAN_LINK_COUNT_LIMIT, OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT, OTEL_LINK_ATTRIBUTE_COUNT_LIMIT, plus the general OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT / OTEL_ATTRIBUTE_COUNT_LIMIT, with the span-specific variables taking precedence per the spec.
  • Explicitly passed SpanLimits (programmatic, or declarative configuration through the sdk builder) continue to take precedence over the environment, matching the spec's configuration-precedence order.

Follow-up once merged: flip the C++ cells of the span-limit env-variable rows in the spec compliance matrix (separate PR to the specification repo).

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jul 16, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@HrMathematiker
HrMathematiker marked this pull request as ready for review July 16, 2026 16:29
@HrMathematiker
HrMathematiker requested a review from a team as a code owner July 16, 2026 16:29
@ThomsonTan

Copy link
Copy Markdown
Contributor

@HrMathematiker thanks for the contribution. Please take a look on the missing CLA authorization.

@marcalff marcalff added the pr:waiting-on-cla Waiting on CLA label Jul 17, 2026
@marcalff

Copy link
Copy Markdown
Member

@HrMathematiker

Thanks for the contribution, this part is really needed in opentelemetry-cpp.

Please clear the EasyCLA, merging can not happen without it.

@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.20%. Comparing base (676c9dc) to head (e4df4dd).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4258      +/-   ##
==========================================
+ Coverage   81.19%   81.20%   +0.02%     
==========================================
  Files         444      445       +1     
  Lines       18880    18902      +22     
==========================================
+ Hits        15328    15348      +20     
- Misses       3552     3554       +2     
Files with missing lines Coverage Δ
sdk/include/opentelemetry/sdk/trace/span_limits.h 100.00% <100.00%> (ø)
sdk/src/trace/span_limits.cc 100.00% <100.00%> (ø)
sdk/src/trace/tracer_provider_factory.cc 94.55% <100.00%> (ø)

... and 1 file with indirect coverage changes

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

Adds span_limits_env::GetSpanLimitsFromEnv(), which builds a SpanLimits
from the environment variables defined in the specification
(OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT, OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT,
OTEL_SPAN_EVENT_COUNT_LIMIT, OTEL_SPAN_LINK_COUNT_LIMIT,
OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT, OTEL_LINK_ATTRIBUTE_COUNT_LIMIT, and
the general OTEL_ATTRIBUTE_* fallbacks), and uses it as the default in
the TracerProviderFactory::Create overloads that previously defaulted to
SpanLimits::NoLimits(). A field whose variable is unset keeps its
NoLimits() value, so behavior is unchanged when no variables are set;
explicitly passed SpanLimits keep taking precedence.
@HrMathematiker

Copy link
Copy Markdown
Author

@marcalff the CLI is authorized now :)
Could you please review the MR?

@dbarker dbarker removed the pr:waiting-on-cla Waiting on CLA label Jul 17, 2026

@dbarker dbarker 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.

Looks good to me. Thanks for the contribution. Just optional feedback below.

Comment thread sdk/src/trace/span_limits.cc Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Read span limits from environment variables (OTEL_SPAN_EVENT_COUNT_LIMIT etc.)

5 participants