feat(cloudflare): Add instrumentAgentWithSentry for Cloudflare Agents - #22718
Merged
Conversation
Contributor
size-limit report 📦
|
JPeer264
force-pushed
the
jp/cloudflare-instrument-agents
branch
2 times, most recently
from
July 27, 2026 20:01
832a8ba to
4415684
Compare
JPeer264
marked this pull request as ready for review
July 28, 2026 06:14
JPeer264
requested review from
andreiborza and
isaacs
and removed request for
a team
July 28, 2026 06:14
JPeer264
force-pushed
the
jp/cloudflare-instrument-agents
branch
from
July 28, 2026 07:29
4415684 to
e5dbffe
Compare
andreiborza
reviewed
Jul 28, 2026
JPeer264
force-pushed
the
jp/cloudflare-instrument-agents
branch
2 times, most recently
from
July 28, 2026 14:05
b5eee80 to
013bb08
Compare
Add `instrumentAgentWithSentry`, which wraps a Cloudflare Agents SDK `Agent` (or `AIChatAgent`) class the same way `instrumentDurableObjectWithSentry` wraps a plain Durable Object, plus the core `instrumentCloudflareAgent` helper that layers agent-specific instrumentation onto the constructed instance. The shared Durable Object construction path is extracted into `constructInstrumentedDurableObject` / `finalizeWithRpcInstrumentation` so both entry points reuse the same handler, RPC, storage and env instrumentation. Adds Agent- and AIChatAgent-driven integration suites that drive Workers AI through the real Agents SDK + Vercel AI + workers-ai-provider stack, guarding that gen_ai output (including `gen_ai.output.messages`) survives end to end. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Co-Authored-By: Cursor Agent <cursoragent@cursor.com>
JPeer264
force-pushed
the
jp/cloudflare-instrument-agents
branch
from
July 28, 2026 14:05
013bb08 to
8bb6166
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds
instrumentAgentWithSentry. Which is the same asinstrumentDurableObjectWithSentryjust with one more addition: In between it callsinstrumentCloudflareAgent(obj)which adds more instrumentations. The most moving parts are indurableobject.ts, but here the main functionality moved out frominstrumentDurableObjectWithSentryinto its own helper function, so it can get reused withininstrumentAgentWithSentry. The logic didn't change at all.The
Agentclass from theagentsSDK is extending from DurableObjects, so this is why it would work without it, butagentscomes with way more complexity baked in.This PR adds:
@callabledecorator (instrumentAgentCallableRpc.ts)conversationIdbased onthis.name(this is set by the user, e.g.useAgents({ name: sessionId })) (instrumentChatAgentConversation.ts)