Skip to content

fix(openai): Handle content capture with span_and_event mode#4417

Open
Nik-Reddy wants to merge 1 commit intoopen-telemetry:mainfrom
Nik-Reddy:fix/openai-content-capture-4038
Open

fix(openai): Handle content capture with span_and_event mode#4417
Nik-Reddy wants to merge 1 commit intoopen-telemetry:mainfrom
Nik-Reddy:fix/openai-content-capture-4038

Conversation

@Nik-Reddy
Copy link
Copy Markdown

Description

When OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT is set to span_and_event (or other valid ContentCapturingMode values like span_only, event_only), the openai-v2 instrumentation silently drops all message content. This is because is_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() in utils.py:
python return os.environ.get(OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT, "").lower() == "true"

The newer ContentCapturingMode enum values (span_and_event, span_only, event_only) were never recognized — only the legacy "true" string worked.

Changes

  • utils.py: Updated is_content_enabled() to recognize all valid ContentCapturingMode enum values as content-enabled, while preserving backward compatibility with the "true" string
  • conftest.py: Added span_and_event test parameter to verify the legacy semconv path works with newer env var values

Type of change

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

How Has This Been Tested?

All 102 content-related tests pass (57 sync + 45 async), including the new span_and_event on legacy path test cases.

pytest tests/ -v -k content

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

@xrmx xrmx added the gen-ai Related to generative AI label Apr 13, 2026
@Nik-Reddy Nik-Reddy force-pushed the fix/openai-content-capture-4038 branch from 64d1b17 to 5d82d94 Compare April 13, 2026 19:04
@Nik-Reddy Nik-Reddy requested a review from xrmx April 14, 2026 18:01
Copy link
Copy Markdown
Member

@lmolkova lmolkova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's being addressed in #4315, could you please review that PR instead?

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
@Nik-Reddy Nik-Reddy force-pushed the fix/openai-content-capture-4038 branch from 5d82d94 to 25dbc1e Compare April 15, 2026 01:08
@Nik-Reddy
Copy link
Copy Markdown
Author

Nik-Reddy commented Apr 15, 2026

Rebased on latest main. All review feedback addressed, reverted conftest changes and added 12 focused unit tests. Review thread resolved. Ready for review.

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

Labels

gen-ai Related to generative AI

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

openai-v2 instrumentation not capturing content message

3 participants