AgentOps-AI / AgentOps-AI/agentops

Agno async stream wrapper leaks span/context on post-yield errors (span never ended, no ERROR status)

Đang mở
#1,430 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
5.8k
Fork
619
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

**Describe the bug**

`AsyncStreamingResultWrapper.__anext__` in the Agno instrumentor only handles `StopAsyncIteration`. If the wrapped async stream raises any other exception after yielding at least one event, the span is never ended and no error is recorded, and a stale entry is left in the context manager.

https://github.com/AgentOps-AI/agentops/blob/f8e907b92dabe47232978023fdcb01e2a7d4b752/agentops/instrumentation/agentic/agno/instrumentor.py#L133-L147

The outer agent wrapper sets `span.set_status(OK)` before returning the wrapper and returns it, so its own `try/except` cannot catch errors raised later during consumer iteration. `__anext__` catches only `StopAsyncIteration`; its `finally` merely detaches the context token. Any other exception mid-stream therefore skips `span.set_status(ERROR)`, `span.record_exception`, `span.end()`, and `remove_context`.

Net effect: an errored async Agent/Team stream produces a span that is never ended (never exported), with no error recorded, plus a stale `_contexts` entry. For an observability SDK this is a telemetry-correctness defect on a realistic path (LLM streams failing mid-iteration).

**Reproduction**

1. Instrument an Agno `Agent.arun(..., stream=True)` (or `Team.arun`) whose underlying async generator raises after yielding at least one event.
2. Observe that no span is exported for the failed stream, no exception is recorded on it, and a stale entry remains in the context manager.

**Suggested fix**

In `AsyncStreamingResultWrapper.__anext__`, add an `except Exception as e:` that sets `span.set_status(ERROR)`, `span.record_exception(e)`, `span.end()`, and `remove_context(...)` (guarded so it runs once), then re-raises, mirroring the sync path and the outer wrapper's handler.

**Environment:** current `main` (HEAD `f8e907b` at time of report). Path introduced by #1265.

---

_Found while testing [Ito](https://ito.ai), an automated code-review tool, against recently-merged PRs. It's free for open source. Sharing this because it looked like a real bug worth fixing, not to sell anything: https://app.ito.ai/share/8c8baa02-5ba9-416d-b5bb-a7d2e8792c35?tab=details_

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.