SDK
@sentry/nextjs 10.59.0 · Next.js 16.2.9 · Turbopack production build on Vercel · Sentry SaaS
What happens
Sentry.metrics.count() and Sentry.logger.info() (and any capture) called from proxy.ts (the renamed middleware.ts) are never delivered in production. Client-side traces work fine. It works in next dev only because the proxy shares the dev-server process where instrumentation.ts already ran Sentry.init.
In Next.js 16 the proxy runs as its own Node serverless function, separate from the main server, and Sentry is never initialized in that isolate. Vercel runtime logs show the proxy executing (source: serverless-middleware, 200) with an empty logs: []; querying Sentry shows zero vercel-production proxy metrics/logs while client vercel-production traces arrive.
Cause
Under Turbopack, the SDK only injects loaders into instrumentation.* and instrumentation-client.* (packages/nextjs/src/config/turbopack/generateValueInjectionRules.ts). The middleware/proxy auto-instrumentation exists only in the webpack path (packages/nextjs/src/config/webpack.ts:267-282, which already matches both middleware.* and proxy.*). So under a Turbopack build the proxy is neither wrapped nor initialized.
Already flagged in-code: packages/nextjs/src/common/wrapMiddlewareWithSentry.ts:55 — "We still should add central isolation scope creation for when our build-time instrumentation does not work anymore with turbopack."
Note that wrapping alone isn't sufficient here — the gap is Sentry.init not reaching the proxy's Node runtime, not just the missing span wrapper.
Minimal reproduction
https://github.com/getsentry/nextjs-proxy-sentry-api — proxy.ts emits a page.view counter; metric is absent in prod, present in dev.
Workaround
Add import "./sentry.server.config"; at the top of proxy.ts to run Sentry.init in the proxy runtime; the existing event.waitUntil(Sentry.flush()) then delivers. Verified: metrics/logs appear tagged environment: vercel-production.
Expected
@sentry/nextjs instruments proxy.ts/middleware.ts under Turbopack builds so emissions from the proxy are delivered in production without a manual config import.
SDK
@sentry/nextjs10.59.0 · Next.js 16.2.9 · Turbopack production build on Vercel · Sentry SaaSWhat happens
Sentry.metrics.count()andSentry.logger.info()(and any capture) called fromproxy.ts(the renamedmiddleware.ts) are never delivered in production. Client-side traces work fine. It works innext devonly because the proxy shares the dev-server process whereinstrumentation.tsalready ranSentry.init.In Next.js 16 the proxy runs as its own Node serverless function, separate from the main server, and Sentry is never initialized in that isolate. Vercel runtime logs show the proxy executing (
source: serverless-middleware, 200) with an emptylogs: []; querying Sentry shows zerovercel-productionproxy metrics/logs while clientvercel-productiontraces arrive.Cause
Under Turbopack, the SDK only injects loaders into
instrumentation.*andinstrumentation-client.*(packages/nextjs/src/config/turbopack/generateValueInjectionRules.ts). The middleware/proxy auto-instrumentation exists only in the webpack path (packages/nextjs/src/config/webpack.ts:267-282, which already matches bothmiddleware.*andproxy.*). So under a Turbopack build the proxy is neither wrapped nor initialized.Already flagged in-code:
packages/nextjs/src/common/wrapMiddlewareWithSentry.ts:55— "We still should add central isolation scope creation for when our build-time instrumentation does not work anymore with turbopack."Note that wrapping alone isn't sufficient here — the gap is
Sentry.initnot reaching the proxy's Node runtime, not just the missing span wrapper.Minimal reproduction
https://github.com/getsentry/nextjs-proxy-sentry-api —
proxy.tsemits apage.viewcounter; metric is absent in prod, present in dev.Workaround
Add
import "./sentry.server.config";at the top ofproxy.tsto runSentry.initin the proxy runtime; the existingevent.waitUntil(Sentry.flush())then delivers. Verified: metrics/logs appear taggedenvironment: vercel-production.Expected
@sentry/nextjsinstrumentsproxy.ts/middleware.tsunder Turbopack builds so emissions from the proxy are delivered in production without a manual config import.