AgentOps-AI / AgentOps-AI/agentops

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

Aberta
#1,430 1 comentário 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
Python
Estrelas
5.8k
Forks
619
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

**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_

Guia de contribuição

Abrir o guia de contribuição

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.