Skip to content

fix(sdk): use context instead of deprecated trace_id/span_id kwargs in EventLogger.emit#5199

Closed
kimjune01 wants to merge 2 commits into
open-telemetry:mainfrom
kimjune01:fix/event-logger-deprecation-warning
Closed

fix(sdk): use context instead of deprecated trace_id/span_id kwargs in EventLogger.emit#5199
kimjune01 wants to merge 2 commits into
open-telemetry:mainfrom
kimjune01:fix/event-logger-deprecation-warning

Conversation

@kimjune01
Copy link
Copy Markdown

@kimjune01 kimjune01 commented May 12, 2026

Summary

  • EventLogger.emit passes trace_id, span_id, and trace_flags directly to LogRecord.__init__. Those kwargs are documented as deprecated in favor of extracting trace correlation from context (the @typing_extensions.deprecated markers on the relevant @overload are type-checker-only and don't fire a runtime warning, but the API direction is upstream-documented).
  • When the Event carries explicit trace correlation IDs that differ from the current span context, this PR wraps them in a NonRecordingSpan and passes them via the context parameter — matching the supported overload going forward and removing reliance on the deprecated path.
  • Behavior is preserved across all realistic Event-context vs emit-context combinations; the change is a contract migration, not a bug fix.

Test plan

  • Added test_event_logger_emit_explicit_trace_ids verifying that explicit trace IDs are preserved in the emitted LogRecord via the context path.
  • Updated existing tests to use context=event.context instead of the deprecated kwargs.
  • pytest opentelemetry-sdk/tests/events/test_events.py: 10 passed (0.31s).

…tLogger.emit

EventLogger.emit() was constructing LogRecord with explicit trace_id,
span_id, and trace_flags parameters, which triggers a deprecation
warning since 1.35.0. Switch to passing context to LogRecord.

When the Event carries explicit trace_id/span_id/trace_flags that
differ from its captured context, wrap them in a NonRecordingSpan so
LogRecord picks them up from context without the deprecated kwargs.

Fixes open-telemetry#4687

Assisted-by: Claude Opus 4.6
@kimjune01 kimjune01 requested a review from a team as a code owner May 12, 2026 05:48
@emdneto
Copy link
Copy Markdown
Member

emdneto commented May 12, 2026

Thanks for the PR!

Just a heads-up: we no longer update CHANGELOG.md directly. The changelog is now generated from changelog fragments using Towncrier.

Please add the appropriate changelog fragment for this change instead of editing CHANGELOG.md manually. You can find the instructions and expected format in CONTRIBUTING.md.

@kimjune01 kimjune01 closed this May 13, 2026
@kimjune01 kimjune01 deleted the fix/event-logger-deprecation-warning branch May 13, 2026 04:09
@kimjune01 kimjune01 reopened this May 13, 2026
@kimjune01
Copy link
Copy Markdown
Author

Thanks @emdneto — done in cd113cf. Reverted the CHANGELOG.md edit and added .changelog/5199.fixed per the Towncrier instructions in CONTRIBUTING.md.

@tammy-baylis-swi tammy-baylis-swi moved this from Done to Ready for review in Python PR digest May 14, 2026
@tammy-baylis-swi
Copy link
Copy Markdown
Contributor

Hi @kimjune01 , thank you for contributing but this API itself is deprecated. I recommend picking up an issue to stabilize the new Logging API/SDK if you're interested!

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

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants