@sentry/nuxt 8.42.0 → 8.44.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.
- package/build/cjs/module.js +40 -10
- package/build/cjs/module.js.map +1 -1
- package/build/cjs/runtime/nitro-utils/build/esm/nitro/patchEventHandler.js +43 -0
- package/build/cjs/runtime/nitro-utils/build/esm/nitro/patchEventHandler.js.map +1 -0
- package/build/cjs/runtime/nitro-utils/build/esm/util/flush.js +36 -0
- package/build/cjs/runtime/nitro-utils/build/esm/util/flush.js.map +1 -0
- package/build/cjs/runtime/nuxt/src/runtime/plugins/sentry.client.js.map +1 -0
- package/build/cjs/runtime/{plugins → nuxt/src/runtime/plugins}/sentry.server.js +31 -1
- package/build/cjs/runtime/nuxt/src/runtime/plugins/sentry.server.js.map +1 -0
- package/build/cjs/runtime/nuxt/src/runtime/utils.js.map +1 -0
- package/build/cjs/vite/addServerConfig.js +92 -36
- package/build/cjs/vite/addServerConfig.js.map +1 -1
- package/build/cjs/vite/utils.js +11 -1
- package/build/cjs/vite/utils.js.map +1 -1
- package/build/esm/module.js +41 -11
- package/build/esm/module.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/runtime/nitro-utils/build/esm/nitro/patchEventHandler.js +41 -0
- package/build/esm/runtime/nitro-utils/build/esm/nitro/patchEventHandler.js.map +1 -0
- package/build/esm/runtime/nitro-utils/build/esm/util/flush.js +33 -0
- package/build/esm/runtime/nitro-utils/build/esm/util/flush.js.map +1 -0
- package/build/esm/runtime/nuxt/src/runtime/plugins/sentry.client.js.map +1 -0
- package/build/esm/runtime/{plugins → nuxt/src/runtime/plugins}/sentry.server.js +31 -1
- package/build/esm/runtime/nuxt/src/runtime/plugins/sentry.server.js.map +1 -0
- package/build/esm/runtime/nuxt/src/runtime/utils.js.map +1 -0
- package/build/esm/vite/addServerConfig.js +93 -38
- package/build/esm/vite/addServerConfig.js.map +1 -1
- package/build/esm/vite/utils.js +11 -2
- package/build/esm/vite/utils.js.map +1 -1
- package/build/module/module.d.mts +23 -10
- package/build/module/module.d.ts +23 -10
- package/build/module/module.json +1 -1
- package/build/module/module.mjs +98 -37
- package/build/module/runtime/plugins/sentry.server.js +24 -1
- package/build/types/build.config.d.ts +3 -0
- package/build/types/build.config.d.ts.map +1 -0
- package/build/types/src/client/index.d.ts.map +1 -0
- package/build/types/src/client/piniaIntegration.d.ts.map +1 -0
- package/build/types/src/client/sdk.d.ts.map +1 -0
- package/build/types/src/client/vueIntegration.d.ts.map +1 -0
- package/build/types/src/common/debug-build.d.ts.map +1 -0
- package/build/types/{common → src/common}/types.d.ts +23 -10
- package/build/types/src/common/types.d.ts.map +1 -0
- package/build/types/src/index.client.d.ts.map +1 -0
- package/build/types/src/index.server.d.ts.map +1 -0
- package/build/types/src/index.types.d.ts.map +1 -0
- package/build/types/src/module.d.ts.map +1 -0
- package/build/types/src/runtime/plugins/sentry.client.d.ts.map +1 -0
- package/build/types/src/runtime/plugins/sentry.server.d.ts.map +1 -0
- package/build/types/src/runtime/utils.d.ts.map +1 -0
- package/build/types/src/server/index.d.ts.map +1 -0
- package/build/types/src/server/sdk.d.ts.map +1 -0
- package/build/types/{vite → src/vite}/addServerConfig.d.ts +7 -1
- package/build/types/src/vite/addServerConfig.d.ts.map +1 -0
- package/build/types/src/vite/sourceMaps.d.ts.map +1 -0
- package/build/types/{vite → src/vite}/utils.d.ts +4 -0
- package/build/types/src/vite/utils.d.ts.map +1 -0
- package/package.json +8 -7
- package/build/cjs/runtime/plugins/sentry.client.js.map +0 -1
- package/build/cjs/runtime/plugins/sentry.server.js.map +0 -1
- package/build/cjs/runtime/utils.js.map +0 -1
- package/build/esm/runtime/plugins/sentry.client.js.map +0 -1
- package/build/esm/runtime/plugins/sentry.server.js.map +0 -1
- package/build/esm/runtime/utils.js.map +0 -1
- package/build/types/client/index.d.ts.map +0 -1
- package/build/types/client/piniaIntegration.d.ts.map +0 -1
- package/build/types/client/sdk.d.ts.map +0 -1
- package/build/types/client/vueIntegration.d.ts.map +0 -1
- package/build/types/common/debug-build.d.ts.map +0 -1
- package/build/types/common/types.d.ts.map +0 -1
- package/build/types/index.client.d.ts.map +0 -1
- package/build/types/index.server.d.ts.map +0 -1
- package/build/types/index.types.d.ts.map +0 -1
- package/build/types/module.d.ts.map +0 -1
- package/build/types/runtime/plugins/sentry.client.d.ts.map +0 -1
- package/build/types/runtime/plugins/sentry.server.d.ts.map +0 -1
- package/build/types/runtime/utils.d.ts.map +0 -1
- package/build/types/server/index.d.ts.map +0 -1
- package/build/types/server/sdk.d.ts.map +0 -1
- package/build/types/vite/addServerConfig.d.ts.map +0 -1
- package/build/types/vite/sourceMaps.d.ts.map +0 -1
- package/build/types/vite/utils.d.ts.map +0 -1
- /package/build/cjs/runtime/{plugins → nuxt/src/runtime/plugins}/sentry.client.js +0 -0
- /package/build/cjs/runtime/{utils.js → nuxt/src/runtime/utils.js} +0 -0
- /package/build/esm/runtime/{plugins → nuxt/src/runtime/plugins}/sentry.client.js +0 -0
- /package/build/esm/runtime/{utils.js → nuxt/src/runtime/utils.js} +0 -0
- /package/build/types/{client → src/client}/index.d.ts +0 -0
- /package/build/types/{client → src/client}/piniaIntegration.d.ts +0 -0
- /package/build/types/{client → src/client}/sdk.d.ts +0 -0
- /package/build/types/{client → src/client}/vueIntegration.d.ts +0 -0
- /package/build/types/{common → src/common}/debug-build.d.ts +0 -0
- /package/build/types/{index.client.d.ts → src/index.client.d.ts} +0 -0
- /package/build/types/{index.server.d.ts → src/index.server.d.ts} +0 -0
- /package/build/types/{index.types.d.ts → src/index.types.d.ts} +0 -0
- /package/build/types/{module.d.ts → src/module.d.ts} +0 -0
- /package/build/types/{runtime → src/runtime}/plugins/sentry.client.d.ts +0 -0
- /package/build/types/{runtime → src/runtime}/plugins/sentry.server.d.ts +0 -0
- /package/build/types/{runtime → src/runtime}/utils.d.ts +0 -0
- /package/build/types/{server → src/server}/index.d.ts +0 -0
- /package/build/types/{server → src/server}/sdk.d.ts +0 -0
- /package/build/types/{vite → src/vite}/sourceMaps.d.ts +0 -0
package/build/cjs/module.js
CHANGED
|
@@ -18,8 +18,12 @@ const module$1 = kit.defineNuxtModule({
|
|
|
18
18
|
setup(moduleOptionsParam, nuxt) {
|
|
19
19
|
const moduleOptions = {
|
|
20
20
|
...moduleOptionsParam,
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
autoInjectServerSentry: moduleOptionsParam.autoInjectServerSentry,
|
|
22
|
+
experimental_entrypointWrappedFunctions: moduleOptionsParam.experimental_entrypointWrappedFunctions || [
|
|
23
|
+
'default',
|
|
24
|
+
'handler',
|
|
25
|
+
'server',
|
|
26
|
+
],
|
|
23
27
|
};
|
|
24
28
|
|
|
25
29
|
const moduleDirResolver = kit.createResolver((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('module.js', document.baseURI).href)));
|
|
@@ -52,15 +56,15 @@ const module$1 = kit.defineNuxtModule({
|
|
|
52
56
|
const serverConfigFile = utils.findDefaultSdkInitFile('server');
|
|
53
57
|
|
|
54
58
|
if (serverConfigFile) {
|
|
55
|
-
if (moduleOptions.
|
|
56
|
-
// Inject the server-side Sentry config file with a side effect import
|
|
59
|
+
if (moduleOptions.autoInjectServerSentry !== 'experimental_dynamic-import') {
|
|
57
60
|
kit.addPluginTemplate({
|
|
58
61
|
mode: 'server',
|
|
59
62
|
filename: 'sentry-server-config.mjs',
|
|
60
63
|
getContents: () =>
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
// This won't actually import the server config in the build output (so no double init call). The import here is only needed for correctly resolving the Sentry release injection.
|
|
65
|
+
`import "${buildDirResolver.resolve(`/${serverConfigFile}`)}";
|
|
66
|
+
import { defineNuxtPlugin } from "#imports";
|
|
67
|
+
export default defineNuxtPlugin(() => {});`,
|
|
64
68
|
});
|
|
65
69
|
}
|
|
66
70
|
|
|
@@ -77,12 +81,32 @@ const module$1 = kit.defineNuxtModule({
|
|
|
77
81
|
core.consoleSandbox(() => {
|
|
78
82
|
// eslint-disable-next-line no-console
|
|
79
83
|
console.log(
|
|
80
|
-
'[Sentry] Your application is running in development mode. Note: @sentry/nuxt
|
|
84
|
+
'[Sentry] Your application is running in development mode. Note: @sentry/nuxt does not work as expected on the server-side (Nitro). Errors are reported, but tracing does not work.',
|
|
81
85
|
);
|
|
82
86
|
});
|
|
83
87
|
}
|
|
84
88
|
|
|
85
|
-
|
|
89
|
+
core.consoleSandbox(() => {
|
|
90
|
+
const serverDir = nitro.options.output.serverDir;
|
|
91
|
+
|
|
92
|
+
// Netlify env: https://docs.netlify.com/configure-builds/environment-variables/#build-metadata
|
|
93
|
+
if (serverDir.includes('.netlify') || !!process.env.NETLIFY) {
|
|
94
|
+
// eslint-disable-next-line no-console
|
|
95
|
+
console.warn(
|
|
96
|
+
'[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/',
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Vercel env: https://vercel.com/docs/projects/environment-variables/system-environment-variables#VERCEL
|
|
101
|
+
if (serverDir.includes('.vercel') || !!process.env.VERCEL) {
|
|
102
|
+
// eslint-disable-next-line no-console
|
|
103
|
+
console.warn(
|
|
104
|
+
'[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/',
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
if (moduleOptions.autoInjectServerSentry !== 'experimental_dynamic-import') {
|
|
86
110
|
addServerConfig.addServerConfigToBuild(moduleOptions, nuxt, nitro, serverConfigFile);
|
|
87
111
|
|
|
88
112
|
if (moduleOptions.debug) {
|
|
@@ -99,7 +123,13 @@ const module$1 = kit.defineNuxtModule({
|
|
|
99
123
|
);
|
|
100
124
|
});
|
|
101
125
|
}
|
|
102
|
-
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (moduleOptions.autoInjectServerSentry === 'top-level-import') {
|
|
129
|
+
addServerConfig.addSentryTopImport(moduleOptions, nitro);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (moduleOptions.autoInjectServerSentry === 'experimental_dynamic-import') {
|
|
103
133
|
addServerConfig.addDynamicImportEntryFileWrapper(nitro, serverConfigFile, moduleOptions);
|
|
104
134
|
|
|
105
135
|
if (moduleOptions.debug) {
|
package/build/cjs/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.js","sources":["../../src/module.ts"],"sourcesContent":["import * as path from 'path';\nimport { addPlugin, addPluginTemplate, addServerPlugin, createResolver, defineNuxtModule } from '@nuxt/kit';\nimport { consoleSandbox } from '@sentry/core';\nimport type { SentryNuxtModuleOptions } from './common/types';\nimport { addDynamicImportEntryFileWrapper, addServerConfigToBuild } from './vite/addServerConfig';\nimport { setupSourceMaps } from './vite/sourceMaps';\nimport { 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 const moduleOptions = {\n ...moduleOptionsParam,\n dynamicImportForServerEntry: moduleOptionsParam.dynamicImportForServerEntry !== false, // default: true\n entrypointWrappedFunctions: moduleOptionsParam.entrypointWrappedFunctions || ['default', 'handler', 'server'],\n };\n\n const moduleDirResolver = createResolver(import.meta.url);\n const buildDirResolver = createResolver(nuxt.options.buildDir);\n\n const clientConfigFile = findDefaultSdkInitFile('client');\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\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 addPlugin({ src: moduleDirResolver.resolve('./runtime/plugins/sentry.client'), mode: 'client' });\n }\n\n const serverConfigFile = findDefaultSdkInitFile('server');\n\n if (serverConfigFile) {\n if (moduleOptions.dynamicImportForServerEntry === false) {\n // Inject the server-side Sentry config file with a side effect import\n addPluginTemplate({\n mode: 'server',\n filename: 'sentry-server-config.mjs',\n getContents: () =>\n `import \"${buildDirResolver.resolve(`/${serverConfigFile}`)}\"\\n` +\n 'import { defineNuxtPlugin } from \"#imports\"\\n' +\n 'export default defineNuxtPlugin(() => {})',\n });\n }\n\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/sentry.server'));\n }\n\n if (clientConfigFile || serverConfigFile) {\n setupSourceMaps(moduleOptions, nuxt);\n }\n\n nuxt.hooks.hook('nitro:init', nitro => {\n if (serverConfigFile && serverConfigFile.includes('.server.config')) {\n if (nitro.options.dev) {\n consoleSandbox(() => {\n // eslint-disable-next-line no-console\n console.log(\n '[Sentry] Your application is running in development mode. Note: @sentry/nuxt is in beta and may not work as expected on the server-side (Nitro). Errors are reported, but tracing does not work.',\n );\n });\n }\n\n if (moduleOptions.dynamicImportForServerEntry === false) {\n addServerConfigToBuild(moduleOptions, nuxt, 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 your \\`${serverConfigFile}\\` file for the server-side Sentry configuration. Make sure to add the Node option \\`import\\` to the Node command where you deploy and/or run your application. This preloads the Sentry configuration at server startup. You can do this via a command-line flag (\\`node --import ${serverConfigRelativePath} [...]\\`) or via an environment variable (\\`NODE_OPTIONS='--import ${serverConfigRelativePath}' node [...]\\`).`,\n );\n });\n }\n } else {\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","consoleSandbox","addServerConfigToBuild","addDynamicImportEntryFileWrapper"],"mappings":";;;;;;;;AAUA,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,MAAM,gBAAgB;AAC1B,MAAM,GAAG,kBAAkB;AAC3B,MAAM,2BAA2B,EAAE,kBAAkB,CAAC,2BAAA,KAAgC,KAAK;AAC3F,MAAM,0BAA0B,EAAE,kBAAkB,CAAC,0BAA2B,IAAG,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC;AACnH,KAAK;;AAEL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;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 * as path from 'path';\nimport { addPlugin, addPluginTemplate, addServerPlugin, createResolver, defineNuxtModule } from '@nuxt/kit';\nimport { consoleSandbox } from '@sentry/core';\nimport type { SentryNuxtModuleOptions } from './common/types';\nimport { addDynamicImportEntryFileWrapper, addSentryTopImport, addServerConfigToBuild } from './vite/addServerConfig';\nimport { setupSourceMaps } from './vite/sourceMaps';\nimport { 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 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');\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\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 addPlugin({ src: moduleDirResolver.resolve('./runtime/plugins/sentry.client'), mode: 'client' });\n }\n\n const serverConfigFile = findDefaultSdkInitFile('server');\n\n if (serverConfigFile) {\n if (moduleOptions.autoInjectServerSentry !== 'experimental_dynamic-import') {\n addPluginTemplate({\n mode: 'server',\n filename: 'sentry-server-config.mjs',\n getContents: () =>\n // This won't actually import the server config in the build output (so no double init call). The import here is only needed for correctly resolving the Sentry release injection.\n `import \"${buildDirResolver.resolve(`/${serverConfigFile}`)}\";\n import { defineNuxtPlugin } from \"#imports\";\n export default defineNuxtPlugin(() => {});`,\n });\n }\n\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/sentry.server'));\n }\n\n if (clientConfigFile || serverConfigFile) {\n setupSourceMaps(moduleOptions, nuxt);\n }\n\n nuxt.hooks.hook('nitro:init', nitro => {\n if (serverConfigFile && serverConfigFile.includes('.server.config')) {\n if (nitro.options.dev) {\n consoleSandbox(() => {\n // eslint-disable-next-line no-console\n console.log(\n '[Sentry] Your application is running in development mode. Note: @sentry/nuxt does not work as expected on the server-side (Nitro). Errors are reported, but tracing does not work.',\n );\n });\n }\n\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, nuxt, 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 your \\`${serverConfigFile}\\` file for the server-side Sentry configuration. Make sure to add the Node option \\`import\\` to the Node command where you deploy and/or run your application. This preloads the Sentry configuration at server startup. You can do this via a command-line flag (\\`node --import ${serverConfigRelativePath} [...]\\`) or via an environment variable (\\`NODE_OPTIONS='--import ${serverConfigRelativePath}' node [...]\\`).`,\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","consoleSandbox","addServerConfigToBuild","addSentryTopImport","addDynamicImportEntryFileWrapper"],"mappings":";;;;;;;;AAUA,iBAAeA,oBAAgB,CAAgB;AAC/C,EAAE,IAAI,EAAE;AACR,IAAI,IAAI,EAAE,qBAAqB;AAC/B,IAAI,SAAS,EAAE,QAAQ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
|
2
|
+
|
|
3
|
+
const core = require('@sentry/core');
|
|
4
|
+
const flush = require('../util/flush.js');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A helper to patch a given `h3` event handler, ensuring that
|
|
8
|
+
* requests are properly isolated and data is flushed to Sentry.
|
|
9
|
+
*/
|
|
10
|
+
function patchEventHandler(handler) {
|
|
11
|
+
return new Proxy(handler, {
|
|
12
|
+
async apply(handlerTarget, handlerThisArg, handlerArgs) {
|
|
13
|
+
// In environments where we cannot make use of the OTel
|
|
14
|
+
// http instrumentation (e.g. when using top level import
|
|
15
|
+
// of the server instrumentation file instead of
|
|
16
|
+
// `--import` or dynamic import, like on vercel)
|
|
17
|
+
// we still need to ensure requests are properly isolated
|
|
18
|
+
// by comparing the current isolation scope to the default
|
|
19
|
+
// one.
|
|
20
|
+
// Requests are properly isolated if they differ.
|
|
21
|
+
// If that's not the case, we fork the isolation scope here.
|
|
22
|
+
const isolationScope = core.getIsolationScope();
|
|
23
|
+
const newIsolationScope = isolationScope === core.getDefaultIsolationScope() ? isolationScope.clone() : isolationScope;
|
|
24
|
+
|
|
25
|
+
core.logger.log(
|
|
26
|
+
`Patched h3 event handler. ${
|
|
27
|
+
isolationScope === newIsolationScope ? 'Using existing' : 'Created new'
|
|
28
|
+
} isolation scope.`,
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
return core.withIsolationScope(newIsolationScope, async () => {
|
|
32
|
+
try {
|
|
33
|
+
return await handlerTarget.apply(handlerThisArg, handlerArgs);
|
|
34
|
+
} finally {
|
|
35
|
+
await flush.flushIfServerless();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
exports.patchEventHandler = patchEventHandler;
|
|
43
|
+
//# sourceMappingURL=patchEventHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patchEventHandler.js","sources":["../../../../../../../../nitro-utils/build/esm/nitro/patchEventHandler.js"],"sourcesContent":["import { getIsolationScope, getDefaultIsolationScope, logger, withIsolationScope } from '@sentry/core';\nimport { flushIfServerless } from '../util/flush.js';\n\n/**\n * A helper to patch a given `h3` event handler, ensuring that\n * requests are properly isolated and data is flushed to Sentry.\n */\nfunction patchEventHandler(handler) {\n return new Proxy(handler, {\n async apply(handlerTarget, handlerThisArg, handlerArgs) {\n // In environments where we cannot make use of the OTel\n // http instrumentation (e.g. when using top level import\n // of the server instrumentation file instead of\n // `--import` or dynamic import, like on vercel)\n // we still need to ensure requests are properly isolated\n // by comparing the current isolation scope to the default\n // one.\n // Requests are properly isolated if they differ.\n // If that's not the case, we fork the isolation scope here.\n const isolationScope = getIsolationScope();\n const newIsolationScope = isolationScope === getDefaultIsolationScope() ? isolationScope.clone() : isolationScope;\n\n logger.log(\n `Patched h3 event handler. ${\n isolationScope === newIsolationScope ? 'Using existing' : 'Created new'\n } isolation scope.`,\n );\n\n return withIsolationScope(newIsolationScope, async () => {\n try {\n return await handlerTarget.apply(handlerThisArg, handlerArgs);\n } finally {\n await flushIfServerless();\n }\n });\n },\n });\n}\n\nexport { patchEventHandler };\n//# sourceMappingURL=patchEventHandler.js.map\n"],"names":["getIsolationScope","getDefaultIsolationScope","logger","withIsolationScope","flushIfServerless"],"mappings":";;;;;AAGA;AACA;AACA;AACA;AACA,SAAS,iBAAiB,CAAC,OAAO,EAAE;AACpC,EAAE,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE;AAC5B,IAAI,MAAM,KAAK,CAAC,aAAa,EAAE,cAAc,EAAE,WAAW,EAAE;AAC5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,MAAM,cAAA,GAAiBA,sBAAiB,EAAE;AAChD,MAAM,MAAM,iBAAA,GAAoB,cAAA,KAAmBC,6BAAwB,EAAG,GAAE,cAAc,CAAC,KAAK,EAAC,GAAI,cAAc;;AAEvH,MAAMC,WAAM,CAAC,GAAG;AAChB,QAAQ,CAAC,0BAA0B;AACnC,UAAU,cAAe,KAAI,iBAAkB,GAAE,mBAAmB;AACpE,SAAS,iBAAiB,CAAC;AAC3B,OAAO;;AAEP,MAAM,OAAOC,uBAAkB,CAAC,iBAAiB,EAAE,YAAY;AAC/D,QAAQ,IAAI;AACZ,UAAU,OAAO,MAAM,aAAa,CAAC,KAAK,CAAC,cAAc,EAAE,WAAW,CAAC;AACvE,kBAAkB;AAClB,UAAU,MAAMC,uBAAiB,EAAE;AACnC;AACA,OAAO,CAAC;AACR,KAAK;AACL,GAAG,CAAC;AACJ;;;;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
|
|
3
|
+
const core = require('@sentry/core');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Flushes Sentry for serverless environments.
|
|
7
|
+
*/
|
|
8
|
+
async function flushIfServerless() {
|
|
9
|
+
const isServerless = !!process.env.LAMBDA_TASK_ROOT || !!process.env.VERCEL || !!process.env.NETLIFY;
|
|
10
|
+
|
|
11
|
+
// @ts-expect-error - this is not typed
|
|
12
|
+
if (core.GLOBAL_OBJ[Symbol.for('@vercel/request-context')]) {
|
|
13
|
+
core.vercelWaitUntil(flushWithTimeout());
|
|
14
|
+
} else if (isServerless) {
|
|
15
|
+
await flushWithTimeout();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Flushes Sentry.
|
|
21
|
+
*/
|
|
22
|
+
async function flushWithTimeout() {
|
|
23
|
+
const isDebug = core._optionalChain([core.getClient, 'call', _ => _(), 'optionalAccess', _2 => _2.getOptions, 'call', _3 => _3(), 'optionalAccess', _4 => _4.debug]);
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
isDebug && core.logger.log('Flushing events...');
|
|
27
|
+
await core.flush(2000);
|
|
28
|
+
isDebug && core.logger.log('Done flushing events');
|
|
29
|
+
} catch (e) {
|
|
30
|
+
isDebug && core.logger.log('Error while flushing events:\n', e);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exports.flushIfServerless = flushIfServerless;
|
|
35
|
+
exports.flushWithTimeout = flushWithTimeout;
|
|
36
|
+
//# sourceMappingURL=flush.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flush.js","sources":["../../../../../../../../nitro-utils/build/esm/util/flush.js"],"sourcesContent":["import { _optionalChain } from '@sentry/core';\nimport { GLOBAL_OBJ, vercelWaitUntil, logger, flush, getClient } from '@sentry/core';\n\n/**\n * Flushes Sentry for serverless environments.\n */\nasync function flushIfServerless() {\n const isServerless = !!process.env.LAMBDA_TASK_ROOT || !!process.env.VERCEL || !!process.env.NETLIFY;\n\n // @ts-expect-error - this is not typed\n if (GLOBAL_OBJ[Symbol.for('@vercel/request-context')]) {\n vercelWaitUntil(flushWithTimeout());\n } else if (isServerless) {\n await flushWithTimeout();\n }\n}\n\n/**\n * Flushes Sentry.\n */\nasync function flushWithTimeout() {\n const isDebug = _optionalChain([getClient, 'call', _ => _(), 'optionalAccess', _2 => _2.getOptions, 'call', _3 => _3(), 'optionalAccess', _4 => _4.debug]);\n\n try {\n isDebug && logger.log('Flushing events...');\n await flush(2000);\n isDebug && logger.log('Done flushing events');\n } catch (e) {\n isDebug && logger.log('Error while flushing events:\\n', e);\n }\n}\n\nexport { flushIfServerless, flushWithTimeout };\n//# sourceMappingURL=flush.js.map\n"],"names":["GLOBAL_OBJ","vercelWaitUntil","_optionalChain","getClient","logger","flush"],"mappings":";;;;AAGA;AACA;AACA;AACA,eAAe,iBAAiB,GAAG;AACnC,EAAE,MAAM,YAAa,GAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAA,IAAoB,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,MAAO,IAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO;;AAEtG;AACA,EAAE,IAAIA,eAAU,CAAC,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC,EAAE;AACzD,IAAIC,oBAAe,CAAC,gBAAgB,EAAE,CAAC;AACvC,GAAI,MAAK,IAAI,YAAY,EAAE;AAC3B,IAAI,MAAM,gBAAgB,EAAE;AAC5B;AACA;;AAEA;AACA;AACA;AACA,eAAe,gBAAgB,GAAG;AAClC,EAAE,MAAM,OAAQ,GAAEC,mBAAc,CAAC,CAACC,cAAS,EAAE,MAAM,EAAE,CAAA,IAAK,CAAC,EAAE,EAAE,gBAAgB,EAAE,EAAG,IAAG,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,EAAG,IAAG,EAAE,EAAE,EAAE,gBAAgB,EAAE,EAAG,IAAG,EAAE,CAAC,KAAK,CAAC,CAAC;;AAE5J,EAAE,IAAI;AACN,IAAI,WAAWC,WAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC;AAC/C,IAAI,MAAMC,UAAK,CAAC,IAAI,CAAC;AACrB,IAAI,WAAWD,WAAM,CAAC,GAAG,CAAC,sBAAsB,CAAC;AACjD,GAAI,CAAA,OAAO,CAAC,EAAE;AACd,IAAI,OAAA,IAAWA,WAAM,CAAC,GAAG,CAAC,gCAAgC,EAAE,CAAC,CAAC;AAC9D;AACA;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sentry.client.js","sources":["../../../../../../../src/runtime/plugins/sentry.client.ts"],"sourcesContent":["import { GLOBAL_OBJ, getClient } from '@sentry/core';\nimport { browserTracingIntegration, vueIntegration } from '@sentry/vue';\nimport { defineNuxtPlugin } from 'nuxt/app';\nimport type { GlobalObjWithIntegrationOptions } from '../../client/vueIntegration';\nimport { reportNuxtError } from '../utils';\n\n// --- Types are copied from @sentry/vue (so it does not need to be exported) ---\n// The following type is an intersection of the Route type from VueRouter v2, v3, and v4.\n// This is not great, but kinda necessary to make it work with all versions at the same time.\ntype Route = {\n /** Unparameterized URL */\n path: string;\n /**\n * Query params (keys map to null when there is no value associated, e.g. \"?foo\" and to an array when there are\n * multiple query params that have the same key, e.g. \"?foo&foo=bar\")\n */\n query: Record<string, string | null | (string | null)[]>;\n /** Route name (VueRouter provides a way to give routes individual names) */\n name?: string | symbol | null | undefined;\n /** Evaluated parameters */\n params: Record<string, string | string[]>;\n /** All the matched route objects as defined in VueRouter constructor */\n matched: { path: string }[];\n};\n\ninterface VueRouter {\n onError: (fn: (err: Error) => void) => void;\n beforeEach: (fn: (to: Route, from: Route, next?: () => void) => void) => void;\n}\n\n// Tree-shakable guard to remove all code related to tracing\ndeclare const __SENTRY_TRACING__: boolean;\n\nexport default defineNuxtPlugin({\n name: 'sentry-client-integrations',\n dependsOn: ['sentry-client-config'],\n async setup(nuxtApp) {\n // This evaluates to true unless __SENTRY_TRACING__ is text-replaced with \"false\", in which case everything inside\n // will get tree-shaken away\n if (typeof __SENTRY_TRACING__ === 'undefined' || __SENTRY_TRACING__) {\n const sentryClient = getClient();\n\n if (sentryClient && '$router' in nuxtApp) {\n sentryClient.addIntegration(\n browserTracingIntegration({ router: nuxtApp.$router as VueRouter, routeLabel: 'path' }),\n );\n }\n }\n\n nuxtApp.hook('app:created', vueApp => {\n const sentryClient = getClient();\n\n if (sentryClient) {\n // Adding the Vue integration without the Vue error handler\n // Nuxt is registering their own error handler, which is unset after hydration: https://github.com/nuxt/nuxt/blob/d3fdbcaac6cf66d21e25d259390d7824696f1a87/packages/nuxt/src/app/entry.ts#L64-L73\n // We don't want to wrap the existing error handler, as it leads to a 500 error: https://github.com/getsentry/sentry-javascript/issues/12515\n sentryClient.addIntegration(\n vueIntegration({\n // We pick up the options from the \"fake\" vueIntegration exported by the SDK.\n ...(GLOBAL_OBJ as GlobalObjWithIntegrationOptions)._sentryNuxtVueIntegrationOptions,\n app: vueApp,\n attachErrorHandler: false,\n }),\n );\n }\n });\n\n nuxtApp.hook('app:error', error => {\n reportNuxtError({ error });\n });\n\n nuxtApp.hook('vue:error', (error, instance, info) => {\n reportNuxtError({ error, instance, info });\n });\n },\n});\n"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AC,CAAC;AAChD,KAAK,CAAC;AACN,GAAG;AACH,CAAC,CAAC;;;;"}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
const core = require('@sentry/core');
|
|
1
2
|
const Sentry = require('@sentry/node');
|
|
2
3
|
const h3 = require('h3');
|
|
3
4
|
const runtime = require('nitropack/runtime');
|
|
4
5
|
const utils = require('../utils.js');
|
|
6
|
+
const patchEventHandler = require('../../../../nitro-utils/build/esm/nitro/patchEventHandler.js');
|
|
5
7
|
|
|
6
8
|
const sentry_server = runtime.defineNitroPlugin(nitroApp => {
|
|
7
|
-
nitroApp.
|
|
9
|
+
nitroApp.h3App.handler = patchEventHandler.patchEventHandler(nitroApp.h3App.handler);
|
|
10
|
+
|
|
11
|
+
nitroApp.hooks.hook('error', async (error, errorContext) => {
|
|
8
12
|
// Do not handle 404 and 422
|
|
9
13
|
if (error instanceof h3.H3Error) {
|
|
10
14
|
// Do not report if status code is 3xx or 4xx
|
|
@@ -28,6 +32,8 @@ const sentry_server = runtime.defineNitroPlugin(nitroApp => {
|
|
|
28
32
|
captureContext: { contexts: { nuxt: structuredContext } },
|
|
29
33
|
mechanism: { handled: false },
|
|
30
34
|
});
|
|
35
|
+
|
|
36
|
+
await flushIfServerless();
|
|
31
37
|
});
|
|
32
38
|
|
|
33
39
|
// @ts-expect-error - 'render:html' is a valid hook name in the Nuxt context
|
|
@@ -36,5 +42,29 @@ const sentry_server = runtime.defineNitroPlugin(nitroApp => {
|
|
|
36
42
|
});
|
|
37
43
|
});
|
|
38
44
|
|
|
45
|
+
async function flushIfServerless() {
|
|
46
|
+
const isServerless = !!process.env.LAMBDA_TASK_ROOT || !!process.env.VERCEL || !!process.env.NETLIFY;
|
|
47
|
+
|
|
48
|
+
// @ts-expect-error This is not typed
|
|
49
|
+
if (core.GLOBAL_OBJ[Symbol.for('@vercel/request-context')]) {
|
|
50
|
+
core.vercelWaitUntil(flushWithTimeout());
|
|
51
|
+
} else if (isServerless) {
|
|
52
|
+
await flushWithTimeout();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function flushWithTimeout() {
|
|
57
|
+
const sentryClient = core.getClient();
|
|
58
|
+
const isDebug = sentryClient ? sentryClient.getOptions().debug : false;
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
isDebug && core.logger.log('Flushing events...');
|
|
62
|
+
await core.flush(2000);
|
|
63
|
+
isDebug && core.logger.log('Done flushing events');
|
|
64
|
+
} catch (e) {
|
|
65
|
+
isDebug && core.logger.log('Error while flushing events:\n', e);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
39
69
|
module.exports = sentry_server;
|
|
40
70
|
//# sourceMappingURL=sentry.server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sentry.server.js","sources":["../../../../../../../src/runtime/plugins/sentry.server.ts"],"sourcesContent":["import { patchEventHandler } from '@sentry-internal/nitro-utils';\nimport { GLOBAL_OBJ, flush, getClient, logger, vercelWaitUntil } from '@sentry/core';\nimport * as Sentry from '@sentry/node';\nimport { H3Error } from 'h3';\nimport { defineNitroPlugin } from 'nitropack/runtime';\nimport type { NuxtRenderHTMLContext } from 'nuxt/app';\nimport { addSentryTracingMetaTags, extractErrorContext } from '../utils';\n\nexport default defineNitroPlugin(nitroApp => {\n nitroApp.h3App.handler = patchEventHandler(nitroApp.h3App.handler);\n\n nitroApp.hooks.hook('error', async (error, errorContext) => {\n // Do not handle 404 and 422\n if (error instanceof H3Error) {\n // Do not report if status code is 3xx or 4xx\n if (error.statusCode >= 300 && error.statusCode < 500) {\n return;\n }\n }\n\n const { method, path } = {\n method: errorContext.event && errorContext.event._method ? errorContext.event._method : '',\n path: errorContext.event && errorContext.event._path ? errorContext.event._path : null,\n };\n\n if (path) {\n Sentry.getCurrentScope().setTransactionName(`${method} ${path}`);\n }\n\n const structuredContext = extractErrorContext(errorContext);\n\n Sentry.captureException(error, {\n captureContext: { contexts: { nuxt: structuredContext } },\n mechanism: { handled: false },\n });\n\n await flushIfServerless();\n });\n\n // @ts-expect-error - 'render:html' is a valid hook name in the Nuxt context\n nitroApp.hooks.hook('render:html', (html: NuxtRenderHTMLContext) => {\n addSentryTracingMetaTags(html.head);\n });\n});\n\nasync function flushIfServerless(): Promise<void> {\n const isServerless = !!process.env.LAMBDA_TASK_ROOT || !!process.env.VERCEL || !!process.env.NETLIFY;\n\n // @ts-expect-error This is not typed\n if (GLOBAL_OBJ[Symbol.for('@vercel/request-context')]) {\n vercelWaitUntil(flushWithTimeout());\n } else if (isServerless) {\n await flushWithTimeout();\n }\n}\n\nasync function flushWithTimeout(): Promise<void> {\n const sentryClient = getClient();\n const isDebug = sentryClient ? sentryClient.getOptions().debug : false;\n\n try {\n isDebug && logger.log('Flushing events...');\n await flush(2000);\n isDebug && logger.log('Done flushing events');\n } catch (e) {\n isDebug && logger.log('Error while flushing events:\\n', e);\n }\n}\n"],"names":["defineNitroPlugin","patchEventHandler","H3Error","extractErrorContext","addSentryTracingMetaTags","GLOBAL_OBJ","vercelWaitUntil","getClient","logger","flush"],"mappings":";;;;;;;AAQA,sBAAeA,yBAAiB,CAAC,QAAA,IAAY;AAC7C,EAAE,QAAQ,CAAC,KAAK,CAAC,OAAQ,GAAEC,mCAAiB,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC;;AAEpE,EAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,KAAK,EAAE,YAAY,KAAK;AAC9D;AACA,IAAI,IAAI,KAAM,YAAWC,UAAO,EAAE;AAClC;AACA,MAAM,IAAI,KAAK,CAAC,UAAW,IAAG,GAAI,IAAG,KAAK,CAAC,UAAW,GAAE,GAAG,EAAE;AAC7D,QAAQ;AACR;AACA;;AAEA,IAAI,MAAM,EAAE,MAAM,EAAE,IAAA,KAAS;AAC7B,MAAM,MAAM,EAAE,YAAY,CAAC,KAAM,IAAG,YAAY,CAAC,KAAK,CAAC,OAAA,GAAU,YAAY,C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A,EAAA,MAAA,YAAA,GAAAC,cAAA,EAAA;AACA,EAAA,MAAA,OAAA,GAAA,YAAA,GAAA,YAAA,CAAA,UAAA,EAAA,CAAA,KAAA,GAAA,KAAA;;AAEA,EAAA,IAAA;AACA,IAAA,OAAA,IAAAC,WAAA,CAAA,GAAA,CAAA,oBAAA,CAAA;AACA,IAAA,MAAAC,UAAA,CAAA,IAAA,CAAA;AACA,IAAA,OAAA,IAAAD,WAAA,CAAA,GAAA,CAAA,sBAAA,CAAA;AACA,GAAA,CAAA,OAAA,CAAA,EAAA;AACA,IAAA,OAAA,IAAAA,WAAA,CAAA,GAAA,CAAA,gCAAA,EAAA,CAAA,CAAA;AACA;AACA;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../../../src/runtime/utils.ts"],"sourcesContent":["import type { ClientOptions, Context } from '@sentry/core';\nimport { captureException, dropUndefinedKeys, getClient, getTraceMetaTags } from '@sentry/core';\nimport type { VueOptions } from '@sentry/vue/src/types';\nimport type { CapturedErrorContext } from 'nitropack';\nimport type { NuxtRenderHTMLContext } from 'nuxt/app';\nimport type { ComponentPublicInstance } from 'vue';\n\n/**\n * Extracts the relevant context information from the error context (H3Event in Nitro Error)\n * and created a structured context object.\n */\nexport function extractErrorContext(errorContext: CapturedErrorContext): Context {\n const structuredContext: Context = {\n method: undefined,\n path: undefined,\n tags: undefined,\n };\n\n if (errorContext) {\n if (errorContext.event) {\n structuredContext.method = errorContext.event._method || undefined;\n structuredContext.path = errorContext.event._path || undefined;\n }\n\n if (Array.isArray(errorContext.tags)) {\n structuredContext.tags = errorContext.tags || undefined;\n }\n }\n\n return dropUndefinedKeys(structuredContext);\n}\n\n/**\n * Adds Sentry tracing <meta> tags to the returned html page.\n *\n * Exported only for testing\n */\nexport function addSentryTracingMetaTags(head: NuxtRenderHTMLContext['head']): void {\n const metaTags = getTraceMetaTags();\n\n if (metaTags) {\n head.push(metaTags);\n }\n}\n\n/**\n * Reports an error to Sentry. This function is similar to `attachErrorHandler` in `@sentry/vue`.\n * The Nuxt SDK does not register an error handler, but uses the Nuxt error hooks to report errors.\n *\n * We don't want to use the error handling from `@sentry/vue` as it wraps the existing error handler, which leads to a 500 error: https://github.com/getsentry/sentry-javascript/issues/12515\n */\nexport function reportNuxtError(options: {\n error: unknown;\n instance?: ComponentPublicInstance | null;\n info?: string;\n}): void {\n const { error, instance, info } = options;\n\n const metadata: Record<string, unknown> = {\n info,\n // todo: add component name and trace (like in the vue integration)\n };\n\n if (instance && instance.$props) {\n const sentryClient = getClient();\n const sentryOptions = sentryClient ? (sentryClient.getOptions() as ClientOptions & VueOptions) : null;\n\n // `attachProps` is enabled by default and props should only not be attached if explicitly disabled (see DEFAULT_CONFIG in `vueIntegration`).\n if (sentryOptions && sentryOptions.attachProps && instance.$props !== false) {\n metadata.propsData = instance.$props;\n }\n }\n\n // Capture exception in the next event loop, to make sure that all breadcrumbs are recorded in time.\n setTimeout(() => {\n captureException(error, {\n captureContext: { contexts: { nuxt: metadata } },\n mechanism: { handled: false },\n });\n });\n}\n"],"names":["dropUndefinedKeys","getTraceMetaTags","getClient","captureException"],"mappings":";;;;AAOA;AACA;AACA;AACA;AACO,SAAS,mBAAmB,CAAC,YAAY,EAAiC;AACjF,EAAE,MAAM,iBAAiB,GAAY;AACrC,IAAI,MAAM,EAAE,SAAS;AACrB,IAAI,IAAI,EAAE,SAAS;AACnB,IAAI,IAAI,EAAE,SAAS;AACnB,GAAG;;AAEH,EAAE,IAAI,YAAY,EAAE;AACpB,IAAI,IAAI,YAAY,CAAC,KAAK,EAAE;AAC5B,MAAM,iBAAiB,CAAC,MAAA,GAAS,YAAY,CAAC,KAAK,CAAC,OAAQ,IAAG,SAAS;AACxE,MAAM,iBAAiB,CAAC,IAAA,GAAO,YAAY,CAAC,KAAK,CAAC,KAAM,IAAG,SAAS;AACpE;;AAEA,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,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rollupOptions.input )[SERVER_CONFIG_FILENAME] =
|
|
33
33
|
kit.createResolver(nuxt.options.srcDir).resolve(`/${serverConfigFile}`);
|
|
34
34
|
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* When the build process is finished, copy the `sentry.server.config` file to the `.output` directory.
|
|
39
|
+
* This is necessary because we need to reference this file path in the node --import option.
|
|
40
|
+
*/
|
|
41
|
+
nitro.hooks.hook('close', async () => {
|
|
42
|
+
const buildDirResolver = kit.createResolver(nitro.options.buildDir);
|
|
43
|
+
const serverDirResolver = kit.createResolver(nitro.options.output.serverDir);
|
|
44
|
+
const source = buildDirResolver.resolve(`dist/server/${SERVER_CONFIG_FILENAME}.mjs`);
|
|
45
|
+
const destination = serverDirResolver.resolve(`${SERVER_CONFIG_FILENAME}.mjs`);
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
await fs.promises.access(source, fs.constants.F_OK);
|
|
49
|
+
await fs.promises.copyFile(source, destination);
|
|
50
|
+
|
|
51
|
+
if (moduleOptions.debug) {
|
|
52
|
+
core.consoleSandbox(() => {
|
|
53
|
+
// eslint-disable-next-line no-console
|
|
54
|
+
console.log(
|
|
55
|
+
`[Sentry] Successfully added the content of the \`${serverConfigFile}\` file to \`${destination}\``,
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (moduleOptions.debug) {
|
|
61
|
+
core.consoleSandbox(() => {
|
|
62
|
+
// eslint-disable-next-line no-console
|
|
63
|
+
console.warn(
|
|
64
|
+
`[Sentry] An error occurred when trying to add the \`${serverConfigFile}\` file to the \`.output\` directory`,
|
|
65
|
+
error,
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
35
72
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Adds the Sentry server config import at the top of the server entry file to load the SDK on the server.
|
|
75
|
+
* This is necessary for environments where modifying the node option `--import` is not possible.
|
|
76
|
+
* However, only limited tracing instrumentation is supported when doing this.
|
|
77
|
+
*/
|
|
78
|
+
function addSentryTopImport(moduleOptions, nitro) {
|
|
79
|
+
nitro.hooks.hook('close', async () => {
|
|
80
|
+
const fileNameFromCommand =
|
|
81
|
+
nitro.options.commands.preview && utils.getFilenameFromNodeStartCommand(nitro.options.commands.preview);
|
|
82
|
+
|
|
83
|
+
// other presets ('node-server' or 'vercel') have an index.mjs
|
|
84
|
+
const presetsWithServerFile = ['netlify'];
|
|
85
|
+
|
|
86
|
+
const entryFileName = fileNameFromCommand
|
|
87
|
+
? fileNameFromCommand
|
|
88
|
+
: typeof _optionalChain([nitro, 'access', _4 => _4.options, 'access', _5 => _5.rollupConfig, 'optionalAccess', _6 => _6.output, 'access', _7 => _7.entryFileNames]) === 'string'
|
|
89
|
+
? _optionalChain([nitro, 'access', _8 => _8.options, 'access', _9 => _9.rollupConfig, 'optionalAccess', _10 => _10.output, 'access', _11 => _11.entryFileNames])
|
|
90
|
+
: presetsWithServerFile.includes(nitro.options.preset)
|
|
91
|
+
? 'server.mjs'
|
|
92
|
+
: 'index.mjs';
|
|
93
|
+
|
|
94
|
+
const serverDirResolver = kit.createResolver(nitro.options.output.serverDir);
|
|
95
|
+
const entryFilePath = serverDirResolver.resolve(entryFileName);
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
fs.readFile(entryFilePath, 'utf8', (err, data) => {
|
|
99
|
+
const updatedContent = `import './${SERVER_CONFIG_FILENAME}.mjs';\n${data}`;
|
|
100
|
+
|
|
101
|
+
fs.writeFile(entryFilePath, updatedContent, 'utf8', () => {
|
|
102
|
+
if (moduleOptions.debug) {
|
|
52
103
|
// eslint-disable-next-line no-console
|
|
53
104
|
console.log(
|
|
54
|
-
`[Sentry] Successfully added the
|
|
55
|
-
);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
} catch (error) {
|
|
59
|
-
if (moduleOptions.debug) {
|
|
60
|
-
core.consoleSandbox(() => {
|
|
61
|
-
// eslint-disable-next-line no-console
|
|
62
|
-
console.warn(
|
|
63
|
-
`[Sentry] An error occurred when trying to add the \`${serverConfigFile}\` file to the \`.output\` directory`,
|
|
64
|
-
error,
|
|
105
|
+
`[Sentry] Successfully added the Sentry import to the server entry file "\`${entryFilePath}\`"`,
|
|
65
106
|
);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
} catch (err) {
|
|
111
|
+
if (moduleOptions.debug) {
|
|
112
|
+
// eslint-disable-next-line no-console
|
|
113
|
+
console.warn(
|
|
114
|
+
`[Sentry] An error occurred when trying to add the Sentry import to the server entry file "\`${entryFilePath}\`":`,
|
|
115
|
+
err,
|
|
116
|
+
);
|
|
68
117
|
}
|
|
69
|
-
}
|
|
118
|
+
}
|
|
70
119
|
});
|
|
71
120
|
}
|
|
72
121
|
|
|
@@ -87,7 +136,7 @@ function addDynamicImportEntryFileWrapper(
|
|
|
87
136
|
nitro.options.rollupConfig = { output: {} };
|
|
88
137
|
}
|
|
89
138
|
|
|
90
|
-
if (_optionalChain([nitro, 'access',
|
|
139
|
+
if (_optionalChain([nitro, 'access', _12 => _12.options, 'access', _13 => _13.rollupConfig, 'optionalAccess', _14 => _14.plugins]) === null || _optionalChain([nitro, 'access', _15 => _15.options, 'access', _16 => _16.rollupConfig, 'optionalAccess', _17 => _17.plugins]) === undefined) {
|
|
91
140
|
nitro.options.rollupConfig.plugins = [];
|
|
92
141
|
} else if (!Array.isArray(nitro.options.rollupConfig.plugins)) {
|
|
93
142
|
// `rollupConfig.plugins` can be a single plugin, so we want to put it into an array so that we can push our own plugin
|
|
@@ -97,7 +146,7 @@ function addDynamicImportEntryFileWrapper(
|
|
|
97
146
|
nitro.options.rollupConfig.plugins.push(
|
|
98
147
|
wrapEntryWithDynamicImport({
|
|
99
148
|
resolvedSentryConfigPath: kit.createResolver(nitro.options.srcDir).resolve(`/${serverConfigFile}`),
|
|
100
|
-
|
|
149
|
+
experimental_entrypointWrappedFunctions: moduleOptions.experimental_entrypointWrappedFunctions,
|
|
101
150
|
}),
|
|
102
151
|
);
|
|
103
152
|
}
|
|
@@ -109,9 +158,11 @@ function addDynamicImportEntryFileWrapper(
|
|
|
109
158
|
*/
|
|
110
159
|
function wrapEntryWithDynamicImport({
|
|
111
160
|
resolvedSentryConfigPath,
|
|
112
|
-
|
|
161
|
+
experimental_entrypointWrappedFunctions,
|
|
113
162
|
debug,
|
|
114
|
-
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
) {
|
|
115
166
|
// In order to correctly import the server config file
|
|
116
167
|
// and dynamically import the nitro runtime, we need to
|
|
117
168
|
// mark the resolutionId with '\0raw' to fall into the
|
|
@@ -137,7 +188,7 @@ function wrapEntryWithDynamicImport({
|
|
|
137
188
|
const resolution = await this.resolve(source, importer, options);
|
|
138
189
|
|
|
139
190
|
// If it cannot be resolved or is external, just return it so that Rollup can display an error
|
|
140
|
-
if (!resolution || _optionalChain([resolution, 'optionalAccess',
|
|
191
|
+
if (!resolution || _optionalChain([resolution, 'optionalAccess', _18 => _18.external])) return resolution;
|
|
141
192
|
|
|
142
193
|
const moduleInfo = await this.load(resolution);
|
|
143
194
|
|
|
@@ -150,7 +201,11 @@ function wrapEntryWithDynamicImport({
|
|
|
150
201
|
// Concatenates the query params to mark the file (also attaches names of re-exports - this is needed for serverless functions to re-export the handler)
|
|
151
202
|
.concat(utils.SENTRY_WRAPPED_ENTRY)
|
|
152
203
|
.concat(
|
|
153
|
-
utils.constructWrappedFunctionExportQuery(
|
|
204
|
+
utils.constructWrappedFunctionExportQuery(
|
|
205
|
+
moduleInfo.exportedBindings,
|
|
206
|
+
experimental_entrypointWrappedFunctions,
|
|
207
|
+
debug,
|
|
208
|
+
),
|
|
154
209
|
)
|
|
155
210
|
.concat(utils.QUERY_END_INDICATOR)}`;
|
|
156
211
|
}
|
|
@@ -184,5 +239,6 @@ function wrapEntryWithDynamicImport({
|
|
|
184
239
|
}
|
|
185
240
|
|
|
186
241
|
exports.addDynamicImportEntryFileWrapper = addDynamicImportEntryFileWrapper;
|
|
242
|
+
exports.addSentryTopImport = addSentryTopImport;
|
|
187
243
|
exports.addServerConfigToBuild = addServerConfigToBuild;
|
|
188
244
|
//# sourceMappingURL=addServerConfig.js.map
|