Repository navigation
Description
Goal
Nitro users install the server SDK for their runtime and configure the build in one place: the Nitro module for Nitro CLI apps, sentryVitePlugin for Vite apps. Errors, tracing, tasks and source maps then work in dev and prod. @sentry/nitro gets deprecated, then removed in v12.
// Nitro CLI: nitro.config.ts
import { sentryNitro } from '@sentry/node/nitro';
export default defineNitroConfig({ modules: [sentryNitro({ org, project, authToken })] });
// Vite (nitro/vite): vite.config.ts. No module in nitro.config.ts.
import { sentryVitePlugin } from '@sentry/node/vite';
export default defineConfig({ plugins: [nitro(), sentryVitePlugin({ org, project, authToken })] });
// Both: sentry.server.config.ts
import * as Sentry from '@sentry/node';
Sentry.init({ dsn: '...', tracesSampleRate: 1 });Design
The module lives in @sentry/server-utils and is re-exported as @sentry/{node,bun,deno,cloudflare}/nitro. Its setup(nitro) does four things:
- Tracing channels: when
tracingChannelis unset, it sets Nitro's defaults ({ srvx, h3, unstorage, db0 }) and adds#nitro/virtual/tracing. That repeats Nitro's resolver (src/config/resolvers/tracing.ts), because modules run after it. A user'sfalsestays. Route names,Server-Timing, and the middleware, handler, srvx and cache spans come from thenitroIntegrationsubscribers. - Runtime plugin: it registers one Nitro plugin, first in
plugins.- The plugin imports
sentry.server.config.{ts,js,mjs,cjs,mts,cts}fromrootDir, or the file in theserverConfigFileoption (falseturns this off). - It then registers the error hook and the task wrapper, like
@sentry/nitro's plugin does. - Users need no
definePluginand noserverDir. - The app always has a plugin, so it always has hooks, and errors from later plugins are captured.
- The plugin imports
- Orchestrion transform: added through Nitro's
build:confighook, for third-party library spans. Errors and tasks don't need orchestrion. - Source maps: hidden source maps when
sourcemapis unset, uploaded from.output/serveroncompiled.
When the Vite plugin installs the module, the Vite plugin does the transform and the source maps instead. Only one module instance runs per Nitro app; see Duplicates.
A prototype of the module with no Sentry bundler plugin ran on nitro 3.0.261103-rc under nitro build, vite build and vite dev. In all three, init() ran, the native spans had route names, and Prisma 8 was instrumented.
Configuration
| Setup | User adds | Build options live in | Transform | Server source maps |
|---|---|---|---|---|
| Nitro CLI | sentryNitro() in modules of nitro.config.ts |
module options | module, via build:config |
module: Nitro's sourcemap, upload on compiled |
Vite (nitro/vite), including frameworks on Nitro |
sentryVitePlugin() in vite.config.ts |
Vite plugin options | Vite plugin, in every server environment (nitro and SSR services) |
Vite plugin: Vite's build.sourcemap, upload for every environment |
- Build options are
org,project,authToken,release,sourcemaps,serverConfigFileandbuildTimeInstrumentation.Sentry.init()options always go insentry.server.config.ts. - Vite:
sentryVitePlugin'snitroproperty installs the module with the Vite plugin's options. That module still sets the tracing channels and registers the runtime plugin, but it adds no transform and uploads nothing. Users don't add the module tonitro.config.ts. - SSR services: because the Vite plugin transforms every server environment, frameworks' SSR services are covered too. The module's
build:configtransform would only reach thenitroenvironment. - Module alone under Vite: it works (prototype) but isn't the documented setup. It doesn't cover client builds or SSR services, and the
nitroenvironment likely takes its source maps from Vite'sbuild.sourcemap, not Nitro'ssourcemap. - First request under
vite dev: Vite loads the server entry, and with itinit(), on that request. Its h3 spans become segments without anhttp.serverparent.
Duplicates
At setup, each module instance checks nitro.options.modules for other Sentry instances. Nitro adds the Vite plugins' modules to the config's modules before createNitro, so every instance sees all of them.
- One instance wins: the one from a Vite plugin, otherwise the first in
modules. The others do nothing and warn that Sentry is configured more than once, naming whose options are used. Options are never merged, so a duplicated setting such assourcemapscomes only from the winner. - Module in
nitro.config.tsplussentryVitePlugin: the Vite plugin's instance wins. The warning says to remove the module. withSentryConfig(@sentry/nitro) plus the module orsentryVitePlugin: the same rule applies.withSentryConfigstill setstracingChannel: trueitself.- Module plus
sentryRollupPlugininrollupConfig.plugins(Nitro CLI): not supported. A file transformed twice fails the build, so the module spots the Sentry Rollup plugin inbuild:config, skips its own transform and warns. The Rollup plugin would still upload source maps a second time. - Two Sentry Vite plugins: the existing guard lets only the first one transform, and only one module instance runs.
- Source map generation set by the user (Nitro's
sourcemapor Vite'sbuild.sourcemap): the user's value wins. Sentry only fills it in (hidden) when it's unset, and logs at debug level when maps it needs are off.
@sentry/nitro
withSentryConfigkeeps settingtracingChannel: truebefore Nitro resolves it. It installs the shared module instead of its own.- Its
init(SDK metadata, dev serverhttpfilter) and/importstay for apps that preloadinstrument.mjs. - Both installed: see Duplicates.
instrument.mjsandsentry.server.config.tsboth callinit(): the first call wins (docs/repeated-init.md).- Migration:
- replace
withSentryConfig(config)with the module (Nitro CLI) orsentryVitePlugin(Vite), as in Configuration - move
initintosentry.server.config.ts, imported from@sentry/node - drop
--import ./instrument.mjs
- replace
When --import @sentry/node/import is needed
| Where | Needed | Why |
|---|---|---|
| Prod | not by default | Nitro bundles every module Sentry instruments. Only needed for instrumented packages that stay external (nf3's lists, traceDeps). |
nitro dev |
for third-party library spans | Nitro keeps node_modules external in dev. |
vite dev |
for most third-party libraries | Vite keeps dependencies external in dev. Prisma 8 fired without it. |
| No module | always, plus tracingChannel: true |
Best effort. |
Steps
- Core module and
@sentry/node/nitro:- shared capture helpers:
HTTPErrorfiltering, mechanism,contexts.nitro,flushIfServerless - tracing channels, the runtime plugin with the server config, the transform
- choosing one instance and warning about the others (Duplicates)
- the
node-nitro-3e2e app on the module with the Nitro CLI, dev and prod, with and withoutserverDir
- shared capture helpers:
- Vite:
sentryVitePlugin'snitroproperty installs the module with the Vite plugin's options, without its transform or upload- the Vite variants of
node-nitro-3use onlysentryVitePlugin - an e2e variant with both the module and the Vite plugin checks that the warning appears and nothing is duplicated
- Source maps:
- Nitro CLI: hidden maps when
sourcemapis unset, and the upload oncompiled - Vite: check that the plugin uploads the
nitroenvironment's output and thatbuild.sourcemapcontrols it - coordinate with Bundler plugins should handle source maps without any user configuration #25609
- Nitro CLI: hidden maps when
@sentry/nitroon the shared module, with a test that installs both.- Bun and Deno:
/nitroexports, plus e2e tests for their presets. - Cloudflare
/nitro: investigate first. It needs init per request throughfetch, thedcModulefaçade, and workerd tests. - Migrate and deprecate: move SolidStart off
setupSentryNitroModule, rewrite the Nitro guide in getsentry/sentry-docs, deprecate@sentry/nitro, and remove it in v12.
Asks to Nitro, in parallel: a native tasks channel, and tracingChannel on by default.
Open questions
- Where do the SDK metadata (
nitro) and the tunnel base path come from without@sentry/nitro? - Mechanism types: keep
auto.function.nitro.captureErrorHookandauto.function.nitro.task? - Nuxt 5: does Nuxt's Nitro also get the module through
sentryVitePlugin? Nuxt registerssentry.server.configitself. - Prod with external instrumented packages:
--importneeds@sentry/nodeinnode_modules, which an.output-only deployment doesn't have.
Findings (nitro 3.0.261103-rc)
- Prod bundling: Nitro bundles everything except nf3's lists, which are native addons plus 19 packages such as
prisma,@prisma/clientandtypeorm. None of the 67 modules Sentry instruments are on them. - Prisma 8 (
@prisma/orm-postgres) is bundled and instrumented in prod. Prisma 5–7 use the global tracing helper, so@prisma/clientstaying external doesn't matter. serverDir: Nitro scans<serverDir>/plugins/only whenserverDiris set, and Nitro 3 defaults it tofalse.- Plugin order: a plugin the module puts first runs before the plugins Nitro scans, both when the modules load and when the plugins run.
- Hooks: with tracing channels on, h3's
onErrorreachescaptureErrorand theerrorhook. Without plugins, the app has no hooks.
Earlier approach
The first plan put Nitro hooks in the Vite and Rollup plugins (#26809, #26858). It was dropped for three reasons:
- the Rollup path needed the private
globalThis.__nitro_instances__ - the Rollup path ran after
build:before - it put Nitro-only options on generic plugins
via @mydea.
--
Activity
linear-code commentedon Sep 30, 2026
JS-3858
[-]Nitro: move the runtime error-hook plugin out of @sentry/nitro for full cross-runtime instrumentation[/-][+]Nitro: instrument through the runtime SDKs and their bundler plugins, deprecate `@sentry/nitro`[/+]sentry-junior commentedon Nov 24, 2026
Step 0 update
@sentry/nitro's runtime plugin bundles its own copy of@sentry/server-utils, because nf3 doesn't externalize it. A marker that crosses between@sentry/nitroand the orchestrion path therefore has to sit on a shared object, such as a non-enumerable property on the Nitro app. Module-scope state won't work.@sentry/nitro's wrapper captures first and core marks the error as captured, so the orchestrion side can skip errors whereisAlreadyCapturedis true.WeakSet<H3Event>live innitroIntegration, so module scope is fine there.nitroConfigand asserts real events. Thefeat/nitro-orchestrion-fixturebranch has the scaffolding to reuse: the four build modes, the runtime hook preload, and no event proxy.Findings from #26806
Tested with nitro
3.0.261103-rc, h32.0.8, vite8.3.8and rolldown1.3.3, undervite build,vite dev,nitro buildandnitro dev.latestis now an-rcbuild. Version ranges need>=3.0.0-0.useNitroApprunTaskprepareResponseH3Core#handler, via{ className: 'H3Core', methodName: 'handler' }indist/cache.mjscallLayerindist/middleware.mjs, which only fires when there is global middlewareNitroDevAppconstructor, only through the runtime hook on the main threaduseNitroAppendevent carries the app asresult, with the keyscaptureError,fetch,h3andhooks. This settles that item under "Not verified yet".hooks: void 0and acaptureErrorthat never calls theerrorhook. Registering the shared hook from theuseNitroAppendevent only works when the app has a plugin or setsfeatures.runtimeHooks: true. The errors PR has to decide how to handle this, for example by wrappingcaptureErroron the app.useNitroAppcaches the app, but its channel fires on every call, andserverFetchcalls it on every request. The subscriber has to be idempotent.prepareResponsecalls itself again on the error path (nested), so it fires twice for one error.rollupConfig.pluginsinto Vite builds. A setup with bothsentryVitePluginandsentryRollupPluginwould transform the same modules twice.nitro devwithout the runtime hook, onlyuseNitroAppandrunTaskfire, because h3 stays external. Undervite dev, the plugin alone covers everything exceptNitroDevApp.@sentry/node/importonly applies the built-in configs. Until the targets are innitroConfig, testing them through the runtime hook needs a custom load hook.feat(nitro): Add the orchestrion plugin to the server build (#26799)