Skip to content

logs: add Enabled support to Logger API, SDK, and LogRecordProcessor - #5380

Open
ocelotl wants to merge 11 commits into
open-telemetry:mainfrom
ocelotl:issue_5360
Open

logs: add Enabled support to Logger API, SDK, and LogRecordProcessor#5380
ocelotl wants to merge 11 commits into
open-telemetry:mainfrom
ocelotl:issue_5360

Conversation

@ocelotl

@ocelotl ocelotl commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements the Enabled chain from the OpenTelemetry Logs specification, closes #5360.

  • API Logger.enabled(context, severity_number, event_name) -> bool: non-abstract default returning True; NoOpLogger returns False; ProxyLogger delegates to the real logger.
  • SDK LogRecordProcessor.enabled(context, instrumentation_scope, severity_number, event_name) -> bool: non-abstract default returning True — processors opt into filtering by overriding this method.
  • SDK SynchronousMultiLogRecordProcessor / ConcurrentMultiLogRecordProcessor: enabled() returns False when no processors are registered, False when all processors return False, True otherwise.
  • SDK Logger.enabled(): checks LoggerConfig.is_enabled first, then delegates to the multi-processor with the logger's instrumentation scope.

Test plan

  • New SDK tests covering: no processors → False, processor present → True, disabled logger config → False, args forwarded to processor, all processors disabled → False, one processor enabled → True
  • New API tests covering: NoOpLogger.enabled()False, ProxyLogger.enabled() delegates to real logger, ProxyLogger.enabled() falls back to no-op

@ocelotl
ocelotl marked this pull request as ready for review July 3, 2026 23:45
@ocelotl
ocelotl requested a review from a team as a code owner July 3, 2026 23:45
Comment thread opentelemetry-api/src/opentelemetry/_logs/_internal/__init__.py Outdated
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py
@carlosalberto

carlosalberto commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Symbolic approval. Overall good, just a non blocking comment regarding the default implementation for Logger.enabled()

Comment thread opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py
Comment thread .changelog/5380.added Outdated
Comment thread .changelog/5380.added

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

Small nit on the changelog but LGTM

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

LGTM. Nit: since making Logger.enabled abstract breaks external Logger subclasses, worth prefixing the 5380.changed entry with [BREAKING] like we did in #4676 / #4647

@github-project-automation github-project-automation Bot moved this to Approved PRs in Python PR digest Jul 22, 2026
@ocelotl

ocelotl commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

LGTM. Nit: since making Logger.enabled abstract breaks external Logger subclasses, worth prefixing the 5380.changed entry with [BREAKING] like we did in #4676 / #4647

We are not yet stable, so this is not breaking ✌️

@aabmass

aabmass commented Aug 4, 2026

Copy link
Copy Markdown
Member

LGTM. Nit: since making Logger.enabled abstract breaks external Logger subclasses, worth prefixing the 5380.changed entry with [BREAKING] like we did in #4676 / #4647

The PRs Hector linked were for logs too. It's still breaking change even to logging (even if it's in an unstable component) so it's nice to call attention in the changelog

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-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py Outdated
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py Outdated
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py
@aabmass aabmass moved this from Approved PRs to Approved PRs that need fixes in Python PR digest Aug 4, 2026
@aabmass
aabmass requested a lite review from Copilot August 4, 2026 18:45

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Adds enabled() support across the Logs API + SDK to allow instrumentation to cheaply decide whether to construct/emit log records.

Changes:

  • Introduces enabled() on API Logger and SDK Logger/LogRecordProcessor, including multi-processor aggregation behavior.
  • Adds SDK and API tests covering enabled/no-op/proxy delegation scenarios.
  • Adds changelog entries documenting the API/SDK change.

Reviewed changes

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

Show a summary per file
File Description
opentelemetry-sdk/tests/logs/test_logs.py Adds SDK tests for Logger.enabled() behavior with/without processors and config gating.
opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/init.py Implements enabled() on LogRecordProcessor, multi-processors, and SDK Logger.
opentelemetry-api/tests/logs/test_proxy.py Adds API tests for ProxyLogger.enabled() delegation and NoOpLogger.enabled().
opentelemetry-api/src/opentelemetry/_logs/_internal/init.py Adds enabled() to API Logger plus implementations in NoOpLogger and ProxyLogger.
.changelog/5380.changed Notes a breaking requirement for Logger subclasses regarding enabled().
.changelog/5380.added Announces enabled() support addition across API/SDK and processors.

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

Comment thread opentelemetry-api/src/opentelemetry/_logs/_internal/__init__.py
Comment thread opentelemetry-sdk/tests/logs/test_logs.py
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py Outdated
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py
ocelotl added 3 commits August 7, 2026 16:47
Implements the Enabled chain from the OpenTelemetry Logs specification:

- API Logger.enabled(context, severity_number, event_name) -> bool:
  default True; NoOpLogger returns False; ProxyLogger delegates.
- SDK LogRecordProcessor.enabled(...) -> bool: non-abstract default True
  so existing processors opt-in by overriding.
- SDK SynchronousMultiLogRecordProcessor/ConcurrentMultiLogRecordProcessor:
  enabled() returns False when no processors are registered, False when
  all processors return False, otherwise True.
- SDK Logger.enabled(): checks LoggerConfig.is_enabled first, then
  delegates to the multi-processor with the instrumentation scope.

Closes open-telemetry#5360
…g fragment

Add pylint disable=no-self-use annotations to the enabled() default
implementations in the Logger API and LogRecordProcessor SDK base
classes, matching the existing pattern used for force_flush(). Also
add the missing .changelog/5380.added fragment required by the
changelog CI check.
ocelotl and others added 5 commits August 7, 2026 16:47
Since the logs API is not yet stable, adding enabled() as an abstract
method does not break a released version. All concrete Logger subclasses
(NoOpLogger, ProxyLogger, and the SDK Logger) already provide an
implementation.
…__.py

Co-authored-by: Aaron Abbott <aaronabbott@google.com>
…__.py

Co-authored-by: Aaron Abbott <aaronabbott@google.com>
Set enabled.return_value = True on the mock processor and assert it was
called, so the test verifies the multi-processor wiring rather than
passing on a bare Mock's truthiness.
ocelotl added 2 commits August 7, 2026 16:53
pylint reports unused-argument on the parameter lines, so the disable on
the return statement did not suppress it. Fold it into the disable on the
def line where it is effective.
Reflow assertions to the project's ruff-format style so the precommit
check passes.
@ocelotl
ocelotl requested a review from aabmass August 7, 2026 22:24
Even though logs are not yet stable, adding an abstract enabled() breaks
external Logger subclasses, so call it out in the changelog.
@ocelotl

ocelotl commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Good point, agreed. Prefixed the 5380.changed entry with [BREAKING] in 5bab95b to call attention to it in the changelog, even though logs are still unstable.

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Aug 14, 2026

Copy link
Copy Markdown

Pull request dashboard status

Waiting on maintainers · refreshed 2026-08-17 17:31 UTC

Merge when ready.

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.

@github-project-automation github-project-automation Bot moved this from Approved PRs that need fixes to Approved PRs in Python PR digest Aug 17, 2026
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

Development

Successfully merging this pull request may close these issues.

Logging stability review: [major] No Enabled support across API, SDK, and processors

9 participants