cloudflare / cloudflare/agents

Think: Improve Otel hooks so we can wrap the whole turn in `startActiveSpan`

Open
#1,834 0 comments 4 reactions 1 assignee Claimed by @mattzcarey View on GitHub
enhancement think
Dominant language
TypeScript
Stars
5.6k
Forks
711
Avg merge
1d 20h
Merged PRs (30d)
53

Description

It's me again, sorry. That's a proposal, not a bug.

So, I'm trying to get visibility on my agents using an Otel based tool like https://latitude.so. The challenge is that in Otel, you want to use `startActiveSpan` so you create a hierarchy (https://www.honeycomb.io/blog/startspan-versus-startactivespan-opentelemetry) of spans. The challenge is that there is nothing to wrap since the only hooks that Think provide are lifecycle hooks (before/after). I can use `startSpan` using those lifecycle hooks, but then the instrumented spans from AI sdk coming from the inner `streamText` won't belong to the parent span (which I want to give context about the user and whatnot).

I hope that makes sense to you. Basically, if instead of hooks Think would expose a middleware-like API instead, we could wrap things (like telemetry) around it.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.