@sentry/nuxt 9.33.0 → 9.34.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/vite/utils.js +7 -1
- package/build/cjs/vite/utils.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/vite/utils.js +7 -1
- package/build/esm/vite/utils.js.map +1 -1
- package/build/module/module.json +1 -1
- package/build/module/module.mjs +6 -1
- package/build/module/runtime/hooks/captureErrorHook.d.ts +5 -0
- package/build/module/runtime/hooks/captureErrorHook.js +28 -0
- package/build/module/runtime/plugins/index.d.ts +1 -0
- package/build/module/runtime/plugins/index.js +1 -0
- package/build/module/runtime/plugins/sentry-cloudflare.server.d.ts +35 -0
- package/build/module/runtime/plugins/sentry-cloudflare.server.js +64 -0
- package/build/module/runtime/plugins/sentry.server.js +4 -58
- package/build/module/runtime/utils.d.ts +6 -2
- package/build/module/runtime/utils.js +37 -3
- package/build/types/runtime/hooks/captureErrorHook.d.ts +6 -0
- package/build/types/runtime/hooks/captureErrorHook.d.ts.map +1 -0
- package/build/types/runtime/plugins/index.d.ts +2 -0
- package/build/types/runtime/plugins/index.d.ts.map +1 -0
- package/build/types/runtime/plugins/sentry-cloudflare.server.d.ts +36 -0
- package/build/types/runtime/plugins/sentry-cloudflare.server.d.ts.map +1 -0
- package/build/types/runtime/plugins/sentry.server.d.ts.map +1 -1
- package/build/types/runtime/utils.d.ts +6 -2
- package/build/types/runtime/utils.d.ts.map +1 -1
- package/build/types/vite/utils.d.ts.map +1 -1
- package/package.json +10 -5
package/build/cjs/vite/utils.js
CHANGED
|
@@ -192,11 +192,17 @@ function constructFunctionReExport(pathWithQuery, entryId) {
|
|
|
192
192
|
* @see https://nuxt.com/docs/guide/concepts/esm#aliasing-libraries
|
|
193
193
|
*/
|
|
194
194
|
function addOTelCommonJSImportAlias(nuxt) {
|
|
195
|
+
if (!nuxt.options.dev) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
195
199
|
if (!nuxt.options.alias) {
|
|
196
200
|
nuxt.options.alias = {};
|
|
197
201
|
}
|
|
198
202
|
|
|
199
|
-
nuxt.options.alias['@opentelemetry/resources']
|
|
203
|
+
if (!nuxt.options.alias['@opentelemetry/resources']) {
|
|
204
|
+
nuxt.options.alias['@opentelemetry/resources'] = '@opentelemetry/resources/build/src/index.js';
|
|
205
|
+
}
|
|
200
206
|
}
|
|
201
207
|
|
|
202
208
|
exports.QUERY_END_INDICATOR = QUERY_END_INDICATOR;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../src/vite/utils.ts"],"sourcesContent":["import { consoleSandbox } from '@sentry/core';\nimport * as fs from 'fs';\nimport type { Nuxt } from 'nuxt/schema';\nimport * as path from 'path';\n\n/**\n * Find the default SDK init file for the given type (client or server).\n * The sentry.server.config file is prioritized over the instrument.server file.\n */\nexport function findDefaultSdkInitFile(type: 'server' | 'client', nuxt?: Nuxt): string | undefined {\n const possibleFileExtensions = ['ts', 'js', 'mjs', 'cjs', 'mts', 'cts'];\n const relativePaths: string[] = [];\n\n if (type === 'server') {\n for (const ext of possibleFileExtensions) {\n relativePaths.push(`sentry.${type}.config.${ext}`);\n relativePaths.push(path.join('public', `instrument.${type}.${ext}`));\n }\n } else {\n for (const ext of possibleFileExtensions) {\n relativePaths.push(`sentry.${type}.config.${ext}`);\n }\n }\n\n // Get layers from highest priority to lowest\n const layers = [...(nuxt?.options._layers ?? [])].reverse();\n\n for (const layer of layers) {\n for (const relativePath of relativePaths) {\n const fullPath = path.resolve(layer.cwd, relativePath);\n if (fs.existsSync(fullPath)) {\n return fullPath;\n }\n }\n }\n\n // As a fallback, also check CWD (left for pure compatibility)\n const cwd = process.cwd();\n for (const relativePath of relativePaths) {\n const fullPath = path.resolve(cwd, relativePath);\n if (fs.existsSync(fullPath)) {\n return fullPath;\n }\n }\n\n return undefined;\n}\n\n/**\n * Extracts the filename from a node command with a path.\n */\nexport function getFilenameFromNodeStartCommand(nodeCommand: string): string | null {\n const regex = /[^/\\\\]+\\.[^/\\\\]+$/;\n const match = nodeCommand.match(regex);\n return match ? match[0] : null;\n}\n\nexport const SENTRY_WRAPPED_ENTRY = '?sentry-query-wrapped-entry';\nexport const SENTRY_WRAPPED_FUNCTIONS = '?sentry-query-wrapped-functions=';\nexport const SENTRY_REEXPORTED_FUNCTIONS = '?sentry-query-reexported-functions=';\nexport const QUERY_END_INDICATOR = 'SENTRY-QUERY-END';\n\n/**\n * Strips the Sentry query part from a path.\n * Example: example/path?sentry-query-wrapped-entry?sentry-query-functions-reexport=foo,SENTRY-QUERY-END -> /example/path\n *\n * Only exported for testing.\n */\nexport function removeSentryQueryFromPath(url: string): string {\n // eslint-disable-next-line @sentry-internal/sdk/no-regexp-constructor\n const regex = new RegExp(`\\\\${SENTRY_WRAPPED_ENTRY}.*?\\\\${QUERY_END_INDICATOR}`);\n return url.replace(regex, '');\n}\n\n/**\n * Extracts and sanitizes function re-export and function wrap query parameters from a query string.\n * If it is a default export, it is not considered for re-exporting.\n *\n * Only exported for testing.\n */\nexport function extractFunctionReexportQueryParameters(query: string): { wrap: string[]; reexport: string[] } {\n // Regex matches the comma-separated params between the functions query\n // eslint-disable-next-line @sentry-internal/sdk/no-regexp-constructor\n const wrapRegex = new RegExp(\n `\\\\${SENTRY_WRAPPED_FUNCTIONS}(.*?)(\\\\${QUERY_END_INDICATOR}|\\\\${SENTRY_REEXPORTED_FUNCTIONS})`,\n );\n // eslint-disable-next-line @sentry-internal/sdk/no-regexp-constructor\n const reexportRegex = new RegExp(`\\\\${SENTRY_REEXPORTED_FUNCTIONS}(.*?)(\\\\${QUERY_END_INDICATOR})`);\n\n const wrapMatch = query.match(wrapRegex);\n const reexportMatch = query.match(reexportRegex);\n\n const wrap =\n wrapMatch?.[1]\n ?.split(',')\n .filter(param => param !== '')\n // Sanitize, as code could be injected with another rollup plugin\n .map((str: string) => str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')) || [];\n\n const reexport =\n reexportMatch?.[1]\n ?.split(',')\n .filter(param => param !== '' && param !== 'default')\n // Sanitize, as code could be injected with another rollup plugin\n .map((str: string) => str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')) || [];\n\n return { wrap, reexport };\n}\n\n/**\n * Constructs a comma-separated string with all functions that need to be re-exported later from the server entry.\n * It uses Rollup's `exportedBindings` to determine the functions to re-export. Functions which should be wrapped\n * (e.g. serverless handlers) are wrapped by Sentry.\n */\nexport function constructWrappedFunctionExportQuery(\n exportedBindings: Record<string, string[]> | null,\n entrypointWrappedFunctions: string[],\n debug?: boolean,\n): string {\n const functionsToExport: { wrap: string[]; reexport: string[] } = {\n wrap: [],\n reexport: [],\n };\n\n // `exportedBindings` can look like this: `{ '.': [ 'handler' ] }` or `{ '.': [], './firebase-gen-1.mjs': [ 'server' ] }`\n // The key `.` refers to exports within the current file, while other keys show from where exports were imported first.\n Object.values(exportedBindings || {}).forEach(functions =>\n functions.forEach(fn => {\n if (entrypointWrappedFunctions.includes(fn)) {\n functionsToExport.wrap.push(fn);\n } else {\n functionsToExport.reexport.push(fn);\n }\n }),\n );\n\n if (debug && functionsToExport.wrap.length === 0) {\n consoleSandbox(() =>\n // eslint-disable-next-line no-console\n console.warn(\n \"[Sentry] No functions found to wrap. In case the server needs to export async functions other than `handler` or `server`, consider adding the name(s) to Sentry's build options `sentry.experimental_entrypointWrappedFunctions` in `nuxt.config.ts`.\",\n ),\n );\n }\n\n const wrapQuery = functionsToExport.wrap.length\n ? `${SENTRY_WRAPPED_FUNCTIONS}${functionsToExport.wrap.join(',')}`\n : '';\n const reexportQuery = functionsToExport.reexport.length\n ? `${SENTRY_REEXPORTED_FUNCTIONS}${functionsToExport.reexport.join(',')}`\n : '';\n\n return [wrapQuery, reexportQuery].join('');\n}\n\n/**\n * Constructs a code snippet with function reexports (can be used in Rollup plugins as a return value for `load()`)\n */\nexport function constructFunctionReExport(pathWithQuery: string, entryId: string): string {\n const { wrap: wrapFunctions, reexport: reexportFunctions } = extractFunctionReexportQueryParameters(pathWithQuery);\n\n return wrapFunctions\n .reduce(\n (functionsCode, currFunctionName) =>\n functionsCode.concat(\n `async function ${currFunctionName}_sentryWrapped(...args) {\\n` +\n ` const res = await import(${JSON.stringify(entryId)});\\n` +\n ` return res.${currFunctionName}.call(this, ...args);\\n` +\n '}\\n' +\n `export { ${currFunctionName}_sentryWrapped as ${currFunctionName} };\\n`,\n ),\n '',\n )\n .concat(\n reexportFunctions.reduce(\n (functionsCode, currFunctionName) =>\n functionsCode.concat(`export { ${currFunctionName} } from ${JSON.stringify(entryId)};`),\n '',\n ),\n );\n}\n\n/**\n * Sets up alias to work around OpenTelemetry's incomplete ESM imports.\n * https://github.com/getsentry/sentry-javascript/issues/15204\n *\n * OpenTelemetry's @opentelemetry/resources package has incomplete imports missing\n * the .js file extensions (like execAsync for machine-id detection). This causes module resolution\n * errors in certain Nuxt configurations, particularly when local Nuxt modules in Nuxt 4 are present.\n *\n * @see https://nuxt.com/docs/guide/concepts/esm#aliasing-libraries\n */\nexport function addOTelCommonJSImportAlias(nuxt: Nuxt): void {\n if (!nuxt.options.alias) {\n nuxt.options.alias = {};\n }\n\n nuxt.options.alias['@opentelemetry/resources'] = '@opentelemetry/resources/build/src/index.js';\n}\n"],"names":["consoleSandbox"],"mappings":";;;;;;AAKA;AACA;AACA;AACA;AACO,SAAS,sBAAsB,CAAC,IAAI,EAAuB,IAAI,EAA6B;AACnG,EAAE,MAAM,sBAAA,GAAyB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC;AACzE,EAAE,MAAM,aAAa,GAAa,EAAE;;AAEpC,EAAE,IAAI,IAAK,KAAI,QAAQ,EAAE;AACzB,IAAI,KAAK,MAAM,GAAI,IAAG,sBAAsB,EAAE;AAC9C,MAAM,aAAa,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,EAAE,G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,KAAA,GAAA,EAAA;AACA;;AAEA,EAAA,IAAA,CAAA,OAAA,CAAA,KAAA,CAAA,0BAAA,CAAA,GAAA,6CAAA;AACA;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../src/vite/utils.ts"],"sourcesContent":["import { consoleSandbox } from '@sentry/core';\nimport * as fs from 'fs';\nimport type { Nuxt } from 'nuxt/schema';\nimport * as path from 'path';\n\n/**\n * Find the default SDK init file for the given type (client or server).\n * The sentry.server.config file is prioritized over the instrument.server file.\n */\nexport function findDefaultSdkInitFile(type: 'server' | 'client', nuxt?: Nuxt): string | undefined {\n const possibleFileExtensions = ['ts', 'js', 'mjs', 'cjs', 'mts', 'cts'];\n const relativePaths: string[] = [];\n\n if (type === 'server') {\n for (const ext of possibleFileExtensions) {\n relativePaths.push(`sentry.${type}.config.${ext}`);\n relativePaths.push(path.join('public', `instrument.${type}.${ext}`));\n }\n } else {\n for (const ext of possibleFileExtensions) {\n relativePaths.push(`sentry.${type}.config.${ext}`);\n }\n }\n\n // Get layers from highest priority to lowest\n const layers = [...(nuxt?.options._layers ?? [])].reverse();\n\n for (const layer of layers) {\n for (const relativePath of relativePaths) {\n const fullPath = path.resolve(layer.cwd, relativePath);\n if (fs.existsSync(fullPath)) {\n return fullPath;\n }\n }\n }\n\n // As a fallback, also check CWD (left for pure compatibility)\n const cwd = process.cwd();\n for (const relativePath of relativePaths) {\n const fullPath = path.resolve(cwd, relativePath);\n if (fs.existsSync(fullPath)) {\n return fullPath;\n }\n }\n\n return undefined;\n}\n\n/**\n * Extracts the filename from a node command with a path.\n */\nexport function getFilenameFromNodeStartCommand(nodeCommand: string): string | null {\n const regex = /[^/\\\\]+\\.[^/\\\\]+$/;\n const match = nodeCommand.match(regex);\n return match ? match[0] : null;\n}\n\nexport const SENTRY_WRAPPED_ENTRY = '?sentry-query-wrapped-entry';\nexport const SENTRY_WRAPPED_FUNCTIONS = '?sentry-query-wrapped-functions=';\nexport const SENTRY_REEXPORTED_FUNCTIONS = '?sentry-query-reexported-functions=';\nexport const QUERY_END_INDICATOR = 'SENTRY-QUERY-END';\n\n/**\n * Strips the Sentry query part from a path.\n * Example: example/path?sentry-query-wrapped-entry?sentry-query-functions-reexport=foo,SENTRY-QUERY-END -> /example/path\n *\n * Only exported for testing.\n */\nexport function removeSentryQueryFromPath(url: string): string {\n // eslint-disable-next-line @sentry-internal/sdk/no-regexp-constructor\n const regex = new RegExp(`\\\\${SENTRY_WRAPPED_ENTRY}.*?\\\\${QUERY_END_INDICATOR}`);\n return url.replace(regex, '');\n}\n\n/**\n * Extracts and sanitizes function re-export and function wrap query parameters from a query string.\n * If it is a default export, it is not considered for re-exporting.\n *\n * Only exported for testing.\n */\nexport function extractFunctionReexportQueryParameters(query: string): { wrap: string[]; reexport: string[] } {\n // Regex matches the comma-separated params between the functions query\n // eslint-disable-next-line @sentry-internal/sdk/no-regexp-constructor\n const wrapRegex = new RegExp(\n `\\\\${SENTRY_WRAPPED_FUNCTIONS}(.*?)(\\\\${QUERY_END_INDICATOR}|\\\\${SENTRY_REEXPORTED_FUNCTIONS})`,\n );\n // eslint-disable-next-line @sentry-internal/sdk/no-regexp-constructor\n const reexportRegex = new RegExp(`\\\\${SENTRY_REEXPORTED_FUNCTIONS}(.*?)(\\\\${QUERY_END_INDICATOR})`);\n\n const wrapMatch = query.match(wrapRegex);\n const reexportMatch = query.match(reexportRegex);\n\n const wrap =\n wrapMatch?.[1]\n ?.split(',')\n .filter(param => param !== '')\n // Sanitize, as code could be injected with another rollup plugin\n .map((str: string) => str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')) || [];\n\n const reexport =\n reexportMatch?.[1]\n ?.split(',')\n .filter(param => param !== '' && param !== 'default')\n // Sanitize, as code could be injected with another rollup plugin\n .map((str: string) => str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')) || [];\n\n return { wrap, reexport };\n}\n\n/**\n * Constructs a comma-separated string with all functions that need to be re-exported later from the server entry.\n * It uses Rollup's `exportedBindings` to determine the functions to re-export. Functions which should be wrapped\n * (e.g. serverless handlers) are wrapped by Sentry.\n */\nexport function constructWrappedFunctionExportQuery(\n exportedBindings: Record<string, string[]> | null,\n entrypointWrappedFunctions: string[],\n debug?: boolean,\n): string {\n const functionsToExport: { wrap: string[]; reexport: string[] } = {\n wrap: [],\n reexport: [],\n };\n\n // `exportedBindings` can look like this: `{ '.': [ 'handler' ] }` or `{ '.': [], './firebase-gen-1.mjs': [ 'server' ] }`\n // The key `.` refers to exports within the current file, while other keys show from where exports were imported first.\n Object.values(exportedBindings || {}).forEach(functions =>\n functions.forEach(fn => {\n if (entrypointWrappedFunctions.includes(fn)) {\n functionsToExport.wrap.push(fn);\n } else {\n functionsToExport.reexport.push(fn);\n }\n }),\n );\n\n if (debug && functionsToExport.wrap.length === 0) {\n consoleSandbox(() =>\n // eslint-disable-next-line no-console\n console.warn(\n \"[Sentry] No functions found to wrap. In case the server needs to export async functions other than `handler` or `server`, consider adding the name(s) to Sentry's build options `sentry.experimental_entrypointWrappedFunctions` in `nuxt.config.ts`.\",\n ),\n );\n }\n\n const wrapQuery = functionsToExport.wrap.length\n ? `${SENTRY_WRAPPED_FUNCTIONS}${functionsToExport.wrap.join(',')}`\n : '';\n const reexportQuery = functionsToExport.reexport.length\n ? `${SENTRY_REEXPORTED_FUNCTIONS}${functionsToExport.reexport.join(',')}`\n : '';\n\n return [wrapQuery, reexportQuery].join('');\n}\n\n/**\n * Constructs a code snippet with function reexports (can be used in Rollup plugins as a return value for `load()`)\n */\nexport function constructFunctionReExport(pathWithQuery: string, entryId: string): string {\n const { wrap: wrapFunctions, reexport: reexportFunctions } = extractFunctionReexportQueryParameters(pathWithQuery);\n\n return wrapFunctions\n .reduce(\n (functionsCode, currFunctionName) =>\n functionsCode.concat(\n `async function ${currFunctionName}_sentryWrapped(...args) {\\n` +\n ` const res = await import(${JSON.stringify(entryId)});\\n` +\n ` return res.${currFunctionName}.call(this, ...args);\\n` +\n '}\\n' +\n `export { ${currFunctionName}_sentryWrapped as ${currFunctionName} };\\n`,\n ),\n '',\n )\n .concat(\n reexportFunctions.reduce(\n (functionsCode, currFunctionName) =>\n functionsCode.concat(`export { ${currFunctionName} } from ${JSON.stringify(entryId)};`),\n '',\n ),\n );\n}\n\n/**\n * Sets up alias to work around OpenTelemetry's incomplete ESM imports.\n * https://github.com/getsentry/sentry-javascript/issues/15204\n *\n * OpenTelemetry's @opentelemetry/resources package has incomplete imports missing\n * the .js file extensions (like execAsync for machine-id detection). This causes module resolution\n * errors in certain Nuxt configurations, particularly when local Nuxt modules in Nuxt 4 are present.\n *\n * @see https://nuxt.com/docs/guide/concepts/esm#aliasing-libraries\n */\nexport function addOTelCommonJSImportAlias(nuxt: Nuxt): void {\n if (!nuxt.options.dev) {\n return;\n }\n\n if (!nuxt.options.alias) {\n nuxt.options.alias = {};\n }\n\n if (!nuxt.options.alias['@opentelemetry/resources']) {\n nuxt.options.alias['@opentelemetry/resources'] = '@opentelemetry/resources/build/src/index.js';\n }\n}\n"],"names":["consoleSandbox"],"mappings":";;;;;;AAKA;AACA;AACA;AACA;AACO,SAAS,sBAAsB,CAAC,IAAI,EAAuB,IAAI,EAA6B;AACnG,EAAE,MAAM,sBAAA,GAAyB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC;AACzE,EAAE,MAAM,aAAa,GAAa,EAAE;;AAEpC,EAAE,IAAI,IAAK,KAAI,QAAQ,EAAE;AACzB,IAAI,KAAK,MAAM,GAAI,IAAG,sBAAsB,EAAE;AAC9C,MAAM,aAAa,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA,CAAA;AACA,MAAA,aAAA,CAAA,IAAA,CAAA,IAAA,CAAA,IAAA,CAAA,QAAA,EAAA,CAAA,WAAA,EAAA,IAAA,CAAA,CAAA,EAAA,GAAA,CAAA,CAAA,CAAA,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A,0BAAA,CAAA,EAAA;AACA,IAAA,IAAA,CAAA,OAAA,CAAA,KAAA,CAAA,0BAAA,CAAA,GAAA,6CAAA;AACA;AACA;;;;;;;;;;;;;;"}
|
package/build/esm/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"module","version":"9.
|
|
1
|
+
{"type":"module","version":"9.34.0"}
|
package/build/esm/vite/utils.js
CHANGED
|
@@ -190,11 +190,17 @@ function constructFunctionReExport(pathWithQuery, entryId) {
|
|
|
190
190
|
* @see https://nuxt.com/docs/guide/concepts/esm#aliasing-libraries
|
|
191
191
|
*/
|
|
192
192
|
function addOTelCommonJSImportAlias(nuxt) {
|
|
193
|
+
if (!nuxt.options.dev) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
|
|
193
197
|
if (!nuxt.options.alias) {
|
|
194
198
|
nuxt.options.alias = {};
|
|
195
199
|
}
|
|
196
200
|
|
|
197
|
-
nuxt.options.alias['@opentelemetry/resources']
|
|
201
|
+
if (!nuxt.options.alias['@opentelemetry/resources']) {
|
|
202
|
+
nuxt.options.alias['@opentelemetry/resources'] = '@opentelemetry/resources/build/src/index.js';
|
|
203
|
+
}
|
|
198
204
|
}
|
|
199
205
|
|
|
200
206
|
export { QUERY_END_INDICATOR, SENTRY_REEXPORTED_FUNCTIONS, SENTRY_WRAPPED_ENTRY, SENTRY_WRAPPED_FUNCTIONS, addOTelCommonJSImportAlias, constructFunctionReExport, constructWrappedFunctionExportQuery, extractFunctionReexportQueryParameters, findDefaultSdkInitFile, getFilenameFromNodeStartCommand, removeSentryQueryFromPath };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../src/vite/utils.ts"],"sourcesContent":["import { consoleSandbox } from '@sentry/core';\nimport * as fs from 'fs';\nimport type { Nuxt } from 'nuxt/schema';\nimport * as path from 'path';\n\n/**\n * Find the default SDK init file for the given type (client or server).\n * The sentry.server.config file is prioritized over the instrument.server file.\n */\nexport function findDefaultSdkInitFile(type: 'server' | 'client', nuxt?: Nuxt): string | undefined {\n const possibleFileExtensions = ['ts', 'js', 'mjs', 'cjs', 'mts', 'cts'];\n const relativePaths: string[] = [];\n\n if (type === 'server') {\n for (const ext of possibleFileExtensions) {\n relativePaths.push(`sentry.${type}.config.${ext}`);\n relativePaths.push(path.join('public', `instrument.${type}.${ext}`));\n }\n } else {\n for (const ext of possibleFileExtensions) {\n relativePaths.push(`sentry.${type}.config.${ext}`);\n }\n }\n\n // Get layers from highest priority to lowest\n const layers = [...(nuxt?.options._layers ?? [])].reverse();\n\n for (const layer of layers) {\n for (const relativePath of relativePaths) {\n const fullPath = path.resolve(layer.cwd, relativePath);\n if (fs.existsSync(fullPath)) {\n return fullPath;\n }\n }\n }\n\n // As a fallback, also check CWD (left for pure compatibility)\n const cwd = process.cwd();\n for (const relativePath of relativePaths) {\n const fullPath = path.resolve(cwd, relativePath);\n if (fs.existsSync(fullPath)) {\n return fullPath;\n }\n }\n\n return undefined;\n}\n\n/**\n * Extracts the filename from a node command with a path.\n */\nexport function getFilenameFromNodeStartCommand(nodeCommand: string): string | null {\n const regex = /[^/\\\\]+\\.[^/\\\\]+$/;\n const match = nodeCommand.match(regex);\n return match ? match[0] : null;\n}\n\nexport const SENTRY_WRAPPED_ENTRY = '?sentry-query-wrapped-entry';\nexport const SENTRY_WRAPPED_FUNCTIONS = '?sentry-query-wrapped-functions=';\nexport const SENTRY_REEXPORTED_FUNCTIONS = '?sentry-query-reexported-functions=';\nexport const QUERY_END_INDICATOR = 'SENTRY-QUERY-END';\n\n/**\n * Strips the Sentry query part from a path.\n * Example: example/path?sentry-query-wrapped-entry?sentry-query-functions-reexport=foo,SENTRY-QUERY-END -> /example/path\n *\n * Only exported for testing.\n */\nexport function removeSentryQueryFromPath(url: string): string {\n // eslint-disable-next-line @sentry-internal/sdk/no-regexp-constructor\n const regex = new RegExp(`\\\\${SENTRY_WRAPPED_ENTRY}.*?\\\\${QUERY_END_INDICATOR}`);\n return url.replace(regex, '');\n}\n\n/**\n * Extracts and sanitizes function re-export and function wrap query parameters from a query string.\n * If it is a default export, it is not considered for re-exporting.\n *\n * Only exported for testing.\n */\nexport function extractFunctionReexportQueryParameters(query: string): { wrap: string[]; reexport: string[] } {\n // Regex matches the comma-separated params between the functions query\n // eslint-disable-next-line @sentry-internal/sdk/no-regexp-constructor\n const wrapRegex = new RegExp(\n `\\\\${SENTRY_WRAPPED_FUNCTIONS}(.*?)(\\\\${QUERY_END_INDICATOR}|\\\\${SENTRY_REEXPORTED_FUNCTIONS})`,\n );\n // eslint-disable-next-line @sentry-internal/sdk/no-regexp-constructor\n const reexportRegex = new RegExp(`\\\\${SENTRY_REEXPORTED_FUNCTIONS}(.*?)(\\\\${QUERY_END_INDICATOR})`);\n\n const wrapMatch = query.match(wrapRegex);\n const reexportMatch = query.match(reexportRegex);\n\n const wrap =\n wrapMatch?.[1]\n ?.split(',')\n .filter(param => param !== '')\n // Sanitize, as code could be injected with another rollup plugin\n .map((str: string) => str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')) || [];\n\n const reexport =\n reexportMatch?.[1]\n ?.split(',')\n .filter(param => param !== '' && param !== 'default')\n // Sanitize, as code could be injected with another rollup plugin\n .map((str: string) => str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')) || [];\n\n return { wrap, reexport };\n}\n\n/**\n * Constructs a comma-separated string with all functions that need to be re-exported later from the server entry.\n * It uses Rollup's `exportedBindings` to determine the functions to re-export. Functions which should be wrapped\n * (e.g. serverless handlers) are wrapped by Sentry.\n */\nexport function constructWrappedFunctionExportQuery(\n exportedBindings: Record<string, string[]> | null,\n entrypointWrappedFunctions: string[],\n debug?: boolean,\n): string {\n const functionsToExport: { wrap: string[]; reexport: string[] } = {\n wrap: [],\n reexport: [],\n };\n\n // `exportedBindings` can look like this: `{ '.': [ 'handler' ] }` or `{ '.': [], './firebase-gen-1.mjs': [ 'server' ] }`\n // The key `.` refers to exports within the current file, while other keys show from where exports were imported first.\n Object.values(exportedBindings || {}).forEach(functions =>\n functions.forEach(fn => {\n if (entrypointWrappedFunctions.includes(fn)) {\n functionsToExport.wrap.push(fn);\n } else {\n functionsToExport.reexport.push(fn);\n }\n }),\n );\n\n if (debug && functionsToExport.wrap.length === 0) {\n consoleSandbox(() =>\n // eslint-disable-next-line no-console\n console.warn(\n \"[Sentry] No functions found to wrap. In case the server needs to export async functions other than `handler` or `server`, consider adding the name(s) to Sentry's build options `sentry.experimental_entrypointWrappedFunctions` in `nuxt.config.ts`.\",\n ),\n );\n }\n\n const wrapQuery = functionsToExport.wrap.length\n ? `${SENTRY_WRAPPED_FUNCTIONS}${functionsToExport.wrap.join(',')}`\n : '';\n const reexportQuery = functionsToExport.reexport.length\n ? `${SENTRY_REEXPORTED_FUNCTIONS}${functionsToExport.reexport.join(',')}`\n : '';\n\n return [wrapQuery, reexportQuery].join('');\n}\n\n/**\n * Constructs a code snippet with function reexports (can be used in Rollup plugins as a return value for `load()`)\n */\nexport function constructFunctionReExport(pathWithQuery: string, entryId: string): string {\n const { wrap: wrapFunctions, reexport: reexportFunctions } = extractFunctionReexportQueryParameters(pathWithQuery);\n\n return wrapFunctions\n .reduce(\n (functionsCode, currFunctionName) =>\n functionsCode.concat(\n `async function ${currFunctionName}_sentryWrapped(...args) {\\n` +\n ` const res = await import(${JSON.stringify(entryId)});\\n` +\n ` return res.${currFunctionName}.call(this, ...args);\\n` +\n '}\\n' +\n `export { ${currFunctionName}_sentryWrapped as ${currFunctionName} };\\n`,\n ),\n '',\n )\n .concat(\n reexportFunctions.reduce(\n (functionsCode, currFunctionName) =>\n functionsCode.concat(`export { ${currFunctionName} } from ${JSON.stringify(entryId)};`),\n '',\n ),\n );\n}\n\n/**\n * Sets up alias to work around OpenTelemetry's incomplete ESM imports.\n * https://github.com/getsentry/sentry-javascript/issues/15204\n *\n * OpenTelemetry's @opentelemetry/resources package has incomplete imports missing\n * the .js file extensions (like execAsync for machine-id detection). This causes module resolution\n * errors in certain Nuxt configurations, particularly when local Nuxt modules in Nuxt 4 are present.\n *\n * @see https://nuxt.com/docs/guide/concepts/esm#aliasing-libraries\n */\nexport function addOTelCommonJSImportAlias(nuxt: Nuxt): void {\n if (!nuxt.options.alias) {\n nuxt.options.alias = {};\n }\n\n nuxt.options.alias['@opentelemetry/resources'] = '@opentelemetry/resources/build/src/index.js';\n}\n"],"names":[],"mappings":";;;;AAKA;AACA;AACA;AACA;AACO,SAAS,sBAAsB,CAAC,IAAI,EAAuB,IAAI,EAA6B;AACnG,EAAE,MAAM,sBAAA,GAAyB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC;AACzE,EAAE,MAAM,aAAa,GAAa,EAAE;;AAEpC,EAAE,IAAI,IAAK,KAAI,QAAQ,EAAE;AACzB,IAAI,KAAK,MAAM,GAAI,IAAG,sBAAsB,EAAE;AAC9C,MAAM,aAAa,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA,CAAA;AACA,MAAA,aAAA,CAAA,IAAA,CAAA,IAAA,CAAA,IAAA,CAAA,QAAA,EAAA,CAAA,WAAA,EAAA,IAAA,CAAA,CAAA,EAAA,GAAA,CAAA,CAAA,CAAA,CAAA;AACA;AACA,GAAA,MAAA;AACA,IAAA,KAAA,MAAA,GAAA,IAAA,sBAAA,EAAA;AACA,MAAA,aAAA,CAAA,IAAA,CAAA,CAAA,OAAA,EAAA,IAAA,CAAA,QAAA,EAAA,GAAA,CAAA,CAAA,CAAA;AACA;AACA;;AAEA;AACA,EAAA,MAAA,MAAA,GAAA,CAAA,IAAA,IAAA,EAAA,OAAA,CAAA,OAAA,IAAA,EAAA,CAAA,CAAA,CAAA,OAAA,EAAA;;AAEA,EAAA,KAAA,MAAA,KAAA,IAAA,MAAA,EAAA;AACA,IAAA,KAAA,MAAA,YAAA,IAAA,aAAA,EAAA;AACA,MAAA,MAAA,QA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CAAA,IAAA,CAAA;AACA,YAAA,CAAA,aAAA,EAAA,gBAAA,CAAA,uBAAA,CAAA;AACA,YAAA,KAAA;AACA,YAAA,CAAA,SAAA,EAAA,gBAAA,CAAA,kBAAA,EAAA,gBAAA,CAAA,KAAA,CAAA;AACA,SAAA;AACA,MAAA,EAAA;AACA;AACA,KAAA,MAAA;AACA,MAAA,iBAAA,CAAA,MAAA;AACA,QAAA,CAAA,aAAA,EAAA,gBAAA;AACA,UAAA,aAAA,CAAA,MAAA,CAAA,CAAA,SAAA,EAAA,gBAAA,CAAA,QAAA,EAAA,IAAA,CAAA,SAAA,CAAA,OAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AACA,QAAA,EAAA;AACA,OAAA;AACA,KAAA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,0BAAA,CAAA,IAAA,EAAA;AACA,EAAA,IAAA,CAAA,IAAA,CAAA,OAAA,CAAA,KAAA,EAAA;AACA,IAAA,IAAA,CAAA,OAAA,CAAA,KAAA,GAAA,EAAA;AACA;;AAEA,EAAA,IAAA,CAAA,OAAA,CAAA,KAAA,CAAA,0BAAA,CAAA,GAAA,6CAAA;AACA;;;;"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../src/vite/utils.ts"],"sourcesContent":["import { consoleSandbox } from '@sentry/core';\nimport * as fs from 'fs';\nimport type { Nuxt } from 'nuxt/schema';\nimport * as path from 'path';\n\n/**\n * Find the default SDK init file for the given type (client or server).\n * The sentry.server.config file is prioritized over the instrument.server file.\n */\nexport function findDefaultSdkInitFile(type: 'server' | 'client', nuxt?: Nuxt): string | undefined {\n const possibleFileExtensions = ['ts', 'js', 'mjs', 'cjs', 'mts', 'cts'];\n const relativePaths: string[] = [];\n\n if (type === 'server') {\n for (const ext of possibleFileExtensions) {\n relativePaths.push(`sentry.${type}.config.${ext}`);\n relativePaths.push(path.join('public', `instrument.${type}.${ext}`));\n }\n } else {\n for (const ext of possibleFileExtensions) {\n relativePaths.push(`sentry.${type}.config.${ext}`);\n }\n }\n\n // Get layers from highest priority to lowest\n const layers = [...(nuxt?.options._layers ?? [])].reverse();\n\n for (const layer of layers) {\n for (const relativePath of relativePaths) {\n const fullPath = path.resolve(layer.cwd, relativePath);\n if (fs.existsSync(fullPath)) {\n return fullPath;\n }\n }\n }\n\n // As a fallback, also check CWD (left for pure compatibility)\n const cwd = process.cwd();\n for (const relativePath of relativePaths) {\n const fullPath = path.resolve(cwd, relativePath);\n if (fs.existsSync(fullPath)) {\n return fullPath;\n }\n }\n\n return undefined;\n}\n\n/**\n * Extracts the filename from a node command with a path.\n */\nexport function getFilenameFromNodeStartCommand(nodeCommand: string): string | null {\n const regex = /[^/\\\\]+\\.[^/\\\\]+$/;\n const match = nodeCommand.match(regex);\n return match ? match[0] : null;\n}\n\nexport const SENTRY_WRAPPED_ENTRY = '?sentry-query-wrapped-entry';\nexport const SENTRY_WRAPPED_FUNCTIONS = '?sentry-query-wrapped-functions=';\nexport const SENTRY_REEXPORTED_FUNCTIONS = '?sentry-query-reexported-functions=';\nexport const QUERY_END_INDICATOR = 'SENTRY-QUERY-END';\n\n/**\n * Strips the Sentry query part from a path.\n * Example: example/path?sentry-query-wrapped-entry?sentry-query-functions-reexport=foo,SENTRY-QUERY-END -> /example/path\n *\n * Only exported for testing.\n */\nexport function removeSentryQueryFromPath(url: string): string {\n // eslint-disable-next-line @sentry-internal/sdk/no-regexp-constructor\n const regex = new RegExp(`\\\\${SENTRY_WRAPPED_ENTRY}.*?\\\\${QUERY_END_INDICATOR}`);\n return url.replace(regex, '');\n}\n\n/**\n * Extracts and sanitizes function re-export and function wrap query parameters from a query string.\n * If it is a default export, it is not considered for re-exporting.\n *\n * Only exported for testing.\n */\nexport function extractFunctionReexportQueryParameters(query: string): { wrap: string[]; reexport: string[] } {\n // Regex matches the comma-separated params between the functions query\n // eslint-disable-next-line @sentry-internal/sdk/no-regexp-constructor\n const wrapRegex = new RegExp(\n `\\\\${SENTRY_WRAPPED_FUNCTIONS}(.*?)(\\\\${QUERY_END_INDICATOR}|\\\\${SENTRY_REEXPORTED_FUNCTIONS})`,\n );\n // eslint-disable-next-line @sentry-internal/sdk/no-regexp-constructor\n const reexportRegex = new RegExp(`\\\\${SENTRY_REEXPORTED_FUNCTIONS}(.*?)(\\\\${QUERY_END_INDICATOR})`);\n\n const wrapMatch = query.match(wrapRegex);\n const reexportMatch = query.match(reexportRegex);\n\n const wrap =\n wrapMatch?.[1]\n ?.split(',')\n .filter(param => param !== '')\n // Sanitize, as code could be injected with another rollup plugin\n .map((str: string) => str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')) || [];\n\n const reexport =\n reexportMatch?.[1]\n ?.split(',')\n .filter(param => param !== '' && param !== 'default')\n // Sanitize, as code could be injected with another rollup plugin\n .map((str: string) => str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')) || [];\n\n return { wrap, reexport };\n}\n\n/**\n * Constructs a comma-separated string with all functions that need to be re-exported later from the server entry.\n * It uses Rollup's `exportedBindings` to determine the functions to re-export. Functions which should be wrapped\n * (e.g. serverless handlers) are wrapped by Sentry.\n */\nexport function constructWrappedFunctionExportQuery(\n exportedBindings: Record<string, string[]> | null,\n entrypointWrappedFunctions: string[],\n debug?: boolean,\n): string {\n const functionsToExport: { wrap: string[]; reexport: string[] } = {\n wrap: [],\n reexport: [],\n };\n\n // `exportedBindings` can look like this: `{ '.': [ 'handler' ] }` or `{ '.': [], './firebase-gen-1.mjs': [ 'server' ] }`\n // The key `.` refers to exports within the current file, while other keys show from where exports were imported first.\n Object.values(exportedBindings || {}).forEach(functions =>\n functions.forEach(fn => {\n if (entrypointWrappedFunctions.includes(fn)) {\n functionsToExport.wrap.push(fn);\n } else {\n functionsToExport.reexport.push(fn);\n }\n }),\n );\n\n if (debug && functionsToExport.wrap.length === 0) {\n consoleSandbox(() =>\n // eslint-disable-next-line no-console\n console.warn(\n \"[Sentry] No functions found to wrap. In case the server needs to export async functions other than `handler` or `server`, consider adding the name(s) to Sentry's build options `sentry.experimental_entrypointWrappedFunctions` in `nuxt.config.ts`.\",\n ),\n );\n }\n\n const wrapQuery = functionsToExport.wrap.length\n ? `${SENTRY_WRAPPED_FUNCTIONS}${functionsToExport.wrap.join(',')}`\n : '';\n const reexportQuery = functionsToExport.reexport.length\n ? `${SENTRY_REEXPORTED_FUNCTIONS}${functionsToExport.reexport.join(',')}`\n : '';\n\n return [wrapQuery, reexportQuery].join('');\n}\n\n/**\n * Constructs a code snippet with function reexports (can be used in Rollup plugins as a return value for `load()`)\n */\nexport function constructFunctionReExport(pathWithQuery: string, entryId: string): string {\n const { wrap: wrapFunctions, reexport: reexportFunctions } = extractFunctionReexportQueryParameters(pathWithQuery);\n\n return wrapFunctions\n .reduce(\n (functionsCode, currFunctionName) =>\n functionsCode.concat(\n `async function ${currFunctionName}_sentryWrapped(...args) {\\n` +\n ` const res = await import(${JSON.stringify(entryId)});\\n` +\n ` return res.${currFunctionName}.call(this, ...args);\\n` +\n '}\\n' +\n `export { ${currFunctionName}_sentryWrapped as ${currFunctionName} };\\n`,\n ),\n '',\n )\n .concat(\n reexportFunctions.reduce(\n (functionsCode, currFunctionName) =>\n functionsCode.concat(`export { ${currFunctionName} } from ${JSON.stringify(entryId)};`),\n '',\n ),\n );\n}\n\n/**\n * Sets up alias to work around OpenTelemetry's incomplete ESM imports.\n * https://github.com/getsentry/sentry-javascript/issues/15204\n *\n * OpenTelemetry's @opentelemetry/resources package has incomplete imports missing\n * the .js file extensions (like execAsync for machine-id detection). This causes module resolution\n * errors in certain Nuxt configurations, particularly when local Nuxt modules in Nuxt 4 are present.\n *\n * @see https://nuxt.com/docs/guide/concepts/esm#aliasing-libraries\n */\nexport function addOTelCommonJSImportAlias(nuxt: Nuxt): void {\n if (!nuxt.options.dev) {\n return;\n }\n\n if (!nuxt.options.alias) {\n nuxt.options.alias = {};\n }\n\n if (!nuxt.options.alias['@opentelemetry/resources']) {\n nuxt.options.alias['@op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MAAA,EAAA;AACA;AACA,KAAA,MAAA;AACA,MAAA,iBAAA,CAAA,MAAA;AACA,QAAA,CAAA,aAAA,EAAA,gBAAA;AACA,UAAA,aAAA,CAAA,MAAA,CAAA,CAAA,SAAA,EAAA,gBAAA,CAAA,QAAA,EAAA,IAAA,CAAA,SAAA,CAAA,OAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AACA,QAAA,EAAA;AACA,OAAA;AACA,KAAA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,0BAAA,CAAA,IAAA,EAAA;AACA,EAAA,IAAA,CAAA,IAAA,CAAA,OAAA,CAAA,GAAA,EAAA;AACA,IAAA;AACA;;AAEA,EAAA,IAAA,CAAA,IAAA,CAAA,OAAA,CAAA,KAAA,EAAA;AACA,IAAA,IAAA,CAAA,OAAA,CAAA,KAAA,GAAA,EAAA;AACA;;AAEA,EAAA,IAAA,CAAA,IAAA,CAAA,OAAA,CAAA,KAAA,CAAA,0BAAA,CAAA,EAAA;AACA,IAAA,IAAA,CAAA,OAAA,CAAA,KAAA,CAAA,0BAAA,CAAA,GAAA,6CAAA;AACA;AACA;;;;"}
|
package/build/module/module.json
CHANGED
package/build/module/module.mjs
CHANGED
|
@@ -109,10 +109,15 @@ export { ${currFunctionName}_sentryWrapped as ${currFunctionName} };
|
|
|
109
109
|
);
|
|
110
110
|
}
|
|
111
111
|
function addOTelCommonJSImportAlias(nuxt) {
|
|
112
|
+
if (!nuxt.options.dev) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
112
115
|
if (!nuxt.options.alias) {
|
|
113
116
|
nuxt.options.alias = {};
|
|
114
117
|
}
|
|
115
|
-
nuxt.options.alias["@opentelemetry/resources"]
|
|
118
|
+
if (!nuxt.options.alias["@opentelemetry/resources"]) {
|
|
119
|
+
nuxt.options.alias["@opentelemetry/resources"] = "@opentelemetry/resources/build/src/index.js";
|
|
120
|
+
}
|
|
116
121
|
}
|
|
117
122
|
|
|
118
123
|
const SERVER_CONFIG_FILENAME = "sentry.server.config";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { captureException, getClient, getCurrentScope } from "@sentry/core";
|
|
2
|
+
import { H3Error } from "h3";
|
|
3
|
+
import { extractErrorContext, flushIfServerless } from "../utils.js";
|
|
4
|
+
export async function sentryCaptureErrorHook(error, errorContext) {
|
|
5
|
+
const sentryClient = getClient();
|
|
6
|
+
const sentryClientOptions = sentryClient?.getOptions();
|
|
7
|
+
if (sentryClientOptions && "enableNitroErrorHandler" in sentryClientOptions && sentryClientOptions.enableNitroErrorHandler === false) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (error instanceof H3Error) {
|
|
11
|
+
if (error.statusCode >= 300 && error.statusCode < 500) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const { method, path } = {
|
|
16
|
+
method: errorContext.event?._method ? errorContext.event._method : "",
|
|
17
|
+
path: errorContext.event?._path ? errorContext.event._path : null
|
|
18
|
+
};
|
|
19
|
+
if (path) {
|
|
20
|
+
getCurrentScope().setTransactionName(`${method} ${path}`);
|
|
21
|
+
}
|
|
22
|
+
const structuredContext = extractErrorContext(errorContext);
|
|
23
|
+
captureException(error, {
|
|
24
|
+
captureContext: { contexts: { nuxt: structuredContext } },
|
|
25
|
+
mechanism: { handled: false }
|
|
26
|
+
});
|
|
27
|
+
await flushIfServerless();
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { sentryCloudflareNitroPlugin } from './sentry-cloudflare.server.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { sentryCloudflareNitroPlugin } from "./sentry-cloudflare.server.js";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { CloudflareOptions } from '@sentry/cloudflare';
|
|
2
|
+
import type { NitroApp, NitroAppPlugin } from 'nitropack';
|
|
3
|
+
/**
|
|
4
|
+
* Sentry Cloudflare Nitro plugin for when using the "cloudflare-pages" preset in Nuxt.
|
|
5
|
+
* This plugin automatically sets up Sentry error monitoring and performance tracking for Cloudflare Pages projects.
|
|
6
|
+
*
|
|
7
|
+
* Instead of adding a `sentry.server.config.ts` file, export this plugin in the `server/plugins` directory
|
|
8
|
+
* with the necessary Sentry options to enable Sentry for your Cloudflare Pages project.
|
|
9
|
+
*
|
|
10
|
+
*
|
|
11
|
+
* @example Basic usage
|
|
12
|
+
* ```ts
|
|
13
|
+
* // nitro/plugins/sentry.ts
|
|
14
|
+
* import { defineNitroPlugin } from '#imports'
|
|
15
|
+
* import { sentryCloudflareNitroPlugin } from '@sentry/nuxt/module/plugins'
|
|
16
|
+
*
|
|
17
|
+
* export default defineNitroPlugin(sentryCloudflareNitroPlugin({
|
|
18
|
+
* dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0',
|
|
19
|
+
* tracesSampleRate: 1.0,
|
|
20
|
+
* }));
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @example Dynamic configuration with nitroApp
|
|
24
|
+
* ```ts
|
|
25
|
+
* // nitro/plugins/sentry.ts
|
|
26
|
+
* import { defineNitroPlugin } from '#imports'
|
|
27
|
+
* import { sentryCloudflareNitroPlugin } from '@sentry/nuxt/module/plugins'
|
|
28
|
+
*
|
|
29
|
+
* export default defineNitroPlugin(sentryCloudflareNitroPlugin(nitroApp => ({
|
|
30
|
+
* dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0',
|
|
31
|
+
* debug: nitroApp.h3App.options.debug
|
|
32
|
+
* })));
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare const sentryCloudflareNitroPlugin: (optionsOrFn: CloudflareOptions | ((nitroApp: NitroApp) => CloudflareOptions)) => NitroAppPlugin;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { setAsyncLocalStorageAsyncContextStrategy, wrapRequestHandler } from "@sentry/cloudflare";
|
|
2
|
+
import { getDefaultIsolationScope, getIsolationScope, getTraceData, logger } from "@sentry/core";
|
|
3
|
+
import { sentryCaptureErrorHook } from "../hooks/captureErrorHook.js";
|
|
4
|
+
import { addSentryTracingMetaTags } from "../utils.js";
|
|
5
|
+
function isEventType(event) {
|
|
6
|
+
if (event === null || typeof event !== "object") return false;
|
|
7
|
+
return (
|
|
8
|
+
// basic properties
|
|
9
|
+
"protocol" in event && "host" in event && typeof event.protocol === "string" && typeof event.host === "string" && // context property
|
|
10
|
+
"context" in event && typeof event.context === "object" && event.context !== null && // context.cf properties
|
|
11
|
+
"cf" in event.context && typeof event.context.cf === "object" && event.context.cf !== null && // context.cloudflare properties
|
|
12
|
+
"cloudflare" in event.context && typeof event.context.cloudflare === "object" && event.context.cloudflare !== null && "context" in event.context.cloudflare
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
export const sentryCloudflareNitroPlugin = (optionsOrFn) => (nitroApp) => {
|
|
16
|
+
const traceDataMap = /* @__PURE__ */ new WeakMap();
|
|
17
|
+
nitroApp.localFetch = new Proxy(nitroApp.localFetch, {
|
|
18
|
+
async apply(handlerTarget, handlerThisArg, handlerArgs) {
|
|
19
|
+
setAsyncLocalStorageAsyncContextStrategy();
|
|
20
|
+
const cloudflareOptions = typeof optionsOrFn === "function" ? optionsOrFn(nitroApp) : optionsOrFn;
|
|
21
|
+
const pathname = handlerArgs[0];
|
|
22
|
+
const event = handlerArgs[1];
|
|
23
|
+
if (!isEventType(event)) {
|
|
24
|
+
logger.log("Nitro Cloudflare plugin did not detect a Cloudflare event type. Won't patch Cloudflare handler.");
|
|
25
|
+
return handlerTarget.apply(handlerThisArg, handlerArgs);
|
|
26
|
+
} else {
|
|
27
|
+
const url = `${event.protocol}${event.protocol.endsWith(":") ? "" : ":"}//${event.host}${pathname}`;
|
|
28
|
+
const request = new Request(url, {
|
|
29
|
+
method: event.method,
|
|
30
|
+
headers: event.headers,
|
|
31
|
+
cf: event.context.cf
|
|
32
|
+
});
|
|
33
|
+
const requestHandlerOptions = {
|
|
34
|
+
options: cloudflareOptions,
|
|
35
|
+
request,
|
|
36
|
+
context: event.context.cloudflare.context
|
|
37
|
+
};
|
|
38
|
+
return wrapRequestHandler(requestHandlerOptions, () => {
|
|
39
|
+
const isolationScope = getIsolationScope();
|
|
40
|
+
const newIsolationScope = isolationScope === getDefaultIsolationScope() ? isolationScope.clone() : isolationScope;
|
|
41
|
+
const traceData = getTraceData();
|
|
42
|
+
if (traceData && Object.keys(traceData).length > 0) {
|
|
43
|
+
traceDataMap.set(event.context.cf, traceData);
|
|
44
|
+
logger.log("Stored trace data for later use in HTML meta-tags: ", traceData);
|
|
45
|
+
}
|
|
46
|
+
logger.log(
|
|
47
|
+
`Patched Cloudflare handler (\`nitroApp.localFetch\`). ${isolationScope === newIsolationScope ? "Using existing" : "Created new"} isolation scope.`
|
|
48
|
+
);
|
|
49
|
+
return handlerTarget.apply(handlerThisArg, handlerArgs);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
nitroApp.hooks.hook("render:html", (html, { event }) => {
|
|
55
|
+
const storedTraceData = event?.context?.cf ? traceDataMap.get(event.context.cf) : void 0;
|
|
56
|
+
if (storedTraceData && Object.keys(storedTraceData).length > 0) {
|
|
57
|
+
logger.log("Using stored trace data for HTML meta-tags: ", storedTraceData);
|
|
58
|
+
addSentryTracingMetaTags(html.head, storedTraceData);
|
|
59
|
+
} else {
|
|
60
|
+
addSentryTracingMetaTags(html.head);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
nitroApp.hooks.hook("error", sentryCaptureErrorHook);
|
|
64
|
+
};
|
|
@@ -1,68 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
flush,
|
|
3
|
-
getDefaultIsolationScope,
|
|
4
|
-
getIsolationScope,
|
|
5
|
-
GLOBAL_OBJ,
|
|
6
|
-
logger,
|
|
7
|
-
vercelWaitUntil,
|
|
8
|
-
withIsolationScope
|
|
9
|
-
} from "@sentry/core";
|
|
10
|
-
import * as SentryNode from "@sentry/node";
|
|
11
|
-
import { H3Error } from "h3";
|
|
1
|
+
import { getDefaultIsolationScope, getIsolationScope, logger, withIsolationScope } from "@sentry/core";
|
|
12
2
|
import { defineNitroPlugin } from "nitropack/runtime";
|
|
13
|
-
import {
|
|
3
|
+
import { sentryCaptureErrorHook } from "../hooks/captureErrorHook.js";
|
|
4
|
+
import { addSentryTracingMetaTags, flushIfServerless } from "../utils.js";
|
|
14
5
|
export default defineNitroPlugin((nitroApp) => {
|
|
15
6
|
nitroApp.h3App.handler = patchEventHandler(nitroApp.h3App.handler);
|
|
16
|
-
nitroApp.hooks.hook("error",
|
|
17
|
-
const sentryClient = SentryNode.getClient();
|
|
18
|
-
const sentryClientOptions = sentryClient?.getOptions();
|
|
19
|
-
if (sentryClientOptions && "enableNitroErrorHandler" in sentryClientOptions && sentryClientOptions.enableNitroErrorHandler === false) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (error instanceof H3Error) {
|
|
23
|
-
if (error.statusCode >= 300 && error.statusCode < 500) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
const { method, path } = {
|
|
28
|
-
method: errorContext.event?._method ? errorContext.event._method : "",
|
|
29
|
-
path: errorContext.event?._path ? errorContext.event._path : null
|
|
30
|
-
};
|
|
31
|
-
if (path) {
|
|
32
|
-
SentryNode.getCurrentScope().setTransactionName(`${method} ${path}`);
|
|
33
|
-
}
|
|
34
|
-
const structuredContext = extractErrorContext(errorContext);
|
|
35
|
-
SentryNode.captureException(error, {
|
|
36
|
-
captureContext: { contexts: { nuxt: structuredContext } },
|
|
37
|
-
mechanism: { handled: false }
|
|
38
|
-
});
|
|
39
|
-
await flushIfServerless();
|
|
40
|
-
});
|
|
7
|
+
nitroApp.hooks.hook("error", sentryCaptureErrorHook);
|
|
41
8
|
nitroApp.hooks.hook("render:html", (html) => {
|
|
42
9
|
addSentryTracingMetaTags(html.head);
|
|
43
10
|
});
|
|
44
11
|
});
|
|
45
|
-
async function flushIfServerless() {
|
|
46
|
-
const isServerless = !!process.env.FUNCTIONS_WORKER_RUNTIME || // Azure Functions
|
|
47
|
-
!!process.env.LAMBDA_TASK_ROOT || // AWS Lambda
|
|
48
|
-
!!process.env.VERCEL || !!process.env.NETLIFY;
|
|
49
|
-
if (GLOBAL_OBJ[Symbol.for("@vercel/request-context")]) {
|
|
50
|
-
vercelWaitUntil(flushWithTimeout());
|
|
51
|
-
} else if (isServerless) {
|
|
52
|
-
await flushWithTimeout();
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
async function flushWithTimeout() {
|
|
56
|
-
const sentryClient = SentryNode.getClient();
|
|
57
|
-
const isDebug = sentryClient ? sentryClient.getOptions().debug : false;
|
|
58
|
-
try {
|
|
59
|
-
isDebug && logger.log("Flushing events...");
|
|
60
|
-
await flush(2e3);
|
|
61
|
-
isDebug && logger.log("Done flushing events");
|
|
62
|
-
} catch (e) {
|
|
63
|
-
isDebug && logger.log("Error while flushing events:\n", e);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
12
|
function patchEventHandler(handler) {
|
|
67
13
|
return new Proxy(handler, {
|
|
68
14
|
async apply(handlerTarget, handlerThisArg, handlerArgs) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Context } from '@sentry/core';
|
|
1
|
+
import type { Context, SerializedTraceData } from '@sentry/core';
|
|
2
2
|
import type { CapturedErrorContext } from 'nitropack';
|
|
3
3
|
import type { NuxtRenderHTMLContext } from 'nuxt/app';
|
|
4
4
|
import type { ComponentPublicInstance } from 'vue';
|
|
@@ -12,7 +12,7 @@ export declare function extractErrorContext(errorContext: CapturedErrorContext |
|
|
|
12
12
|
*
|
|
13
13
|
* Exported only for testing
|
|
14
14
|
*/
|
|
15
|
-
export declare function addSentryTracingMetaTags(head: NuxtRenderHTMLContext['head']): void;
|
|
15
|
+
export declare function addSentryTracingMetaTags(head: NuxtRenderHTMLContext['head'], traceData?: SerializedTraceData): void;
|
|
16
16
|
/**
|
|
17
17
|
* Reports an error to Sentry. This function is similar to `attachErrorHandler` in `@sentry/vue`.
|
|
18
18
|
* The Nuxt SDK does not register an error handler, but uses the Nuxt error hooks to report errors.
|
|
@@ -24,3 +24,7 @@ export declare function reportNuxtError(options: {
|
|
|
24
24
|
instance?: ComponentPublicInstance | null;
|
|
25
25
|
info?: string;
|
|
26
26
|
}): void;
|
|
27
|
+
/**
|
|
28
|
+
* Flushes if in a serverless environment
|
|
29
|
+
*/
|
|
30
|
+
export declare function flushIfServerless(): Promise<void>;
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
captureException,
|
|
3
|
+
flush,
|
|
4
|
+
getClient,
|
|
5
|
+
getTraceMetaTags,
|
|
6
|
+
GLOBAL_OBJ,
|
|
7
|
+
logger,
|
|
8
|
+
vercelWaitUntil
|
|
9
|
+
} from "@sentry/core";
|
|
2
10
|
export function extractErrorContext(errorContext) {
|
|
3
11
|
const ctx = {};
|
|
4
12
|
if (!errorContext) {
|
|
@@ -13,8 +21,14 @@ export function extractErrorContext(errorContext) {
|
|
|
13
21
|
}
|
|
14
22
|
return ctx;
|
|
15
23
|
}
|
|
16
|
-
export function addSentryTracingMetaTags(head) {
|
|
17
|
-
const metaTags = getTraceMetaTags();
|
|
24
|
+
export function addSentryTracingMetaTags(head, traceData) {
|
|
25
|
+
const metaTags = getTraceMetaTags(traceData);
|
|
26
|
+
if (head.some((tag) => tag.includes("meta") && tag.includes("sentry-trace"))) {
|
|
27
|
+
logger.warn(
|
|
28
|
+
"Skipping addition of meta tags. Sentry tracing meta tags are already present in HTML page. Make sure to only set up Sentry once on the server-side. "
|
|
29
|
+
);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
18
32
|
if (metaTags) {
|
|
19
33
|
logger.log("Adding Sentry tracing meta tags to HTML page:", metaTags);
|
|
20
34
|
head.push(metaTags);
|
|
@@ -40,3 +54,23 @@ export function reportNuxtError(options) {
|
|
|
40
54
|
});
|
|
41
55
|
});
|
|
42
56
|
}
|
|
57
|
+
async function flushWithTimeout() {
|
|
58
|
+
try {
|
|
59
|
+
logger.log("Flushing events...");
|
|
60
|
+
await flush(2e3);
|
|
61
|
+
logger.log("Done flushing events");
|
|
62
|
+
} catch (e) {
|
|
63
|
+
logger.log("Error while flushing events:\n", e);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export async function flushIfServerless() {
|
|
67
|
+
const isServerless = !!process.env.FUNCTIONS_WORKER_RUNTIME || // Azure Functions
|
|
68
|
+
!!process.env.LAMBDA_TASK_ROOT || // AWS Lambda
|
|
69
|
+
!!process.env.CF_PAGES || // Cloudflare
|
|
70
|
+
!!process.env.VERCEL || !!process.env.NETLIFY;
|
|
71
|
+
if (GLOBAL_OBJ[Symbol.for("@vercel/request-context")]) {
|
|
72
|
+
vercelWaitUntil(flushWithTimeout());
|
|
73
|
+
} else if (isServerless) {
|
|
74
|
+
await flushWithTimeout();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CapturedErrorContext } from 'nitropack';
|
|
2
|
+
/**
|
|
3
|
+
* Hook that can be added in a Nitro plugin. It captures an error and sends it to Sentry.
|
|
4
|
+
*/
|
|
5
|
+
export declare function sentryCaptureErrorHook(error: Error, errorContext: CapturedErrorContext): Promise<void>;
|
|
6
|
+
//# sourceMappingURL=captureErrorHook.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"captureErrorHook.d.ts","sourceRoot":"","sources":["../../../../src/runtime/hooks/captureErrorHook.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAGtD;;GAEG;AACH,wBAAsB,sBAAsB,CAAC,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAqC5G"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/runtime/plugins/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { CloudflareOptions } from '@sentry/cloudflare';
|
|
2
|
+
import type { NitroApp, NitroAppPlugin } from 'nitropack';
|
|
3
|
+
/**
|
|
4
|
+
* Sentry Cloudflare Nitro plugin for when using the "cloudflare-pages" preset in Nuxt.
|
|
5
|
+
* This plugin automatically sets up Sentry error monitoring and performance tracking for Cloudflare Pages projects.
|
|
6
|
+
*
|
|
7
|
+
* Instead of adding a `sentry.server.config.ts` file, export this plugin in the `server/plugins` directory
|
|
8
|
+
* with the necessary Sentry options to enable Sentry for your Cloudflare Pages project.
|
|
9
|
+
*
|
|
10
|
+
*
|
|
11
|
+
* @example Basic usage
|
|
12
|
+
* ```ts
|
|
13
|
+
* // nitro/plugins/sentry.ts
|
|
14
|
+
* import { defineNitroPlugin } from '#imports'
|
|
15
|
+
* import { sentryCloudflareNitroPlugin } from '@sentry/nuxt/module/plugins'
|
|
16
|
+
*
|
|
17
|
+
* export default defineNitroPlugin(sentryCloudflareNitroPlugin({
|
|
18
|
+
* dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0',
|
|
19
|
+
* tracesSampleRate: 1.0,
|
|
20
|
+
* }));
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @example Dynamic configuration with nitroApp
|
|
24
|
+
* ```ts
|
|
25
|
+
* // nitro/plugins/sentry.ts
|
|
26
|
+
* import { defineNitroPlugin } from '#imports'
|
|
27
|
+
* import { sentryCloudflareNitroPlugin } from '@sentry/nuxt/module/plugins'
|
|
28
|
+
*
|
|
29
|
+
* export default defineNitroPlugin(sentryCloudflareNitroPlugin(nitroApp => ({
|
|
30
|
+
* dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0',
|
|
31
|
+
* debug: nitroApp.h3App.options.debug
|
|
32
|
+
* })));
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare const sentryCloudflareNitroPlugin: (optionsOrFn: CloudflareOptions | ((nitroApp: NitroApp) => CloudflareOptions)) => NitroAppPlugin;
|
|
36
|
+
//# sourceMappingURL=sentry-cloudflare.server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sentry-cloudflare.server.d.ts","sourceRoot":"","sources":["../../../../src/runtime/plugins/sentry-cloudflare.server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAI5D,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAiD1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,2BAA2B,gDACQ,QAAQ,KAAK,iBAAiB,MAAI,cAmE/E,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentry.server.d.ts","sourceRoot":"","sources":["../../../../src/runtime/plugins/sentry.server.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"sentry.server.d.ts","sourceRoot":"","sources":["../../../../src/runtime/plugins/sentry.server.ts"],"names":[],"mappings":";AASA,wBASG"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Context } from '@sentry/core';
|
|
1
|
+
import type { Context, SerializedTraceData } from '@sentry/core';
|
|
2
2
|
import type { CapturedErrorContext } from 'nitropack';
|
|
3
3
|
import type { NuxtRenderHTMLContext } from 'nuxt/app';
|
|
4
4
|
import type { ComponentPublicInstance } from 'vue';
|
|
@@ -12,7 +12,7 @@ export declare function extractErrorContext(errorContext: CapturedErrorContext |
|
|
|
12
12
|
*
|
|
13
13
|
* Exported only for testing
|
|
14
14
|
*/
|
|
15
|
-
export declare function addSentryTracingMetaTags(head: NuxtRenderHTMLContext['head']): void;
|
|
15
|
+
export declare function addSentryTracingMetaTags(head: NuxtRenderHTMLContext['head'], traceData?: SerializedTraceData): void;
|
|
16
16
|
/**
|
|
17
17
|
* Reports an error to Sentry. This function is similar to `attachErrorHandler` in `@sentry/vue`.
|
|
18
18
|
* The Nuxt SDK does not register an error handler, but uses the Nuxt error hooks to report errors.
|
|
@@ -24,4 +24,8 @@ export declare function reportNuxtError(options: {
|
|
|
24
24
|
instance?: ComponentPublicInstance | null;
|
|
25
25
|
info?: string;
|
|
26
26
|
}): void;
|
|
27
|
+
/**
|
|
28
|
+
* Flushes if in a serverless environment
|
|
29
|
+
*/
|
|
30
|
+
export declare function flushIfServerless(): Promise<void>;
|
|
27
31
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/runtime/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,OAAO,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/runtime/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAWhF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,KAAK,CAAC;AAEnD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,oBAAoB,GAAG,SAAS,GAAG,OAAO,CAiB3F;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,qBAAqB,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAcnH;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE;IACvC,KAAK,EAAE,OAAO,C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,IAAI,GAAG,IAAI,CAY3D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentry/nuxt",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.34.0",
|
|
4
4
|
"description": "Official Sentry SDK for Nuxt (EXPERIMENTAL)",
|
|
5
5
|
"repository": "git://github.com/getsentry/sentry-javascript.git",
|
|
6
6
|
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/nuxt",
|
|
@@ -33,6 +33,10 @@
|
|
|
33
33
|
"types": "./build/module/types.d.ts",
|
|
34
34
|
"import": "./build/module/module.mjs",
|
|
35
35
|
"require": "./build/module/module.cjs"
|
|
36
|
+
},
|
|
37
|
+
"./module/plugins": {
|
|
38
|
+
"types": "./build/module/runtime/plugins/index.d.ts",
|
|
39
|
+
"import": "./build/module/runtime/plugins/index.js"
|
|
36
40
|
}
|
|
37
41
|
},
|
|
38
42
|
"publishConfig": {
|
|
@@ -43,12 +47,13 @@
|
|
|
43
47
|
},
|
|
44
48
|
"dependencies": {
|
|
45
49
|
"@nuxt/kit": "^3.13.2",
|
|
46
|
-
"@sentry/browser": "9.
|
|
47
|
-
"@sentry/
|
|
48
|
-
"@sentry/
|
|
50
|
+
"@sentry/browser": "9.34.0",
|
|
51
|
+
"@sentry/cloudflare": "9.34.0",
|
|
52
|
+
"@sentry/core": "9.34.0",
|
|
53
|
+
"@sentry/node": "9.34.0",
|
|
49
54
|
"@sentry/rollup-plugin": "^3.5.0",
|
|
50
55
|
"@sentry/vite-plugin": "^3.5.0",
|
|
51
|
-
"@sentry/vue": "9.
|
|
56
|
+
"@sentry/vue": "9.34.0"
|
|
52
57
|
},
|
|
53
58
|
"devDependencies": {
|
|
54
59
|
"@nuxt/module-builder": "^0.8.4",
|