util-genai | Add RetrievalInvocation and lifecycle API#36
Merged
lmolkova merged 12 commits intoJun 1, 2026
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds retrieval-operation tracing support to opentelemetry-util-genai, introducing a new invocation type and lifecycle APIs aligned with the GenAI utility’s invocation model.
Changes:
- Adds
RetrievalInvocationand exports it through the public invocation module. - Adds
TelemetryHandler.start_retrieval()andTelemetryHandler.retrieval(). - Adds retrieval tests plus changelog/AGENTS documentation updates.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
util/opentelemetry-util-genai/src/opentelemetry/util/genai/_retrieval_invocation.py |
Implements retrieval span attributes, content capture, error handling, and metrics recording. |
util/opentelemetry-util-genai/src/opentelemetry/util/genai/handler.py |
Adds retrieval factory and context-manager APIs. |
util/opentelemetry-util-genai/src/opentelemetry/util/genai/invocation.py |
Exports RetrievalInvocation. |
util/opentelemetry-util-genai/tests/test_handler_retrieval.py |
Adds span, error, content-capture, context-manager, and sampling tests for retrieval. |
util/opentelemetry-util-genai/CHANGELOG.md |
Documents the new retrieval API. |
util/opentelemetry-util-genai/AGENTS.md |
Updates maintainer guidance to include retrieval APIs. |
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
util/opentelemetry-util-genai/tests/test_handler_retrieval.py:199
- This test also leaves the semantic-convention stability singleton initialized with the patched experimental environment after
patch.dictexits. Without cleanup, later tests can observe stale experimental mode even though the environment was restored.
_OpenTelemetrySemanticConventionStability._initialized = False
_OpenTelemetrySemanticConventionStability._initialize()
Contributor
|
This might conflict with the changes being made here |
Contributor
Author
lmolkova
reviewed
May 18, 2026
keith-decker
force-pushed
the
add-retrieval-invocation
branch
from
May 19, 2026 15:37
ef3c1a2 to
39c8e7f
Compare
lzchen
reviewed
May 20, 2026
lmolkova
approved these changes
May 21, 2026
aabmass
reviewed
May 21, 2026
aabmass
reviewed
May 21, 2026
| attributes[GenAI.GEN_AI_REQUEST_TOP_K] = self.top_k | ||
| attributes.update(self._get_content_attributes_for_span()) | ||
| attributes.update(self.attributes) | ||
| self.span.set_attributes(attributes) |
Member
There was a problem hiding this comment.
from call: why isn't type checker complaining here about set_attributes not being Attributes type
lzchen
approved these changes
May 22, 2026
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.
This pull request adds support for tracing retrieval operations in the GenAI OpenTelemetry utility by introducing a new
RetrievalInvocationtype, along with corresponding factory and context manager methods. This enhancement ensures that retrieval operations are properly instrumented and aligned with the GenAI semantic conventions.Retrieval operation tracing support:
RetrievalInvocationclass to represent retrieval spans, capturing attributes such as data source ID, provider, model, server details, top-k, query text, and retrieved documents, in accordance with GenAI semantic conventions.start_retrievalandretrievalmethods to theTelemetryHandler(handler.py), enabling both direct and context-managed retrieval span creation. [1] [2]RetrievalInvocationininvocation.pyand related files. [1] [2] [3] [4]Documentation and changelog:
AGENTS.md) and changelog to reflect the addition of retrieval span support and new APIs. [1] [2]