Skip to content

Replace manual wrapping with build-time auto-wrapping on one shared rewriter #25776

Open

Description

@timfish

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.ts handlers → wrapServerRouteWithSentry
    • hooks.server handle → sentryHandle()
    • hooks.client / hooks.server handleError → handleErrorWithSentry
  • @sentry/tanstackstart-react
    • server.ts default export → wrapFetchWithSentry
    • Registering sentryGlobalRequestMiddleware and sentryGlobalFunctionMiddleware in createStart
  • @sentry/nextjs
    • instrumentation.ts onRequestError → captureRequestError
    • 'use server' actions → withServerActionInstrumentation
    • global-error.tsx / error.tsx error capture
  • @sentry/react-router
    • entry.server handleRequest / handleError
    • root ErrorBoundary error capture
  • @sentry/react (React Router in library mode)
    • createBrowserRouter / createMemoryRouter → wrapCreateBrowserRouterV6/V7, wrapCreateMemoryRouterV6/V7
    • useRoutes → wrapUseRoutesV6/V7
    • <Routes> → withSentryReactRouterV6Routing / withSentryReactRouterV7Routing
  • @sentry/remix
    • Root withSentry(App)
    • entry.server handleError → sentryHandleError
  • @sentry/solidstart
    • 'use server' functions → withServerActionInstrumentation
    • middleware.ts → sentryBeforeResponseMiddleware
    • Router → withSentryRouterRouting
  • @sentry/solid
    • Router → withSentryRouterRouting
    • ErrorBoundary → withSentryErrorBoundary
  • @sentry/vue
    • pinia.use(createSentryPiniaPlugin()) at createPinia()
  • @sentry/cloudflare
    • Pages functions/_middleware → sentryPagesPlugin
  • @sentry/aws-serverless
    • handler export → wrapHandler
  • @sentry/google-cloud-serverless
    • wrapHttpFunction / 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

  1. linear-code commented on Oct 27, 2026

    @linear-code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeaturejavascriptPull requests that update javascript code

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions