Move capture_message_content kwarg logic to genai-utils#140
Open
rads-1996 wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
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_eventproperties toContentCapturingModeand 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. |
rads-1996
commented
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] = { |
Author
There was a problem hiding this comment.
Do we still want to allow for such flexibility or make it more stricter?
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
The
opentelemetry-instrumentation-genai-openai-agentspackage carried its own_resolve_content_modehelper to translate acapture_message_contentkwarg into a ContentCapturingMode (handling enum/bool/string aliases and falling back to theOTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENTenv var). This change lifts that logic intoopentelemetry-util-genaias a sharedresolve_capture_message_content()helper so every GenAI instrumentation can adopt the same kwarg pattern without copying the code. TheContentCapturingModeenum 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-agentsBreaking 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.
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.
Checklist
See CONTRIBUTING.md
for the style guide, changelog guidance, and more.