Skip to content

Vite auto-instrumentation renames wrapped classes, mangling span names #24696

Description

@RulaKhaled

Summary

Under zero config (sentryCloudflareVitePlugin()), a wrapped class reports its name as __SENTRY_ORIGINAL_<Name>__ at runtime. Anything that reads Class.name shows that placeholder: a @cloudflare/think agent span reads invoke_agent __SENTRY_ORIGINAL_ThinkAgent__ with gen_ai.function_id to match, and agents puts it in gen_ai.agent.name. Applies to every class the plugin wraps (Durable Objects, Agents, Workflows, WorkerEntrypoints). Manual instrument*WithSentry is unaffected.

Root cause

packages/cloudflare/src/vite/transform.ts frees the export binding for the wrapper by renaming the user's class declaration:

class __SENTRY_ORIGINAL_ThinkAgent__ extends Think {}
export const ThinkAgent = instrumentAgentWithSentry(opts, __SENTRY_ORIGINAL_ThinkAgent__);

Renaming a declaration changes Function.prototype.name. Think passes this.constructor.name to the AI SDK as functionId, which the vercel-ai subscriber uses as the span name.

Fix: leave the declaration alone and alias the export instead, the shape the plugin already emits for cross-module re-exports and the docs show for manual wrapping:

class ThinkAgent extends Think {}
const __SENTRY_WRAPPED_ThinkAgent__ = instrumentAgentWithSentry(opts, ThinkAgent);
export { __SENTRY_WRAPPED_ThinkAgent__ as ThinkAgent };

Environment

  • @sentry/cloudflare 10.67.0, @cloudflare/vite-plugin 1.57.2
  • @cloudflare/think 0.19.0, ai 7, agents 0.24
  • Reproduced on a local worker with the cloudflare-think e2e app

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions