fix(cloudflare): Keep the user's class name when auto-wrapping an export - #24700
Draft
RulaKhaled wants to merge 1 commit into
Draft
RulaKhaled wants to merge 1 commit into
RulaKhaled wants to merge 1 commit into
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>
Contributor
size-limit report 📦
|
This branch has not been deployed
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.
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