fix(cloudflare): Keep the user's class name when auto-wrapping an export - #24700
Conversation
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>
size-limit report 📦
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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}`; |
There was a problem hiding this comment.
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.
Reviewed by Cursor Bugbot for commit c560dd0. Configure here.
…name Depends on #24700, which stops the Vite transform from renaming the wrapped class. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>


The Vite transform freed an exported class's binding for the wrapper by renaming the declaration to
__SENTRY_ORIGINAL_<Name>__. That also renamesFunction.prototype.name, and libraries read it:@cloudflare/thinkpassesthis.constructor.nameto the AI SDK as thefunctionId, so a zero-config agent span came out asinvoke_agent __SENTRY_ORIGINAL_ThinkAgent__, andagentsputs the same string ingen_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-autoinstrumente2e app, wheregen_ai.agent.nameis now an exact match. The Think span-name assertions land with #24660.Fixes #24696
🤖 Generated with Claude Code