Skip to content

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

Open
kimjune01 wants to merge 1 commit into
open-telemetry:mainfrom
kimjune01:fix/event-logger-deprecation-warning
Open

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

Conversation

@kimjune01
Copy link
Copy Markdown

Summary

  • EventLogger.emit passes trace_id, span_id, and trace_flags directly to LogRecord.__init__, which triggers a deprecation warning because those keyword arguments are deprecated in favor of extracting them from context.
  • When the Event carries explicit trace correlation IDs that differ from the current span context, wraps them in a NonRecordingSpan and passes them via the context parameter instead.

Test plan

  • Added test_event_logger_emit_explicit_trace_ids verifying that explicit trace IDs are preserved in the emitted LogRecord without triggering deprecation warnings
  • Updated existing tests to use context=event.context instead of the deprecated kwargs
  • pytest opentelemetry-sdk/tests/events/test_events.py: 10 passed

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

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

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants