Add retrieval support in langchain#124
Open
wrisa wants to merge 12 commits into
Open
Conversation
…python-genai into langchain-retrieval
…python-genai into langchain-retrieval
Contributor
There was a problem hiding this comment.
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_errorin 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] = [] |
…python-genai into langchain-retrieval
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.
Retrieval span and metric,

Fixes # (issue)
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.