Skip to content

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

Merged
RulaKhaled merged 1 commit into
developfrom
fix/cloudflare-vite-keep-class-name
Sep 25, 2026
Merged

RulaKhaled merged 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

@JPeer264 JPeer264 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this fix

@RulaKhaled
RulaKhaled marked this pull request as ready for review September 25, 2026 08:51
@RulaKhaled
RulaKhaled requested a review from a team as a code owner September 25, 2026 08:51
@RulaKhaled
RulaKhaled requested review from isaacs and mydea and removed request for a team September 25, 2026 08:51
@RulaKhaled
RulaKhaled merged commit 3761378 into develop Sep 25, 2026
98 of 99 checks passed
@RulaKhaled
RulaKhaled deleted the fix/cloudflare-vite-keep-class-name branch September 25, 2026 08:51

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c560dd0. Configure here.

state.wrappedClasses.add(exportedName);
state.needsImport = true;
return undefined;
return `${wrappedName} as ${exportedName}`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aliased export skips existing wrapper

Low Severity

wrapSpecifier reuses a wrapper only when the class is in topLevelClasses. An inline export class is not collected there, so a later configured alias does not consult wrappedLocals and wraps the original class again instead of sharing the existing binding.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c560dd0. Configure here.

RulaKhaled added a commit that referenced this pull request Sep 25, 2026
…name

Depends on #24700, which stops the Vite transform from renaming the wrapped class.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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

2 participants