Skip to content

feat(config): wire top-level attribute_limits into per-signal providers - #5365

Open
ocelotl wants to merge 5 commits into
open-telemetry:mainfrom
ocelotl:diego/config-attribute-limits
Open

feat(config): wire top-level attribute_limits into per-signal providers#5365
ocelotl wants to merge 5 commits into
open-telemetry:mainfrom
ocelotl:diego/config-attribute-limits

Conversation

@ocelotl

@ocelotl ocelotl commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Closes #5357

Summary

  • Reads config.attribute_limits in configure_sdk() and passes it as a global fallback to create_tracer_provider() and create_logger_provider()
  • Per-signal limits (tracer_provider.limits / logger_provider.limits) always take precedence; absent fields fall back to the global value, then to OTel spec defaults
  • Adds log_record_limits parameter to LoggerProvider, threads it through Logger down to each ReadWriteLogRecord — mirroring how SpanLimits flows through TracerProvider

Test plan

  • tests/_configuration/test_sdk.py — global limits passed to per-signal factories
  • tests/_configuration/test_tracer_provider.py — per-signal override, global fallback, spec defaults
  • tests/_configuration/test_logger_provider.py — same coverage for logs; verifies limits are applied (not just warned about)
  • tests/logs/ — no regressions in existing log SDK tests

ocelotl added a commit to ocelotl/opentelemetry-python that referenced this pull request Jun 26, 2026
@ocelotl
ocelotl marked this pull request as ready for review June 26, 2026 21:28
@ocelotl
ocelotl requested a review from a team as a code owner June 26, 2026 21:28
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py
Comment thread opentelemetry-configuration/src/opentelemetry/configuration/_logger_provider.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the OpenTelemetry SDK declarative configuration path to support top-level attribute_limits as a global fallback for traces and logs, and adds programmatic log_record_limits support to LoggerProvider so log attribute limits can be configured consistently with SpanLimits.

Changes:

  • Thread config.attribute_limits through configure_sdk() into create_tracer_provider() / create_logger_provider() as a fallback when per-signal limits are absent.
  • Implement log-record limits creation in declarative config and pass the resulting log_record_limits into LoggerProvider, propagating to Logger and ReadWriteLogRecord.
  • Update/expand configuration tests and add a changelog entry.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
opentelemetry-sdk/src/opentelemetry/sdk/_configuration/_sdk.py Plumbs top-level attribute_limits into per-signal configurators.
opentelemetry-sdk/src/opentelemetry/sdk/_configuration/_tracer_provider.py Adds global fallback handling for span attribute limits in declarative config.
opentelemetry-sdk/src/opentelemetry/sdk/_configuration/_logger_provider.py Adds log-record limits handling and wires limits into LoggerProvider construction.
opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/init.py Threads log_record_limits from provider → logger → emitted log records.
opentelemetry-sdk/tests/_configuration/test_sdk.py Updates expectations for updated configurator call signatures.
opentelemetry-sdk/tests/_configuration/test_tracer_provider.py Adds tests covering global fallback semantics for traces.
opentelemetry-sdk/tests/_configuration/test_logger_provider.py Updates tests to validate log-record limits are applied (not just warned/ignored).
opentelemetry-sdk/src/opentelemetry/sdk/trace/export/init.py Minor formatting-only change to console exporter default formatter.
.changelog/5365.added Documents the new config wiring and LoggerProvider limits support.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread opentelemetry-sdk/src/opentelemetry/sdk/_configuration/_tracer_provider.py Outdated
Comment thread opentelemetry-sdk/tests/_configuration/test_tracer_provider.py
Comment thread opentelemetry-sdk/tests/_configuration/test_logger_provider.py
@xrmx

xrmx commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

This needs a rebase after declarative config move

@xrmx xrmx moved this to Approved PRs that need fixes in Python PR digest Jul 13, 2026
@ocelotl
ocelotl force-pushed the diego/config-attribute-limits branch 2 times, most recently from 9f37481 to 5a0a1d0 Compare July 20, 2026 15:41

@rads-1996 rads-1996 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Need to rebase but otherwise LGTM.

@github-project-automation github-project-automation Bot moved this from Approved PRs that need fixes to Approved PRs in Python PR digest Jul 29, 2026
@ocelotl
ocelotl force-pushed the diego/config-attribute-limits branch from 5a0a1d0 to a1c69ca Compare July 30, 2026 21:11

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

Wasn't super clear to me, is there any behavior change for users who are not using declarative config?

