Repository navigation
Replace manual wrapping with build-time auto-wrapping on one shared rewriter #25776
Description
Description
Many SDKs ask users to wrap their own code by hand: route handlers, hooks, entry files, routers, error boundaries, clients. Each manual step is a place where setup can go wrong or get skipped, and the result is missing spans and errors. Three SDKs already automate part of this at build time (Cloudflare, SvelteKit load, TanStack Start middleware), but each uses its own parser and export handling, so a fix in one does not reach the others. Next.js wraps routes by running a separate Rollup build for every wrapped file.
The proposal is one shared rewriter in @sentry/bundler-plugins. It parses each file once (with Rolldown's parser under Vite 8, and oxc-parser elsewhere), runs a set of rules from the SDKs, and makes all edits in one pass with an exact source map. On Vite it runs inside sentryVitePlugin in one filtered transform hook, so files that cannot match are never parsed. Hosts for webpack and Turbopack, esbuild, and Node can follow, and they reuse the same rules. The three existing transforms and the Next.js wrapping loader move onto it. If oxc-parser cannot load on a platform, the build logs a warning and continues without the rewrite.
Manual wrapping this could replace:
@sentry/sveltekit+server.tshandlers →wrapServerRouteWithSentryhooks.serverhandle→sentryHandle()hooks.client/hooks.serverhandleError→handleErrorWithSentry
@sentry/tanstackstart-reactserver.tsdefault export →wrapFetchWithSentry- Registering
sentryGlobalRequestMiddlewareandsentryGlobalFunctionMiddlewareincreateStart
@sentry/nextjsinstrumentation.tsonRequestError→captureRequestError'use server'actions →withServerActionInstrumentationglobal-error.tsx/error.tsxerror capture
@sentry/react-routerentry.serverhandleRequest/handleErrorrootErrorBoundaryerror capture
@sentry/react(React Router in library mode)createBrowserRouter/createMemoryRouter→wrapCreateBrowserRouterV6/V7,wrapCreateMemoryRouterV6/V7useRoutes→wrapUseRoutesV6/V7<Routes>→withSentryReactRouterV6Routing/withSentryReactRouterV7Routing
@sentry/remix- Root
withSentry(App) entry.serverhandleError→sentryHandleError
- Root
@sentry/solidstart'use server'functions →withServerActionInstrumentationmiddleware.ts→sentryBeforeResponseMiddlewareRouter→withSentryRouterRouting
@sentry/solidRouter→withSentryRouterRoutingErrorBoundary→withSentryErrorBoundary
@sentry/vuepinia.use(createSentryPiniaPlugin())atcreatePinia()
@sentry/cloudflare- Pages
functions/_middleware→sentryPagesPlugin
- Pages
@sentry/aws-serverlesshandlerexport →wrapHandler
@sentry/google-cloud-serverlesswrapHttpFunction/wrapEventFunction/wrapCloudEventFunction
- Supabase in every SDK
createClient(...)→instrumentSupabaseClient
Out of scope: instrumenting dependencies in node_modules, which orchestrion already covers, and framework error handlers such as setupExpressErrorHandler. Those handlers must run after all routes are registered, which a build-time rewrite cannot detect.
Activity
linear-code commentedon Oct 27, 2026
JS-4013