-
Notifications
You must be signed in to change notification settings - Fork 62
Add LlamaIndex retrieval instrumentation #698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lmolkova
merged 16 commits into
open-telemetry:main
from
eternalcuriouslearner:feat/llama-index-retrieval-v2
Sep 13, 2026
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b9a1f66
Add LlamaIndex retrieval instrumentation
eternalcuriouslearner 360f9fc
Add LlamaIndex retrieval changelog
eternalcuriouslearner 6bace05
Merge upstream main
eternalcuriouslearner 1844ec7
Use shared retrieval document model
eternalcuriouslearner 5e4f169
Update retrieval changelog fragments
eternalcuriouslearner 1b1d5b5
Refactor import statements and improve code formatting in retrieval t…
eternalcuriouslearner 2fd996c
Fix LlamaIndex retrieval document content
eternalcuriouslearner 3fbdab0
Test LlamaIndex QueryBundle retrieval
eternalcuriouslearner 0689e35
Keep retrieval documents instrumentation-local
eternalcuriouslearner a5d5bfb
Change exception handling to BaseException
eternalcuriouslearner 3343682
Harden retrieval metadata extraction
eternalcuriouslearner b35eb13
Assert retrieval attribute types
eternalcuriouslearner 29c1b86
Refactor _retrieval_documents to improve type casting and return logic
eternalcuriouslearner f68ac74
Merge branch 'main' into feat/llama-index-retrieval-v2
eternalcuriouslearner 17a95d1
Match retrieval metadata access pattern
eternalcuriouslearner d9c5f93
Add missing import for json in test_retrieval.py
eternalcuriouslearner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
instrumentation/opentelemetry-instrumentation-genai-llama-index/.changelog/698.added
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add retrieval span instrumentation for LlamaIndex ``BaseRetriever`` operations. |
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
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
66 changes: 66 additions & 0 deletions
66
...umentation/opentelemetry-instrumentation-genai-llama-index/tests/conformance/retrieval.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # Copyright The OpenTelemetry Authors | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Any | ||
|
|
||
| from llama_index.core.base.base_retriever import BaseRetriever | ||
| from llama_index.core.schema import NodeWithScore, QueryBundle, TextNode | ||
|
|
||
| from opentelemetry.instrumentation.genai.llama_index import ( | ||
| LlamaIndexInstrumentor, | ||
| ) | ||
| from opentelemetry.sdk._logs import LoggerProvider | ||
| from opentelemetry.sdk.metrics import MeterProvider | ||
| from opentelemetry.sdk.trace import TracerProvider | ||
| from opentelemetry.test_util_genai.conformance import ( | ||
| ExpectedViolation, | ||
| Scenario, | ||
| ) | ||
| from opentelemetry.test_util_genai.instrumentor import instrument | ||
|
|
||
|
|
||
| class _ConformanceRetriever(BaseRetriever): | ||
| def __init__(self) -> None: | ||
| super().__init__() | ||
| self.similarity_top_k = 1 | ||
|
|
||
| def _retrieve(self, query_bundle: QueryBundle) -> list[NodeWithScore]: | ||
| return [ | ||
| NodeWithScore( | ||
| node=TextNode( | ||
| id_="capital-france", | ||
| text="Paris is the capital of France.", | ||
| ), | ||
| score=0.99, | ||
| ) | ||
| ] | ||
|
|
||
|
|
||
| class RetrievalScenario(Scenario): | ||
| expected_spans = {"retrieval": 1} | ||
| expected_metrics = ("gen_ai.client.operation.duration",) | ||
| expected_violations = ( | ||
| ExpectedViolation( | ||
| advice_id="genai_expected_attribute_missing", | ||
| message_substring="server.address", | ||
| ), | ||
| ) | ||
|
|
||
| def run( | ||
| self, | ||
| *, | ||
| tracer_provider: TracerProvider, | ||
| meter_provider: MeterProvider, | ||
| logger_provider: LoggerProvider, | ||
| vcr: Any, | ||
| ) -> None: | ||
| with instrument( | ||
| LlamaIndexInstrumentor(), | ||
| tracer_provider=tracer_provider, | ||
| logger_provider=logger_provider, | ||
| meter_provider=meter_provider, | ||
| content_capture="SPAN_ONLY", | ||
| ): | ||
| _ConformanceRetriever().retrieve("What is the capital of France?") |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.