Skip to content

Add retrieval support in langchain#124

Open
wrisa wants to merge 12 commits into
open-telemetry:mainfrom
wrisa:langchain-retrieval
Open

Add retrieval support in langchain#124
wrisa wants to merge 12 commits into
open-telemetry:mainfrom
wrisa:langchain-retrieval

Conversation

@wrisa

@wrisa wrisa commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Retrieval span and metric,
Screenshot 2026-06-12 at 12 27 51 PM

Fixes # (issue)

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.

  • Test A

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

@wrisa wrisa marked this pull request as ready for review June 15, 2026 07:40
@wrisa wrisa requested a review from a team as a code owner June 15, 2026 07:40
Copilot AI review requested due to automatic review settings June 15, 2026 07:40

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.

Adds LangChain retriever (vector-store retrieval) instrumentation coverage, including callback handler support and end-to-end validation via integration + conformance tests.

Changes:

  • Implemented on_retriever_start/on_retriever_end/on_retriever_error in the LangChain callback handler.
  • Added integration tests for retriever spans/attributes/metrics and callback-handler unit tests for retrieval lifecycle.
  • Added a conformance retrieval scenario and registered it in the conformance test suite; updated dependency + changelog.

Reviewed changes

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

Show a summary per file
File Description
instrumentation/opentelemetry-instrumentation-genai-langchain/src/opentelemetry/instrumentation/genai/langchain/callback_handler.py Adds retriever lifecycle callbacks and maps retrieved documents into invocation data.
instrumentation/opentelemetry-instrumentation-genai-langchain/tests/test_callback_handler.py Adds unit tests validating retriever callback behavior and state management.
instrumentation/opentelemetry-instrumentation-genai-langchain/tests/test_retriever.py Adds end-to-end integration tests for retrieval spans, attributes, and duration metrics.
instrumentation/opentelemetry-instrumentation-genai-langchain/tests/conformance/retrieval.py Introduces a conformance scenario for retrieval instrumentation.
instrumentation/opentelemetry-instrumentation-genai-langchain/tests/test_conformance.py Registers the new RetrievalScenario in the conformance suite.
instrumentation/opentelemetry-instrumentation-genai-langchain/pyproject.toml Adjusts opentelemetry-util-genai minimum dependency version.
instrumentation/opentelemetry-instrumentation-genai-langchain/.changelog/124.added Changelog entry for retrieval span support.

Comment on lines +445 to +454
invocation.documents = [
{
"content": doc.page_content,
**({"id": doc.id} if doc.id is not None else {}),
**{
k: v
for k, v in cast(dict[str, Any], doc.metadata).items()
if v is not None
},
}
dependencies = [
"opentelemetry-instrumentation >= 0.62b0",
"opentelemetry-util-genai >= 1.0b0.dev",
"opentelemetry-util-genai >= 0.1b0",
class _FakeRetriever(BaseRetriever):
"""In-memory retriever — no network calls, no embeddings."""

documents: list[Document] = []
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.

2 participants