Skip to content

Move capture_message_content kwarg logic to genai-utils#140

Open
rads-1996 wants to merge 2 commits into
open-telemetry:mainfrom
rads-1996:fix-content-capture
Open

Move capture_message_content kwarg logic to genai-utils#140
rads-1996 wants to merge 2 commits into
open-telemetry:mainfrom
rads-1996:fix-content-capture

Conversation

@rads-1996

@rads-1996 rads-1996 commented Jun 15, 2026

Copy link
Copy Markdown

Description

The opentelemetry-instrumentation-genai-openai-agents package carried its own _resolve_content_mode helper to translate a capture_message_content kwarg into a ContentCapturingMode (handling enum/bool/string aliases and falling back to the OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT env var). This change lifts that logic into opentelemetry-util-genai as a shared resolve_capture_message_content() helper so every GenAI instrumentation can adopt the same kwarg pattern without copying the code. The ContentCapturingMode enum also gains capture_in_span / capture_in_event properties so callers no longer need to hard-code which modes imply span vs. event capture.

opentelemetry-instrumentation-genai-openai-agents
Breaking Change - Previous behavior: Previously when neither the kwarg nor the env var were set, content capture defaulted to SPAN_AND_EVENT.

New Behavior: Like other instrumentations when neither the kwarg nor the env var were set, content capture is defaulted to NO_CONTENT. Users who want sensitive content captured must opt in explicitly via the env var or the new kwarg.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How has this been tested?

Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. List any relevant details for your test
configuration.

  • Unit tests

Checklist

See CONTRIBUTING.md
for the style guide, changelog guidance, and more.

  • Followed the style guidelines of this project
  • Changelog updated if the change requires an entry
  • Unit tests added
  • Documentation updated

Copilot AI review requested due to automatic review settings June 15, 2026 21:27
@rads-1996 rads-1996 requested a review from a team as a code owner June 15, 2026 21:27
@rads-1996 rads-1996 marked this pull request as draft June 15, 2026 21:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Centralizes and standardizes “message content capture” resolution across GenAI instrumentations by introducing a shared resolver, and consolidates capture-mode semantics into the shared ContentCapturingMode type.

Changes:

  • Added resolve_capture_message_content(...) helper with alias support and warning-on-unknown behavior.
  • Added capture_in_span / capture_in_event properties to ContentCapturingMode and migrated OpenAI Agents to use the shared enum.
  • Updated and expanded tests; adjusted OpenAI Agents tests to set a default capture mode and removed coverage tests for deleted private resolver.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
util/opentelemetry-util-genai/tests/test_utils.py Adds unit tests for the new capture-mode resolver and enum properties.
util/opentelemetry-util-genai/src/opentelemetry/util/genai/utils.py Introduces the shared resolve_capture_message_content resolver and alias map.
util/opentelemetry-util-genai/src/opentelemetry/util/genai/types.py Adds helper properties for capture-in-span / capture-in-event checks.
instrumentation/opentelemetry-instrumentation-genai-openai-agents/tests/test_zz_coverage_improvements.py Removes tests for deleted _resolve_content_mode and updates coverage note.
instrumentation/opentelemetry-instrumentation-genai-openai-agents/tests/test_tracer.py Sets default capture_message_content for tests that assert captured content.
instrumentation/opentelemetry-instrumentation-genai-openai-agents/src/opentelemetry/instrumentation/genai/openai_agents/span_processor.py Switches to shared ContentCapturingMode and provides a compatibility alias.
instrumentation/opentelemetry-instrumentation-genai-openai-agents/src/opentelemetry/instrumentation/genai/openai_agents/init.py Replaces local resolver/env handling with shared resolve_capture_message_content.

Comment thread util/opentelemetry-util-genai/tests/test_utils.py
@rads-1996 rads-1996 changed the title Move capture_message_content kwarg to utils Move capture_message_content kwarg logic to genai-utils Jun 15, 2026
# Map of accepted kwarg string aliases to ContentCapturingMode. Kept lenient
# for backwards compatibility with existing instrumentations that historically
# accepted boolean-ish strings or hyphenated forms.
_CAPTURE_MODE_ALIASES: dict[str, ContentCapturingMode] = {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Do we still want to allow for such flexibility or make it more stricter?

@rads-1996 rads-1996 marked this pull request as ready for review June 15, 2026 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants