@sentry/nuxt 10.46.0 → 10.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/build/cjs/module.js +35 -21
  2. package/build/cjs/module.js.map +1 -1
  3. package/build/cjs/vite/middlewareConfig.js +6 -1
  4. package/build/cjs/vite/middlewareConfig.js.map +1 -1
  5. package/build/esm/module.js +36 -22
  6. package/build/esm/module.js.map +1 -1
  7. package/build/esm/package.json +1 -1
  8. package/build/esm/vite/middlewareConfig.js +6 -1
  9. package/build/esm/vite/middlewareConfig.js.map +1 -1
  10. package/build/module/module.json +1 -1
  11. package/build/module/module.mjs +33 -19
  12. package/build/module/runtime/hooks/updateRouteBeforeResponse.d.ts +3 -1
  13. package/build/module/runtime/hooks/updateRouteBeforeResponse.js +7 -2
  14. package/build/module/runtime/hooks/wrapMiddlewareHandler.js +25 -15
  15. package/build/module/runtime/plugins/route-detector-legacy.server.d.ts +2 -0
  16. package/build/module/runtime/plugins/route-detector-legacy.server.js +37 -0
  17. package/build/module/runtime/plugins/route-detector.server.js +1 -1
  18. package/build/module/runtime/plugins/sentry.server.js +6 -3
  19. package/build/module/runtime/plugins/update-route-name-legacy.server.d.ts +2 -0
  20. package/build/module/runtime/plugins/update-route-name-legacy.server.js +4 -0
  21. package/build/module/runtime/plugins/update-route-name.server.d.ts +4 -0
  22. package/build/module/runtime/plugins/update-route-name.server.js +4 -0
  23. package/build/types/index.types.d.ts +2 -0
  24. package/build/types/index.types.d.ts.map +1 -1
  25. package/build/types/module.d.ts.map +1 -1
  26. package/build/types/runtime/hooks/updateRouteBeforeResponse.d.ts +3 -1
  27. package/build/types/runtime/hooks/updateRouteBeforeResponse.d.ts.map +1 -1
  28. package/build/types/runtime/hooks/wrapMiddlewareHandler.d.ts.map +1 -1
  29. package/build/types/runtime/plugins/route-detector-legacy.server.d.ts +3 -0
  30. package/build/types/runtime/plugins/route-detector-legacy.server.d.ts.map +1 -0
  31. package/build/types/runtime/plugins/sentry.server.d.ts.map +1 -1
  32. package/build/types/runtime/plugins/update-route-name-legacy.server.d.ts +3 -0
  33. package/build/types/runtime/plugins/update-route-name-legacy.server.d.ts.map +1 -0
  34. package/build/types/runtime/plugins/update-route-name.server.d.ts +5 -0
  35. package/build/types/runtime/plugins/update-route-name.server.d.ts.map +1 -0
  36. package/package.json +9 -9
