Skip to content

util-genai | Add RetrievalInvocation and lifecycle API#36

Merged
lmolkova merged 12 commits into
open-telemetry:mainfrom
keith-decker:add-retrieval-invocation
Jun 1, 2026
Merged

util-genai | Add RetrievalInvocation and lifecycle API#36
lmolkova merged 12 commits into
open-telemetry:mainfrom
keith-decker:add-retrieval-invocation

Conversation

@keith-decker

Copy link
Copy Markdown
Contributor

This pull request adds support for tracing retrieval operations in the GenAI OpenTelemetry utility by introducing a new RetrievalInvocation type, 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:

  • Introduced the RetrievalInvocation class 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.
  • Added start_retrieval and retrieval methods to the TelemetryHandler (handler.py), enabling both direct and context-managed retrieval span creation. [1] [2]
  • Updated the module exports and imports to include RetrievalInvocation in invocation.py and related files. [1] [2] [3] [4]

Documentation and changelog:

  • Updated the documentation (AGENTS.md) and changelog to reflect the addition of retrieval span support and new APIs. [1] [2]

Copilot AI review requested due to automatic review settings May 18, 2026 15:55
@keith-decker
keith-decker requested a review from a team as a code owner May 18, 2026 15:55

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

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 RetrievalInvocation and exports it through the public invocation module.
  • Adds TelemetryHandler.start_retrieval() and TelemetryHandler.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.

Comment thread util/opentelemetry-util-genai/tests/test_handler_retrieval.py
Comment thread util/opentelemetry-util-genai/CHANGELOG.md Outdated
Comment thread util/opentelemetry-util-genai/AGENTS.md Outdated
Comment thread util/opentelemetry-util-genai/src/opentelemetry/util/genai/handler.py Outdated

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

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.dict exits. Without cleanup, later tests can observe stale experimental mode even though the environment was restored.
        _OpenTelemetrySemanticConventionStability._initialized = False
        _OpenTelemetrySemanticConventionStability._initialize()

Comment thread util/opentelemetry-util-genai/tests/test_handler_retrieval.py
Comment thread util/opentelemetry-util-genai/CHANGELOG.md Outdated
@lzchen

lzchen commented May 18, 2026

Copy link
Copy Markdown
Contributor

This might conflict with the changes being made here

@keith-decker

Copy link
Copy Markdown
Contributor Author

This might conflict with the changes being made here

Understood, I can rework this one to comply with #17 if it merges first.

Comment thread util/opentelemetry-util-genai/src/opentelemetry/util/genai/handler.py Outdated
Comment thread instrumentation/opentelemetry-instrumentation-langchain/.changelog/36.added Outdated
@keith-decker
keith-decker force-pushed the add-retrieval-invocation branch from ef3c1a2 to 39c8e7f Compare May 19, 2026 15:37
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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

from call: why isn't type checker complaining here about set_attributes not being Attributes type

@lmolkova
lmolkova added this pull request to the merge queue Jun 1, 2026
Merged via the queue into open-telemetry:main with commit b83f540 Jun 1, 2026
84 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants