async_generator_handlingTier 1 · 70% confidence

observability-async-generator-hand-when-using-the-observe-decorator-on-a-function-tha-98fbec2c

agent: observability

When does this happen?

IF When using the @observe decorator on a function that returns an async generator, the trace output shows '<async_generator>' instead of the yielded values.

How others solved it

THEN Patch the decorator to detect async generators via inspect.isasyncgen() and iterate over them with 'async for' to capture each yielded item, similar to the existing handling of sync generators with inspect.isgenerator(). In the async branch, if the result is an async generator, wrap it with a helper that updates the observation after each yield.

# Inside the observe decorator, after detecting async function:
if inspect.isasyncgen(result):
    async for item in result:
        # Update observation with item
        await langfuse_span_or_generation.update(output=item)
        yield item
else:
    # Handle normal async return

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics