Skip to content

Align OTel LLM-parent to the per-instance fan-out dispatch span#195

Merged
chris-colinsky merged 2 commits into
mainfrom
fix/otel-llm-parent-instance-span
Jun 26, 2026
Merged

Align OTel LLM-parent to the per-instance fan-out dispatch span#195
chris-colinsky merged 2 commits into
mainfrom
fix/otel-llm-parent-instance-span

Conversation

@chris-colinsky

Copy link
Copy Markdown
Member

Summary

An LLM provider span whose calling node has no open span (for example a provider
call originating from middleware or a wrapper) and which fires inside a fan-out
instance now parents under the per-instance fan-out dispatch span in the OTel
observer, matching the Langfuse observer, instead of falling through to the
subgraph or invocation span. This resolves a divergence between the two
observers.

_resolve_llm_parent gains a fallback between the exact calling-node match and
the subgraph walk, mirroring the Langfuse _resolve_llm_parent_observation_id
fallback. Observability §5.5 defines no parent for an orphaned LLM span; the
per-instance instance span is the canonical choice (the §6 driving-span stack,
proposal 0045 §3.4, and §4.4's detached shape all point to it).

Scope

Top-level instance parity only. The generalized nearest-open-ancestor fallback
(nested fan-out instances at any depth, where the parity key can mis-resolve to a
sibling top-level instance, plus the instance-vs-deeper-subgraph ordering) is
pending an observability spec clause and fixture, and will land in both observers
together against that fixture.

Tests

New regression test (test_llm_span_parents_under_fan_out_instance_dispatch)
asserting an orphaned LLM span in a top-level fan-out instance parents under the
per-instance dispatch span; it fails without the fallback (the span would
otherwise be a trace root). Full suite green (1475), ruff and pyright clean.

Align OTel's _resolve_llm_parent with the spec ruling
(review-nested-fan-out-lineage): an orphaned LLM span (calling node
has no open span) inside a fan-out instance now parents under the
per-instance fan-out dispatch span, matching the Langfuse observer,
instead of falling through to the subgraph or invocation span.

Top-level instance parity only. The generalized nearest-open-ancestor
walk -- nested instances at any depth (where the parity key can
mis-resolve to a sibling top-level instance) and the
instance-vs-deeper-subgraph ordering -- rides the pending spec
observability fallback clause and fixture.
Copilot AI review requested due to automatic review settings June 26, 2026 19:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Aligns the OpenTelemetry observer’s LLM span parenting behavior with the Langfuse observer when an LLM provider span is emitted from “orphaned” call sites inside a top-level fan-out instance (i.e., no calling-node span is open). This improves observability parity by ensuring the LLM span parents under the per-instance fan-out dispatch span.

Changes:

  • Add a fan-out-instance dispatch-span fallback in OTelObserver._resolve_llm_parent before the subgraph/invocation fallbacks.
  • Add a regression test asserting the orphaned LLM span parents under the per-instance dispatch span in a top-level fan-out instance.
  • Document the fix in CHANGELOG.md.

Reviewed changes

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

File Description
src/openarmature/observability/otel/observer.py Adds per-instance fan-out dispatch fallback for orphaned LLM span parent resolution.
tests/unit/test_observability_otel.py Adds regression coverage for fan-out-instance parenting of orphaned LLM spans.
CHANGELOG.md Notes the OTel parenting change and its current scope limitations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/openarmature/observability/otel/observer.py
Comment thread tests/unit/test_observability_otel.py Outdated
PR review follow-ups:
- _resolve_llm_parent docstring now lists the per-instance fan-out
  dispatch fallback added in this PR.
- Drop the manual dispatch_span.end() in the new test: shutdown()
  drains fan_out_instance_spans and ends the span, so the manual end
  double-ended it.
@chris-colinsky chris-colinsky merged commit 620b010 into main Jun 26, 2026
6 checks passed
@chris-colinsky chris-colinsky deleted the fix/otel-llm-parent-instance-span branch June 26, 2026 20:13
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