fix(instrumentation-logging): promote otel.event.name to LogRecord.event_name in _translate#4750
Open
rajdhruvsingh wants to merge 4 commits into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
LoggingHandler._translatenever set the first-classevent_namefield onLogRecord. When a user passedotel.event.name(or the deprecatedevent.name)via
extra={...}, it silently landed inattributesas a plain key and wasexported as a regular OTLP attribute instead of the dedicated
event_namefield.This fix updates
_get_attributesto pop both keys from the attributes dict andreturn the resolved event name alongside the attributes.
_translatethen passesit as
event_name=toLogRecord(...).otel.event.name(stable) takes precedenceevent.name(deprecated) is used only as a fallbackFixes #4743
Part of open-telemetry/community#1751
Type of change
How Has This Been Tested?
Five new unit tests added to
TestLoggingHandlerintests/test_handler.py:test_otel_event_name_promoted_to_event_name_field— stable key is promoted toevent_name, removed from attributestest_deprecated_event_name_promoted_as_fallback— deprecatedevent.nameworks when stable key is absenttest_otel_event_name_takes_precedence_over_deprecated_event_name— stable key wins when both are present, both popped from attributestest_event_name_is_none_when_not_provided—event_nameisNonewhen neither key is passed (no regression)test_other_extra_attributes_unaffected_by_event_name_promotion— unrelatedextrafields still land in attributes normallyAll 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?
Checklist