Skip to content

fix(cloudflare): Keep the user's class name when auto-wrapping an export - #24700

Draft
RulaKhaled wants to merge 1 commit into
developfrom
fix/cloudflare-vite-keep-class-name
Draft

RulaKhaled wants to merge 1 commit into
developfrom
fix/cloudflare-vite-keep-class-name

Conversation

@RulaKhaled

Copy link
Copy Markdown
Collaborator

The Vite transform freed an exported class's binding for the wrapper by renaming the declaration to __SENTRY_ORIGINAL_<Name>__. That also renames Function.prototype.name, and libraries read it: @cloudflare/think passes this.constructor.name to the AI SDK as the functionId, so a zero-config agent span came out as invoke_agent __SENTRY_ORIGINAL_ThinkAgent__, and agents puts the same string in gen_ai.agent.name.

Only the export has to be the wrapper, so the declaration now stays exactly as written and the export is aliased to a wrapper binding. That is the shape the transform already emits for classes re-exported from another module and the shape the docs show for manual wrapping, so local and cross-module classes now share one code path. A default export of an already-wrapped class is re-pointed at that binding.

The one observable change is that in-module references to the class see the original rather than the wrapper. That matches manual wrapping, and Durable Objects, Agents, Workflows and entrypoints are constructed by the runtime through the export.

Verified against a real worker with the cloudflare-autoinstrument e2e app, where gen_ai.agent.name is now an exact match. The Think span-name assertions land with #24660.

Fixes #24696

🤖 Generated with Claude Code

The Vite transform renamed a wrapped class declaration to free its binding for the
wrapper, which also renamed `Function.prototype.name`. `@cloudflare/think` passes
`this.constructor.name` to the AI SDK as the `functionId`, so a zero-config agent
showed up as `invoke_agent __SENTRY_ORIGINAL_ThinkAgent__`. The `agents` package
reads the same name for `gen_ai.agent.name`.

Only the export has to be the wrapper, so the declaration now stays exactly as
written and the export is aliased to a wrapper binding. That is the shape the
cross-module re-export path and the documented manual pattern already produce.
A default export of the same class is re-pointed at that binding.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 29.24 kB - -
@sentry/browser - with treeshaking flags 27.5 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.4 kB - -
@sentry/browser (incl. Tracing) 51.15 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 51.17 kB - -
@sentry/browser (incl. Tracing, Profiling) 54.18 kB - -
@sentry/browser (incl. Tracing, Replay) 90.76 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 79.86 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 95.46 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 108.41 kB - -
@sentry/browser (incl. Feedback) 46.76 kB - -
@sentry/browser (incl. sendFeedback) 34.3 kB - -
@sentry/browser (incl. FeedbackAsync) 39.41 kB - -
@sentry/browser (incl. Metrics) 30.25 kB - -
@sentry/browser (incl. Logs) 30.51 kB - -
@sentry/browser (incl. Metrics & Logs) 31.18 kB - -
@sentry/react 31 kB - -
@sentry/react (incl. Tracing) 53.45 kB - -
@sentry/vue 36.74 kB - -
@sentry/vue (incl. Tracing) 53.7 kB - -
@sentry/svelte 29.26 kB - -
CDN Bundle 30.93 kB - -
CDN Bundle (incl. Tracing) 51.69 kB - -
CDN Bundle (incl. Logs, Metrics) 33.2 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 53.66 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 73.92 kB - -
CDN Bundle (incl. Tracing, Replay) 89.28 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 91.25 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 95.45 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 97.42 kB - -
CDN Bundle - uncompressed 91.4 kB - -
CDN Bundle (incl. Tracing) - uncompressed 153.77 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 97.97 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 159.73 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 227.54 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 273.5 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 279.44 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 287.2 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 293.13 kB - -
@sentry/nextjs (client) 55.77 kB - -
@sentry/sveltekit (client) 51.59 kB - -
@sentry/core/server 39.95 kB - -
@sentry/core/browser 13.63 kB - -
@sentry/node 133.88 kB +0.01% +6 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.4 kB - -
@sentry/node - without tracing 90.43 kB +0.02% +16 B 🔺
@sentry/node - without channel injection 112.41 kB +0.01% +10 B 🔺
@sentry/aws-serverless 98.7 kB +0.01% +8 B 🔺
@sentry/cloudflare (withSentry) - minified 206.49 kB - -
@sentry/cloudflare (withSentry) 513.73 kB - -

View base workflow run

@RulaKhaled
RulaKhaled requested a review from JPeer264 September 24, 2026 14:22

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vite auto-instrumentation renames wrapped classes, mangling span names

1 participant