Skip to content

feat(api): add forward-compatible kwargs to Logger and LoggerProvider - #5851

Open
herin049 wants to merge 2 commits into
open-telemetry:mainfrom
herin049:feat/logs-fwd-compat
Open

herin049 wants to merge 2 commits into
open-telemetry:mainfrom
herin049:feat/logs-fwd-compat

Conversation

@herin049

Copy link
Copy Markdown
Contributor

Description

Makes the logs API forward compatible: new keyword-only parameters can be added later without breaking existing Logger/LoggerProvider implementations.

  • Add empty public TypedDicts LoggerOptions and LoggerProviderOptions, exported from opentelemetry._logs.
  • Logger.emit, Logger.enabled, LoggerProvider.get_logger and the module-level get_logger() now accept **kwargs: Unpack[...] of these types.
  • ProxyLoggerProvider/ProxyLogger forward the kwargs; NoOp and SDK implementations accept and ignore them.
  • SDK Logger.emit gains @overloads that match the API so pyright accepts the override.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • I am a human and not a bot
  • I have run tox -e precommit
  • I have run tox -e typecheck
  • I have run the relevant tests and linting tox environments
  • This requires the following PR in contrib:

@herin049
herin049 requested a review from a team as a code owner October 28, 2026 03:08
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on the author · refreshed 2026-10-29 15:45 UTC

Respond to 1 review item (e.g. link a commit, explain why not, ask a follow-up):

  • Inline threads: 1
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.
  • Should this be with reviewers? Comment /dashboard route:reviewers to route it to them.
  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.

@github-project-automation github-project-automation Bot moved this to Approved PRs in Python PR digest Oct 28, 2026
attributes: Attributes = None,
event_name: str | None = None,
exception: BaseException | None = None,
**kwargs: Unpack[LoggerOptions],

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.

WDYT of using **kwargs: Never? Based on some (AI) testing I did, mypy and pyright don't behave consistently; mypy doesn't force implementations to have a catch all **kwargs in their signature if the TypedDict is empty (like we have here).

Table from AI testing

Base-class annotation (2) typos at call site are caught (3) override that drops **kwargs Notes
**kwargs: Any ❌ pyright, ❌ mypy ✅ both What OTel metrics does today (implicitly). Forces implementers, but callers can pass anything.
**kwargs: Never ✅ both ("int not assignable to Never") ✅ both Single method, no runtime cost, works in both checkers. Slightly unusual-looking
**kwargs: Unpack[EmptyTypedDict] ✅ both ✅ pyright, ❌ mypy mypy treats an empty TypedDict unpack as "no extra params" and accepts an implementation declared with **kwargs.

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.

Sure, let me give it a go. May also update the advisory attributes PR with this convention as well.

"""


class LoggerOptions(TypedDict):

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.

Would we leave this empty and add new parameters to the actual signatures, or would we actually add new params here?

@herin049 herin049 Oct 29, 2026 •

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.

I guess there's a few options here:

  • Use **kwargs: Never as you suggested above, and just add additional keyword arguments to the API/SDK signatures directly. This should be safe since if an implementation has **kwargs: Never, it must always accept any keyword arguments (at runtime), even though it might ignore them.
  • Stick with **kwargs: Never initially, and then switch to **kwargs: Unpack[LoggerOptions] once we have additional options we want to add.

I actually didn't think about the first case until you brought it up, and I do somewhat like it better.

This branch has not been deployed

No deployments
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.

3 participants