@sentry/nuxt 10.16.0 → 10.18.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.
@@ -2,6 +2,7 @@ const kit = require('@nuxt/kit');
2
2
  const core = require('@sentry/core');
3
3
  const path = require('path');
4
4
  const addServerConfig = require('./vite/addServerConfig.js');
5
+ const middlewareConfig = require('./vite/middlewareConfig.js');
5
6
  const sourceMaps = require('./vite/sourceMaps.js');
6
7
  const utils = require('./vite/utils.js');
7
8
 
@@ -62,6 +63,18 @@ const module$1 = kit.defineNuxtModule({
62
63
  mode: 'client',
63
64
  order: 1,
64
65
  });
66
+
67
+ // Add the sentry config file to the include array
68
+ nuxt.hook('prepare:types', options => {
69
+ if (!options.tsConfig.include) {
70
+ options.tsConfig.include = [];
71
+ }
72
+
73
+ // Add type references for useRuntimeConfig in root files for nuxt v4
74
+ // Should be relative to `root/.nuxt`
75
+ const relativePath = path.relative(nuxt.options.buildDir, clientConfigFile);
76
+ options.tsConfig.include.push(relativePath);
77
+ });
65
78
  }
66
79
 
67
80
  const serverConfigFile = utils.findDefaultSdkInitFile('server', nuxt);
@@ -101,7 +114,16 @@ const module$1 = kit.defineNuxtModule({
101
114
  };
102
115
  });
103
116
 
