fix(openai): Handle content capture with span_and_event mode#4417
Open
Nik-Reddy wants to merge 1 commit intoopen-telemetry:mainfrom
Open
fix(openai): Handle content capture with span_and_event mode#4417Nik-Reddy wants to merge 1 commit intoopen-telemetry:mainfrom
Nik-Reddy wants to merge 1 commit intoopen-telemetry:mainfrom
Conversation
xrmx
reviewed
Apr 13, 2026
instrumentation-genai/opentelemetry-instrumentation-openai-v2/tests/conftest.py
Outdated
Show resolved
Hide resolved
64d1b17 to
5d82d94
Compare
The is_content_enabled() function only recognized 'true' as a valid value for OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT, causing newer enum values like 'span_and_event' to be treated as disabled. Updated is_content_enabled() to recognize all valid ContentCapturingMode enum values (span_only, event_only, span_and_event) in addition to the legacy 'true' value. Added dedicated unit tests for is_content_enabled() covering all ContentCapturingMode values instead of fixture-based testing. Fixes open-telemetry#4038
5d82d94 to
25dbc1e
Compare
Author
|
Rebased on latest main. All review feedback addressed, reverted conftest changes and added 12 focused unit tests. Review thread resolved. Ready for review. |
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
When
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENTis set tospan_and_event(or other validContentCapturingModevalues likespan_only,event_only), the openai-v2 instrumentation silently drops all message content. This is becauseis_content_enabled()only checks for the string"true"— any other value is treated as disabled.This affects the OTel Demo's product-reviews service and any user following the current semantic conventions documentation.
Fixes #4038
Root Cause
is_content_enabled()inutils.py:python return os.environ.get(OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT, "").lower() == "true"The newer
ContentCapturingModeenum values (span_and_event,span_only,event_only) were never recognized — only the legacy"true"string worked.Changes
utils.py: Updatedis_content_enabled()to recognize all validContentCapturingModeenum values as content-enabled, while preserving backward compatibility with the"true"stringconftest.py: Addedspan_and_eventtest parameter to verify the legacy semconv path works with newer env var valuesType of change
How Has This Been Tested?
All 102 content-related tests pass (57 sync + 45 async), including the new
span_and_eventon legacy path test cases.Does This PR Require a Core Repo Change?
Checklist: