You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Next.js proxy.ts/middleware not instrumented under Turbopack builds (metrics/logs/init dropped in prod) #21713
@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.
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.
Activity
linear-code commentedon Jun 23, 2026
JS-2830
JPeer264 commentedon Jun 24, 2026
confirmed. It works locally just fine while it doesn't when deployed.
Local trace: https://sentry-sdks.sentry.io/explore/traces/trace/0f24de98cc184d7f954069f4bc6ccb5d
vs. deployed trace: https://sentry-sdks.sentry.io/explore/traces/trace/82d79e4999364d02a8aa0a36efc2e6a4
I tried to have fix it, but failed. I would leave this to our NextJS gurus
Fix instrumentation hook awaiting for middleware with adapters (#95357)
chargome commentedon Jul 6, 2026
fixed with vercel/next.js#95357
Fix instrumentation hook awaiting for middleware with adapters (verce…