117
+ // Preps the the middleware instrumentation module.
118
+ if (serverConfigFile) {
119
+ middlewareConfig.addMiddlewareImports();
120
+ }
121
+
104
122
  nuxt.hooks.hook('nitro:init', nitro => {
123
+ if (serverConfigFile) {
124
+ middlewareConfig.addMiddlewareInstrumentation(nitro);
125
+ }
126
+
105
127
  if (serverConfigFile?.includes('.server.config')) {
106
128
  core.consoleSandbox(() => {
107
129
  const serverDir = nitro.options.output.serverDir;
@@ -1 +1 @@
1
- {"version":3,"file":"module.js","sources":["../../src/module.ts"],"sourcesContent":["import {\n addPlugin,\n addPluginTemplate,\n addServerPlugin,\n addTemplate,\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 { setupSourceMaps } from './vite/sourceMaps';\nimport { addOTelCommonJSImportAlias, findDefaultSdkInitFile } 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 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\n if (serverConfigFile) {\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\n if (clientConfigFile || serverConfigFile) {\n setupSourceMaps(moduleOptions, nuxt);\n }\n\n addOTelCommonJSImportAlias(nuxt);\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 nuxt.hooks.hook('nitro:init', nitro => {\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","addServerPlugin","setupSourceMaps","addOTelCommonJSIm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gBAAA,CAAA,CAAA,CAAA;;AAEA,YAAAQ,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,eAAA,MAAA;AACA;AACA,gBAAA,OAAA,CAAA,GAAA;AACA,kBAAA,CAAA,sGAAA,EAAA,wBAAA,CAAA,mEAAA,EAAA,wBAAA,CAAA,gBAAA,CAAA;AACA,iBAAA;AACA;AACA,aAAA,CAAA;AACA;AACA;;AAEA,QAAA,IAAA,aAAA,CAAA,sBAAA,KAAA,kBAAA,EAAA;AACA,UAAAE,kCAAA,CAAA,aAAA,EAAA,KAAA,CAAA;AACA;;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,aAAA,CAAA;AACA;AACA;AACA;AACA,KAAA,CAAA;AACA,GAAA;AACA,CAAA,CAAA;;;;"}
1
+ {"version":3,"file":"module.js","sources":["../../src/module.ts"],"sourcesContent":["import {\n addPlugin,\n addPluginTemplate,\n addServerPlugin,\n addTemplate,\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 { addMiddlewareImports, addMiddlewareInstrumentation } from './vite/middlewareConfig';\nimport { setupSourceMaps } from './vite/sourceMaps';\nimport { addOTelCommonJSImportAlias, findDefaultSdkInitFile } 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 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 // Add the sentry config file to the include array\n nuxt.hook('prepare:types', options => {\n if (!options.tsConfig.include) {\n options.tsConfig.include = [];\n }\n\n // Add type references for useRuntimeConfig in root files for nuxt v4\n // Should be relative to `root/.nuxt`\n const relativePath = path.relative(nuxt.options.buildDir, clientConfigFile);\n options.tsConfig.include.push(relativePath);\n });\n }\n\n const serverConfigFile = findDefaultSdkInitFile('server', nuxt);\n\n if (serverConfigFile) {\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\n if (clientConfigFile || serverConfigFile) {\n setupSourceMaps(moduleOptions, nuxt);\n }\n\n addOTelCommonJSImportAlias(nuxt);\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 // Preps the the middleware instrumentation module.\n if (serverConfigFile) {\n addMiddlewareImports();\n }\n\n nuxt.hooks.hook('nitro:init', nitro => {\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","addServerPlugin","setupSourceMaps","addOTelCommonJSImportAlias","addTemplate","addMiddlewareImports","addMiddlewareInstrumentation","consoleSandbox","addServerConfigToBuild","addSentryTopImport","addDynamicImportEntryFileWrapper"],"mappings":";;;;;;;;;AAkBA,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,KAAK,CAAC,kBAAkB,EAAE,IAAI,EAAE;AAClC,IAAI,IAAI,kBAAkB,EAAE,OAAA,KAAY,KAAK,EAAE;AAC/C,MAAM;AACN;;AAEA,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,CAAC;;AAEnE,IAAI,IAAI,gBAAgB,EAAE;AAC1B;AACA,MAAMC,qBAAiB,C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AAA,wBAAA,CAAA,gBAAA,CAAA;AACA,iBAAA;AACA;AACA,aAAA,CAAA;AACA;AACA;;AAEA,QAAA,IAAA,aAAA,CAAA,sBAAA,KAAA,kBAAA,EAAA;AACA,UAAAE,kCAAA,CAAA,aAAA,EAAA,KAAA,CAAA;AACA;;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,aAAA,CAAA;AACA;AACA;AACA;AACA,KAAA,CAAA;AACA,GAAA;AACA,CAAA,CAAA;;;;"}
@@ -0,0 +1,102 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const kit = require('@nuxt/kit');
4
+ const path = require('path');
5
+
6
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
7
+ /**
8
+ * Adds a server import for the middleware instrumentation.
9
+ */
10
+ function addMiddlewareImports() {
11
+ kit.addServerImports([
12
+ {
13
+ name: 'wrapMiddlewareHandlerWithSentry',
14
+ from: kit.createResolver((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite/middlewareConfig.js', document.baseURI).href))).resolve('./runtime/hooks/wrapMiddlewareHandler'),
15
+ },
16
+ ]);
17
+ }
18
+
19
+ /**
20
+ * Adds middleware instrumentation to the Nitro build.
21
+ *
22
+ * @param nitro Nitro instance
23
+ */
24
+ function addMiddlewareInstrumentation(nitro) {
25
+ nitro.hooks.hook('rollup:before', (nitro, rollupConfig) => {
26
+ if (!rollupConfig.plugins) {
27
+ rollupConfig.plugins = [];
28
+ }
29
+
30
+ if (!Array.isArray(rollupConfig.plugins)) {
31
+ rollupConfig.plugins = [rollupConfig.plugins];
32
+ }
33
+
34
+ rollupConfig.plugins.push(middlewareInstrumentationPlugin(nitro));
35
+ });
36
+ }
37
+
38
+ /**
39
+ * Creates a rollup plugin for the middleware instrumentation by transforming the middleware code.
40
+ *
41
+ * @param nitro Nitro instance
42
+ * @returns The rollup plugin for the middleware instrumentation.
43
+ */
44
+ function middlewareInstrumentationPlugin(nitro) {
45
+ const middlewareFiles = new Set();
46
+
47
+ return {
48
+ name: 'sentry-nuxt-middleware-instrumentation',
49
+ buildStart() {
50
+ // Collect middleware files during build start
51
+ nitro.scannedHandlers?.forEach(({ middleware, handler }) => {
52
+ if (middleware && handler) {
53
+ middlewareFiles.add(handler);
54
+ }
55
+ });
56
+ },
57
+ transform(code, id) {
58
+ // Only transform files we've identified as middleware
59
+ if (middlewareFiles.has(id)) {
60
+ const fileName = path.basename(id);
61
+ return {
62
+ code: wrapMiddlewareCode(code, fileName),
63
+ map: null,
64
+ };
65
+ }
66
+ return null;
67
+ },
68
+ };
69
+ }
70
+
71
+ /**
72
+ * Wraps the middleware user code to instrument it.
73
+ *
74
+ * @param originalCode The original user code of the middleware.
75
+ * @param fileName The name of the middleware file, used for the span name and logging.
76
+ *
77
+ * @returns The wrapped user code of the middleware.
78
+ */
79
+ function wrapMiddlewareCode(originalCode, fileName) {
80
+ // Remove common file extensions
81
+ const cleanFileName = fileName.replace(/\.(ts|js|mjs|mts|cts)$/, '');
82
+
83
+ return `
84
+ import { wrapMiddlewareHandlerWithSentry } from '#imports';
85
+
86
+ function defineInstrumentedEventHandler(handlerOrObject) {
87
+ return defineEventHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));
88
+ }
89
+
90
+ function instrumentedEventHandler(handlerOrObject) {
91
+ return eventHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));
92
+ }
93
+
94
+ ${originalCode
95
+ .replace(/defineEventHandler\(/g, 'defineInstrumentedEventHandler(')
96
+ .replace(/eventHandler\(/g, 'instrumentedEventHandler(')}
97
+ `;
98
+ }
99
+
100
+ exports.addMiddlewareImports = addMiddlewareImports;
101
+ exports.addMiddlewareInstrumentation = addMiddlewareInstrumentation;
102
+ //# sourceMappingURL=middlewareConfig.js.map
@@ -0,0 +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,CAAC,YAAY,CAAC,OAAO,EAAE;AAC/B,MAAM,YAAY,CAAC,OAAA,GAAU,EAAE;AAC/B;;AAEA,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE;AAC9C,MAAM,Y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;;AAEA,EAAE;AACF,GAAG,OAAO,CAAC,uBAAuB,EAAE,iCAAiC;AACrE,GAAG,OAAO,CAAC,iBAAiB,EAAE,2BAA2B,CAAC;AAC1D,CAAC;AACD;;;;;"}
@@ -2,6 +2,7 @@ import { defineNuxtModule, createResolver, addPluginTemplate, addPlugin, addServ
2
2
  import { consoleSandbox } from '@sentry/core';
3
3
  import * as path from 'path';
4
4
  import { addServerConfigToBuild, addSentryTopImport, addDynamicImportEntryFileWrapper } from './vite/addServerConfig.js';
5
+ import { addMiddlewareImports, addMiddlewareInstrumentation } from './vite/middlewareConfig.js';
5
6
  import { setupSourceMaps } from './vite/sourceMaps.js';
6
7
  import { findDefaultSdkInitFile, addOTelCommonJSImportAlias } from './vite/utils.js';
7
8
 
@@ -61,6 +62,18 @@ const module = defineNuxtModule({
61
62
  mode: 'client',
62
63
  order: 1,
63
64
  });
65
+
66
+ // Add the sentry config file to the include array
67
+ nuxt.hook('prepare:types', options => {
68
+ if (!options.tsConfig.include) {
69
+ options.tsConfig.include = [];
70
+ }
71
+
72
+ // Add type references for useRuntimeConfig in root files for nuxt v4
73
+ // Should be relative to `root/.nuxt`
74
+ const relativePath = path.relative(nuxt.options.buildDir, clientConfigFile);
75
+ options.tsConfig.include.push(relativePath);
76
+ });
64
77
  }
65
78
 
66
79
  const serverConfigFile = findDefaultSdkInitFile('server', nuxt);
@@ -100,7 +113,16 @@ const module = defineNuxtModule({
100
113
  };
101
114
  });
102
115
 
116
+ // Preps the the middleware instrumentation module.
117
+ if (serverConfigFile) {
118
+ addMiddlewareImports();
119
+ }
120
+
103
121
  nuxt.hooks.hook('nitro:init', nitro => {
122
+ if (serverConfigFile) {
123
+ addMiddlewareInstrumentation(nitro);
124
+ }
125
+
104
126
  if (serverConfigFile?.includes('.server.config')) {
105
127
  consoleSandbox(() => {
106
128
  const serverDir = nitro.options.output.serverDir;
@@ -1 +1 @@
1
- {"version":3,"file":"module.js","sources":["../../src/module.ts"],"sourcesContent":["import {\n addPlugin,\n addPluginTemplate,\n addServerPlugin,\n addTemplate,\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 { setupSourceMaps } from './vite/sourceMaps';\nimport { addOTelCommonJSImportAlias, findDefaultSdkInitFile } 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 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\n if (serverConfigFile) {\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\n if (clientConfigFile || serverConfigFile) {\n setupSourceMaps(moduleOptions, nuxt);\n }\n\n addOTelCommonJSImportAlias(nuxt);\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 nuxt.hooks.hook('nitro:init', nitro => {\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 }\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AAA,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,eAAA,MAAA;AACA;AACA,gBAAA,OAAA,CAAA,GAAA;AACA,kBAAA,CAAA,sGAAA,EAAA,wBAAA,CAAA,mEAAA,EAAA,wBAAA,CAAA,gBAAA,CAAA;AACA,iBAAA;AACA;AACA,aAAA,CAAA;AACA;AACA;;AAEA,QAAA,IAAA,aAAA,CAAA,sBAAA,KAAA,kBAAA,EAAA;AACA,UAAA,kBAAA,CAAA,aAAA,EAAA,KAAA,CAAA;AACA;;AAEA,QAAA,IAAA,aAAA,CAAA,sBAAA,KAAA,6BAAA,EAAA;AACA,UAAA,gCAAA,CAAA,KAAA,EAAA,gBAAA,EAAA,aAAA,CAAA;;AAEA,UAAA,IAAA,aAAA,CAAA,KAAA,EAAA;AACA,YAAA,cAAA,CAAA,MAAA;AACA;AACA,cAAA,OAAA,CAAA,GAAA;AACA,gBAAA,8HAAA;AACA,eAAA;AACA,aAAA,CAAA;AACA;AACA;AACA;AACA,KAAA,CAAA;AACA,GAAA;AACA,CAAA,CAAA;;;;"}
1
+ {"version":3,"file":"module.js","sources":["../../src/module.ts"],"sourcesContent":["import {\n addPlugin,\n addPluginTemplate,\n addServerPlugin,\n addTemplate,\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 { addMiddlewareImports, addMiddlewareInstrumentation } from './vite/middlewareConfig';\nimport { setupSourceMaps } from './vite/sourceMaps';\nimport { addOTelCommonJSImportAlias, findDefaultSdkInitFile } 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 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 // Add the sentry config file to the include array\n nuxt.hook('prepare:types', options => {\n if (!options.tsConfig.include) {\n options.tsConfig.include = [];\n }\n\n // Add type references for useRuntimeConfig in root files for nuxt v4\n // Should be relative to `root/.nuxt`\n const relativePath = path.relative(nuxt.options.buildDir, clientConfigFile);\n options.tsConfig.include.push(relativePath);\n });\n }\n\n const serverConfigFile = findDefaultSdkInitFile('server', nuxt);\n\n if (serverConfigFile) {\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\n if (clientConfigFile || serverConfigFile) {\n setupSourceMaps(moduleOptions, nuxt);\n }\n\n addOTelCommonJSImportAlias(nuxt);\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 // Preps the the middleware instrumentation module.\n if (serverConfigFile) {\n addMiddlewareImports();\n }\n\n nuxt.hooks.hook('nitro:init', nitro => {\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":";;;;;;;;AAkBA,eAAe,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,KAAK,CAAC,kBAAkB,EAAE,IAAI,EAAE;AAClC,IAAI,IAAI,kBAAkB,EAAE,OAAA,KAAY,KAAK,EAAE;AAC/C,MAAM;AACN;;AAEA,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;AAC1B;AACA,MAAM,iBAAiB,CAAC;AACxB,QAAQ,IAAI,EAAE,QAAQ;AACtB,QAAQ,QAAQ,EAAE,0BAA0B;AAC5C,QAAQ,KAAK,EAAE,CAAC;;AAEhB;AACA;AACA,QAAQ,WAAW,EAAE,MAAM;AAC3B;;AAEA;AACA;AACA;AACA,4BAA4B,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAA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AACA,UAAA,gCAAA,CAAA,KAAA,EAAA,gBAAA,EAAA,aAAA,CAAA;;AAEA,UAAA,IAAA,aAAA,CAAA,KAAA,EAAA;AACA,YAAA,cAAA,CAAA,MAAA;AACA;AACA,cAAA,OAAA,CAAA,GAAA;AACA,gBAAA,8HAAA;AACA,eAAA;AACA,aAAA,CAAA;AACA;AACA;AACA;AACA,KAAA,CAAA;AACA,GAAA;AACA,CAAA,CAAA;;;;"}
@@ -1 +1 @@
1
- {"type":"module","version":"10.16.0"}
1
+ {"type":"module","version":"10.18.0"}
@@ -0,0 +1,98 @@
1
+ import { addServerImports, createResolver } from '@nuxt/kit';
2
+ import * as path from 'path';
3
+
4
+ /**
5
+ * Adds a server import for the middleware instrumentation.
6
+ */
7
+ function addMiddlewareImports() {
8
+ addServerImports([
9
+ {
10
+ name: 'wrapMiddlewareHandlerWithSentry',
11
+ from: createResolver(import.meta.url).resolve('./runtime/hooks/wrapMiddlewareHandler'),
12
+ },
13
+ ]);
14
+ }
15
+
16
+ /**
17
+ * Adds middleware instrumentation to the Nitro build.
18
+ *
19
+ * @param nitro Nitro instance
20
+ */
21
+ function addMiddlewareInstrumentation(nitro) {
22
+ nitro.hooks.hook('rollup:before', (nitro, rollupConfig) => {
23
+ if (!rollupConfig.plugins) {
24
+ rollupConfig.plugins = [];
25
+ }
26
+
27
+ if (!Array.isArray(rollupConfig.plugins)) {
28
+ rollupConfig.plugins = [rollupConfig.plugins];
29
+ }
30
+
31
+ rollupConfig.plugins.push(middlewareInstrumentationPlugin(nitro));
32
+ });
33
+ }
34
+
35
+ /**
36
+ * Creates a rollup plugin for the middleware instrumentation by transforming the middleware code.
37
+ *
38
+ * @param nitro Nitro instance
39
+ * @returns The rollup plugin for the middleware instrumentation.
40
+ */
41
+ function middlewareInstrumentationPlugin(nitro) {
42
+ const middlewareFiles = new Set();
43
+
44
+ return {
45
+ name: 'sentry-nuxt-middleware-instrumentation',
46
+ buildStart() {
47
+ // Collect middleware files during build start
48
+ nitro.scannedHandlers?.forEach(({ middleware, handler }) => {
49
+ if (middleware && handler) {
50
+ middlewareFiles.add(handler);
51
+ }
52
+ });
53
+ },
54
+ transform(code, id) {
55
+ // Only transform files we've identified as middleware
56
+ if (middlewareFiles.has(id)) {
57
+ const fileName = path.basename(id);
58
+ return {
59
+ code: wrapMiddlewareCode(code, fileName),
60
+ map: null,
61
+ };
62
+ }
63
+ return null;
64
+ },
65
+ };
66
+ }
67
+
68
+ /**
69
+ * Wraps the middleware user code to instrument it.
70
+ *
71
+ * @param originalCode The original user code of the middleware.
72
+ * @param fileName The name of the middleware file, used for the span name and logging.
73
+ *
74
+ * @returns The wrapped user code of the middleware.
75
+ */
76
+ function wrapMiddlewareCode(originalCode, fileName) {
77
+ // Remove common file extensions
78
+ const cleanFileName = fileName.replace(/\.(ts|js|mjs|mts|cts)$/, '');
79
+
80
+ return `
81
+ import { wrapMiddlewareHandlerWithSentry } from '#imports';
82
+
83
+ function defineInstrumentedEventHandler(handlerOrObject) {
84
+ return defineEventHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));
85
+ }
86
+
87
+ function instrumentedEventHandler(handlerOrObject) {
88
+ return eventHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));
89
+ }
90
+
91
+ ${originalCode
92
+ .replace(/defineEventHandler\(/g, 'defineInstrumentedEventHandler(')
93
+ .replace(/eventHandler\(/g, 'instrumentedEventHandler(')}
94
+ `;
95
+ }
96
+
97
+ export { addMiddlewareImports, addMiddlewareInstrumentation };
98
+ //# sourceMappingURL=middlewareConfig.js.map
@@ -0,0 +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,KAAK,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK;AAC7D,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE;AAC/B,MAAM,YAAY,CAAC,OAAA,GAAU,EAAE;AAC/B;;AAEA,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE;AAC9C,MAAM,YAAY,CAAC,OAAA,GAAU,CAAC,YAAY,CAAC,OAAO,CAAC;AACnD;;AAEA,IAAI,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,+BAA+B,CAAC,KAAK,CAAC,CAAC;AACrE,GAAG,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,+BAA+B,CAAC,KAAK,EAA4B;AAC1E,EAAE,MAAM,eAAA,GAAkB,IAAI,GAAG,EAAU;;AAE3C,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,wCAAwC;AAClD,IAAI,UAAU,GAAG;AACjB;AACA,MAAM,KAAK,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,OAAA,EAAS,KAAK;AAClE,QAAQ,IAAI,UAAA,IAAc,OAAO,EAAE;AACnC,UAAU,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC;AACtC;AACA,OAAO,CAAC;AACR,KAAK;AACL,IAAI,SAAS,CAAC,IAAI,EAAU,EAAE,EAAU;AACxC;AACA,MAAM,IAAI,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;AACnC,QAAQ,MAAM,WAAW,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;AAC1C,QAAQ,OAAO;AACf,UAAU,IAAI,EAAE,kBAAkB,CAAC,IAAI,EAAE,QAAQ,CAAC;AAClD,UAAU,GAAG,EAAE,IAAI;AACnB,SAAS;AACT;AACA,MAAM,OAAO,IAAI;AACjB,KAAK;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;;;;"}
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.7.0"
6
6
  },
7
- "version": "10.16.0",
7
+ "version": "10.18.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, defineNuxtModule, addPluginTemplate, addPlugin, addServerPlugin, addTemplate } from '@nuxt/kit';
1
+ import { createResolver, addServerImports, defineNuxtModule, addPluginTemplate, addPlugin, addServerPlugin, 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';
@@ -253,6 +253,65 @@ ${reExportedFunctions}
253
253
  };
254
254
  }
255
255
 
256
+ function addMiddlewareImports() {
257
+ addServerImports([
258
+ {
259
+ name: "wrapMiddlewareHandlerWithSentry",
260
+ from: createResolver(import.meta.url).resolve("./runtime/hooks/wrapMiddlewareHandler")
261
+ }
262
+ ]);
263
+ }
264
+ function addMiddlewareInstrumentation(nitro) {
265
+ nitro.hooks.hook("rollup:before", (nitro2, rollupConfig) => {
266
+ if (!rollupConfig.plugins) {
267
+ rollupConfig.plugins = [];
268
+ }
269
+ if (!Array.isArray(rollupConfig.plugins)) {
270
+ rollupConfig.plugins = [rollupConfig.plugins];
271
+ }
272
+ rollupConfig.plugins.push(middlewareInstrumentationPlugin(nitro2));
273
+ });
274
+ }
275
+ function middlewareInstrumentationPlugin(nitro) {
276
+ const middlewareFiles = /* @__PURE__ */ new Set();
277
+ return {
278
+ name: "sentry-nuxt-middleware-instrumentation",
279
+ buildStart() {
280
+ nitro.scannedHandlers?.forEach(({ middleware, handler }) => {
281
+ if (middleware && handler) {
282
+ middlewareFiles.add(handler);
283
+ }
284
+ });
285
+ },
286
+ transform(code, id) {
287
+ if (middlewareFiles.has(id)) {
288
+ const fileName = path.basename(id);
289
+ return {
290
+ code: wrapMiddlewareCode(code, fileName),
291
+ map: null
292
+ };
293
+ }
294
+ return null;
295
+ }
296
+ };
297
+ }
298
+ function wrapMiddlewareCode(originalCode, fileName) {
299
+ const cleanFileName = fileName.replace(/\.(ts|js|mjs|mts|cts)$/, "");
300
+ return `
301
+ import { wrapMiddlewareHandlerWithSentry } from '#imports';
302
+
303
+ function defineInstrumentedEventHandler(handlerOrObject) {
304
+ return defineEventHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));
305
+ }
306
+
307
+ function instrumentedEventHandler(handlerOrObject) {
308
+ return eventHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));
309
+ }
310
+
311
+ ${originalCode.replace(/defineEventHandler\(/g, "defineInstrumentedEventHandler(").replace(/eventHandler\(/g, "instrumentedEventHandler(")}
312
+ `;
313
+ }
314
+
256
315
  function setupSourceMaps(moduleOptions, nuxt) {
257
316
  const isDebug = moduleOptions.debug;
258
317
  const sourceMapsUploadOptions = moduleOptions.sourceMapsUploadOptions || {};
@@ -551,6 +610,13 @@ const module = defineNuxtModule({
551
610
  mode: "client",
552
611
  order: 1
553
612
  });
613
+ nuxt.hook("prepare:types", (options) => {
614
+ if (!options.tsConfig.include) {
615
+ options.tsConfig.include = [];
616
+ }
617
+ const relativePath = path.relative(nuxt.options.buildDir, clientConfigFile);
618
+ options.tsConfig.include.push(relativePath);
619
+ });
554
620
  }
555
621
  const serverConfigFile = findDefaultSdkInitFile("server", nuxt);
556
622
  if (serverConfigFile) {
@@ -578,7 +644,13 @@ const module = defineNuxtModule({
578
644
  return `export default ${JSON.stringify(pagesSubset, null, 2)};`;
579
645
  };
580
646
  });
647
+ if (serverConfigFile) {
648
+ addMiddlewareImports();
649
+ }
581
650
  nuxt.hooks.hook("nitro:init", (nitro) => {
651
+ if (serverConfigFile) {
652
+ addMiddlewareInstrumentation(nitro);
653
+ }
582
654
  if (serverConfigFile?.includes(".server.config")) {
583
655
  consoleSandbox(() => {
584
656
  const serverDir = nitro.options.output.serverDir;
@@ -0,0 +1,8 @@
1
+ import type { EventHandler, EventHandlerObject } from 'h3';
2
+ /**
3
+ * Wraps a middleware handler with Sentry instrumentation.
4
+ *
5
+ * @param handler The middleware handler.
6
+ * @param fileName The name of the middleware file.
7
+ */
8
+ export declare function wrapMiddlewareHandlerWithSentry<THandler extends EventHandler | EventHandlerObject>(handler: THandler, fileName: string): THandler;
@@ -0,0 +1,106 @@
1
+ import {
2
+ captureException,
3
+ debug,
4
+ flushIfServerless,
5
+ getClient,
6
+ httpHeadersToSpanAttributes,
7
+ SEMANTIC_ATTRIBUTE_SENTRY_OP,
8
+ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
9
+ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
10
+ SPAN_STATUS_ERROR,
11
+ SPAN_STATUS_OK,
12
+ startSpan
13
+ } from "@sentry/core";
14
+ export function wrapMiddlewareHandlerWithSentry(handler, fileName) {
15
+ if (!isEventHandlerObject(handler)) {
16
+ return wrapEventHandler(handler, fileName);
17
+ }
18
+ const handlerObj = {
19
+ ...handler,
20
+ handler: wrapEventHandler(handler.handler, fileName)
21
+ };
22
+ if (handlerObj.onRequest) {
23
+ handlerObj.onRequest = normalizeHandlers(
24
+ handlerObj.onRequest,
25
+ (h, index) => wrapEventHandler(h, fileName, "onRequest", index)
26
+ );
27
+ }
28
+ if (handlerObj.onBeforeResponse) {
29
+ handlerObj.onBeforeResponse = normalizeHandlers(
30
+ handlerObj.onBeforeResponse,
31
+ (h, index) => wrapResponseHandler(h, fileName, index)
32
+ );
33
+ }
34
+ return handlerObj;
35
+ }
36
+ function wrapEventHandler(handler, middlewareName, hookName, index) {
37
+ return async (event) => {
38
+ debug.log(`Sentry middleware: ${middlewareName}${hookName ? `.${hookName}` : ""} handling ${event.path}`);
39
+ const attributes = getSpanAttributes(event, middlewareName, hookName, index);
40
+ return withSpan(() => handler(event), attributes, middlewareName, hookName);
41
+ };
42
+ }
43
+ function wrapResponseHandler(handler, middlewareName, index) {
44
+ return async (event, response) => {
45
+ debug.log(`Sentry middleware: ${middlewareName}.onBeforeResponse handling ${event.path}`);
46
+ const attributes = getSpanAttributes(event, middlewareName, "onBeforeResponse", index);
47
+ return withSpan(() => handler(event, response), attributes, middlewareName, "onBeforeResponse");
48
+ };
49
+ }
50
+ function withSpan(handler, attributes, middlewareName, hookName) {
51
+ const spanName = hookName && hookName !== "handler" ? `${middlewareName}.${hookName}` : middlewareName;
52
+ return startSpan(
53
+ {
54
+ name: spanName,
55
+ attributes
56
+ },
57
+ async (span) => {
58
+ try {
59
+ const result = await handler();
60
+ span.setStatus({ code: SPAN_STATUS_OK });
61
+ return result;
62
+ } catch (error) {
63
+ span.setStatus({ code: SPAN_STATUS_ERROR, message: "internal_error" });
64
+ captureException(error, {
65
+ mechanism: {
66
+ handled: false,
67
+ type: attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]
68
+ }
69
+ });
70
+ throw error;
71
+ } finally {
72
+ await flushIfServerless();
73
+ }
74
+ }
75
+ );
76
+ }
77
+ function normalizeHandlers(handlers, normalizer) {
78
+ return Array.isArray(handlers) ? handlers.map((handler, index) => normalizer(handler, index)) : normalizer(handlers);
79
+ }
80
+ function getSpanAttributes(event, middlewareName, hookName, index) {
81
+ const attributes = {
82
+ [SEMANTIC_ATTRIBUTE_SENTRY_OP]: "middleware.nuxt",
83
+ [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "custom",
84
+ [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.middleware.nuxt",
85
+ "nuxt.middleware.name": middlewareName,
86
+ "nuxt.middleware.hook.name": hookName ?? "handler"
87
+ };
88
+ if (typeof index === "number") {
89
+ attributes["nuxt.middleware.hook.index"] = index;
90
+ }
91
+ if (event.method) {
92
+ attributes["http.request.method"] = event.method;
93
+ }
94
+ if (event.path) {
95
+ attributes["http.route"] = event.path;
96
+ }
97
+ const client = getClient();
98
+ const sendDefaultPii = client?.getOptions().sendDefaultPii ?? false;
99
+ const headers = event.node?.req?.headers || {};
100
+ const headerAttributes = httpHeadersToSpanAttributes(headers, sendDefaultPii);
101
+ Object.assign(attributes, headerAttributes);
102
+ return attributes;
103
+ }
104
+ function isEventHandlerObject(handler) {
105
+ return typeof handler !== "function";
106
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/module.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAK9D,MAAM,MAAM,aAAa,GAAG,uBAAuB,CAAC;;AAEpD,wBAuKG"}
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/module.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAM9D,MAAM,MAAM,aAAa,GAAG,uBAAuB,CAAC;;AAEpD,wBA4LG"}
@@ -0,0 +1,9 @@
1
+ import type { EventHandler, EventHandlerObject } from 'h3';
2
+ /**
3
+ * Wraps a middleware handler with Sentry instrumentation.
4
+ *
5
+ * @param handler The middleware handler.
6
+ * @param fileName The name of the middleware file.
7
+ */
8
+ export declare function wrapMiddlewareHandlerWithSentry<THandler extends EventHandler | EventHandlerObject>(handler: THandler, fileName: string): THandler;
9
+ //# sourceMappingURL=wrapMiddlewareHandler.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,12 @@
1
+ import type { Nitro } from 'nitropack/types';
2
+ /**
3
+ * Adds a server import for the middleware instrumentation.
4
+ */
5
+ export declare function addMiddlewareImports(): void;
6
+ /**
7
+ * Adds middleware instrumentation to the Nitro build.
8
+ *
9
+ * @param nitro Nitro instance
10
+ */
11
+ export declare function addMiddlewareInstrumentation(nitro: Nitro): void;
12
+ //# sourceMappingURL=middlewareConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middlewareConfig.d.ts","sourceRoot":"","sources":["../../../src/vite/middlewareConfig.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAI7C;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAO3C;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAY/D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/nuxt",
3
- "version": "10.16.0",
3
+ "version": "10.18.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",
@@ -47,13 +47,13 @@
47
47
  },
48
48
  "dependencies": {
49
49
  "@nuxt/kit": "^3.13.2",
50
- "@sentry/browser": "10.16.0",
51
- "@sentry/cloudflare": "10.16.0",
52
- "@sentry/core": "10.16.0",
53
- "@sentry/node": "10.16.0",
50
+ "@sentry/browser": "10.18.0",
51
+ "@sentry/cloudflare": "10.18.0",
52
+ "@sentry/core": "10.18.0",
53
+ "@sentry/node": "10.18.0",
54
54
  "@sentry/rollup-plugin": "^4.3.0",
55
55
  "@sentry/vite-plugin": "^4.3.0",
56
- "@sentry/vue": "10.16.0"
56
+ "@sentry/vue": "10.18.0"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@nuxt/module-builder": "^0.8.4",