Comment thread opentelemetry-configuration/src/opentelemetry/configuration/_logger_provider.py Outdated
Comment thread opentelemetry-configuration/src/opentelemetry/configuration/_sdk.py Outdated
default values and from user provided arguments.

All limit arguments must be either a non-negative integer or ``None``.
All limit arguments must be either a non-negative integer, ``None`` or ``LogRecordLimits.UNSET``.

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.

Is it part of the spec, and specifically the -1 value? I'm wondering if it's valid to set -1 in the declarative config yaml.

It's also different from the _ENV_VALUE_UNSET constant

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

-1 never appears in the YAML. The config schema constrains these fields to minimum: 0 or null, so null/omitted means "no limit" and the config layer turns that into the internal -1. It's an in-process sentinel, not a user value. Schema refs:

https://github.com/open-telemetry/opentelemetry-configuration/blob/52c265e8a59fbf25348be7dfd2cb5c432801358d/schema/opentelemetry_configuration.yaml#L69-L81
https://github.com/open-telemetry/opentelemetry-configuration/blob/52c265e8a59fbf25348be7dfd2cb5c432801358d/schema/logger_provider.yaml#L108-L127

It's also not new. I'm mirroring the existing SpanLimits.UNSET = -1 and its _from_env_if_absent guard:


def _from_env_if_absent(
cls, value: int | None, env_var: str, default: int | None = None
) -> int | None:
if value == cls.UNSET:
return None

It differs from _ENV_VALUE_UNSET = "" because that guards the raw env-var string, while -1 guards the parsed int arg. Both already coexist in SpanLimits:

@aabmass aabmass moved this from Approved PRs to Approved PRs that need fixes in Python PR digest Aug 3, 2026
@ocelotl
ocelotl force-pushed the diego/config-attribute-limits branch from a1c69ca to 8c0e64e Compare August 6, 2026 22:15
@ocelotl

ocelotl commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Wasn't super clear to me, is there any behavior change for users who are not using declarative config?

Nope, no behavior change

ReadWriteLogRecord.limits already defaults to LogRecordLimits() via field(default_factory=LogRecordLimits), so every log record was already being constructed with the default limits (128
attribute count, no length limit, env vars read):

This PR just threads an explicit log_record_limits through LoggerProvider -> Logger -> _from_api_log_record. Both LoggerProvider and Logger fall back to log_record_limits or
LogRecordLimits(), so when nobody sets it (the programmatic, non-config path) they get the exact same default they got before.

The only observable difference: the OTEL_* env-based limits are now read once at LoggerProvider construction instead of once per log record. Same values in practice, and arguably more
consistent, unless something mutates the env vars mid-process between records, which isn't a supported pattern.

@ocelotl
ocelotl force-pushed the diego/config-attribute-limits branch 2 times, most recently from 7b70474 to f0ef10d Compare August 7, 2026 16:07
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Aug 14, 2026

Copy link
Copy Markdown

Pull request dashboard status

Waiting on reviewers · refreshed 2026-08-22 22:16 UTC

Review the latest changes.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

@opentelemetry-pr-dashboard

This comment has been minimized.

@ocelotl

ocelotl commented Aug 22, 2026

Copy link
Copy Markdown
Contributor Author

This needs a rebase after declarative config move

done

@ocelotl

ocelotl commented Aug 22, 2026

Copy link
Copy Markdown
Contributor Author

Need to rebase but otherwise LGTM.

done

ocelotl and others added 4 commits August 22, 2026 16:51
Parses config.attribute_limits in configure_sdk() and passes it as a
global fallback to create_tracer_provider() and create_logger_provider().
Per-signal limits (tracer_provider.limits / logger_provider.limits)
always take precedence; absent fields fall back to the global value, then
to OTel spec defaults.

For logs, adds log_record_limits to the LoggerProvider constructor,
threads it through Logger, and applies it when constructing each
ReadWriteLogRecord — mirroring how SpanLimits flows through TracerProvider.
…dk.py

Co-authored-by: Aaron Abbott <aaronabbott@google.com>
@ocelotl
ocelotl force-pushed the diego/config-attribute-limits branch from f0ef10d to 252abd5 Compare August 22, 2026 21:51
@ocelotl

ocelotl commented Aug 22, 2026

Copy link
Copy Markdown
Contributor Author

/dashboard route:reviewers

@opentelemetry-pr-dashboard

Copy link
Copy Markdown

@ocelotl, this pull request was routed to reviewers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved PRs that need fixes

Development

Successfully merging this pull request may close these issues.

Logging stability review: [minor] LogRecord attribute limits not configurable via LoggerProvider

6 participants