@@ -69,20 +69,25 @@ const module$1 = kit.defineNuxtModule({
69
69
 
70
70
  const serverConfigFile = utils.findDefaultSdkInitFile('server', nuxt);
71
71
  const isNitroV3 = (await utils.getNitroMajorVersion()) >= 3;
72
+ const nuxtMajor = parseInt((nuxt )._version?.split('.')[0] ?? '3', 10);
73
+ const isMinNuxtV4 = nuxtMajor >= 4;
72
74
 
73
75
  if (serverConfigFile) {
74
76
  if (isNitroV3) {
75
77
  kit.addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/handler.server'));
78
+ kit.addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/update-route-name.server'));
76
79
  } else {
77
80
  kit.addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/handler-legacy.server'));
81
+ kit.addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/update-route-name-legacy.server'));
78
82
  }
79
83
 
80
84
  kit.addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/sentry.server'));
81
85
 
82
- kit.addPlugin({
83
- src: moduleDirResolver.resolve('./runtime/plugins/route-detector.server'),
84
- mode: 'server',
85
- });
86
+ if (isMinNuxtV4) {
87
+ kit.addPlugin({ src: moduleDirResolver.resolve('./runtime/plugins/route-detector.server'), mode: 'server' });
88
+ } else {
89
+ kit.addPlugin({ src: moduleDirResolver.resolve('./runtime/plugins/route-detector-legacy.server'), mode: 'server' });
90
+ }
86
91
 
87
92
  // Preps the middleware instrumentation module.
88
93
  middlewareConfig.addMiddlewareImports();
@@ -96,26 +101,35 @@ const module$1 = kit.defineNuxtModule({
96
101
 
97
102
  utils.addOTelCommonJSImportAlias(nuxt, isNitroV3);
98
103
 
99
- const pagesDataTemplate = kit.addTemplate({
100
- filename: 'sentry--nuxt-pages-data.mjs',
101
- // Initial empty array (later filled in pages:extend hook)
102
- // Template needs to be created in the root-level of the module to work
103
- getContents: () => 'export default [];',
104
- });
104
+ let pagesData = [];
105
105
 
106
106
  nuxt.hooks.hook('pages:extend', pages => {
107
- pagesDataTemplate.getContents = () => {
108
- const pagesSubset = pages
109
- .map(page => ({ file: page.file, path: page.path }))
110
- .filter(page => {
111
- // Check for dynamic parameter (e.g., :userId or [userId])
112
- return page.path.includes(':') || page?.file?.includes('[');
113
- });
114
-
115
- return `export default ${JSON.stringify(pagesSubset, null, 2)};`;
116
- };
107
+ pagesData = pages
108
+ .map(page => ({ file: page.file, path: page.path }))
109
+ .filter(page => {
110
+ // Check for dynamic parameter (e.g., :userId or [userId])
111
+ return page.path.includes(':') || page?.file?.includes('[');
112
+ });
117
113
  });
118
114
 
115
+ if (isMinNuxtV4) {
116
+ const pagesDataVirtualModuleId = '#sentry/nuxt-pages-data.mjs';
117
+
118
+ // Vite virtual plugin (for the Vite SSR build, where addPlugin mode:'server' plugins are bundled)
119
+ kit.addVitePlugin({
120
+ name: 'sentry-nuxt-pages-data-virtual',
121
+ resolveId: id => (id === pagesDataVirtualModuleId ? `\0${pagesDataVirtualModuleId}` : null),
122
+ load: id =>
123
+ id === `\0${pagesDataVirtualModuleId}` ? `export default ${JSON.stringify(pagesData, null, 2)};` : undefined,
124
+ });
125
+ } else {
126
+ // Nuxt v3: register as a build template (accessible via #build/)
127
+ kit.addTemplate({
128
+ filename: 'sentry--nuxt-pages-data.mjs',
129
+ getContents: () => `export default ${JSON.stringify(pagesData, null, 2)};`,
130
+ });
131
+ }
132
+
119
133
  // Add the sentry config file to the include array
120
134
  nuxt.hook('prepare:types', options => {
121
135
  const tsConfig = options.tsConfig ;
@@ -141,7 +155,7 @@ const module$1 = kit.defineNuxtModule({
141
155
  return;
142
156
  }
143
157
 
144
- if (serverConfigFile && !isNitroV3) {
158
+ if (serverConfigFile) {
145
159
  middlewareConfig.addMiddlewareInstrumentation(nitro);
146
160
  }
147
161
 
@@ -1 +1 @@
1
- {"version":3,"file":"module.js","sources":["../../src/module.ts"],"sourcesContent":["import {\n addPlugin,\n addPluginTemplate,\n addServerPlugin,\n addTemplate,\n addVitePlugin,\n createResolver,\n defineNuxtModule,\n} from '@nuxt/kit';\nimport { consoleSandbox } from '@sentry/core';\nimport * as path from 'path';\nimport type { SentryNuxtModuleOptions } from './common/types';\nimport { addDynamicImportEntryFileWrapper, addSentryTopImport, addServerConfigToBuild } from './vite/addServerConfig';\nimport { addDatabaseInstrumentation } from './vite/databaseConfig';\nimport { addMiddlewareImports, addMiddlewareInstrumentation } from './vite/middlewareConfig';\nimport { setupSourceMaps } from './vite/sourceMaps';\nimport { addStorageInstrumentation } from './vite/storageConfig';\nimport { addOTelCommonJSImportAlias, findDefaultSdkInitFile, getNitroMajorVersion } from './vite/utils';\n\nexport type ModuleOptions = SentryNuxtModuleOptions;\n\nexport default defineNuxtModule<ModuleOptions>({\n meta: {\n name: '@sentry/nuxt/module',\n configKey: 'sentry',\n compatibility: {\n nuxt: '>=3.7.0',\n },\n },\n defaults: {},\n async setup(moduleOptionsParam, nuxt) {\n if (moduleOptionsParam?.enabled === false) {\n return;\n }\n\n const moduleOptions = {\n ...moduleOptionsParam,\n autoInjectServerSentry: moduleOptionsParam.autoInjectServerSentry,\n experimental_entrypointWrappedFunctions: moduleOptionsParam.experimental_entrypointWrappedFunctions || [\n 'default',\n 'handler',\n 'server',\n ],\n };\n\n const moduleDirResolver = createResolver(import.meta.url);\n const buildDirResolver = createResolver(nuxt.options.buildDir);\n\n const clientConfigFile = findDefaultSdkInitFile('client', nuxt);\n\n if (clientConfigFile) {\n // Inject the client-side Sentry config file with a side effect import\n addPluginTemplate({\n mode: 'client',\n filename: 'sentry-client-config.mjs',\n order: 0,\n\n // Dynamic import of config file to wrap it within a Nuxt context (here: defineNuxtPlugin)\n // Makes it possible to call useRuntimeConfig() in the user-defined sentry config file\n getContents: () => `\n import { defineNuxtPlugin } from \"#imports\";\n\n export default defineNuxtPlugin({\n name: 'sentry-client-config',\n async setup() {\n await import(\"${buildDirResolver.resolve(`/${clientConfigFile}`)}\")\n }\n });`,\n });\n\n // Add the plugin which loads client integrations etc. -\n // this must run after the sentry-client-config plugin has run, and the client is initialized!\n addPlugin({\n src: moduleDirResolver.resolve('./runtime/plugins/sentry.client'),\n mode: 'client',\n order: 1,\n });\n }\n\n const serverConfigFile = findDefaultSdkInitFile('server', nuxt);\n const isNitroV3 = (await getNitroMajorVersion()) >= 3;\n\n if (serverConfigFile) {\n if (isNitroV3) {\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/handler.server'));\n } else {\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/handler-legacy.server'));\n }\n\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/sentry.server'));\n\n addPlugin({\n src: moduleDirResolver.resolve('./runtime/plugins/route-detector.server'),\n mode: 'server',\n });\n\n // Preps the middleware instrumentation module.\n addMiddlewareImports();\n addStorageInstrumentation(nuxt, !isNitroV3);\n addDatabaseInstrumentation(nuxt.options.nitro, !isNitroV3, moduleOptions);\n }\n\n if (clientConfigFile || serverConfigFile) {\n setupSourceMaps(moduleOptions, nuxt, addVitePlugin);\n }\n\n addOTelCommonJSImportAlias(nuxt, isNitroV3);\n\n const pagesDataTemplate = addTemplate({\n filename: 'sentry--nuxt-pages-data.mjs',\n // Initial empty array (later filled in pages:extend hook)\n // Template needs to be created in the root-level of the module to work\n getContents: () => 'export default [];',\n });\n\n nuxt.hooks.hook('pages:extend', pages => {\n pagesDataTemplate.getContents = () => {\n const pagesSubset = pages\n .map(page => ({ file: page.file, path: page.path }))\n .filter(page => {\n // Check for dynamic parameter (e.g., :userId or [userId])\n return page.path.includes(':') || page?.file?.includes('[');\n });\n\n return `export default ${JSON.stringify(pagesSubset, null, 2)};`;\n };\n });\n\n // Add the sentry config file to the include array\n nuxt.hook('prepare:types', options => {\n const tsConfig = options.tsConfig as { include?: string[] };\n\n if (!tsConfig.include) {\n tsConfig.include = [];\n }\n\n // Add type references for useRuntimeConfig in root files for nuxt v4\n // Should be relative to `root/.nuxt`\n if (clientConfigFile) {\n const relativePath = path.relative(nuxt.options.buildDir, clientConfigFile);\n tsConfig.include.push(relativePath);\n }\n if (serverConfigFile) {\n const relativePath = path.relative(nuxt.options.buildDir, serverConfigFile);\n tsConfig.include.push(relativePath);\n }\n });\n\n nuxt.hooks.hook('nitro:init', nitro => {\n if (nuxt.options?._prepare) {\n return;\n }\n\n if (serverConfigFile && !isNitroV3) {\n addMiddlewareInstrumentation(nitro);\n }\n\n if (serverConfigFile?.includes('.server.config')) {\n consoleSandbox(() => {\n const serverDir = nitro.options.output.serverDir;\n\n // Netlify env: https://docs.netlify.com/configure-builds/environment-variables/#build-metadata\n if (serverDir.includes('.netlify') || !!process.env.NETLIFY) {\n // eslint-disable-next-line no-console\n console.warn(\n '[Sentry] Warning: The Sentry SDK detected a Netlify build. Server-side support for the Sentry Nuxt SDK on Netlify is currently unreliable due to technical limitations of serverless functions. Traces are not collected, and errors may occasionally not be reported. For more information on setting up Sentry on the Nuxt server-side, please refer to the documentation: https://docs.sentry.io/platforms/javascript/guides/nuxt/install/',\n );\n }\n\n // Vercel env: https://vercel.com/docs/projects/environment-variables/system-environment-variables#VERCEL\n if (serverDir.includes('.vercel') || !!process.env.VERCEL) {\n // eslint-disable-next-line no-console\n console.warn(\n '[Sentry] Warning: The Sentry SDK detected a Vercel build. The Sentry Nuxt SDK currently does not support tracing on Vercel. For more information on setting up Sentry on the Nuxt server-side, please refer to the documentation: https://docs.sentry.io/platforms/javascript/guides/nuxt/install/',\n );\n }\n });\n\n if (moduleOptions.autoInjectServerSentry !== 'experimental_dynamic-import') {\n addServerConfigToBuild(moduleOptions, nitro, serverConfigFile);\n\n if (moduleOptions.debug) {\n const serverDirResolver = createResolver(nitro.options.output.serverDir);\n const serverConfigPath = serverDirResolver.resolve('sentry.server.config.mjs');\n\n // For the default nitro node-preset build output this relative path would be: ./.output/server/sentry.server.config.mjs\n const serverConfigRelativePath = `.${path.sep}${path.relative(nitro.options.rootDir, serverConfigPath)}`;\n\n consoleSandbox(() => {\n // eslint-disable-next-line no-console\n console.log(\n `[Sentry] Using \\`${serverConfigFile}\\` for server-side Sentry configuration. To activate Sentry on the Nuxt server-side, this file must be preloaded when starting your application. Make sure to add this where you deploy and/or run your application. Read more here: https://docs.sentry.io/platforms/javascript/guides/nuxt/install/.`,\n );\n\n if (nitro.options.dev) {\n // eslint-disable-next-line no-console\n console.log(\n `[Sentry] During development, preload Sentry with the NODE_OPTIONS environment variable: \\`NODE_OPTIONS='--import ${serverConfigRelativePath}' nuxt dev\\`. The file is generated in the build directory (usually '.nuxt'). If you delete the build directory, run \\`nuxt dev\\` to regenerate it.`,\n );\n } else {\n // eslint-disable-next-line no-console\n console.log(\n `[Sentry] When running your built application, preload Sentry via a command-line flag (\\`node --import ${serverConfigRelativePath} [...]\\`) or via an environment variable (\\`NODE_OPTIONS='--import ${serverConfigRelativePath}' node [...]\\`).`,\n );\n }\n });\n }\n }\n\n if (moduleOptions.autoInjectServerSentry === 'top-level-import') {\n addSentryTopImport(moduleOptions, nitro);\n }\n\n if (moduleOptions.autoInjectServerSentry === 'experimental_dynamic-import') {\n addDynamicImportEntryFileWrapper(nitro, serverConfigFile, moduleOptions);\n\n if (moduleOptions.debug) {\n consoleSandbox(() => {\n // eslint-disable-next-line no-console\n console.log(\n '[Sentry] Wrapping the server entry file with a dynamic `import()`, so Sentry can be preloaded before the server initializes.',\n );\n });\n }\n }\n }\n });\n },\n});\n"],"names":["defineNuxtModule","createResolver","findDefaultSdkInitFile","addPluginTemplate","addPlugin","getNitroMajorVersion","addServerPlugin","addMiddlewareImports","addStorageInstrumentation","addDatabaseInstrumentation","setupSourceMaps","addVitePlugin","addOTelCommonJSImportAlias","addTemplate","addMiddlewareInstrumentation","consoleSandbox","addServerConfigToBuild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A,CAAA,CAAA,EAAA,IAAA,CAAA,GAAA,CAAA,EAAA,IAAA,CAAA,QAAA,CAAA,KAAA,CAAA,OAAA,CAAA,OAAA,EAAA,gBAAA,CAAA,CAAA,CAAA;;AAEA,YAAAc,mBAAA,CAAA,MAAA;AACA;AACA,cAAA,OAAA,CAAA,GAAA;AACA,gBAAA,CAAA,iBAAA,EAAA,gBAAA,CAAA,sSAAA,CAAA;AACA,eAAA;;AAEA,cAAA,IAAA,KAAA,CAAA,OAAA,CAAA,GAAA,EAAA;AACA;AACA,gBAAA,OAAA,CAAA,GAAA;AACA,kBAAA,CAAA,iHAAA,EAAA,wBAAA,CAAA,mJAAA,CAAA;AACA,iBAAA;AACA,cAAA,CAAA,MAAA;AACA;AACA,gBAAA,OAAA,CAAA,GAAA;AACA,kBAAA,CAAA,sGAAA,EAAA,wBAAA,CAAA,mEAAA,EAAA,wBAAA,CAAA,gBAAA,CAAA;AACA,iBAAA;AACA,cAAA;AACA,YAAA,CAAA,CAAA;AACA,UAAA;AACA,QAAA;;AAEA,QAAA,IAAA,aAAA,CAAA,sBAAA,KAAA,kBAAA,EAAA;AACA,UAAAE,kCAAA,CAAA,aAAA,EAAA,KAAA,CAAA;AACA,QAAA;;AAEA,QAAA,IAAA,aAAA,CAAA,sBAAA,KAAA,6BAAA,EAAA;AACA,UAAAC,gDAAA,CAAA,KAAA,EAAA,gBAAA,EAAA,aAAA,CAAA;;AAEA,UAAA,IAAA,aAAA,CAAA,KAAA,EAAA;AACA,YAAAH,mBAAA,CAAA,MAAA;AACA;AACA,cAAA,OAAA,CAAA,GAAA;AACA,gBAAA,8HAAA;AACA,eAAA;AACA,YAAA,CAAA,CAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA,CAAA,CAAA;AACA,EAAA,CAAA;AACA,CAAA,CAAA;;;;"}
1
+ {"version":3,"file":"module.js","sources":["../../src/module.ts"],"sourcesContent":["import {\n addPlugin,\n addPluginTemplate,\n addServerPlugin,\n addTemplate,\n addVitePlugin,\n createResolver,\n defineNuxtModule,\n} from '@nuxt/kit';\nimport { consoleSandbox } from '@sentry/core';\nimport * as path from 'path';\nimport type { SentryNuxtModuleOptions } from './common/types';\nimport { addDynamicImportEntryFileWrapper, addSentryTopImport, addServerConfigToBuild } from './vite/addServerConfig';\nimport { addDatabaseInstrumentation } from './vite/databaseConfig';\nimport { addMiddlewareImports, addMiddlewareInstrumentation } from './vite/middlewareConfig';\nimport { setupSourceMaps } from './vite/sourceMaps';\nimport { addStorageInstrumentation } from './vite/storageConfig';\nimport { addOTelCommonJSImportAlias, findDefaultSdkInitFile, getNitroMajorVersion } from './vite/utils';\n\nexport type ModuleOptions = SentryNuxtModuleOptions;\ntype NuxtPageSubset = { file?: string; path: string };\n\nexport default defineNuxtModule<ModuleOptions>({\n meta: {\n name: '@sentry/nuxt/module',\n configKey: 'sentry',\n compatibility: {\n nuxt: '>=3.7.0',\n },\n },\n defaults: {},\n async setup(moduleOptionsParam, nuxt) {\n if (moduleOptionsParam?.enabled === false) {\n return;\n }\n\n const moduleOptions = {\n ...moduleOptionsParam,\n autoInjectServerSentry: moduleOptionsParam.autoInjectServerSentry,\n experimental_entrypointWrappedFunctions: moduleOptionsParam.experimental_entrypointWrappedFunctions || [\n 'default',\n 'handler',\n 'server',\n ],\n };\n\n const moduleDirResolver = createResolver(import.meta.url);\n const buildDirResolver = createResolver(nuxt.options.buildDir);\n\n const clientConfigFile = findDefaultSdkInitFile('client', nuxt);\n\n if (clientConfigFile) {\n // Inject the client-side Sentry config file with a side effect import\n addPluginTemplate({\n mode: 'client',\n filename: 'sentry-client-config.mjs',\n order: 0,\n\n // Dynamic import of config file to wrap it within a Nuxt context (here: defineNuxtPlugin)\n // Makes it possible to call useRuntimeConfig() in the user-defined sentry config file\n getContents: () => `\n import { defineNuxtPlugin } from \"#imports\";\n\n export default defineNuxtPlugin({\n name: 'sentry-client-config',\n async setup() {\n await import(\"${buildDirResolver.resolve(`/${clientConfigFile}`)}\")\n }\n });`,\n });\n\n // Add the plugin which loads client integrations etc. -\n // this must run after the sentry-client-config plugin has run, and the client is initialized!\n addPlugin({\n src: moduleDirResolver.resolve('./runtime/plugins/sentry.client'),\n mode: 'client',\n order: 1,\n });\n }\n\n const serverConfigFile = findDefaultSdkInitFile('server', nuxt);\n const isNitroV3 = (await getNitroMajorVersion()) >= 3;\n const nuxtMajor = parseInt((nuxt as unknown as { _version: string })._version?.split('.')[0] ?? '3', 10);\n const isMinNuxtV4 = nuxtMajor >= 4;\n\n if (serverConfigFile) {\n if (isNitroV3) {\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/handler.server'));\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/update-route-name.server'));\n } else {\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/handler-legacy.server'));\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/update-route-name-legacy.server'));\n }\n\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/sentry.server'));\n\n if (isMinNuxtV4) {\n addPlugin({ src: moduleDirResolver.resolve('./runtime/plugins/route-detector.server'), mode: 'server' });\n } else {\n addPlugin({ src: moduleDirResolver.resolve('./runtime/plugins/route-detector-legacy.server'), mode: 'server' });\n }\n\n // Preps the middleware instrumentation module.\n addMiddlewareImports();\n addStorageInstrumentation(nuxt, !isNitroV3);\n addDatabaseInstrumentation(nuxt.options.nitro, !isNitroV3, moduleOptions);\n }\n\n if (clientConfigFile || serverConfigFile) {\n setupSourceMaps(moduleOptions, nuxt, addVitePlugin);\n }\n\n addOTelCommonJSImportAlias(nuxt, isNitroV3);\n\n let pagesData: NuxtPageSubset[] = [];\n\n nuxt.hooks.hook('pages:extend', pages => {\n pagesData = pages\n .map(page => ({ file: page.file, path: page.path }))\n .filter(page => {\n // Check for dynamic parameter (e.g., :userId or [userId])\n return page.path.includes(':') || page?.file?.includes('[');\n });\n });\n\n if (isMinNuxtV4) {\n const pagesDataVirtualModuleId = '#sentry/nuxt-pages-data.mjs';\n\n // Vite virtual plugin (for the Vite SSR build, where addPlugin mode:'server' plugins are bundled)\n addVitePlugin({\n name: 'sentry-nuxt-pages-data-virtual',\n resolveId: id => (id === pagesDataVirtualModuleId ? `\\0${pagesDataVirtualModuleId}` : null),\n load: id =>\n id === `\\0${pagesDataVirtualModuleId}` ? `export default ${JSON.stringify(pagesData, null, 2)};` : undefined,\n });\n } else {\n // Nuxt v3: register as a build template (accessible via #build/)\n addTemplate({\n filename: 'sentry--nuxt-pages-data.mjs',\n getContents: () => `export default ${JSON.stringify(pagesData, null, 2)};`,\n });\n }\n\n // Add the sentry config file to the include array\n nuxt.hook('prepare:types', options => {\n const tsConfig = options.tsConfig as { include?: string[] };\n\n if (!tsConfig.include) {\n tsConfig.include = [];\n }\n\n // Add type references for useRuntimeConfig in root files for nuxt v4\n // Should be relative to `root/.nuxt`\n if (clientConfigFile) {\n const relativePath = path.relative(nuxt.options.buildDir, clientConfigFile);\n tsConfig.include.push(relativePath);\n }\n if (serverConfigFile) {\n const relativePath = path.relative(nuxt.options.buildDir, serverConfigFile);\n tsConfig.include.push(relativePath);\n }\n });\n\n nuxt.hooks.hook('nitro:init', nitro => {\n if (nuxt.options?._prepare) {\n return;\n }\n\n if (serverConfigFile) {\n addMiddlewareInstrumentation(nitro);\n }\n\n if (serverConfigFile?.includes('.server.config')) {\n consoleSandbox(() => {\n const serverDir = nitro.options.output.serverDir;\n\n // Netlify env: https://docs.netlify.com/configure-builds/environment-variables/#build-metadata\n if (serverDir.includes('.netlify') || !!process.env.NETLIFY) {\n // eslint-disable-next-line no-console\n console.warn(\n '[Sentry] Warning: The Sentry SDK detected a Netlify build. Server-side support for the Sentry Nuxt SDK on Netlify is currently unreliable due to technical limitations of serverless functions. Traces are not collected, and errors may occasionally not be reported. For more information on setting up Sentry on the Nuxt server-side, please refer to the documentation: https://docs.sentry.io/platforms/javascript/guides/nuxt/install/',\n );\n }\n\n // Vercel env: https://vercel.com/docs/projects/environment-variables/system-environment-variables#VERCEL\n if (serverDir.includes('.vercel') || !!process.env.VERCEL) {\n // eslint-disable-next-line no-console\n console.warn(\n '[Sentry] Warning: The Sentry SDK detected a Vercel build. The Sentry Nuxt SDK currently does not support tracing on Vercel. For more information on setting up Sentry on the Nuxt server-side, please refer to the documentation: https://docs.sentry.io/platforms/javascript/guides/nuxt/install/',\n );\n }\n });\n\n if (moduleOptions.autoInjectServerSentry !== 'experimental_dynamic-import') {\n addServerConfigToBuild(moduleOptions, nitro, serverConfigFile);\n\n if (moduleOptions.debug) {\n const serverDirResolver = createResolver(nitro.options.output.serverDir);\n const serverConfigPath = serverDirResolver.resolve('sentry.server.config.mjs');\n\n // For the default nitro node-preset build output this relative path would be: ./.output/server/sentry.server.config.mjs\n const serverConfigRelativePath = `.${path.sep}${path.relative(nitro.options.rootDir, serverConfigPath)}`;\n\n consoleSandbox(() => {\n // eslint-disable-next-line no-console\n console.log(\n `[Sentry] Using \\`${serverConfigFile}\\` for server-side Sentry configuration. To activate Sentry on the Nuxt server-side, this file must be preloaded when starting your application. Make sure to add this where you deploy and/or run your application. Read more here: https://docs.sentry.io/platforms/javascript/guides/nuxt/install/.`,\n );\n\n if (nitro.options.dev) {\n // eslint-disable-next-line no-console\n console.log(\n `[Sentry] During development, preload Sentry with the NODE_OPTIONS environment variable: \\`NODE_OPTIONS='--import ${serverConfigRelativePath}' nuxt dev\\`. The file is generated in the build directory (usually '.nuxt'). If you delete the build directory, run \\`nuxt dev\\` to regenerate it.`,\n );\n } else {\n // eslint-disable-next-line no-console\n console.log(\n `[Sentry] When running your built application, preload Sentry via a command-line flag (\\`node --import ${serverConfigRelativePath} [...]\\`) or via an environment variable (\\`NODE_OPTIONS='--import ${serverConfigRelativePath}' node [...]\\`).`,\n );\n }\n });\n }\n }\n\n if (moduleOptions.autoInjectServerSentry === 'top-level-import') {\n addSentryTopImport(moduleOptions, nitro);\n }\n\n if (moduleOptions.autoInjectServerSentry === 'experimental_dynamic-import') {\n addDynamicImportEntryFileWrapper(nitro, serverConfigFile, moduleOptions);\n\n if (moduleOptions.debug) {\n consoleSandbox(() => {\n // eslint-disable-next-line no-console\n console.log(\n '[Sentry] Wrapping the server entry file with a dynamic `import()`, so Sentry can be preloaded before the server initializes.',\n );\n });\n }\n }\n }\n });\n },\n});\n"],"names":["defineNuxtModule","createResolver","findDefaultSdkInitFile","addPluginTemplate","addPlugin","getNitroMajorVersion","addServerPlugin","addMiddlewareImports","addStorageInstrumentation","addDatabaseInstrumentation","setupSourceMaps","addVitePlugin","addOTelCommonJSImportAlias","addTemplate","addMiddlewareInstrumentation","consoleSandbox","addServerConfigToBuild","addSentryTopImport","addDynamicImportEntryFileWrapper"],"mappings":";;;;;;;;;;;AAsBA,iBAAeA,oBAAgB,CAAgB;AAC/C,EAAE,IAAI,EAAE;AACR,IAAI,IAAI,EAAE,qBAAqB;AAC/B,IAAI,SAAS,EAAE,QAAQ;AACvB,IAAI,aAAa,EAAE;AACnB,MAAM,IAAI,EAAE,SAAS;AACrB,KAAK;AACL,GAAG;AACH,EAAE,QAAQ,EAAE,EAAE;AACd,EAAE,MAAM,KAAK,CAAC,kBAAkB,EAAE,IAAI,EAAE;AACxC,IAAI,IAAI,kBAAkB,EAAE,OAAA,KAAY,KAAK,EAAE;AAC/C,MAAM;AACN,IAAI;;AAEJ,IAAI,MAAM,gBAAgB;AAC1B,MAAM,GAAG,kBAAkB;AAC3B,MAAM,sBAAsB,EAAE,kBAAkB,CAAC,sBAAsB;AACvE,MAAM,uCAAuC,EAAE,kBAAkB,CAAC,2CAA2C;AAC7G,QAAQ,SAAS;AACjB,QAAQ,SAAS;AACjB,QAAQ,QAAQ;AAChB,OAAO;AACP,KAAK;;AAEL,IAAI,MAAM,iBAAA,GAAoBC,kBAAc,CAAC,2PAAe,CAAC;AAC7D,IAAI,MAAM,gBAAA,GAAmBA,kBAAc,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;;AAElE,IAAI,MAAM,mBAAmBC,4BAAsB,CAAC,QAAQ,EAAE,IAAI,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MiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));
92
92
  }
93
93
 
94
+ function defineInstrumentedHandler(handlerOrObject) {
95
+ return defineHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));
96
+ }
97
+
94
98
  ${originalCode
95
99
  .replace(/defineEventHandler\(/g, 'defineInstrumentedEventHandler(')
96
- .replace(/eventHandler\(/g, 'instrumentedEventHandler(')}
100
+ .replace(/eventHandler\(/g, 'instrumentedEventHandler(')
101
+ .replace(/defineHandler\(/g, 'defineInstrumentedHandler(')}
97
102
  `;
98
103
  }
99
104
 
@@ -1 +1 @@
1
- {"version":3,"file":"middlewareConfig.js","sources":["../../../src/vite/middlewareConfig.ts"],"sourcesContent":["import { addServerImports, createResolver } from '@nuxt/kit';\nimport type { Nitro } from 'nitropack/types';\nimport * as path from 'path';\nimport type { InputPluginOption } from 'rollup';\n\n/**\n * Adds a server import for the middleware instrumentation.\n */\nexport function addMiddlewareImports(): void {\n addServerImports([\n {\n name: 'wrapMiddlewareHandlerWithSentry',\n from: createResolver(import.meta.url).resolve('./runtime/hooks/wrapMiddlewareHandler'),\n },\n ]);\n}\n\n/**\n * Adds middleware instrumentation to the Nitro build.\n *\n * @param nitro Nitro instance\n */\nexport function addMiddlewareInstrumentation(nitro: Nitro): void {\n nitro.hooks.hook('rollup:before', (nitro, rollupConfig) => {\n if (!rollupConfig.plugins) {\n rollupConfig.plugins = [];\n }\n\n if (!Array.isArray(rollupConfig.plugins)) {\n rollupConfig.plugins = [rollupConfig.plugins];\n }\n\n rollupConfig.plugins.push(middlewareInstrumentationPlugin(nitro));\n });\n}\n\n/**\n * Creates a rollup plugin for the middleware instrumentation by transforming the middleware code.\n *\n * @param nitro Nitro instance\n * @returns The rollup plugin for the middleware instrumentation.\n */\nfunction middlewareInstrumentationPlugin(nitro: Nitro): InputPluginOption {\n const middlewareFiles = new Set<string>();\n\n return {\n name: 'sentry-nuxt-middleware-instrumentation',\n buildStart() {\n // Collect middleware files during build start\n nitro.scannedHandlers?.forEach(({ middleware, handler }) => {\n if (middleware && handler) {\n middlewareFiles.add(handler);\n }\n });\n },\n transform(code: string, id: string) {\n // Only transform files we've identified as middleware\n if (middlewareFiles.has(id)) {\n const fileName = path.basename(id);\n return {\n code: wrapMiddlewareCode(code, fileName),\n map: null,\n };\n }\n return null;\n },\n };\n}\n\n/**\n * Wraps the middleware user code to instrument it.\n *\n * @param originalCode The original user code of the middleware.\n * @param fileName The name of the middleware file, used for the span name and logging.\n *\n * @returns The wrapped user code of the middleware.\n */\nfunction wrapMiddlewareCode(originalCode: string, fileName: string): string {\n // Remove common file extensions\n const cleanFileName = fileName.replace(/\\.(ts|js|mjs|mts|cts)$/, '');\n\n return `\nimport { wrapMiddlewareHandlerWithSentry } from '#imports';\n\nfunction defineInstrumentedEventHandler(handlerOrObject) {\n return defineEventHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));\n}\n\nfunction instrumentedEventHandler(handlerOrObject) {\n return eventHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));\n}\n\n${originalCode\n .replace(/defineEventHandler\\(/g, 'defineInstrumentedEventHandler(')\n .replace(/eventHandler\\(/g, 'instrumentedEventHandler(')}\n`;\n}\n"],"names":["addServerImports","createResolver"],"mappings":";;;;;;AAKA;AACA;AACA;AACO,SAAS,oBAAoB,GAAS;AAC7C,EAAEA,oBAAgB,CAAC;AACnB,IAAI;AACJ,MAAM,IAAI,EAAE,iCAAiC;AAC7C,MAAM,IAAI,EAAEC,kBAAc,CAAC,0QAAe,CAAC,CAAC,OAAO,CAAC,uCAAuC,CAAC;AAC5F,KAAK;AACL,GAAG,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACO,SAAS,4BAA4B,CAAC,KAAK,EAAe;AACjE,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK;AAC7D,IAAI,IAAI,CAA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AAU,QAAQ,EAAkB;AAC5E;AACA,EAAE,MAAM,aAAA,GAAgB,QAAQ,CAAC,OAAO,CAAC,wBAAwB,EAAE,EAAE,CAAC;;AAEtE,EAAE,OAAO;AACT;;AAEA;AACA,8EAA8E,EAAE,aAAa,CAAC;AAC9F;;AAEA;AACA,wEAAwE,EAAE,aAAa,CAAC;AACxF;;AAEA,EAAE;AACF,GAAG,OAAO,CAAC,uBAAuB,EAAE,iCAAiC;AACrE,GAAG,OAAO,CAAC,iBAAiB,EAAE,2BAA2B,CAAC;AAC1D,CAAC;AACD;;;;;"}
1
+ {"version":3,"file":"middlewareConfig.js","sources":["../../../src/vite/middlewareConfig.ts"],"sourcesContent":["import { addServerImports, createResolver } from '@nuxt/kit';\nimport type { Nitro } from 'nitropack/types';\nimport * as path from 'path';\nimport type { InputPluginOption } from 'rollup';\n\n/**\n * Adds a server import for the middleware instrumentation.\n */\nexport function addMiddlewareImports(): void {\n addServerImports([\n {\n name: 'wrapMiddlewareHandlerWithSentry',\n from: createResolver(import.meta.url).resolve('./runtime/hooks/wrapMiddlewareHandler'),\n },\n ]);\n}\n\n/**\n * Adds middleware instrumentation to the Nitro build.\n *\n * @param nitro Nitro instance\n */\nexport function addMiddlewareInstrumentation(nitro: Nitro): void {\n nitro.hooks.hook('rollup:before', (nitro, rollupConfig) => {\n if (!rollupConfig.plugins) {\n rollupConfig.plugins = [];\n }\n\n if (!Array.isArray(rollupConfig.plugins)) {\n rollupConfig.plugins = [rollupConfig.plugins];\n }\n\n rollupConfig.plugins.push(middlewareInstrumentationPlugin(nitro));\n });\n}\n\n/**\n * Creates a rollup plugin for the middleware instrumentation by transforming the middleware code.\n *\n * @param nitro Nitro instance\n * @returns The rollup plugin for the middleware instrumentation.\n */\nfunction middlewareInstrumentationPlugin(nitro: Nitro): InputPluginOption {\n const middlewareFiles = new Set<string>();\n\n return {\n name: 'sentry-nuxt-middleware-instrumentation',\n buildStart() {\n // Collect middleware files during build start\n nitro.scannedHandlers?.forEach(({ middleware, handler }) => {\n if (middleware && handler) {\n middlewareFiles.add(handler);\n }\n });\n },\n transform(code: string, id: string) {\n // Only transform files we've identified as middleware\n if (middlewareFiles.has(id)) {\n const fileName = path.basename(id);\n return {\n code: wrapMiddlewareCode(code, fileName),\n map: null,\n };\n }\n return null;\n },\n };\n}\n\n/**\n * Wraps the middleware user code to instrument it.\n *\n * @param originalCode The original user code of the middleware.\n * @param fileName The name of the middleware file, used for the span name and logging.\n *\n * @returns The wrapped user code of the middleware.\n */\nfunction wrapMiddlewareCode(originalCode: string, fileName: string): string {\n // Remove common file extensions\n const cleanFileName = fileName.replace(/\\.(ts|js|mjs|mts|cts)$/, '');\n\n return `\nimport { wrapMiddlewareHandlerWithSentry } from '#imports';\n\nfunction defineInstrumentedEventHandler(handlerOrObject) {\n return defineEventHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));\n}\n\nfunction instrumentedEventHandler(handlerOrObject) {\n return eventHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));\n}\n\nfunction defineInstrumentedHandler(handlerOrObject) {\n return defineHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));\n}\n\n${originalCode\n .replace(/defineEventHandler\\(/g, 'defineInstrumentedEventHandler(')\n .replace(/eventHandler\\(/g, 'instrumentedEventHandler(')\n .replace(/defineHandler\\(/g, 'defineInstrumentedHandler(')}\n`;\n}\n"],"names":["addServerImports","createResolver"],"mappings":";;;;;;AAKA;AACA;AACA;AACO,SAAS,oBAAoB,GAAS;AAC7C,EAAEA,oBAAgB,CAAC;AACnB,IAAI;AACJ,MAAM,IAAI,EAAE,iCAAiC;AAC7C,MAAM,IAAI,EAAEC,kBAAc,CAAC,0QAAe,CAAC,CAAC,OAAO,CAAC,uCAAuC,CAAC;AAC5F,KAAK;AACL,GAAG,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACO,SAAS,4BAA4B,CAAC,KAAK,EAAe;AACjE,E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ACjB,IAAI,CAAC;AACL,GAAG;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,kBAAkB,CAAC,YAAY,EAAU,QAAQ,EAAkB;AAC5E;AACA,EAAE,MAAM,aAAA,GAAgB,QAAQ,CAAC,OAAO,CAAC,wBAAwB,EAAE,EAAE,CAAC;;AAEtE,EAAE,OAAO;AACT;;AAEA;AACA,8EAA8E,EAAE,aAAa,CAAC;AAC9F;;AAEA;AACA,wEAAwE,EAAE,aAAa,CAAC;AACxF;;AAEA;AACA,yEAAyE,EAAE,aAAa,CAAC;AACzF;;AAEA,EAAE;AACF,GAAG,OAAO,CAAC,uBAAuB,EAAE,iCAAiC;AACrE,GAAG,OAAO,CAAC,iBAAiB,EAAE,2BAA2B;AACzD,GAAG,OAAO,CAAC,kBAAkB,EAAE,4BAA4B,CAAC;AAC5D,CAAC;AACD;;;;;"}
@@ -1,4 +1,4 @@
1
- import { defineNuxtModule, createResolver, addPluginTemplate, addPlugin, addServerPlugin, addTemplate, addVitePlugin } from '@nuxt/kit';
1
+ import { defineNuxtModule, createResolver, addPluginTemplate, addPlugin, addServerPlugin, addVitePlugin, addTemplate } from '@nuxt/kit';
2
2
  import { consoleSandbox } from '@sentry/core';
3
3
  import * as path from 'path';
4
4
  import { addServerConfigToBuild, addSentryTopImport, addDynamicImportEntryFileWrapper } from './vite/addServerConfig.js';
@@ -68,20 +68,25 @@ const module$1 = defineNuxtModule({
68
68
 
69
69
  const serverConfigFile = findDefaultSdkInitFile('server', nuxt);
70
70
  const isNitroV3 = (await getNitroMajorVersion()) >= 3;
71
+ const nuxtMajor = parseInt((nuxt )._version?.split('.')[0] ?? '3', 10);
72
+ const isMinNuxtV4 = nuxtMajor >= 4;
71
73
 
72
74
  if (serverConfigFile) {
73
75
  if (isNitroV3) {
74
76
  addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/handler.server'));
77
+ addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/update-route-name.server'));
75
78
  } else {
76
79
  addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/handler-legacy.server'));
80
+ addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/update-route-name-legacy.server'));
77
81
  }
78
82
 
79
83
  addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/sentry.server'));
80
84
 
81
- addPlugin({
82
- src: moduleDirResolver.resolve('./runtime/plugins/route-detector.server'),
83
- mode: 'server',
84
- });
85
+ if (isMinNuxtV4) {
86
+ addPlugin({ src: moduleDirResolver.resolve('./runtime/plugins/route-detector.server'), mode: 'server' });
87
+ } else {
88
+ addPlugin({ src: moduleDirResolver.resolve('./runtime/plugins/route-detector-legacy.server'), mode: 'server' });
89
+ }
85
90
 
86
91
  // Preps the middleware instrumentation module.
87
92
  addMiddlewareImports();
@@ -95,26 +100,35 @@ const module$1 = defineNuxtModule({
95
100
 
96
101
  addOTelCommonJSImportAlias(nuxt, isNitroV3);
97
102
 
98
- const pagesDataTemplate = addTemplate({
99
- filename: 'sentry--nuxt-pages-data.mjs',
100
- // Initial empty array (later filled in pages:extend hook)
101
- // Template needs to be created in the root-level of the module to work
102
- getContents: () => 'export default [];',
103
- });
103
+ let pagesData = [];
104
104
 
105
105
  nuxt.hooks.hook('pages:extend', pages => {
106
- pagesDataTemplate.getContents = () => {
107
- const pagesSubset = pages
108
- .map(page => ({ file: page.file, path: page.path }))
109
- .filter(page => {
110
- // Check for dynamic parameter (e.g., :userId or [userId])
111
- return page.path.includes(':') || page?.file?.includes('[');
112
- });
113
-
114
- return `export default ${JSON.stringify(pagesSubset, null, 2)};`;
115
- };
106
+ pagesData = pages
107
+ .map(page => ({ file: page.file, path: page.path }))
108
+ .filter(page => {
109
+ // Check for dynamic parameter (e.g., :userId or [userId])
110
+ return page.path.includes(':') || page?.file?.includes('[');
111
+ });
116
112
  });
117
113
 
114
+ if (isMinNuxtV4) {
115
+ const pagesDataVirtualModuleId = '#sentry/nuxt-pages-data.mjs';
116
+
117
+ // Vite virtual plugin (for the Vite SSR build, where addPlugin mode:'server' plugins are bundled)
118
+ addVitePlugin({
119
+ name: 'sentry-nuxt-pages-data-virtual',
120
+ resolveId: id => (id === pagesDataVirtualModuleId ? `\0${pagesDataVirtualModuleId}` : null),
121
+ load: id =>
122
+ id === `\0${pagesDataVirtualModuleId}` ? `export default ${JSON.stringify(pagesData, null, 2)};` : undefined,
123
+ });
124
+ } else {
125
+ // Nuxt v3: register as a build template (accessible via #build/)
126
+ addTemplate({
127
+ filename: 'sentry--nuxt-pages-data.mjs',
128
+ getContents: () => `export default ${JSON.stringify(pagesData, null, 2)};`,
129
+ });
130
+ }
131
+
118
132
  // Add the sentry config file to the include array
119
133
  nuxt.hook('prepare:types', options => {
120
134
  const tsConfig = options.tsConfig ;
@@ -140,7 +154,7 @@ const module$1 = defineNuxtModule({
140
154
  return;
141
155
  }
142
156
 
143
- if (serverConfigFile && !isNitroV3) {
157
+ if (serverConfigFile) {
144
158
  addMiddlewareInstrumentation(nitro);
145
159
  }
146
160
 
@@ -1 +1 @@
1
- {"version":3,"file":"module.js","sources":["../../src/module.ts"],"sourcesContent":["import {\n addPlugin,\n addPluginTemplate,\n addServerPlugin,\n addTemplate,\n addVitePlugin,\n createResolver,\n defineNuxtModule,\n} from '@nuxt/kit';\nimport { consoleSandbox } from '@sentry/core';\nimport * as path from 'path';\nimport type { SentryNuxtModuleOptions } from './common/types';\nimport { addDynamicImportEntryFileWrapper, addSentryTopImport, addServerConfigToBuild } from './vite/addServerConfig';\nimport { addDatabaseInstrumentation } from './vite/databaseConfig';\nimport { addMiddlewareImports, addMiddlewareInstrumentation } from './vite/middlewareConfig';\nimport { setupSourceMaps } from './vite/sourceMaps';\nimport { addStorageInstrumentation } from './vite/storageConfig';\nimport { addOTelCommonJSImportAlias, findDefaultSdkInitFile, getNitroMajorVersion } from './vite/utils';\n\nexport type ModuleOptions = SentryNuxtModuleOptions;\n\nexport default defineNuxtModule<ModuleOptions>({\n meta: {\n name: '@sentry/nuxt/module',\n configKey: 'sentry',\n compatibility: {\n nuxt: '>=3.7.0',\n },\n },\n defaults: {},\n async setup(moduleOptionsParam, nuxt) {\n if (moduleOptionsParam?.enabled === false) {\n return;\n }\n\n const moduleOptions = {\n ...moduleOptionsParam,\n autoInjectServerSentry: moduleOptionsParam.autoInjectServerSentry,\n experimental_entrypointWrappedFunctions: moduleOptionsParam.experimental_entrypointWrappedFunctions || [\n 'default',\n 'handler',\n 'server',\n ],\n };\n\n const moduleDirResolver = createResolver(import.meta.url);\n const buildDirResolver = createResolver(nuxt.options.buildDir);\n\n const clientConfigFile = findDefaultSdkInitFile('client', nuxt);\n\n if (clientConfigFile) {\n // Inject the client-side Sentry config file with a side effect import\n addPluginTemplate({\n mode: 'client',\n filename: 'sentry-client-config.mjs',\n order: 0,\n\n // Dynamic import of config file to wrap it within a Nuxt context (here: defineNuxtPlugin)\n // Makes it possible to call useRuntimeConfig() in the user-defined sentry config file\n getContents: () => `\n import { defineNuxtPlugin } from \"#imports\";\n\n export default defineNuxtPlugin({\n name: 'sentry-client-config',\n async setup() {\n await import(\"${buildDirResolver.resolve(`/${clientConfigFile}`)}\")\n }\n });`,\n });\n\n // Add the plugin which loads client integrations etc. -\n // this must run after the sentry-client-config plugin has run, and the client is initialized!\n addPlugin({\n src: moduleDirResolver.resolve('./runtime/plugins/sentry.client'),\n mode: 'client',\n order: 1,\n });\n }\n\n const serverConfigFile = findDefaultSdkInitFile('server', nuxt);\n const isNitroV3 = (await getNitroMajorVersion()) >= 3;\n\n if (serverConfigFile) {\n if (isNitroV3) {\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/handler.server'));\n } else {\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/handler-legacy.server'));\n }\n\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/sentry.server'));\n\n addPlugin({\n src: moduleDirResolver.resolve('./runtime/plugins/route-detector.server'),\n mode: 'server',\n });\n\n // Preps the middleware instrumentation module.\n addMiddlewareImports();\n addStorageInstrumentation(nuxt, !isNitroV3);\n addDatabaseInstrumentation(nuxt.options.nitro, !isNitroV3, moduleOptions);\n }\n\n if (clientConfigFile || serverConfigFile) {\n setupSourceMaps(moduleOptions, nuxt, addVitePlugin);\n }\n\n addOTelCommonJSImportAlias(nuxt, isNitroV3);\n\n const pagesDataTemplate = addTemplate({\n filename: 'sentry--nuxt-pages-data.mjs',\n // Initial empty array (later filled in pages:extend hook)\n // Template needs to be created in the root-level of the module to work\n getContents: () => 'export default [];',\n });\n\n nuxt.hooks.hook('pages:extend', pages => {\n pagesDataTemplate.getContents = () => {\n const pagesSubset = pages\n .map(page => ({ file: page.file, path: page.path }))\n .filter(page => {\n // Check for dynamic parameter (e.g., :userId or [userId])\n return page.path.includes(':') || page?.file?.includes('[');\n });\n\n return `export default ${JSON.stringify(pagesSubset, null, 2)};`;\n };\n });\n\n // Add the sentry config file to the include array\n nuxt.hook('prepare:types', options => {\n const tsConfig = options.tsConfig as { include?: string[] };\n\n if (!tsConfig.include) {\n tsConfig.include = [];\n }\n\n // Add type references for useRuntimeConfig in root files for nuxt v4\n // Should be relative to `root/.nuxt`\n if (clientConfigFile) {\n const relativePath = path.relative(nuxt.options.buildDir, clientConfigFile);\n tsConfig.include.push(relativePath);\n }\n if (serverConfigFile) {\n const relativePath = path.relative(nuxt.options.buildDir, serverConfigFile);\n tsConfig.include.push(relativePath);\n }\n });\n\n nuxt.hooks.hook('nitro:init', nitro => {\n if (nuxt.options?._prepare) {\n return;\n }\n\n if (serverConfigFile && !isNitroV3) {\n addMiddlewareInstrumentation(nitro);\n }\n\n if (serverConfigFile?.includes('.server.config')) {\n consoleSandbox(() => {\n const serverDir = nitro.options.output.serverDir;\n\n // Netlify env: https://docs.netlify.com/configure-builds/environment-variables/#build-metadata\n if (serverDir.includes('.netlify') || !!process.env.NETLIFY) {\n // eslint-disable-next-line no-console\n console.warn(\n '[Sentry] Warning: The Sentry SDK detected a Netlify build. Server-side support for the Sentry Nuxt SDK on Netlify is currently unreliable due to technical limitations of serverless functions. Traces are not collected, and errors may occasionally not be reported. For more information on setting up Sentry on the Nuxt server-side, please refer to the documentation: https://docs.sentry.io/platforms/javascript/guides/nuxt/install/',\n );\n }\n\n // Vercel env: https://vercel.com/docs/projects/environment-variables/system-environment-variables#VERCEL\n if (serverDir.includes('.vercel') || !!process.env.VERCEL) {\n // eslint-disable-next-line no-console\n console.warn(\n '[Sentry] Warning: The Sentry SDK detected a Vercel build. The Sentry Nuxt SDK currently does not support tracing on Vercel. For more information on setting up Sentry on the Nuxt server-side, please refer to the documentation: https://docs.sentry.io/platforms/javascript/guides/nuxt/install/',\n );\n }\n });\n\n if (moduleOptions.autoInjectServerSentry !== 'experimental_dynamic-import') {\n addServerConfigToBuild(moduleOptions, nitro, serverConfigFile);\n\n if (moduleOptions.debug) {\n const serverDirResolver = createResolver(nitro.options.output.serverDir);\n const serverConfigPath = serverDirResolver.resolve('sentry.server.config.mjs');\n\n // For the default nitro node-preset build output this relative path would be: ./.output/server/sentry.server.config.mjs\n const serverConfigRelativePath = `.${path.sep}${path.relative(nitro.options.rootDir, serverConfigPath)}`;\n\n consoleSandbox(() => {\n // eslint-disable-next-line no-console\n console.log(\n `[Sentry] Using \\`${serverConfigFile}\\` for server-side Sentry configuration. To activate Sentry on the Nuxt server-side, this file must be preloaded when starting your application. Make sure to add this where you deploy and/or run your application. Read more here: https://docs.sentry.io/platforms/javascript/guides/nuxt/install/.`,\n );\n\n if (nitro.options.dev) {\n // eslint-disable-next-line no-console\n console.log(\n `[Sentry] During development, preload Sentry with the NODE_OPTIONS environment variable: \\`NODE_OPTIONS='--import ${serverConfigRelativePath}' nuxt dev\\`. The file is generated in the build directory (usually '.nuxt'). If you delete the build directory, run \\`nuxt dev\\` to regenerate it.`,\n );\n } else {\n // eslint-disable-next-line no-console\n console.log(\n `[Sentry] When running your built application, preload Sentry via a command-line flag (\\`node --import ${serverConfigRelativePath} [...]\\`) or via an environment variable (\\`NODE_OPTIONS='--import ${serverConfigRelativePath}' node [...]\\`).`,\n );\n }\n });\n }\n }\n\n if (moduleOptions.autoInjectServerSentry === 'top-level-import') {\n addSentryTopImport(moduleOptions, nitro);\n }\n\n if (moduleOptions.autoInjectServerSentry === 'experimental_dynamic-import') {\n addDynamicImportEntryFileWrapper(nitro, serverConfigFile, moduleOptions);\n\n if (moduleOptions.debug) {\n consoleSandbox(() => {\n // eslint-disable-next-line no-console\n console.log(\n '[Sentry] Wrapping the server entry file with a dynamic `import()`, so Sentry can be preloaded before the server initializes.',\n );\n });\n }\n }\n }\n });\n },\n});\n"],"names":[],"mappings":";;;;;;;;;;AAqBA,iBAAe,gBAAgB,CAAgB;AAC/C,EAAE,IAAI,EAAE;AACR,IAAI,IAAI,EAAE,qBAAqB;AAC/B,IAAI,SAAS,EAAE,QAAQ;AACvB,IAAI,aAAa,EAAE;AACnB,MAAM,IAAI,EAAE,SAAS;AACrB,KAAK;AACL,GAAG;AACH,EAAE,QAAQ,EAAE,EAAE;AACd,EAAE,MAAM,KAAK,CAAC,kBAAkB,EAAE,IAAI,EAAE;AACxC,IAAI,IAAI,kBAAkB,EAAE,OAAA,KAAY,KAAK,EAAE;AAC/C,MAAM;AACN,IAAI;;AAEJ,IAAI,MAAM,gBAAgB;AAC1B,MAAM,GAAG,kBAAkB;AAC3B,MAAM,sBAAsB,EAAE,kBAAkB,CAAC,sBAAsB;AACvE,MAAM,uCAAuC,EAAE,kBAAkB,CAAC,2CAA2C;AAC7G,QAAQ,SAAS;AACjB,QAAQ,SAAS;AACjB,QAAQ,QAAQ;AAChB,OAAO;AACP,KAAK;;AAEL,IAAI,MAAM,iBAAA,GAAoB,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;AAC7D,IAAI,MAAM,gBAAA,GAAmB,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;;AAElE,IAAI,MAAM,mBAAmB,sBAAsB,CAAC,QAAQ,EAAE,IAAI,CAAC;;AAEnE,IAAI,IAAI,gBAAgB,EAAE;AA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,MAAA;AACA;AACA,cAAA,OAAA,CAAA,GAAA;AACA,gBAAA,8HAAA;AACA,eAAA;AACA,YAAA,CAAA,CAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA,CAAA,CAAA;AACA,EAAA,CAAA;AACA,CAAA,CAAA;;;;"}
1
+ {"version":3,"file":"module.js","sources":["../../src/module.ts"],"sourcesContent":["import {\n addPlugin,\n addPluginTemplate,\n addServerPlugin,\n addTemplate,\n addVitePlugin,\n createResolver,\n defineNuxtModule,\n} from '@nuxt/kit';\nimport { consoleSandbox } from '@sentry/core';\nimport * as path from 'path';\nimport type { SentryNuxtModuleOptions } from './common/types';\nimport { addDynamicImportEntryFileWrapper, addSentryTopImport, addServerConfigToBuild } from './vite/addServerConfig';\nimport { addDatabaseInstrumentation } from './vite/databaseConfig';\nimport { addMiddlewareImports, addMiddlewareInstrumentation } from './vite/middlewareConfig';\nimport { setupSourceMaps } from './vite/sourceMaps';\nimport { addStorageInstrumentation } from './vite/storageConfig';\nimport { addOTelCommonJSImportAlias, findDefaultSdkInitFile, getNitroMajorVersion } from './vite/utils';\n\nexport type ModuleOptions = SentryNuxtModuleOptions;\ntype NuxtPageSubset = { file?: string; path: string };\n\nexport default defineNuxtModule<ModuleOptions>({\n meta: {\n name: '@sentry/nuxt/module',\n configKey: 'sentry',\n compatibility: {\n nuxt: '>=3.7.0',\n },\n },\n defaults: {},\n async setup(moduleOptionsParam, nuxt) {\n if (moduleOptionsParam?.enabled === false) {\n return;\n }\n\n const moduleOptions = {\n ...moduleOptionsParam,\n autoInjectServerSentry: moduleOptionsParam.autoInjectServerSentry,\n experimental_entrypointWrappedFunctions: moduleOptionsParam.experimental_entrypointWrappedFunctions || [\n 'default',\n 'handler',\n 'server',\n ],\n };\n\n const moduleDirResolver = createResolver(import.meta.url);\n const buildDirResolver = createResolver(nuxt.options.buildDir);\n\n const clientConfigFile = findDefaultSdkInitFile('client', nuxt);\n\n if (clientConfigFile) {\n // Inject the client-side Sentry config file with a side effect import\n addPluginTemplate({\n mode: 'client',\n filename: 'sentry-client-config.mjs',\n order: 0,\n\n // Dynamic import of config file to wrap it within a Nuxt context (here: defineNuxtPlugin)\n // Makes it possible to call useRuntimeConfig() in the user-defined sentry config file\n getContents: () => `\n import { defineNuxtPlugin } from \"#imports\";\n\n export default defineNuxtPlugin({\n name: 'sentry-client-config',\n async setup() {\n await import(\"${buildDirResolver.resolve(`/${clientConfigFile}`)}\")\n }\n });`,\n });\n\n // Add the plugin which loads client integrations etc. -\n // this must run after the sentry-client-config plugin has run, and the client is initialized!\n addPlugin({\n src: moduleDirResolver.resolve('./runtime/plugins/sentry.client'),\n mode: 'client',\n order: 1,\n });\n }\n\n const serverConfigFile = findDefaultSdkInitFile('server', nuxt);\n const isNitroV3 = (await getNitroMajorVersion()) >= 3;\n const nuxtMajor = parseInt((nuxt as unknown as { _version: string })._version?.split('.')[0] ?? '3', 10);\n const isMinNuxtV4 = nuxtMajor >= 4;\n\n if (serverConfigFile) {\n if (isNitroV3) {\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/handler.server'));\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/update-route-name.server'));\n } else {\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/handler-legacy.server'));\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/update-route-name-legacy.server'));\n }\n\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/sentry.server'));\n\n if (isMinNuxtV4) {\n addPlugin({ src: moduleDirResolver.resolve('./runtime/plugins/route-detector.server'), mode: 'server' });\n } else {\n addPlugin({ src: moduleDirResolver.resolve('./runtime/plugins/route-detector-legacy.server'), mode: 'server' });\n }\n\n // Preps the middleware instrumentation module.\n addMiddlewareImports();\n addStorageInstrumentation(nuxt, !isNitroV3);\n addDatabaseInstrumentation(nuxt.options.nitro, !isNitroV3, moduleOptions);\n }\n\n if (clientConfigFile || serverConfigFile) {\n setupSourceMaps(moduleOptions, nuxt, addVitePlugin);\n }\n\n addOTelCommonJSImportAlias(nuxt, isNitroV3);\n\n let pagesData: NuxtPageSubset[] = [];\n\n nuxt.hooks.hook('pages:extend', pages => {\n pagesData = pages\n .map(page => ({ file: page.file, path: page.path }))\n .filter(page => {\n // Check for dynamic parameter (e.g., :userId or [userId])\n return page.path.includes(':') || page?.file?.includes('[');\n });\n });\n\n if (isMinNuxtV4) {\n const pagesDataVirtualModuleId = '#sentry/nuxt-pages-data.mjs';\n\n // Vite virtual plugin (for the Vite SSR build, where addPlugin mode:'server' plugins are bundled)\n addVitePlugin({\n name: 'sentry-nuxt-pages-data-virtual',\n resolveId: id => (id === pagesDataVirtualModuleId ? `\\0${pagesDataVirtualModuleId}` : null),\n load: id =>\n id === `\\0${pagesDataVirtualModuleId}` ? `export default ${JSON.stringify(pagesData, null, 2)};` : undefined,\n });\n } else {\n // Nuxt v3: register as a build template (accessible via #build/)\n addTemplate({\n filename: 'sentry--nuxt-pages-data.mjs',\n getContents: () => `export default ${JSON.stringify(pagesData, null, 2)};`,\n });\n }\n\n // Add the sentry config file to the include array\n nuxt.hook('prepare:types', options => {\n const tsConfig = options.tsConfig as { include?: string[] };\n\n if (!tsConfig.include) {\n tsConfig.include = [];\n }\n\n // Add type references for useRuntimeConfig in root files for nuxt v4\n // Should be relative to `root/.nuxt`\n if (clientConfigFile) {\n const relativePath = path.relative(nuxt.options.buildDir, clientConfigFile);\n tsConfig.include.push(relativePath);\n }\n if (serverConfigFile) {\n const relativePath = path.relative(nuxt.options.buildDir, serverConfigFile);\n tsConfig.include.push(relativePath);\n }\n });\n\n nuxt.hooks.hook('nitro:init', nitro => {\n if (nuxt.options?._prepare) {\n return;\n }\n\n if (serverConfigFile) {\n addMiddlewareInstrumentation(nitro);\n }\n\n if (serverConfigFile?.includes('.server.config')) {\n consoleSandbox(() => {\n const serverDir = nitro.options.output.serverDir;\n\n // Netlify env: https://docs.netlify.com/configure-builds/environment-variables/#build-metadata\n if (serverDir.includes('.netlify') || !!process.env.NETLIFY) {\n // eslint-disable-next-line no-console\n console.warn(\n '[Sentry] Warning: The Sentry SDK detected a Netlify build. Server-side support for the Sentry Nuxt SDK on Netlify is currently unreliable due to technical limitations of serverless functions. Traces are not collected, and errors may occasionally not be reported. For more information on setting up Sentry on the Nuxt server-side, please refer to the documentation: https://docs.sentry.io/platforms/javascript/guides/nuxt/install/',\n );\n }\n\n // Vercel env: https://vercel.com/docs/projects/environment-variables/system-environment-variables#VERCEL\n if (serverDir.includes('.vercel') || !!process.env.VERCEL) {\n // eslint-disable-next-line no-console\n console.warn(\n '[Sentry] Warning: The Sentry SDK detected a Vercel build. The Sentry Nuxt SDK currently does not support tracing on Vercel. For more information on setting up Sentry on the Nuxt server-side, please refer to the documentation: https://docs.sentry.io/platforms/javascript/guides/nuxt/install/',\n );\n }\n });\n\n if (moduleOptions.autoInjectServerSentry !== 'experimental_dynamic-import') {\n addServerConfigToBuild(moduleOptions, nitro, serverConfigFile);\n\n if (moduleOptions.debug) {\n const serverDirResolver = createResolver(nitro.options.output.serverDir);\n const serverConfigPath = serverDirResolver.resolve('sentry.server.config.mjs');\n\n // For the default nitro node-preset build output this relative path would be: ./.output/server/sentry.server.config.mjs\n const serverConfigRelativePath = `.${path.sep}${path.relative(nitro.options.rootDir, serverConfigPath)}`;\n\n consoleSandbox(() => {\n // eslint-disable-next-line no-console\n console.log(\n `[Sentry] Using \\`${serverConfigFile}\\` for server-side Sentry configuration. To activate Sentry on the Nuxt server-side, this file must be preloaded when starting your application. Make sure to add this where you deploy and/or run your application. Read more here: https://docs.sentry.io/platforms/javascript/guides/nuxt/install/.`,\n );\n\n if (nitro.options.dev) {\n // eslint-disable-next-line no-console\n console.log(\n `[Sentry] During development, preload Sentry with the NODE_OPTIONS environment variable: \\`NODE_OPTIONS='--import ${serverConfigRelativePath}' nuxt dev\\`. The file is generated in the build directory (usually '.nuxt'). If you delete the build directory, run \\`nuxt dev\\` to regenerate it.`,\n );\n } else {\n // eslint-disable-next-line no-console\n console.log(\n `[Sentry] When running your built application, preload Sentry via a command-line flag (\\`node --import ${serverConfigRelativePath} [...]\\`) or via an environment variable (\\`NODE_OPTIONS='--import ${serverConfigRelativePath}' node [...]\\`).`,\n );\n }\n });\n }\n }\n\n if (moduleOptions.autoInjectServerSentry === 'top-level-import') {\n addSentryTopImport(moduleOptions, nitro);\n }\n\n if (moduleOptions.autoInjectServerSentry === 'experimental_dynamic-import') {\n addDynamicImportEntryFileWrapper(nitro, serverConfigFile, moduleOptions);\n\n if (moduleOptions.debug) {\n consoleSandbox(() => {\n // eslint-disable-next-line no-console\n console.log(\n '[Sentry] Wrapping the server entry file with a dynamic `import()`, so Sentry can be preloaded before the server initializes.',\n );\n });\n }\n }\n }\n });\n },\n});\n"],"names":[],"mappings":";;;;;;;;;;AAsBA,iBAAe,gBAAgB,CAAgB;AAC/C,EAAE,IAAI,EAAE;AACR,IAAI,IAAI,EAAE,qBAAqB;AAC/B,IAAI,SAAS,EAAE,QAAQ;AACvB,IAAI,aAAa,EAAE;AACnB,MAAM,IAAI,EAAE,SAAS;AACrB,KAAK;AACL,GAAG;AACH,EAAE,QAAQ,EAAE,EAAE;AACd,EAAE,MAAM,KAAK,CAAC,kBAAkB,EAAE,IAAI,EAAE;AACxC,IAAI,IAAI,kBAAkB,EAAE,OAAA,KAAY,KAAK,EAAE;AAC/C,MAAM;AACN,IAAI;;AAEJ,IAAI,MAAM,gBAAgB;AAC1B,MAAM,GAAG,kBAAkB;AAC3B,MAAM,sBAAsB,EAAE,kBAAkB,CAAC,sBAAsB;AACvE,MAAM,uCAAuC,EAAE,kBAAkB,CAAC,2CAA2C;AAC7G,QAAQ,SAAS;AACjB,QAAQ,SAAS;AACjB,QAAQ,QAAQ;AAChB,OAAO;AACP,KAAK;;AAEL,IAAI,MAAM,iBAAA,GAAoB,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;AAC7D,IAAI,MAAM,gBAAA,GAAmB,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ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+ {"type":"module","version":"10.48.0"}
@@ -88,9 +88,14 @@ function instrumentedEventHandler(handlerOrObject) {
88
88
  return eventHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));
89
89
  }
90
90
 
91
+ function defineInstrumentedHandler(handlerOrObject) {
92
+ return defineHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));
93
+ }
94
+
91
95
  ${originalCode
92
96
  .replace(/defineEventHandler\(/g, 'defineInstrumentedEventHandler(')
93
- .replace(/eventHandler\(/g, 'instrumentedEventHandler(')}
97
+ .replace(/eventHandler\(/g, 'instrumentedEventHandler(')
98
+ .replace(/defineHandler\(/g, 'defineInstrumentedHandler(')}
94
99
  `;
95
100
  }
96
101
 
@@ -1 +1 @@
1
- {"version":3,"file":"middlewareConfig.js","sources":["../../../src/vite/middlewareConfig.ts"],"sourcesContent":["import { addServerImports, createResolver } from '@nuxt/kit';\nimport type { Nitro } from 'nitropack/types';\nimport * as path from 'path';\nimport type { InputPluginOption } from 'rollup';\n\n/**\n * Adds a server import for the middleware instrumentation.\n */\nexport function addMiddlewareImports(): void {\n addServerImports([\n {\n name: 'wrapMiddlewareHandlerWithSentry',\n from: createResolver(import.meta.url).resolve('./runtime/hooks/wrapMiddlewareHandler'),\n },\n ]);\n}\n\n/**\n * Adds middleware instrumentation to the Nitro build.\n *\n * @param nitro Nitro instance\n */\nexport function addMiddlewareInstrumentation(nitro: Nitro): void {\n nitro.hooks.hook('rollup:before', (nitro, rollupConfig) => {\n if (!rollupConfig.plugins) {\n rollupConfig.plugins = [];\n }\n\n if (!Array.isArray(rollupConfig.plugins)) {\n rollupConfig.plugins = [rollupConfig.plugins];\n }\n\n rollupConfig.plugins.push(middlewareInstrumentationPlugin(nitro));\n });\n}\n\n/**\n * Creates a rollup plugin for the middleware instrumentation by transforming the middleware code.\n *\n * @param nitro Nitro instance\n * @returns The rollup plugin for the middleware instrumentation.\n */\nfunction middlewareInstrumentationPlugin(nitro: Nitro): InputPluginOption {\n const middlewareFiles = new Set<string>();\n\n return {\n name: 'sentry-nuxt-middleware-instrumentation',\n buildStart() {\n // Collect middleware files during build start\n nitro.scannedHandlers?.forEach(({ middleware, handler }) => {\n if (middleware && handler) {\n middlewareFiles.add(handler);\n }\n });\n },\n transform(code: string, id: string) {\n // Only transform files we've identified as middleware\n if (middlewareFiles.has(id)) {\n const fileName = path.basename(id);\n return {\n code: wrapMiddlewareCode(code, fileName),\n map: null,\n };\n }\n return null;\n },\n };\n}\n\n/**\n * Wraps the middleware user code to instrument it.\n *\n * @param originalCode The original user code of the middleware.\n * @param fileName The name of the middleware file, used for the span name and logging.\n *\n * @returns The wrapped user code of the middleware.\n */\nfunction wrapMiddlewareCode(originalCode: string, fileName: string): string {\n // Remove common file extensions\n const cleanFileName = fileName.replace(/\\.(ts|js|mjs|mts|cts)$/, '');\n\n return `\nimport { wrapMiddlewareHandlerWithSentry } from '#imports';\n\nfunction defineInstrumentedEventHandler(handlerOrObject) {\n return defineEventHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));\n}\n\nfunction instrumentedEventHandler(handlerOrObject) {\n return eventHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));\n}\n\n${originalCode\n .replace(/defineEventHandler\\(/g, 'defineInstrumentedEventHandler(')\n .replace(/eventHandler\\(/g, 'instrumentedEventHandler(')}\n`;\n}\n"],"names":[],"mappings":";;;AAKA;AACA;AACA;AACO,SAAS,oBAAoB,GAAS;AAC7C,EAAE,gBAAgB,CAAC;AACnB,IAAI;AACJ,MAAM,IAAI,EAAE,iCAAiC;AAC7C,MAAM,IAAI,EAAE,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,uCAAuC,CAAC;AAC5F,KAAK;AACL,GAAG,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACO,SAAS,4BAA4B,CAAC,KAAK,EAAe;AACjE,EAAE,KAAK,CAAC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;AACL,GAAG;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,kBAAkB,CAAC,YAAY,EAAU,QAAQ,EAAkB;AAC5E;AACA,EAAE,MAAM,aAAA,GAAgB,QAAQ,CAAC,OAAO,CAAC,wBAAwB,EAAE,EAAE,CAAC;;AAEtE,EAAE,OAAO;AACT;;AAEA;AACA,8EAA8E,EAAE,aAAa,CAAC;AAC9F;;AAEA;AACA,wEAAwE,EAAE,aAAa,CAAC;AACxF;;AAEA,EAAE;AACF,GAAG,OAAO,CAAC,uBAAuB,EAAE,iCAAiC;AACrE,GAAG,OAAO,CAAC,iBAAiB,EAAE,2BAA2B,CAAC;AAC1D,CAAC;AACD;;;;"}
1
+ {"version":3,"file":"middlewareConfig.js","sources":["../../../src/vite/middlewareConfig.ts"],"sourcesContent":["import { addServerImports, createResolver } from '@nuxt/kit';\nimport type { Nitro } from 'nitropack/types';\nimport * as path from 'path';\nimport type { InputPluginOption } from 'rollup';\n\n/**\n * Adds a server import for the middleware instrumentation.\n */\nexport function addMiddlewareImports(): void {\n addServerImports([\n {\n name: 'wrapMiddlewareHandlerWithSentry',\n from: createResolver(import.meta.url).resolve('./runtime/hooks/wrapMiddlewareHandler'),\n },\n ]);\n}\n\n/**\n * Adds middleware instrumentation to the Nitro build.\n *\n * @param nitro Nitro instance\n */\nexport function addMiddlewareInstrumentation(nitro: Nitro): void {\n nitro.hooks.hook('rollup:before', (nitro, rollupConfig) => {\n if (!rollupConfig.plugins) {\n rollupConfig.plugins = [];\n }\n\n if (!Array.isArray(rollupConfig.plugins)) {\n rollupConfig.plugins = [rollupConfig.plugins];\n }\n\n rollupConfig.plugins.push(middlewareInstrumentationPlugin(nitro));\n });\n}\n\n/**\n * Creates a rollup plugin for the middleware instrumentation by transforming the middleware code.\n *\n * @param nitro Nitro instance\n * @returns The rollup plugin for the middleware instrumentation.\n */\nfunction middlewareInstrumentationPlugin(nitro: Nitro): InputPluginOption {\n const middlewareFiles = new Set<string>();\n\n return {\n name: 'sentry-nuxt-middleware-instrumentation',\n buildStart() {\n // Collect middleware files during build start\n nitro.scannedHandlers?.forEach(({ middleware, handler }) => {\n if (middleware && handler) {\n middlewareFiles.add(handler);\n }\n });\n },\n transform(code: string, id: string) {\n // Only transform files we've identified as middleware\n if (middlewareFiles.has(id)) {\n const fileName = path.basename(id);\n return {\n code: wrapMiddlewareCode(code, fileName),\n map: null,\n };\n }\n return null;\n },\n };\n}\n\n/**\n * Wraps the middleware user code to instrument it.\n *\n * @param originalCode The original user code of the middleware.\n * @param fileName The name of the middleware file, used for the span name and logging.\n *\n * @returns The wrapped user code of the middleware.\n */\nfunction wrapMiddlewareCode(originalCode: string, fileName: string): string {\n // Remove common file extensions\n const cleanFileName = fileName.replace(/\\.(ts|js|mjs|mts|cts)$/, '');\n\n return `\nimport { wrapMiddlewareHandlerWithSentry } from '#imports';\n\nfunction defineInstrumentedEventHandler(handlerOrObject) {\n return defineEventHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));\n}\n\nfunction instrumentedEventHandler(handlerOrObject) {\n return eventHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));\n}\n\nfunction defineInstrumentedHandler(handlerOrObject) {\n return defineHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));\n}\n\n${originalCode\n .replace(/defineEventHandler\\(/g, 'defineInstrumentedEventHandler(')\n .replace(/eventHandler\\(/g, 'instrumentedEventHandler(')\n .replace(/defineHandler\\(/g, 'defineInstrumentedHandler(')}\n`;\n}\n"],"names":[],"mappings":";;;AAKA;AACA;AACA;AACO,SAAS,oBAAoB,GAAS;AAC7C,EAAE,gBAAgB,CAAC;AACnB,IAAI;AACJ,MAAM,IAAI,EAAE,iCAAiC;AAC7C,MAAM,IAAI,EAAE,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,uCAAuC,CAAC;AAC5F,KAAK;AAC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,QAAQ,CAAC;AAClD,UAAU,GAAG,EAAE,IAAI;AACnB,SAAS;AACT,MAAM;AACN,MAAM,OAAO,IAAI;AACjB,IAAI,CAAC;AACL,GAAG;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,kBAAkB,CAAC,YAAY,EAAU,QAAQ,EAAkB;AAC5E;AACA,EAAE,MAAM,aAAA,GAAgB,QAAQ,CAAC,OAAO,CAAC,wBAAwB,EAAE,EAAE,CAAC;;AAEtE,EAAE,OAAO;AACT;;AAEA;AACA,8EAA8E,EAAE,aAAa,CAAC;AAC9F;;AAEA;AACA,wEAAwE,EAAE,aAAa,CAAC;AACxF;;AAEA;AACA,yEAAyE,EAAE,aAAa,CAAC;AACzF;;AAEA,EAAE;AACF,GAAG,OAAO,CAAC,uBAAuB,EAAE,iCAAiC;AACrE,GAAG,OAAO,CAAC,iBAAiB,EAAE,2BAA2B;AACzD,GAAG,OAAO,CAAC,kBAAkB,EAAE,4BAA4B,CAAC;AAC5D,CAAC;AACD;;;;"}
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.7.0"
6
6
  },
7
- "version": "10.46.0",
7
+ "version": "10.48.0",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "0.8.4",
10
10
  "unbuild": "2.0.0"
@@ -1,4 +1,4 @@
1
- import { createResolver, useNuxt, addServerPlugin, addServerImports, defineNuxtModule, addPluginTemplate, addPlugin, addTemplate, addVitePlugin } from '@nuxt/kit';
1
+ import { createResolver, useNuxt, addServerPlugin, addServerImports, defineNuxtModule, addPluginTemplate, addPlugin, addVitePlugin, addTemplate } from '@nuxt/kit';
2
2
  import { consoleSandbox, debug } from '@sentry/core';
3
3
  import * as path from 'path';
4
4
  import { existsSync } from 'node:fs';
@@ -352,7 +352,11 @@ function instrumentedEventHandler(handlerOrObject) {
352
352
  return eventHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));
353
353
  }
354
354
 
355
- ${originalCode.replace(/defineEventHandler\(/g, "defineInstrumentedEventHandler(").replace(/eventHandler\(/g, "instrumentedEventHandler(")}
355
+ function defineInstrumentedHandler(handlerOrObject) {
356
+ return defineHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));
357
+ }
358
+
359
+ ${originalCode.replace(/defineEventHandler\(/g, "defineInstrumentedEventHandler(").replace(/eventHandler\(/g, "instrumentedEventHandler(").replace(/defineHandler\(/g, "defineInstrumentedHandler(")}
356
360
  `;
357
361
  }
358
362
 
@@ -692,17 +696,22 @@ const module = defineNuxtModule({
692
696
  }
693
697
  const serverConfigFile = findDefaultSdkInitFile("server", nuxt);
694
698
  const isNitroV3 = await getNitroMajorVersion() >= 3;
699
+ const nuxtMajor = parseInt(nuxt._version?.split(".")[0] ?? "3", 10);
700
+ const isMinNuxtV4 = nuxtMajor >= 4;
695
701
  if (serverConfigFile) {
696
702
  if (isNitroV3) {
697
703
  addServerPlugin(moduleDirResolver.resolve("./runtime/plugins/handler.server"));
704
+ addServerPlugin(moduleDirResolver.resolve("./runtime/plugins/update-route-name.server"));
698
705
  } else {
699
706
  addServerPlugin(moduleDirResolver.resolve("./runtime/plugins/handler-legacy.server"));
707
+ addServerPlugin(moduleDirResolver.resolve("./runtime/plugins/update-route-name-legacy.server"));
700
708
  }
701
709
  addServerPlugin(moduleDirResolver.resolve("./runtime/plugins/sentry.server"));
702
- addPlugin({
703
- src: moduleDirResolver.resolve("./runtime/plugins/route-detector.server"),
704
- mode: "server"
705
- });
710
+ if (isMinNuxtV4) {
711
+ addPlugin({ src: moduleDirResolver.resolve("./runtime/plugins/route-detector.server"), mode: "server" });
712
+ } else {
713
+ addPlugin({ src: moduleDirResolver.resolve("./runtime/plugins/route-detector-legacy.server"), mode: "server" });
714
+ }
706
715
  addMiddlewareImports();
707
716
  addStorageInstrumentation(nuxt, !isNitroV3);
708
717
  addDatabaseInstrumentation(nuxt.options.nitro, !isNitroV3, moduleOptions);
@@ -711,20 +720,25 @@ const module = defineNuxtModule({
711
720
  setupSourceMaps(moduleOptions, nuxt, addVitePlugin);
712
721
  }
713
722
  addOTelCommonJSImportAlias(nuxt, isNitroV3);
714
- const pagesDataTemplate = addTemplate({
715
- filename: "sentry--nuxt-pages-data.mjs",
716
- // Initial empty array (later filled in pages:extend hook)
717
- // Template needs to be created in the root-level of the module to work
718
- getContents: () => "export default [];"
719
- });
723
+ let pagesData = [];
720
724
  nuxt.hooks.hook("pages:extend", (pages) => {
721
- pagesDataTemplate.getContents = () => {
722
- const pagesSubset = pages.map((page) => ({ file: page.file, path: page.path })).filter((page) => {
723
- return page.path.includes(":") || page?.file?.includes("[");
724
- });
725
- return `export default ${JSON.stringify(pagesSubset, null, 2)};`;
726
- };
725
+ pagesData = pages.map((page) => ({ file: page.file, path: page.path })).filter((page) => {
726
+ return page.path.includes(":") || page?.file?.includes("[");
727
+ });
727
728
  });
729
+ if (isMinNuxtV4) {
730
+ const pagesDataVirtualModuleId = "#sentry/nuxt-pages-data.mjs";
731
+ addVitePlugin({
732
+ name: "sentry-nuxt-pages-data-virtual",
733
+ resolveId: (id) => id === pagesDataVirtualModuleId ? `\0${pagesDataVirtualModuleId}` : null,
734
+ load: (id) => id === `\0${pagesDataVirtualModuleId}` ? `export default ${JSON.stringify(pagesData, null, 2)};` : void 0
735
+ });
736
+ } else {
737
+ addTemplate({
738
+ filename: "sentry--nuxt-pages-data.mjs",
739
+ getContents: () => `export default ${JSON.stringify(pagesData, null, 2)};`
740
+ });
741
+ }
728
742
  nuxt.hook("prepare:types", (options) => {
729
743
  const tsConfig = options.tsConfig;
730
744
  if (!tsConfig.include) {
@@ -743,7 +757,7 @@ const module = defineNuxtModule({
743
757
  if (nuxt.options?._prepare) {
744
758
  return;
745
759
  }
746
- if (serverConfigFile && !isNitroV3) {
760
+ if (serverConfigFile) {
747
761
  addMiddlewareInstrumentation(nitro);
748
762
  }
749
763
  if (serverConfigFile?.includes(".server.config")) {
@@ -1,5 +1,7 @@
1
1
  import type { H3Event } from 'h3';
2
+ type EventWithMatchedRoute = Pick<H3Event, 'context'> & Partial<Pick<H3Event, 'path' | '_path'>>;
2
3
  /**
3
4
  * Update the root span (transaction) name for routes with parameters based on the matched route.
4
5
  */
5
- export declare function updateRouteBeforeResponse(event: H3Event): void;
6
+ export declare function updateRouteBeforeResponse(event: EventWithMatchedRoute): void;
7
+ export {};
@@ -1,10 +1,15 @@
1
1
  import { debug, getActiveSpan, getRootSpan, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from "@sentry/core";
2
+ function getMatchedRoutePath(event) {
3
+ const matchedRoute = event.context.matchedRoute;
4
+ return matchedRoute?.path ?? matchedRoute?.route;
5
+ }
2
6
  export function updateRouteBeforeResponse(event) {
3
7
  if (!event.context.matchedRoute) {
4
8
  return;
5
9
  }
6
- const matchedRoutePath = event.context.matchedRoute.path;
7
- if (matchedRoutePath && matchedRoutePath !== event._path) {
10
+ const matchedRoutePath = getMatchedRoutePath(event);
11
+ const requestPath = event.path ?? event._path;
12
+ if (matchedRoutePath && matchedRoutePath !== requestPath) {
8
13
  if (matchedRoutePath === "/**") {
9
14
  return;
10
15
  }
@@ -15,23 +15,27 @@ export function wrapMiddlewareHandlerWithSentry(handler, fileName) {
15
15
  if (!isEventHandlerObject(handler)) {
16
16
  return wrapEventHandler(handler, fileName);
17
17
  }
18
- const handlerObj = {
19
- ...handler,
20
- handler: wrapEventHandler(handler.handler, fileName)
18
+ const handlerObj = handler;
19
+ const result = {
20
+ ...handlerObj,
21
+ ...handlerObj.handler && { handler: wrapEventHandler(handlerObj.handler, fileName) }
21
22
  };
22
- if (handlerObj.onRequest) {
23
- handlerObj.onRequest = normalizeHandlers(
24
- handlerObj.onRequest,
23
+ if (result.onRequest) {
24
+ result.onRequest = normalizeHandlers(
25
+ result.onRequest,
25
26
  (h, index) => wrapEventHandler(h, fileName, "onRequest", index)
26
27
  );
27
28
  }
28
- if (handlerObj.onBeforeResponse) {
29
- handlerObj.onBeforeResponse = normalizeHandlers(
30
- handlerObj.onBeforeResponse,
29
+ if (result.onBeforeResponse) {
30
+ result.onBeforeResponse = normalizeHandlers(
31
+ result.onBeforeResponse,
31
32
  (h, index) => wrapResponseHandler(h, fileName, index)
32
33
  );
33
34
  }
34
- return handlerObj;
35
+ if (result.middleware?.length) {
36
+ result.middleware = result.middleware.map((h, index) => wrapEventHandler(h, fileName, "middleware", index));
37
+ }
38
+ return result;
35
39
  }
36
40
  function wrapEventHandler(handler, middlewareName, hookName, index) {
37
41
  return async (event) => {
@@ -88,13 +92,19 @@ function getSpanAttributes(event, middlewareName, hookName, index) {
88
92
  if (typeof index === "number") {
89
93
  attributes["nuxt.middleware.hook.index"] = index;
90
94
  }
91
- if (event.method) {
92
- attributes["http.request.method"] = event.method;
95
+ const eventH3v2 = event;
96
+ const method = event.method ?? eventH3v2?.req?.method;
97
+ const path = event.path ?? eventH3v2?.url?.pathname;
98
+ if (method) {
99
+ attributes["http.request.method"] = method;
100
+ }
101
+ if (path) {
102
+ attributes["http.route"] = path;
93
103
  }
94
- if (event.path) {
95
- attributes["http.route"] = event.path;
104
+ let headers = event.node?.req?.headers || {};
105
+ if (!Object.keys(headers).length && eventH3v2?.req?.headers instanceof Headers) {
106
+ headers = Object.fromEntries(eventH3v2?.req.headers.entries());
96
107
  }
97
- const headers = event.node?.req?.headers || {};
98
108
  const headerAttributes = httpHeadersToSpanAttributes(headers, getClient()?.getOptions().sendDefaultPii ?? false);
99
109
  Object.assign(attributes, headerAttributes);
100
110
  return attributes;
@@ -0,0 +1,2 @@
1
+ declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
2
+ export default _default;
@@ -0,0 +1,37 @@
1
+ import { debug, getActiveSpan, getRootSpan, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from "@sentry/core";
2
+ import { defineNuxtPlugin } from "nuxt/app";
3
+ import { extractParametrizedRouteFromContext } from "../utils/route-extraction.js";
4
+ export default defineNuxtPlugin((nuxtApp) => {
5
+ nuxtApp.hooks.hook("app:rendered", async (renderContext) => {
6
+ let buildTimePagesData;
7
+ try {
8
+ const { default: importedPagesData } = await import("#build/sentry--nuxt-pages-data.mjs");
9
+ buildTimePagesData = importedPagesData || [];
10
+ debug.log("Imported build-time pages data:", buildTimePagesData);
11
+ } catch (error) {
12
+ buildTimePagesData = [];
13
+ debug.warn("Failed to import build-time pages data:", error);
14
+ }
15
+ const ssrContext = renderContext.ssrContext;
16
+ const routeInfo = extractParametrizedRouteFromContext(
17
+ ssrContext?.modules,
18
+ ssrContext?.url || ssrContext?.event._path,
19
+ buildTimePagesData
20
+ );
21
+ if (routeInfo === null) {
22
+ return;
23
+ }
24
+ const activeSpan = getActiveSpan();
25
+ if (activeSpan && routeInfo.parametrizedRoute) {
26
+ const rootSpan = getRootSpan(activeSpan);
27
+ if (!rootSpan) {
28
+ return;
29
+ }
30
+ debug.log("Matched parametrized server route:", routeInfo.parametrizedRoute);
31
+ rootSpan.setAttributes({
32
+ [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "route",
33
+ "http.route": routeInfo.parametrizedRoute
34
+ });
35
+ }
36
+ });
37
+ });
@@ -5,7 +5,7 @@ export default defineNuxtPlugin((nuxtApp) => {
5
5
  nuxtApp.hooks.hook("app:rendered", async (renderContext) => {
6
6
  let buildTimePagesData;
7
7
  try {
8
- const { default: importedPagesData } = await import("#build/sentry--nuxt-pages-data.mjs");
8
+ const { default: importedPagesData } = await import("#sentry/nuxt-pages-data.mjs");
9
9
  buildTimePagesData = importedPagesData || [];
10
10
  debug.log("Imported build-time pages data:", buildTimePagesData);
11
11
  } catch (error) {
@@ -1,16 +1,19 @@
1
1
  import { debug } from "@sentry/core";
2
2
  import { sentryCaptureErrorHook } from "../hooks/captureErrorHook.js";
3
- import { updateRouteBeforeResponse } from "../hooks/updateRouteBeforeResponse.js";
4
3
  import { addSentryTracingMetaTags } from "../utils.js";
5
4
  export default (nitroApp) => {
6
- nitroApp.hooks.hook("beforeResponse", updateRouteBeforeResponse);
7
5
  nitroApp.hooks.hook("error", sentryCaptureErrorHook);
8
6
  nitroApp.hooks.hook("render:html", (html, { event }) => {
9
7
  const nodeResHeadersH3v1 = event.node?.res?.getHeaders() || {};
10
8
  const isPreRenderedPage = Object.keys(nodeResHeadersH3v1).includes("x-nitro-prerender") || // fix × typescript-eslint(no-unsafe-member-access): Unsafe member access .res on an `any` value.
11
9
  // oxlint-disable-next-line typescript/no-explicit-any,typescript-oxlint/no-unsafe-member-access
12
10
  !!event.res?.headers?.has?.("x-nitro-prerender");
13
- const isSWRCachedPage = event?.context?.cache?.options?.swr;
11
+ const isSWRCachedPage = (
12
+ /* Nitro v2 */
13
+ event?.context?.cache?.options?.swr || // oxlint-disable-next-line typescript-oxlint/no-unsafe-member-access
14
+ /* Nitro v3 */
15
+ event?.context?.routeRules?.swr
16
+ );
14
17
  if (!isPreRenderedPage && !isSWRCachedPage) {
15
18
  addSentryTracingMetaTags(html.head);
16
19
  } else {
@@ -0,0 +1,2 @@
1
+ declare const _default: (nitroApp: import("nitropack").NitroApp) => void;
2
+ export default _default;
@@ -0,0 +1,4 @@
1
+ import { updateRouteBeforeResponse } from "../hooks/updateRouteBeforeResponse.js";
2
+ export default (nitroApp) => {
3
+ nitroApp.hooks.hook("beforeResponse", updateRouteBeforeResponse);
4
+ };
@@ -0,0 +1,4 @@
1
+ declare const _default: (nitroApp: import("nitro/types").NitroApp & {
2
+ hooks: NonNullable<import("nitro/types").NitroApp["hooks"]>;
3
+ }) => void;
4
+ export default _default;
@@ -0,0 +1,4 @@
1
+ import { updateRouteBeforeResponse } from "../hooks/updateRouteBeforeResponse.js";
2
+ export default (nitroApp) => {
3
+ nitroApp.hooks.hook("response", (_response, event) => updateRouteBeforeResponse(event));
4
+ };
@@ -7,6 +7,8 @@ export * from './index.server';
7
7
  export declare function init(options: Options | SentryNuxtClientOptions | SentryNuxtServerOptions): Client | undefined;
8
8
  export declare const linkedErrorsIntegration: typeof clientSdk.linkedErrorsIntegration;
9
9
  export declare const contextLinesIntegration: typeof clientSdk.contextLinesIntegration;
10
+ export declare const spanStreamingIntegration: typeof clientSdk.spanStreamingIntegration;
11
+ export declare const withStreamedSpan: typeof clientSdk.withStreamedSpan;
10
12
  export declare const getDefaultIntegrations: (options: Options) => Integration[];
11
13
  export declare const defaultStackParser: StackParser;
12
14
  export declare const logger: typeof clientSdk.logger | typeof serverSdk.logger;
@@ -1 +1 @@
1
- {"version":3,"file":"index.types.d.ts","sourceRoot":"","sources":["../../src/index.types.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,KAAK,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACvF,OAAO,KAAK,KAAK,SAAS,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAIjD,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAG/B,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,uBAAuB,GAAG,uBAAuB,GAAG,MAAM,GAAG,SAAS,CAAC;AACvH,MAAM,CAAC,OAAO,CAAC,MAAM,uBAAuB,EAAE,OAAO,SAAS,CAAC,uBAAuB,CAAC;AACvF,MAAM,CAAC,OAAO,CAAC,MAAM,uBAAuB,EAAE,OAAO,SAAS,CAAC,uBAAuB,CAAC;AACvF,MAAM,CAAC,OAAO,CAAC,MAAM,sBAAsB,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,WAAW,EAAE,CAAC;AACjF,MAAM,CAAC,OAAO,CAAC,MAAM,kBAAkB,EAAE,WAAW,CAAC;AAErD,MAAM,CAAC,OAAO,CAAC,MAAM,MAAM,EAAE,OAAO,SAAS,CAAC,MAAM,GAAG,OAAO,SAAS,CAAC,MAAM,CAAC;A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B,CAAC;;AAEpD,wBA+MG"}
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/module.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAQ9D,MAAM,MAAM,aAAa,GAAG,uBAAuB,CAAC;;AAGpD,wBA6NG"}
@@ -1,6 +1,8 @@
1
1
  import type { H3Event } from 'h3';
2
+ type EventWithMatchedRoute = Pick<H3Event, 'context'> & Partial<Pick<H3Event, 'path' | '_path'>>;
2
3
  /**
3
4
  * Update the root span (transaction) name for routes with parameters based on the matched route.
4
5
  */
5
- export declare function updateRouteBeforeResponse(event: H3Event): void;
6
+ export declare function updateRouteBeforeResponse(event: EventWithMatchedRoute): void;
7
+ export {};
6
8
  //# sourceMappingURL=updateRouteBeforeResponse.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"updateRouteBeforeResponse.d.ts","sourceRoot":"","sources":["../../../../src/runtime/hooks/updateRouteBeforeResponse.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAElC;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CA4C9D"}
1
+ {"version":3,"file":"updateRouteBeforeResponse.d.ts","sourceRoot":"","sources":["../../../../src/runtime/hooks/updateRouteBeforeResponse.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAGlC,KAAK,qBAAqB,GAAG,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;AAQjG;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,qBAAqB,GAAG,IAAI,CA6C5E"}
@@ -1 +1 @@
1
- {"version":3,"file":"wrapMiddlewareHandler.d.ts","sourceRoot":"","sources":["../../../../src/runtime/hooks/wrapMiddlewareHandler.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAEV,YAAY,EACZ,kBAAkB,EAInB,MAAM,IAAI,CAAC;AAEZ;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAAC,QAAQ,SAAS,YAAY,GAAG,kBAAkB,EAChG,OAAO,EAAE,QAAQ,EACjB,QAAQ,EAAE,MAAM,GACf,QAAQ,CAuBV"}
1
+ {"version":3,"file":"wrapMiddlewareHandler.d.ts","sourceRoot":"","sources":["../../../../src/runtime/hooks/wrapMiddlewareHandler.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAEV,YAAY,EACZ,kBAAkB,EAInB,MAAM,IAAI,CAAC;AAeZ;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAAC,QAAQ,SAAS,YAAY,GAAG,kBAAkB,EAChG,OAAO,EAAE,QAAQ,EACjB,QAAQ,EAAE,MAAM,GACf,QAAQ,CA+BV"}
@@ -0,0 +1,3 @@
1
+ declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
2
+ export default _default;
3
+ //# sourceMappingURL=route-detector-legacy.server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route-detector-legacy.server.d.ts","sourceRoot":"","sources":["../../../../src/runtime/plugins/route-detector-legacy.server.ts"],"names":[],"mappings":";AAKA,wBA2CG"}
@@ -1 +1 @@
1
- {"version":3,"file":"sentry.server.d.ts","sourceRoot":"","sources":["../../../../src/runtime/plugins/sentry.server.ts"],"names":[],"mappings":";AAQA,wBA6B4B"}
1
+ {"version":3,"file":"sentry.server.d.ts","sourceRoot":"","sources":["../../../../src/runtime/plugins/sentry.server.ts"],"names":[],"mappings":";AAOA,wBA6B4B"}
@@ -0,0 +1,3 @@
1
+ declare const _default: (nitroApp: import("nitropack").NitroApp) => void;
2
+ export default _default;
3
+ //# sourceMappingURL=update-route-name-legacy.server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-route-name-legacy.server.d.ts","sourceRoot":"","sources":["../../../../src/runtime/plugins/update-route-name-legacy.server.ts"],"names":[],"mappings":";AAGA,wBAE4B"}
@@ -0,0 +1,5 @@
1
+ declare const _default: (nitroApp: import("nitro/types").NitroApp & {
2
+ hooks: NonNullable<import("nitro/types").NitroApp["hooks"]>;
3
+ }) => void;
4
+ export default _default;
5
+ //# sourceMappingURL=update-route-name.server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-route-name.server.d.ts","sourceRoot":"","sources":["../../../../src/runtime/plugins/update-route-name.server.ts"],"names":[],"mappings":";;;AAIA,wBAG4B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/nuxt",
3
- "version": "10.46.0",
3
+ "version": "10.48.0",
4
4
  "description": "Official Sentry SDK for Nuxt",
5
5
  "repository": "git://github.com/getsentry/sentry-javascript.git",
6
6
  "homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/nuxt",
@@ -55,14 +55,14 @@
55
55
  },
56
56
  "dependencies": {
57
57
  "@nuxt/kit": "^3.13.2",
58
- "@sentry/browser": "10.46.0",
59
- "@sentry/cloudflare": "10.46.0",
60
- "@sentry/core": "10.46.0",
61
- "@sentry/node": "10.46.0",
62
- "@sentry/node-core": "10.46.0",
63
- "@sentry/rollup-plugin": "^5.1.1",
64
- "@sentry/vite-plugin": "^5.1.0",
65
- "@sentry/vue": "10.46.0",
58
+ "@sentry/browser": "10.48.0",
59
+ "@sentry/cloudflare": "10.48.0",
60
+ "@sentry/core": "10.48.0",
61
+ "@sentry/node": "10.48.0",
62
+ "@sentry/node-core": "10.48.0",
63
+ "@sentry/rollup-plugin": "^5.2.0",
64
+ "@sentry/vite-plugin": "^5.2.0",
65
+ "@sentry/vue": "10.48.0",
66
66
  "local-pkg": "^1.1.2"
67
67
  },
68
68
  "devDependencies": {