Skip to content

fix(instrumentation-logging): promote otel.event.name to LogRecord.event_name in _translate#4750

Open
rajdhruvsingh wants to merge 4 commits into
open-telemetry:mainfrom
rajdhruvsingh:fix/4743-promote-event-name-in-logging-handler
Open

fix(instrumentation-logging): promote otel.event.name to LogRecord.event_name in _translate#4750
rajdhruvsingh wants to merge 4 commits into
open-telemetry:mainfrom
rajdhruvsingh:fix/4743-promote-event-name-in-logging-handler

Conversation

@rajdhruvsingh

Copy link
Copy Markdown
Contributor

Description

LoggingHandler._translate never set the first-class event_name field on
LogRecord. When a user passed otel.event.name (or the deprecated event.name)
via extra={...}, it silently landed in attributes as a plain key and was
exported as a regular OTLP attribute instead of the dedicated event_name field.

This fix updates _get_attributes to pop both keys from the attributes dict and
return the resolved event name alongside the attributes. _translate then passes
it as event_name= to LogRecord(...).

  • otel.event.name (stable) takes precedence
  • event.name (deprecated) is used only as a fallback
  • Both keys are always popped so neither leaks into attributes

Fixes #4743

Part of open-telemetry/community#1751

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Five new unit tests added to TestLoggingHandler in tests/test_handler.py:

  • test_otel_event_name_promoted_to_event_name_field — stable key is promoted to event_name, removed from attributes
  • test_deprecated_event_name_promoted_as_fallback — deprecated event.name works when stable key is absent
  • test_otel_event_name_takes_precedence_over_deprecated_event_name — stable key wins when both are present, both popped from attributes
  • test_event_name_is_none_when_not_providedevent_name is None when neither key is passed (no regression)
  • test_other_extra_attributes_unaffected_by_event_name_promotion — unrelated extra fields still land in attributes normally

All 36 existing tests continue to pass (41 total).

To reproduce:
python3 -m pytest instrumentation/opentelemetry-instrumentation-logging/tests/test_handler.py -v

Does This PR Require a Core Repo Change?

  • No.

Checklist

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

…ent_name in _translate

Per OTel semantic conventions, otel.event.name (stable) and event.name
(deprecated) should be set as the first-class event_name field on
LogRecord rather than left as plain attributes.

Both keys are always popped from the attributes dict so neither leaks
through. otel.event.name takes precedence; event.name is used only as
a fallback.

Fixes open-telemetry#4743
@rajdhruvsingh rajdhruvsingh requested a review from a team as a code owner June 27, 2026 04:53
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.

Logging stability review: [minor] otel.event.name not promoted to the EventName by logging bridge

1 participant