Repository navigation
Conversation
Applies the same inversion the Anthropic integration received to LlamaIndex, so the contrib no longer imports LLMObs. The contrib previously constructed a LlamaIndexIntegration in patch(), stashed it on llama_index.core._datadog_integration, and hung it off every LlmRequestEvent, which meant ddtrace/contrib/internal/llama_index imported ddtrace.llmobs. Now the contrib dispatches the shared LlmEvents span lifecycle and LLMObs attaches its own subscribers on the llama_index.patch core event, mirroring ddtrace/llmobs/_contrib/anthropic. - patch(): drop the integration instance and _get_integration(); take integration_config/service from config.llama_index; own the llama_index.request.model and llama_index.request.provider APM tags via event.tags so they are set whether or not LLMObs is present; dispatch llama_index.patch / llama_index.unpatch. - _streaming.py: drop the integration parameter; the stream handlers only need the context to dispatch the deferred ended event. - LlamaIndexIntegration._set_base_span_tags is now a no-op: the contrib owns the APM tags and LlamaIndex has no per-request base_url to record. - The LLMObs subscribers register off the patch event, with the already-patched fallback keyed on llama_index.core rather than the top-level package. The dependency direction detector drops from 183 to 181 violations (both contrib.internal.llama_index -> llmobs._integrations edges removed, no new violations, no uncovered modules). Testing: llmobs::llama_index (61 passed) and llmobs::anthropic (108 passed) on py3.14; llmobs::llmobs matches the branch baseline exactly (1563 passed, same 11 pre-existing RC/sampling failures with and without this change). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codeowners resolved asResolved from the full PR diff against |
Circular import analysis
|
Dependency direction analysis📈 Existing violations got worse1 pre-existing violation(s) increased in severity (e.g. their target became more depended-on, or got pulled into an import cycle), though the edge itself isn't new:
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
emmettbutler
left a comment
There was a problem hiding this comment.
Pretty much matches what we discussed. Nice work.
| class LLMObsLlamaIndexSubscriber(LLMObsLlmSubscriber): | ||
| component = LLAMA_INDEX_COMPONENT | ||
| integration_cls = LlamaIndexIntegration |
There was a problem hiding this comment.
Any reason to not just compute the component and integration class on the main LLMObsLlmSubscriber class? We wouldnt need these per integration subscribers AFAIK if we did that.
Description
Stacked on PR #20760 which introduced the
LlmEventsspan-lifecycle events and first LLMObs subscriber. This PR does the same forllama_indexand generalizes the machinery so each additional integration is a ~40 line file.Changes:
ddtrace/llmobs/_contrib/_subscribers.pyasLLMObsLlmSubscriber: lazy integration construction fromconfig.<component>, component filtering (theLlmEventsare shared by every LLM integration, so handlers must ignore other components' contexts), and the three lifecycle handlers. A concrete integration now supplies only a component name and integration class. Each subscriber still declares its own one-lineon_eventbecauseSubscriber.__init_subclass__bindson_eventto the class that defines it.patch.pygainsMODEL_TAG/PROVIDER_TAG(
llama_index.request.{model,provider}) and sets them on the event. Non-LLM operations(query, retrieval, agent) have no model or provider, so those tags are omitted rather
than written as null.
handle_streamed_responseno longer takes an integration; the LlamaIndex stream handlers only need the context to dispatch the deferred ended event, so theBaseStreamHandlerintegration slot goes unused (None)Testing
Existing
llama_indexandllmobssuites are the behavioral contract and pass unchanged.Risks
Additional Notes