Skip to content

[SDK] Read span limits from environment variables#4258

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

[SDK] Read span limits from environment variables#4258
HrMathematiker wants to merge 2 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 Not Signed

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

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.
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.)

2 participants