@sentry/wizard 3.42.1 → 4.0.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/.node-cache/node-v22.14.0-darwin-arm64 +0 -0
- package/.node-cache/node-v22.14.0-darwin-x64 +0 -0
- package/.node-cache/node-v22.14.0-linux-arm64 +0 -0
- package/.node-cache/node-v22.14.0-linux-x64 +0 -0
- package/.node-cache/node-v22.14.0-win-x64.exe +0 -0
- package/CHANGELOG.md +26 -0
- package/COPYING +3575 -0
- package/bin.ts +85 -80
- package/dist/bin.js +44 -35
- package/dist/bin.js.map +1 -1
- package/dist/e2e-tests/jest.config.js +1 -1
- package/dist/e2e-tests/jest.config.js.map +1 -1
- package/dist/e2e-tests/tests/flutter.test.js +62 -147
- package/dist/e2e-tests/tests/flutter.test.js.map +1 -1
- package/dist/e2e-tests/tests/nextjs.test.js +77 -175
- package/dist/e2e-tests/tests/nextjs.test.js.map +1 -1
- package/dist/e2e-tests/tests/nuxt-3.test.js +61 -162
- package/dist/e2e-tests/tests/nuxt-3.test.js.map +1 -1
- package/dist/e2e-tests/tests/nuxt-4.test.js +62 -163
- package/dist/e2e-tests/tests/nuxt-4.test.js.map +1 -1
- package/dist/e2e-tests/tests/remix.test.js +147 -189
- package/dist/e2e-tests/tests/remix.test.js.map +1 -1
- package/dist/e2e-tests/tests/sveltekit.test.js +133 -187
- package/dist/e2e-tests/tests/sveltekit.test.js.map +1 -1
- package/dist/e2e-tests/utils/index.d.ts +1 -1
- package/dist/e2e-tests/utils/index.js +113 -195
- package/dist/e2e-tests/utils/index.js.map +1 -1
- package/dist/lib/Constants.js +5 -5
- package/dist/lib/Constants.js.map +1 -1
- package/dist/lib/Helper/BottomBar.d.ts +1 -1
- package/dist/lib/Helper/BottomBar.js +14 -15
- package/dist/lib/Helper/BottomBar.js.map +1 -1
- package/dist/lib/Helper/Env.js +5 -2
- package/dist/lib/Helper/Env.js.map +1 -1
- package/dist/lib/Helper/File.js +14 -27
- package/dist/lib/Helper/File.js.map +1 -1
- package/dist/lib/Helper/Git.js +24 -59
- package/dist/lib/Helper/Git.js.map +1 -1
- package/dist/lib/Helper/Logging.js +2 -2
- package/dist/lib/Helper/Logging.js.map +1 -1
- package/dist/lib/Helper/MergeConfig.js +4 -4
- package/dist/lib/Helper/MergeConfig.js.map +1 -1
- package/dist/lib/Helper/Package.d.ts +4 -1
- package/dist/lib/Helper/Package.js +12 -38
- package/dist/lib/Helper/Package.js.map +1 -1
- package/dist/lib/Helper/SentryCli.js +77 -149
- package/dist/lib/Helper/SentryCli.js.map +1 -1
- package/dist/lib/Helper/Wizard.js +29 -124
- package/dist/lib/Helper/Wizard.js.map +1 -1
- package/dist/lib/Helper/__tests__/File.js +4 -4
- package/dist/lib/Helper/__tests__/File.js.map +1 -1
- package/dist/lib/Helper/__tests__/MergeConfig.js +24 -24
- package/dist/lib/Helper/__tests__/MergeConfig.js.map +1 -1
- package/dist/lib/Helper/__tests__/SentryCli.js +33 -23
- package/dist/lib/Helper/__tests__/SentryCli.js.map +1 -1
- package/dist/lib/Setup.js +23 -85
- package/dist/lib/Setup.js.map +1 -1
- package/dist/lib/Steps/BaseStep.js +8 -8
- package/dist/lib/Steps/BaseStep.js.map +1 -1
- package/dist/lib/Steps/ChooseIntegration.js +80 -125
- package/dist/lib/Steps/ChooseIntegration.js.map +1 -1
- package/dist/lib/Steps/ConfigureProject.js +6 -66
- package/dist/lib/Steps/ConfigureProject.js.map +1 -1
- package/dist/lib/Steps/Initial.js +16 -104
- package/dist/lib/Steps/Initial.js.map +1 -1
- package/dist/lib/Steps/Integrations/BaseIntegration.js +24 -118
- package/dist/lib/Steps/Integrations/BaseIntegration.js.map +1 -1
- package/dist/lib/Steps/Integrations/Cordova.js +95 -183
- package/dist/lib/Steps/Integrations/Cordova.js.map +1 -1
- package/dist/lib/Steps/Integrations/Electron.js +87 -145
- package/dist/lib/Steps/Integrations/Electron.js.map +1 -1
- package/dist/lib/Steps/Integrations/MobileProject.js +40 -148
- package/dist/lib/Steps/Integrations/MobileProject.js.map +1 -1
- package/dist/lib/Steps/OpenSentry.js +63 -126
- package/dist/lib/Steps/OpenSentry.js.map +1 -1
- package/dist/lib/Steps/PromptForParameters.js +110 -206
- package/dist/lib/Steps/PromptForParameters.js.map +1 -1
- package/dist/lib/Steps/Result.js +19 -79
- package/dist/lib/Steps/Result.js.map +1 -1
- package/dist/lib/Steps/SentryProjectSelector.js +57 -148
- package/dist/lib/Steps/SentryProjectSelector.js.map +1 -1
- package/dist/lib/Steps/ShouldConfigure.js +6 -66
- package/dist/lib/Steps/ShouldConfigure.js.map +1 -1
- package/dist/lib/Steps/WaitForSentry.js +43 -120
- package/dist/lib/Steps/WaitForSentry.js.map +1 -1
- package/dist/lib/Steps/Welcome.js +17 -76
- package/dist/lib/Steps/Welcome.js.map +1 -1
- package/dist/lib/__tests__/Env.js +3 -3
- package/dist/lib/__tests__/Env.js.map +1 -1
- package/dist/src/android/android-wizard.js +100 -176
- package/dist/src/android/android-wizard.js.map +1 -1
- package/dist/src/android/code-tools.js +24 -33
- package/dist/src/android/code-tools.js.map +1 -1
- package/dist/src/android/gradle.js +106 -165
- package/dist/src/android/gradle.js.map +1 -1
- package/dist/src/android/manifest.js +26 -27
- package/dist/src/android/manifest.js.map +1 -1
- package/dist/src/android/templates.js +76 -23
- package/dist/src/android/templates.js.map +1 -1
- package/dist/src/apple/apple-wizard.js +129 -225
- package/dist/src/apple/apple-wizard.js.map +1 -1
- package/dist/src/apple/cocoapod.js +47 -109
- package/dist/src/apple/cocoapod.js.map +1 -1
- package/dist/src/apple/code-tools.js +32 -35
- package/dist/src/apple/code-tools.js.map +1 -1
- package/dist/src/apple/fastlane.js +51 -97
- package/dist/src/apple/fastlane.js.map +1 -1
- package/dist/src/apple/templates.js +41 -5
- package/dist/src/apple/templates.js.map +1 -1
- package/dist/src/apple/xcode-manager.d.ts +2 -2
- package/dist/src/apple/xcode-manager.js +93 -108
- package/dist/src/apple/xcode-manager.js.map +1 -1
- package/dist/src/flutter/code-tools.js +79 -127
- package/dist/src/flutter/code-tools.js.map +1 -1
- package/dist/src/flutter/flutter-wizard.js +75 -136
- package/dist/src/flutter/flutter-wizard.js.map +1 -1
- package/dist/src/flutter/templates.js +48 -12
- package/dist/src/flutter/templates.js.map +1 -1
- package/dist/src/nextjs/nextjs-wizard.js +527 -805
- package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
- package/dist/src/nextjs/templates.js +380 -40
- package/dist/src/nextjs/templates.js.map +1 -1
- package/dist/src/nextjs/utils.js +5 -5
- package/dist/src/nextjs/utils.js.map +1 -1
- package/dist/src/nuxt/nuxt-wizard.js +91 -188
- package/dist/src/nuxt/nuxt-wizard.js.map +1 -1
- package/dist/src/nuxt/sdk-example.js +68 -137
- package/dist/src/nuxt/sdk-example.js.map +1 -1
- package/dist/src/nuxt/sdk-setup.d.ts +4 -4
- package/dist/src/nuxt/sdk-setup.js +180 -336
- package/dist/src/nuxt/sdk-setup.js.map +1 -1
- package/dist/src/nuxt/templates.js +195 -18
- package/dist/src/nuxt/templates.js.map +1 -1
- package/dist/src/nuxt/utils.js +29 -76
- package/dist/src/nuxt/utils.js.map +1 -1
- package/dist/src/react-native/expo-env-file.js +41 -94
- package/dist/src/react-native/expo-env-file.js.map +1 -1
- package/dist/src/react-native/expo-metro.d.ts +1 -1
- package/dist/src/react-native/expo-metro.js +75 -130
- package/dist/src/react-native/expo-metro.js.map +1 -1
- package/dist/src/react-native/expo.js +61 -114
- package/dist/src/react-native/expo.js.map +1 -1
- package/dist/src/react-native/git.js +23 -56
- package/dist/src/react-native/git.js.map +1 -1
- package/dist/src/react-native/glob.js +3 -3
- package/dist/src/react-native/glob.js.map +1 -1
- package/dist/src/react-native/gradle.js +4 -4
- package/dist/src/react-native/gradle.js.map +1 -1
- package/dist/src/react-native/javascript.js +51 -95
- package/dist/src/react-native/javascript.js.map +1 -1
- package/dist/src/react-native/metro.js +176 -296
- package/dist/src/react-native/metro.js.map +1 -1
- package/dist/src/react-native/react-native-wizard.js +267 -418
- package/dist/src/react-native/react-native-wizard.js.map +1 -1
- package/dist/src/react-native/uninstall.js +37 -80
- package/dist/src/react-native/uninstall.js.map +1 -1
- package/dist/src/react-native/xcode.js +57 -55
- package/dist/src/react-native/xcode.js.map +1 -1
- package/dist/src/remix/codemods/express-server.js +27 -82
- package/dist/src/remix/codemods/express-server.js.map +1 -1
- package/dist/src/remix/codemods/handle-error.js +28 -31
- package/dist/src/remix/codemods/handle-error.js.map +1 -1
- package/dist/src/remix/codemods/root-common.js +11 -11
- package/dist/src/remix/codemods/root-common.js.map +1 -1
- package/dist/src/remix/codemods/root-v1.js +17 -67
- package/dist/src/remix/codemods/root-v1.js.map +1 -1
- package/dist/src/remix/codemods/root-v2.js +89 -140
- package/dist/src/remix/codemods/root-v2.js.map +1 -1
- package/dist/src/remix/remix-wizard.js +181 -343
- package/dist/src/remix/remix-wizard.js.map +1 -1
- package/dist/src/remix/sdk-example.js +84 -66
- package/dist/src/remix/sdk-example.js.map +1 -1
- package/dist/src/remix/sdk-setup.js +161 -293
- package/dist/src/remix/sdk-setup.js.map +1 -1
- package/dist/src/remix/templates.js +10 -2
- package/dist/src/remix/templates.js.map +1 -1
- package/dist/src/remix/utils.js +13 -14
- package/dist/src/remix/utils.js.map +1 -1
- package/dist/src/run.js +106 -178
- package/dist/src/run.js.map +1 -1
- package/dist/src/sourcemaps/sourcemaps-wizard.js +248 -372
- package/dist/src/sourcemaps/sourcemaps-wizard.js.map +1 -1
- package/dist/src/sourcemaps/tools/angular.js +32 -66
- package/dist/src/sourcemaps/tools/angular.js.map +1 -1
- package/dist/src/sourcemaps/tools/create-react-app.js +14 -59
- package/dist/src/sourcemaps/tools/create-react-app.js.map +1 -1
- package/dist/src/sourcemaps/tools/esbuild.js +34 -77
- package/dist/src/sourcemaps/tools/esbuild.js.map +1 -1
- package/dist/src/sourcemaps/tools/nextjs.d.ts +2 -2
- package/dist/src/sourcemaps/tools/nextjs.js +75 -102
- package/dist/src/sourcemaps/tools/nextjs.js.map +1 -1
- package/dist/src/sourcemaps/tools/remix.js +53 -93
- package/dist/src/sourcemaps/tools/remix.js.map +1 -1
- package/dist/src/sourcemaps/tools/rollup.js +35 -76
- package/dist/src/sourcemaps/tools/rollup.js.map +1 -1
- package/dist/src/sourcemaps/tools/sentry-cli.js +157 -289
- package/dist/src/sourcemaps/tools/sentry-cli.js.map +1 -1
- package/dist/src/sourcemaps/tools/tsc.js +68 -134
- package/dist/src/sourcemaps/tools/tsc.js.map +1 -1
- package/dist/src/sourcemaps/tools/vite.js +111 -196
- package/dist/src/sourcemaps/tools/vite.js.map +1 -1
- package/dist/src/sourcemaps/tools/webpack.d.ts +1 -1
- package/dist/src/sourcemaps/tools/webpack.js +158 -260
- package/dist/src/sourcemaps/tools/webpack.js.map +1 -1
- package/dist/src/sourcemaps/utils/detect-tool.js +9 -54
- package/dist/src/sourcemaps/utils/detect-tool.js.map +1 -1
- package/dist/src/sourcemaps/utils/other-wizards.js +77 -144
- package/dist/src/sourcemaps/utils/other-wizards.js.map +1 -1
- package/dist/src/sourcemaps/utils/sdk-version.js +112 -191
- package/dist/src/sourcemaps/utils/sdk-version.js.map +1 -1
- package/dist/src/sveltekit/sdk-example.js +20 -70
- package/dist/src/sveltekit/sdk-example.js.map +1 -1
- package/dist/src/sveltekit/sdk-setup.js +250 -411
- package/dist/src/sveltekit/sdk-setup.js.map +1 -1
- package/dist/src/sveltekit/sveltekit-wizard.js +107 -191
- package/dist/src/sveltekit/sveltekit-wizard.js.map +1 -1
- package/dist/src/sveltekit/templates.js +147 -13
- package/dist/src/sveltekit/templates.js.map +1 -1
- package/dist/src/sveltekit/utils.js +3 -3
- package/dist/src/sveltekit/utils.js.map +1 -1
- package/dist/src/telemetry.d.ts +2 -2
- package/dist/src/telemetry.js +58 -108
- package/dist/src/telemetry.js.map +1 -1
- package/dist/src/utils/ast-utils.js +39 -54
- package/dist/src/utils/ast-utils.js.map +1 -1
- package/dist/src/utils/bash.js +28 -75
- package/dist/src/utils/bash.js.map +1 -1
- package/dist/src/utils/clack-utils.d.ts +3 -7
- package/dist/src/utils/clack-utils.js +688 -1083
- package/dist/src/utils/clack-utils.js.map +1 -1
- package/dist/src/utils/debug.js +6 -10
- package/dist/src/utils/debug.js.map +1 -1
- package/dist/src/utils/package-json.js +5 -6
- package/dist/src/utils/package-json.js.map +1 -1
- package/dist/src/utils/package-manager.js +65 -139
- package/dist/src/utils/package-manager.js.map +1 -1
- package/dist/src/utils/release-registry.js +12 -59
- package/dist/src/utils/release-registry.js.map +1 -1
- package/dist/src/utils/semver.js +3 -4
- package/dist/src/utils/semver.js.map +1 -1
- package/dist/src/utils/sentrycli-utils.js +4 -4
- package/dist/src/utils/sentrycli-utils.js.map +1 -1
- package/dist/src/utils/url.js +5 -6
- package/dist/src/utils/url.js.map +1 -1
- package/dist/test/android/code-tools.test.js +18 -18
- package/dist/test/android/code-tools.test.js.map +1 -1
- package/dist/test/apple/cocoapod.test.js +154 -299
- package/dist/test/apple/cocoapod.test.js.map +1 -1
- package/dist/test/apple/code-tools.test.js +375 -263
- package/dist/test/apple/code-tools.test.js.map +1 -1
- package/dist/test/apple/fastfile.test.js +319 -271
- package/dist/test/apple/fastfile.test.js.map +1 -1
- package/dist/test/apple/templates.test.js +114 -30
- package/dist/test/apple/templates.test.js.map +1 -1
- package/dist/test/apple/xcode-manager.test.js +230 -234
- package/dist/test/apple/xcode-manager.test.js.map +1 -1
- package/dist/test/flutter/code-tools.test.js +119 -48
- package/dist/test/flutter/code-tools.test.js.map +1 -1
- package/dist/test/flutter/templates.test.js +63 -20
- package/dist/test/flutter/templates.test.js.map +1 -1
- package/dist/test/nextjs/templates.test.js +332 -43
- package/dist/test/nextjs/templates.test.js.map +1 -1
- package/dist/test/nuxt/templates.test.js +161 -33
- package/dist/test/nuxt/templates.test.js.map +1 -1
- package/dist/test/react-native/expo-metro.test.js +61 -15
- package/dist/test/react-native/expo-metro.test.js.map +1 -1
- package/dist/test/react-native/expo.test.js +37 -17
- package/dist/test/react-native/expo.test.js.map +1 -1
- package/dist/test/react-native/gradle.test.js +260 -28
- package/dist/test/react-native/gradle.test.js.map +1 -1
- package/dist/test/react-native/javascript.test.js +85 -19
- package/dist/test/react-native/javascript.test.js.map +1 -1
- package/dist/test/react-native/metro.test.js +261 -187
- package/dist/test/react-native/metro.test.js.map +1 -1
- package/dist/test/react-native/xcode.test.js +243 -62
- package/dist/test/react-native/xcode.test.js.map +1 -1
- package/dist/test/remix/client-entry.test.js +81 -21
- package/dist/test/remix/client-entry.test.js.map +1 -1
- package/dist/test/remix/server-instrumentation.test.js +21 -8
- package/dist/test/remix/server-instrumentation.test.js.map +1 -1
- package/dist/test/sourcemaps/tools/sentry-cli.test.js +20 -72
- package/dist/test/sourcemaps/tools/sentry-cli.test.js.map +1 -1
- package/dist/test/sourcemaps/tools/tsc.test.js +142 -68
- package/dist/test/sourcemaps/tools/tsc.test.js.map +1 -1
- package/dist/test/sourcemaps/tools/vite.test.js +106 -75
- package/dist/test/sourcemaps/tools/vite.test.js.map +1 -1
- package/dist/test/sourcemaps/tools/webpack.test.js +226 -102
- package/dist/test/sourcemaps/tools/webpack.test.js.map +1 -1
- package/dist/test/sveltekit/templates.test.js +117 -18
- package/dist/test/sveltekit/templates.test.js.map +1 -1
- package/dist/test/utils/ast-utils.test.js +99 -58
- package/dist/test/utils/ast-utils.test.js.map +1 -1
- package/dist/test/utils/clack-utils.test.js +142 -247
- package/dist/test/utils/clack-utils.test.js.map +1 -1
- package/e2e-tests/package.json +1 -1
- package/e2e-tests/tests/flutter.test.ts +20 -20
- package/e2e-tests/tests/nextjs.test.ts +2 -2
- package/e2e-tests/tests/nuxt-3.test.ts +4 -4
- package/e2e-tests/tests/nuxt-4.test.ts +3 -3
- package/e2e-tests/tests/remix.test.ts +3 -3
- package/e2e-tests/tests/sveltekit.test.ts +3 -3
- package/e2e-tests/utils/index.ts +33 -15
- package/lib/Helper/BottomBar.ts +1 -1
- package/lib/Helper/Env.ts +1 -1
- package/lib/Helper/Package.ts +12 -10
- package/lib/Helper/SentryCli.ts +18 -27
- package/lib/Helper/Wizard.ts +1 -2
- package/lib/Setup.ts +4 -5
- package/lib/Steps/ChooseIntegration.ts +40 -8
- package/lib/Steps/Initial.ts +17 -26
- package/lib/Steps/Integrations/BaseIntegration.ts +2 -8
- package/lib/Steps/Integrations/Cordova.ts +9 -15
- package/lib/Steps/Integrations/Electron.ts +23 -20
- package/lib/Steps/Integrations/MobileProject.ts +18 -15
- package/lib/Steps/OpenSentry.ts +12 -7
- package/lib/Steps/PromptForParameters.ts +12 -19
- package/lib/Steps/SentryProjectSelector.ts +30 -29
- package/lib/Steps/WaitForSentry.ts +29 -23
- package/package.json +12 -8
- package/src/apple/xcode-manager.ts +10 -10
- package/src/nextjs/templates.ts +2 -3
- package/src/nuxt/sdk-setup.ts +21 -18
- package/src/react-native/expo-metro.ts +2 -2
- package/src/react-native/react-native-wizard.ts +1 -2
- package/src/react-native/uninstall.ts +1 -2
- package/src/react-native/xcode.ts +1 -1
- package/src/run.ts +12 -5
- package/src/sourcemaps/tools/nextjs.ts +2 -2
- package/src/sourcemaps/tools/webpack.ts +3 -3
- package/src/telemetry.ts +27 -7
- package/src/utils/clack-utils.ts +50 -47
- package/test/apple/cocoapod.test.ts +4 -0
- package/test/apple/fastfile.test.ts +12 -7
- package/test/apple/xcode-manager.test.ts +13 -11
- package/test/utils/clack-utils.test.ts +40 -50
- package/types/read-env.d.ts +3 -0
- package/types/xcode.d.ts +1 -0
- package/dist/package.json +0 -128
|
@@ -4,115 +4,455 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getGlobalErrorCopyPasteSnippet = exports.getSentryDefaultGlobalErrorPage = exports.getInstrumentationHookCopyPasteSnippet = exports.getInstrumentationHookContent = exports.getFullUnderscoreErrorCopyPasteSnippet = exports.getSimpleUnderscoreErrorCopyPasteSnippet = exports.getSentryDefaultUnderscoreErrorPage = exports.getSentryExampleAppDirApiRoute = exports.getSentryExamplePagesDirApiRoute = exports.getSentryExamplePageContents = exports.getSentryConfigContents = exports.getNextjsConfigEsmCopyPasteSnippet = exports.getNextjsConfigCjsAppendix = exports.getNextjsConfigMjsTemplate = exports.getNextjsConfigCjsTemplate = exports.getWithSentryConfigOptionsTemplate = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function getWithSentryConfigOptionsTemplate(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const clack_utils_1 = require("../utils/clack-utils");
|
|
9
|
+
function getWithSentryConfigOptionsTemplate({ orgSlug, projectSlug, selfHosted, tunnelRoute, reactComponentAnnotation, sentryUrl, }) {
|
|
10
|
+
return `{
|
|
11
|
+
// For all available options, see:
|
|
12
|
+
// https://github.com/getsentry/sentry-webpack-plugin#options
|
|
13
|
+
|
|
14
|
+
org: "${orgSlug}",
|
|
15
|
+
project: "${projectSlug}",${selfHosted ? `\n sentryUrl: "${sentryUrl}",` : ''}
|
|
16
|
+
|
|
17
|
+
// Only print logs for uploading source maps in CI
|
|
18
|
+
silent: !process.env.CI,
|
|
19
|
+
|
|
20
|
+
// For all available options, see:
|
|
21
|
+
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
|
|
22
|
+
|
|
23
|
+
// Upload a larger set of source maps for prettier stack traces (increases build time)
|
|
24
|
+
widenClientFileUpload: true,${reactComponentAnnotation
|
|
25
|
+
? `\n
|
|
26
|
+
// Automatically annotate React components to show their full name in breadcrumbs and session replay
|
|
27
|
+
reactComponentAnnotation: {
|
|
28
|
+
enabled: true,
|
|
29
|
+
},`
|
|
30
|
+
: ''}
|
|
31
|
+
|
|
32
|
+
// ${tunnelRoute ? 'Route' : 'Uncomment to route'} browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
|
|
33
|
+
// This can increase your server load as well as your hosting bill.
|
|
34
|
+
// Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
|
|
35
|
+
// side errors will fail.
|
|
36
|
+
${tunnelRoute ? '' : '// '}tunnelRoute: "/monitoring",
|
|
37
|
+
|
|
38
|
+
// Automatically tree-shake Sentry logger statements to reduce bundle size
|
|
39
|
+
disableLogger: true,
|
|
40
|
+
|
|
41
|
+
// Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)
|
|
42
|
+
// See the following for more information:
|
|
43
|
+
// https://docs.sentry.io/product/crons/
|
|
44
|
+
// https://vercel.com/docs/cron-jobs
|
|
45
|
+
automaticVercelMonitors: true,
|
|
46
|
+
}`;
|
|
14
47
|
}
|
|
15
48
|
exports.getWithSentryConfigOptionsTemplate = getWithSentryConfigOptionsTemplate;
|
|
16
49
|
function getNextjsConfigCjsTemplate(withSentryConfigOptionsTemplate) {
|
|
17
|
-
return
|
|
50
|
+
return `const { withSentryConfig } = require("@sentry/nextjs");
|
|
51
|
+
|
|
52
|
+
/** @type {import('next').NextConfig} */
|
|
53
|
+
const nextConfig = {};
|
|
54
|
+
|
|
55
|
+
module.exports = withSentryConfig(
|
|
56
|
+
nextConfig,
|
|
57
|
+
${withSentryConfigOptionsTemplate}
|
|
58
|
+
);
|
|
59
|
+
`;
|
|
18
60
|
}
|
|
19
61
|
exports.getNextjsConfigCjsTemplate = getNextjsConfigCjsTemplate;
|
|
20
62
|
function getNextjsConfigMjsTemplate(withSentryConfigOptionsTemplate) {
|
|
21
|
-
return
|
|
63
|
+
return `import { withSentryConfig } from "@sentry/nextjs";
|
|
64
|
+
|
|
65
|
+
/** @type {import('next').NextConfig} */
|
|
66
|
+
const nextConfig = {};
|
|
67
|
+
|
|
68
|
+
export default withSentryConfig(
|
|
69
|
+
nextConfig,
|
|
70
|
+
${withSentryConfigOptionsTemplate}
|
|
71
|
+
);
|
|
72
|
+
`;
|
|
22
73
|
}
|
|
23
74
|
exports.getNextjsConfigMjsTemplate = getNextjsConfigMjsTemplate;
|
|
24
75
|
function getNextjsConfigCjsAppendix(withSentryConfigOptionsTemplate) {
|
|
25
|
-
return
|
|
76
|
+
return `
|
|
77
|
+
|
|
78
|
+
// Injected content via Sentry wizard below
|
|
79
|
+
|
|
80
|
+
const { withSentryConfig } = require("@sentry/nextjs");
|
|
81
|
+
|
|
82
|
+
module.exports = withSentryConfig(
|
|
83
|
+
module.exports,
|
|
84
|
+
${withSentryConfigOptionsTemplate}
|
|
85
|
+
);
|
|
86
|
+
`;
|
|
26
87
|
}
|
|
27
88
|
exports.getNextjsConfigCjsAppendix = getNextjsConfigCjsAppendix;
|
|
28
89
|
function getNextjsConfigEsmCopyPasteSnippet(withSentryConfigOptionsTemplate) {
|
|
29
|
-
return
|
|
90
|
+
return `
|
|
91
|
+
|
|
92
|
+
// next.config.mjs
|
|
93
|
+
import { withSentryConfig } from "@sentry/nextjs";
|
|
94
|
+
|
|
95
|
+
export default withSentryConfig(
|
|
96
|
+
yourNextConfig,
|
|
97
|
+
${withSentryConfigOptionsTemplate}
|
|
98
|
+
);
|
|
99
|
+
`;
|
|
30
100
|
}
|
|
31
101
|
exports.getNextjsConfigEsmCopyPasteSnippet = getNextjsConfigEsmCopyPasteSnippet;
|
|
32
102
|
function getClientIntegrationsSnippet(features) {
|
|
33
103
|
if (features.replay) {
|
|
34
|
-
return
|
|
104
|
+
return `
|
|
105
|
+
|
|
106
|
+
// Add optional integrations for additional features
|
|
107
|
+
integrations: [
|
|
108
|
+
Sentry.replayIntegration(),
|
|
109
|
+
],`;
|
|
35
110
|
}
|
|
36
111
|
return '';
|
|
37
112
|
}
|
|
38
113
|
function getSentryConfigContents(dsn, config, selectedFeaturesMap) {
|
|
39
|
-
|
|
114
|
+
let primer;
|
|
40
115
|
if (config === 'server') {
|
|
41
|
-
primer =
|
|
116
|
+
primer = `// This file configures the initialization of Sentry on the server.
|
|
117
|
+
// The config you add here will be used whenever the server handles a request.
|
|
118
|
+
// https://docs.sentry.io/platforms/javascript/guides/nextjs/`;
|
|
42
119
|
}
|
|
43
120
|
else if (config === 'client') {
|
|
44
|
-
primer =
|
|
121
|
+
primer = `// This file configures the initialization of Sentry on the client.
|
|
122
|
+
// The config you add here will be used whenever a users loads a page in their browser.
|
|
123
|
+
// https://docs.sentry.io/platforms/javascript/guides/nextjs/`;
|
|
45
124
|
}
|
|
46
125
|
else if (config === 'edge') {
|
|
47
|
-
primer =
|
|
126
|
+
primer = `// This file configures the initialization of Sentry for edge features (middleware, edge routes, and so on).
|
|
127
|
+
// The config you add here will be used whenever one of the edge features is loaded.
|
|
128
|
+
// Note that this config is unrelated to the Vercel Edge Runtime and is also required when running locally.
|
|
129
|
+
// https://docs.sentry.io/platforms/javascript/guides/nextjs/`;
|
|
48
130
|
}
|
|
49
|
-
|
|
131
|
+
const integrationsOptions = getClientIntegrationsSnippet({
|
|
50
132
|
replay: config === 'client' && selectedFeaturesMap.replay,
|
|
51
133
|
});
|
|
52
|
-
|
|
134
|
+
let replayOptions = '';
|
|
53
135
|
if (config === 'client') {
|
|
54
136
|
if (selectedFeaturesMap.replay) {
|
|
55
|
-
replayOptions +=
|
|
137
|
+
replayOptions += `
|
|
138
|
+
|
|
139
|
+
// Define how likely Replay events are sampled.
|
|
140
|
+
// This sets the sample rate to be 10%. You may want this to be 100% while
|
|
141
|
+
// in development and sample at a lower rate in production
|
|
142
|
+
replaysSessionSampleRate: 0.1,
|
|
143
|
+
|
|
144
|
+
// Define how likely Replay events are sampled when an error occurs.
|
|
145
|
+
replaysOnErrorSampleRate: 1.0,`;
|
|
56
146
|
}
|
|
57
147
|
}
|
|
58
|
-
|
|
148
|
+
let performanceOptions = '';
|
|
59
149
|
if (selectedFeaturesMap.performance) {
|
|
60
|
-
performanceOptions +=
|
|
150
|
+
performanceOptions += `
|
|
151
|
+
|
|
152
|
+
// Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
|
|
153
|
+
tracesSampleRate: 1,`;
|
|
61
154
|
}
|
|
62
155
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
63
|
-
return
|
|
156
|
+
return `${primer}
|
|
157
|
+
|
|
158
|
+
import * as Sentry from "@sentry/nextjs";
|
|
159
|
+
|
|
160
|
+
Sentry.init({
|
|
161
|
+
dsn: "${dsn}",${integrationsOptions}${performanceOptions}${replayOptions}
|
|
162
|
+
|
|
163
|
+
// Setting this option to true will print useful information to the console while you're setting up Sentry.
|
|
164
|
+
debug: false,
|
|
165
|
+
});
|
|
166
|
+
`;
|
|
64
167
|
}
|
|
65
168
|
exports.getSentryConfigContents = getSentryConfigContents;
|
|
66
169
|
function getSentryExamplePageContents(options) {
|
|
67
|
-
|
|
68
|
-
?
|
|
69
|
-
:
|
|
70
|
-
return
|
|
170
|
+
const issuesPageLink = options.selfHosted
|
|
171
|
+
? `${options.sentryUrl}organizations/${options.orgSlug}/issues/?project=${options.projectId}`
|
|
172
|
+
: `https://${options.orgSlug}.sentry.io/issues/?project=${options.projectId}`;
|
|
173
|
+
return `${options.useClient ? '"use client";\n\n' : ''}import Head from "next/head";
|
|
174
|
+
import * as Sentry from "@sentry/nextjs";
|
|
175
|
+
|
|
176
|
+
export default function Page() {
|
|
177
|
+
return (
|
|
178
|
+
<div>
|
|
179
|
+
<Head>
|
|
180
|
+
<title>Sentry Onboarding</title>
|
|
181
|
+
<meta name="description" content="Test Sentry for your Next.js app!" />
|
|
182
|
+
</Head>
|
|
183
|
+
|
|
184
|
+
<main
|
|
185
|
+
style={{
|
|
186
|
+
minHeight: "100vh",
|
|
187
|
+
display: "flex",
|
|
188
|
+
flexDirection: "column",
|
|
189
|
+
justifyContent: "center",
|
|
190
|
+
alignItems: "center",
|
|
191
|
+
}}
|
|
192
|
+
>
|
|
193
|
+
<h1 style={{ fontSize: "4rem", margin: "14px 0" }}>
|
|
194
|
+
<svg
|
|
195
|
+
style={{
|
|
196
|
+
height: "1em",
|
|
197
|
+
}}
|
|
198
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
199
|
+
viewBox="0 0 200 44"
|
|
200
|
+
>
|
|
201
|
+
<path
|
|
202
|
+
fill="currentColor"
|
|
203
|
+
d="M124.32,28.28,109.56,9.22h-3.68V34.77h3.73V15.19l15.18,19.58h3.26V9.22h-3.73ZM87.15,23.54h13.23V20.22H87.14V12.53h14.93V9.21H83.34V34.77h18.92V31.45H87.14ZM71.59,20.3h0C66.44,19.06,65,18.08,65,15.7c0-2.14,1.89-3.59,4.71-3.59a12.06,12.06,0,0,1,7.07,2.55l2-2.83a14.1,14.1,0,0,0-9-3c-5.06,0-8.59,3-8.59,7.27,0,4.6,3,6.19,8.46,7.52C74.51,24.74,76,25.78,76,28.11s-2,3.77-5.09,3.77a12.34,12.34,0,0,1-8.3-3.26l-2.25,2.69a15.94,15.94,0,0,0,10.42,3.85c5.48,0,9-2.95,9-7.51C79.75,23.79,77.47,21.72,71.59,20.3ZM195.7,9.22l-7.69,12-7.64-12h-4.46L186,24.67V34.78h3.84V24.55L200,9.22Zm-64.63,3.46h8.37v22.1h3.84V12.68h8.37V9.22H131.08ZM169.41,24.8c3.86-1.07,6-3.77,6-7.63,0-4.91-3.59-8-9.38-8H154.67V34.76h3.8V25.58h6.45l6.48,9.2h4.44l-7-9.82Zm-10.95-2.5V12.6h7.17c3.74,0,5.88,1.77,5.88,4.84s-2.29,4.86-5.84,4.86Z M29,2.26a4.67,4.67,0,0,0-8,0L14.42,13.53A32.21,32.21,0,0,1,32.17,40.19H27.55A27.68,27.68,0,0,0,12.09,17.47L6,28a15.92,15.92,0,0,1,9.23,12.17H4.62A.76.76,0,0,1,4,39.06l2.94-5a10.74,10.74,0,0,0-3.36-1.9l-2.91,5a4.54,4.54,0,0,0,1.69,6.24A4.66,4.66,0,0,0,4.62,44H19.15a19.4,19.4,0,0,0-8-17.31l2.31-4A23.87,23.87,0,0,1,23.76,44H36.07a35.88,35.88,0,0,0-16.41-31.8l4.67-8a.77.77,0,0,1,1.05-.27c.53.29,20.29,34.77,20.66,35.17a.76.76,0,0,1-.68,1.13H40.6q.09,1.91,0,3.81h4.78A4.59,4.59,0,0,0,50,39.43a4.49,4.49,0,0,0-.62-2.28Z"
|
|
204
|
+
></path>
|
|
205
|
+
</svg>
|
|
206
|
+
</h1>
|
|
207
|
+
|
|
208
|
+
<p>Get started by sending us a sample error:</p>
|
|
209
|
+
<button
|
|
210
|
+
type="button"
|
|
211
|
+
style={{
|
|
212
|
+
padding: "12px",
|
|
213
|
+
cursor: "pointer",
|
|
214
|
+
backgroundColor: "#AD6CAA",
|
|
215
|
+
borderRadius: "4px",
|
|
216
|
+
border: "none",
|
|
217
|
+
color: "white",
|
|
218
|
+
fontSize: "14px",
|
|
219
|
+
margin: "18px",
|
|
220
|
+
}}
|
|
221
|
+
onClick={async () => {
|
|
222
|
+
await Sentry.startSpan({
|
|
223
|
+
name: 'Example Frontend Span',
|
|
224
|
+
op: 'test'
|
|
225
|
+
}, async () => {
|
|
226
|
+
const res = await fetch("/api/sentry-example-api");
|
|
227
|
+
if (!res.ok) {
|
|
228
|
+
throw new Error("Sentry Example Frontend Error");
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}}
|
|
232
|
+
>
|
|
233
|
+
Throw error!
|
|
234
|
+
</button>
|
|
235
|
+
|
|
236
|
+
<p>
|
|
237
|
+
Next, look for the error on the{" "}
|
|
238
|
+
<a href="${issuesPageLink}">Issues Page</a>.
|
|
239
|
+
</p>
|
|
240
|
+
<p style={{ marginTop: "24px" }}>
|
|
241
|
+
For more information, see{" "}
|
|
242
|
+
<a href="https://docs.sentry.io/platforms/javascript/guides/nextjs/">
|
|
243
|
+
https://docs.sentry.io/platforms/javascript/guides/nextjs/
|
|
244
|
+
</a>
|
|
245
|
+
</p>
|
|
246
|
+
</main>
|
|
247
|
+
</div>
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
`;
|
|
71
251
|
}
|
|
72
252
|
exports.getSentryExamplePageContents = getSentryExamplePageContents;
|
|
73
253
|
function getSentryExamplePagesDirApiRoute() {
|
|
74
|
-
return
|
|
254
|
+
return `// A faulty API route to test Sentry's error monitoring
|
|
255
|
+
export default function handler(_req, res) {
|
|
256
|
+
throw new Error("Sentry Example API Route Error");
|
|
257
|
+
res.status(200).json({ name: "John Doe" });
|
|
258
|
+
}
|
|
259
|
+
`;
|
|
75
260
|
}
|
|
76
261
|
exports.getSentryExamplePagesDirApiRoute = getSentryExamplePagesDirApiRoute;
|
|
77
262
|
function getSentryExampleAppDirApiRoute() {
|
|
78
|
-
return
|
|
263
|
+
return `import { NextResponse } from "next/server";
|
|
264
|
+
|
|
265
|
+
export const dynamic = "force-dynamic";
|
|
266
|
+
|
|
267
|
+
// A faulty API route to test Sentry's error monitoring
|
|
268
|
+
export function GET() {
|
|
269
|
+
throw new Error("Sentry Example API Route Error");
|
|
270
|
+
return NextResponse.json({ data: "Testing Sentry Error..." });
|
|
271
|
+
}
|
|
272
|
+
`;
|
|
79
273
|
}
|
|
80
274
|
exports.getSentryExampleAppDirApiRoute = getSentryExampleAppDirApiRoute;
|
|
81
275
|
function getSentryDefaultUnderscoreErrorPage() {
|
|
82
|
-
return
|
|
276
|
+
return `import * as Sentry from "@sentry/nextjs";
|
|
277
|
+
import Error from "next/error";
|
|
278
|
+
|
|
279
|
+
const CustomErrorComponent = (props) => {
|
|
280
|
+
return <Error statusCode={props.statusCode} />;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
CustomErrorComponent.getInitialProps = async (contextData) => {
|
|
284
|
+
// In case this is running in a serverless function, await this in order to give Sentry
|
|
285
|
+
// time to send the error before the lambda exits
|
|
286
|
+
await Sentry.captureUnderscoreErrorException(contextData);
|
|
287
|
+
|
|
288
|
+
// This will contain the status code of the response
|
|
289
|
+
return Error.getInitialProps(contextData);
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
export default CustomErrorComponent;
|
|
293
|
+
`;
|
|
83
294
|
}
|
|
84
295
|
exports.getSentryDefaultUnderscoreErrorPage = getSentryDefaultUnderscoreErrorPage;
|
|
85
296
|
function getSimpleUnderscoreErrorCopyPasteSnippet() {
|
|
86
|
-
return
|
|
297
|
+
return `
|
|
298
|
+
${chalk_1.default.green(`import * as Sentry from '@sentry/nextjs';`)}
|
|
299
|
+
${chalk_1.default.green(`import Error from "next/error";`)}
|
|
300
|
+
|
|
301
|
+
${chalk_1.default.dim('// Replace "YourCustomErrorComponent" with your custom error component!')}
|
|
302
|
+
YourCustomErrorComponent.getInitialProps = async (${chalk_1.default.green('contextData')}) => {
|
|
303
|
+
${chalk_1.default.green('await Sentry.captureUnderscoreErrorException(contextData);')}
|
|
304
|
+
|
|
305
|
+
${chalk_1.default.dim('// ...other getInitialProps code')}
|
|
306
|
+
|
|
307
|
+
return Error.getInitialProps(contextData);
|
|
308
|
+
};
|
|
309
|
+
`;
|
|
87
310
|
}
|
|
88
311
|
exports.getSimpleUnderscoreErrorCopyPasteSnippet = getSimpleUnderscoreErrorCopyPasteSnippet;
|
|
89
312
|
function getFullUnderscoreErrorCopyPasteSnippet(isTs) {
|
|
90
|
-
return
|
|
313
|
+
return `
|
|
314
|
+
import * as Sentry from '@sentry/nextjs';${isTs ? '\nimport type { NextPageContext } from "next";' : ''}
|
|
315
|
+
import Error from "next/error";
|
|
316
|
+
|
|
317
|
+
${chalk_1.default.dim('// Replace "YourCustomErrorComponent" with your custom error component!')}
|
|
318
|
+
YourCustomErrorComponent.getInitialProps = async (contextData${isTs ? ': NextPageContext' : ''}) => {
|
|
319
|
+
await Sentry.captureUnderscoreErrorException(contextData);
|
|
320
|
+
|
|
321
|
+
return Error.getInitialProps(contextData);
|
|
322
|
+
};
|
|
323
|
+
`;
|
|
91
324
|
}
|
|
92
325
|
exports.getFullUnderscoreErrorCopyPasteSnippet = getFullUnderscoreErrorCopyPasteSnippet;
|
|
93
326
|
function getInstrumentationHookContent(instrumentationHookLocation) {
|
|
94
|
-
return
|
|
327
|
+
return `import * as Sentry from '@sentry/nextjs';
|
|
328
|
+
|
|
329
|
+
export async function register() {
|
|
330
|
+
if (process.env.NEXT_RUNTIME === 'nodejs') {
|
|
331
|
+
await import('${instrumentationHookLocation === 'root' ? '.' : '..'}/sentry.server.config');
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (process.env.NEXT_RUNTIME === 'edge') {
|
|
335
|
+
await import('${instrumentationHookLocation === 'root' ? '.' : '..'}/sentry.edge.config');
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export const onRequestError = Sentry.captureRequestError;
|
|
340
|
+
`;
|
|
95
341
|
}
|
|
96
342
|
exports.getInstrumentationHookContent = getInstrumentationHookContent;
|
|
97
343
|
function getInstrumentationHookCopyPasteSnippet(instrumentationHookLocation) {
|
|
98
|
-
return (0, clack_utils_1.makeCodeSnippet)(true,
|
|
99
|
-
return unchanged(
|
|
344
|
+
return (0, clack_utils_1.makeCodeSnippet)(true, (unchanged, plus) => {
|
|
345
|
+
return unchanged(`${plus("import * as Sentry from '@sentry/nextjs';")}
|
|
346
|
+
|
|
347
|
+
export ${plus('async')} function register() {
|
|
348
|
+
${plus(`if (process.env.NEXT_RUNTIME === 'nodejs') {
|
|
349
|
+
await import('${instrumentationHookLocation === 'root' ? '.' : '..'}/sentry.server.config');
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
if (process.env.NEXT_RUNTIME === 'edge') {
|
|
353
|
+
await import('${instrumentationHookLocation === 'root' ? '.' : '..'}/sentry.edge.config');
|
|
354
|
+
}`)}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
${plus('export const onRequestError = Sentry.captureRequestError;')}
|
|
358
|
+
`);
|
|
100
359
|
});
|
|
101
360
|
}
|
|
102
361
|
exports.getInstrumentationHookCopyPasteSnippet = getInstrumentationHookCopyPasteSnippet;
|
|
103
362
|
function getSentryDefaultGlobalErrorPage(isTs) {
|
|
104
363
|
return isTs
|
|
105
|
-
? "
|
|
106
|
-
|
|
364
|
+
? `"use client";
|
|
365
|
+
|
|
366
|
+
import * as Sentry from "@sentry/nextjs";
|
|
367
|
+
import NextError from "next/error";
|
|
368
|
+
import { useEffect } from "react";
|
|
369
|
+
|
|
370
|
+
export default function GlobalError({ error }: { error: Error & { digest?: string } }) {
|
|
371
|
+
useEffect(() => {
|
|
372
|
+
Sentry.captureException(error);
|
|
373
|
+
}, [error]);
|
|
374
|
+
|
|
375
|
+
return (
|
|
376
|
+
<html>
|
|
377
|
+
<body>
|
|
378
|
+
{/* \`NextError\` is the default Next.js error page component. Its type
|
|
379
|
+
definition requires a \`statusCode\` prop. However, since the App Router
|
|
380
|
+
does not expose status codes for errors, we simply pass 0 to render a
|
|
381
|
+
generic error message. */}
|
|
382
|
+
<NextError statusCode={0} />
|
|
383
|
+
</body>
|
|
384
|
+
</html>
|
|
385
|
+
);
|
|
386
|
+
}`
|
|
387
|
+
: `"use client";
|
|
388
|
+
|
|
389
|
+
import * as Sentry from "@sentry/nextjs";
|
|
390
|
+
import NextError from "next/error";
|
|
391
|
+
import { useEffect } from "react";
|
|
392
|
+
|
|
393
|
+
export default function GlobalError({ error }) {
|
|
394
|
+
useEffect(() => {
|
|
395
|
+
Sentry.captureException(error);
|
|
396
|
+
}, [error]);
|
|
397
|
+
|
|
398
|
+
return (
|
|
399
|
+
<html>
|
|
400
|
+
<body>
|
|
401
|
+
{/* \`NextError\` is the default Next.js error page component. Its type
|
|
402
|
+
definition requires a \`statusCode\` prop. However, since the App Router
|
|
403
|
+
does not expose status codes for errors, we simply pass 0 to render a
|
|
404
|
+
generic error message. */}
|
|
405
|
+
<NextError statusCode={0} />
|
|
406
|
+
</body>
|
|
407
|
+
</html>
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
`;
|
|
107
411
|
}
|
|
108
412
|
exports.getSentryDefaultGlobalErrorPage = getSentryDefaultGlobalErrorPage;
|
|
109
413
|
function getGlobalErrorCopyPasteSnippet(isTs) {
|
|
110
414
|
if (isTs) {
|
|
111
|
-
return "
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
415
|
+
return `"use client";
|
|
416
|
+
|
|
417
|
+
${chalk_1.default.green('import * as Sentry from "@sentry/nextjs";')}
|
|
418
|
+
${chalk_1.default.green('import Error from "next/error";')}
|
|
419
|
+
${chalk_1.default.green('import { useEffect } from "react";')}
|
|
420
|
+
|
|
421
|
+
export default function GlobalError(${chalk_1.default.green('{ error }: { error: Error }')}) {
|
|
422
|
+
${chalk_1.default.green(`useEffect(() => {
|
|
423
|
+
Sentry.captureException(error);
|
|
424
|
+
}, [error]);`)}
|
|
425
|
+
|
|
426
|
+
return (
|
|
427
|
+
<html>
|
|
428
|
+
<body>
|
|
429
|
+
{/* Your Error component here... */}
|
|
430
|
+
</body>
|
|
431
|
+
</html>
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
`;
|
|
115
435
|
}
|
|
436
|
+
return `"use client";
|
|
437
|
+
|
|
438
|
+
${chalk_1.default.green('import * as Sentry from "@sentry/nextjs";')}
|
|
439
|
+
${chalk_1.default.green('import Error from "next/error";')}
|
|
440
|
+
${chalk_1.default.green('import { useEffect } from "react";')}
|
|
441
|
+
|
|
442
|
+
export default function GlobalError(${chalk_1.default.green('{ error }')}) {
|
|
443
|
+
${chalk_1.default.green(`useEffect(() => {
|
|
444
|
+
Sentry.captureException(error);
|
|
445
|
+
}, [error]);`)}
|
|
446
|
+
|
|
447
|
+
return (
|
|
448
|
+
<html>
|
|
449
|
+
<body>
|
|
450
|
+
{/* Your Error component here... */}
|
|
451
|
+
</body>
|
|
452
|
+
</html>
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
`;
|
|
116
456
|
}
|
|
117
457
|
exports.getGlobalErrorCopyPasteSnippet = getGlobalErrorCopyPasteSnippet;
|
|
118
458
|
//# sourceMappingURL=templates.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/nextjs/templates.ts"],"names":[],"mappings":";;;;;;AAAA,gDAA0B;AAC1B,oDAAuD;AAWvD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CAAC,oBAGH,IAAI,CAAC,2DAA2D,CAAC,OAClE,CAAC,CAAC;IACD,CAAC,CAAC,CAAC;AACL,CAAC;AAvBD,wFAuBC;AAED,SAAgB,+BAA+B,CAAC,IAAa;IAC3D,OAAO,IAAI;QACT,CAAC,CAAC,wrBAsBJ;QACE,CAAC,CAAC,kpBAuBL,CAAC;AACF,CAAC;AAjDD,0EAiDC;AAED,SAAgB,8BAA8B,CAAC,IAAa;IAC1D,IAAI,IAAI,EAAE;QACR,OAAO,6BAET,eAAK,CAAC,KAAK,CAAC,2CAA2C,CAAC,eACxD,eAAK,CAAC,KAAK,CAAC,iCAAiC,CAAC,eAC9C,eAAK,CAAC,KAAK,CAAC,oCAAoC,CAAC,qDAEb,eAAK,CAAC,KAAK,CAC3C,6BAA6B,CAC9B,oBACD,eAAK,CAAC,KAAK,CAAC,wEAED,CAAC,kIAUf,CAAC;KACC;SAAM;QACL,OAAO,6BAET,eAAK,CAAC,KAAK,CAAC,2CAA2C,CAAC,eACxD,eAAK,CAAC,KAAK,CAAC,iCAAiC,CAAC,eAC9C,eAAK,CAAC,KAAK,CAAC,oCAAoC,CAAC,qDAEb,eAAK,CAAC,KAAK,CAAC,WAAW,CAAC,oBAC1D,eAAK,CAAC,KAAK,CAAC,wEAED,CAAC,kIAUf,CAAC;KACC;AACH,CAAC;AA9CD,wEA8CC","sourcesContent":["import chalk from 'chalk';\nimport { makeCodeSnippet } from '../utils/clack-utils';\n\ntype WithSentryConfigOptions = {\n orgSlug: string;\n projectSlug: string;\n selfHosted: boolean;\n sentryUrl: string;\n tunnelRoute: boolean;\n reactComponentAnnotation: boolean;\n};\n\nexport function getWithSentryConfigOptionsTemplate({\n orgSlug,\n projectSlug,\n selfHosted,\n tunnelRoute,\n reactComponentAnnotation,\n sentryUrl,\n}: WithSentryConfigOptions): string {\n return `{\n // For all available options, see:\n // https://github.com/getsentry/sentry-webpack-plugin#options\n\n org: \"${orgSlug}\",\n project: \"${projectSlug}\",${\n selfHosted ? `\\n sentryUrl: \"${sentryUrl}\",` : ''\n }\n\n // Only print logs for uploading source maps in CI\n silent: !process.env.CI,\n\n // For all available options, see:\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/\n\n // Upload a larger set of source maps for prettier stack traces (increases build time)\n widenClientFileUpload: true,${\n reactComponentAnnotation\n ? `\\n\n // Automatically annotate React components to show their full name in breadcrumbs and session replay\n reactComponentAnnotation: {\n enabled: true,\n },`\n : ''\n }\n\n // ${\n tunnelRoute ? 'Route' : 'Uncomment to route'\n } browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.\n // This can increase your server load as well as your hosting bill.\n // Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-\n // side errors will fail.\n ${tunnelRoute ? '' : '// '}tunnelRoute: \"/monitoring\",\n\n // Automatically tree-shake Sentry logger statements to reduce bundle size\n disableLogger: true,\n\n // Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)\n // See the following for more information:\n // https://docs.sentry.io/product/crons/\n // https://vercel.com/docs/cron-jobs\n automaticVercelMonitors: true,\n }`;\n}\n\nexport function getNextjsConfigCjsTemplate(\n withSentryConfigOptionsTemplate: string,\n): string {\n return `const { withSentryConfig } = require(\"@sentry/nextjs\");\n\n/** @type {import('next').NextConfig} */\nconst nextConfig = {};\n\nmodule.exports = withSentryConfig(\n nextConfig,\n ${withSentryConfigOptionsTemplate}\n);\n`;\n}\n\nexport function getNextjsConfigMjsTemplate(\n withSentryConfigOptionsTemplate: string,\n): string {\n return `import { withSentryConfig } from \"@sentry/nextjs\";\n\n/** @type {import('next').NextConfig} */\nconst nextConfig = {};\n\nexport default withSentryConfig(\n nextConfig,\n ${withSentryConfigOptionsTemplate}\n);\n`;\n}\n\nexport function getNextjsConfigCjsAppendix(\n withSentryConfigOptionsTemplate: string,\n): string {\n return `\n\n// Injected content via Sentry wizard below\n\nconst { withSentryConfig } = require(\"@sentry/nextjs\");\n\nmodule.exports = withSentryConfig(\n module.exports,\n ${withSentryConfigOptionsTemplate}\n);\n`;\n}\n\nexport function getNextjsConfigEsmCopyPasteSnippet(\n withSentryConfigOptionsTemplate: string,\n): string {\n return `\n\n// next.config.mjs\nimport { withSentryConfig } from \"@sentry/nextjs\";\n\nexport default withSentryConfig(\n yourNextConfig,\n ${withSentryConfigOptionsTemplate}\n);\n`;\n}\n\nfunction getClientIntegrationsSnippet(features: { replay: boolean }) {\n if (features.replay) {\n return `\n\n // Add optional integrations for additional features\n integrations: [\n Sentry.replayIntegration(),\n ],`;\n }\n\n return '';\n}\n\nexport function getSentryConfigContents(\n dsn: string,\n config: 'server' | 'client' | 'edge',\n selectedFeaturesMap: {\n replay: boolean;\n performance: boolean;\n },\n): string {\n let primer;\n if (config === 'server') {\n primer = `// This file configures the initialization of Sentry on the server.\n// The config you add here will be used whenever the server handles a request.\n// https://docs.sentry.io/platforms/javascript/guides/nextjs/`;\n } else if (config === 'client') {\n primer = `// This file configures the initialization of Sentry on the client.\n// The config you add here will be used whenever a users loads a page in their browser.\n// https://docs.sentry.io/platforms/javascript/guides/nextjs/`;\n } else if (config === 'edge') {\n primer = `// This file configures the initialization of Sentry for edge features (middleware, edge routes, and so on).\n// The config you add here will be used whenever one of the edge features is loaded.\n// Note that this config is unrelated to the Vercel Edge Runtime and is also required when running locally.\n// https://docs.sentry.io/platforms/javascript/guides/nextjs/`;\n }\n\n const integrationsOptions = getClientIntegrationsSnippet({\n replay: config === 'client' && selectedFeaturesMap.replay,\n });\n\n let replayOptions = '';\n if (config === 'client') {\n if (selectedFeaturesMap.replay) {\n replayOptions += `\n\n // Define how likely Replay events are sampled.\n // This sets the sample rate to be 10%. You may want this to be 100% while\n // in development and sample at a lower rate in production\n replaysSessionSampleRate: 0.1,\n\n // Define how likely Replay events are sampled when an error occurs.\n replaysOnErrorSampleRate: 1.0,`;\n }\n }\n\n let performanceOptions = '';\n if (selectedFeaturesMap.performance) {\n performanceOptions += `\n\n // Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.\n tracesSampleRate: 1,`;\n }\n\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n return `${primer}\n\nimport * as Sentry from \"@sentry/nextjs\";\n\nSentry.init({\n dsn: \"${dsn}\",${integrationsOptions}${performanceOptions}${replayOptions}\n\n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n});\n`;\n}\n\nexport function getSentryExamplePageContents(options: {\n selfHosted: boolean;\n sentryUrl: string;\n orgSlug: string;\n projectId: string;\n useClient: boolean;\n}): string {\n const issuesPageLink = options.selfHosted\n ? `${options.sentryUrl}organizations/${options.orgSlug}/issues/?project=${options.projectId}`\n : `https://${options.orgSlug}.sentry.io/issues/?project=${options.projectId}`;\n\n return `${\n options.useClient ? '\"use client\";\\n\\n' : ''\n }import Head from \"next/head\";\nimport * as Sentry from \"@sentry/nextjs\";\n\nexport default function Page() {\n return (\n <div>\n <Head>\n <title>Sentry Onboarding</title>\n <meta name=\"description\" content=\"Test Sentry for your Next.js app!\" />\n </Head>\n\n <main\n style={{\n minHeight: \"100vh\",\n display: \"flex\",\n flexDirection: \"column\",\n justifyContent: \"center\",\n alignItems: \"center\",\n }}\n >\n <h1 style={{ fontSize: \"4rem\", margin: \"14px 0\" }}>\n <svg\n style={{\n height: \"1em\",\n }}\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 200 44\"\n >\n <path\n fill=\"currentColor\"\n d=\"M124.32,28.28,109.56,9.22h-3.68V34.77h3.73V15.19l15.18,19.58h3.26V9.22h-3.73ZM87.15,23.54h13.23V20.22H87.14V12.53h14.93V9.21H83.34V34.77h18.92V31.45H87.14ZM71.59,20.3h0C66.44,19.06,65,18.08,65,15.7c0-2.14,1.89-3.59,4.71-3.59a12.06,12.06,0,0,1,7.07,2.55l2-2.83a14.1,14.1,0,0,0-9-3c-5.06,0-8.59,3-8.59,7.27,0,4.6,3,6.19,8.46,7.52C74.51,24.74,76,25.78,76,28.11s-2,3.77-5.09,3.77a12.34,12.34,0,0,1-8.3-3.26l-2.25,2.69a15.94,15.94,0,0,0,10.42,3.85c5.48,0,9-2.95,9-7.51C79.75,23.79,77.47,21.72,71.59,20.3ZM195.7,9.22l-7.69,12-7.64-12h-4.46L186,24.67V34.78h3.84V24.55L200,9.22Zm-64.63,3.46h8.37v22.1h3.84V12.68h8.37V9.22H131.08ZM169.41,24.8c3.86-1.07,6-3.77,6-7.63,0-4.91-3.59-8-9.38-8H154.67V34.76h3.8V25.58h6.45l6.48,9.2h4.44l-7-9.82Zm-10.95-2.5V12.6h7.17c3.74,0,5.88,1.77,5.88,4.84s-2.29,4.86-5.84,4.86Z M29,2.26a4.67,4.67,0,0,0-8,0L14.42,13.53A32.21,32.21,0,0,1,32.17,40.19H27.55A27.68,27.68,0,0,0,12.09,17.47L6,28a15.92,15.92,0,0,1,9.23,12.17H4.62A.76.76,0,0,1,4,39.06l2.94-5a10.74,10.74,0,0,0-3.36-1.9l-2.91,5a4.54,4.54,0,0,0,1.69,6.24A4.66,4.66,0,0,0,4.62,44H19.15a19.4,19.4,0,0,0-8-17.31l2.31-4A23.87,23.87,0,0,1,23.76,44H36.07a35.88,35.88,0,0,0-16.41-31.8l4.67-8a.77.77,0,0,1,1.05-.27c.53.29,20.29,34.77,20.66,35.17a.76.76,0,0,1-.68,1.13H40.6q.09,1.91,0,3.81h4.78A4.59,4.59,0,0,0,50,39.43a4.49,4.49,0,0,0-.62-2.28Z\"\n ></path>\n </svg>\n </h1>\n\n <p>Get started by sending us a sample error:</p>\n <button\n type=\"button\"\n style={{\n padding: \"12px\",\n cursor: \"pointer\",\n backgroundColor: \"#AD6CAA\",\n borderRadius: \"4px\",\n border: \"none\",\n color: \"white\",\n fontSize: \"14px\",\n margin: \"18px\",\n }}\n onClick={async () => {\n await Sentry.startSpan({\n name: 'Example Frontend Span',\n op: 'test'\n }, async () => {\n const res = await fetch(\"/api/sentry-example-api\");\n if (!res.ok) {\n throw new Error(\"Sentry Example Frontend Error\");\n }\n });\n }}\n >\n Throw error!\n </button>\n\n <p>\n Next, look for the error on the{\" \"}\n <a href=\"${issuesPageLink}\">Issues Page</a>.\n </p>\n <p style={{ marginTop: \"24px\" }}>\n For more information, see{\" \"}\n <a href=\"https://docs.sentry.io/platforms/javascript/guides/nextjs/\">\n https://docs.sentry.io/platforms/javascript/guides/nextjs/\n </a>\n </p>\n </main>\n </div>\n );\n}\n`;\n}\n\nexport function getSentryExamplePagesDirApiRoute() {\n return `// A faulty API route to test Sentry's error monitoring\nexport default function handler(_req, res) {\n throw new Error(\"Sentry Example API Route Error\");\n res.status(200).json({ name: \"John Doe\" });\n}\n`;\n}\n\nexport function getSentryExampleAppDirApiRoute() {\n return `import { NextResponse } from \"next/server\";\n\nexport const dynamic = \"force-dynamic\";\n\n// A faulty API route to test Sentry's error monitoring\nexport function GET() {\n throw new Error(\"Sentry Example API Route Error\");\n return NextResponse.json({ data: \"Testing Sentry Error...\" });\n}\n`;\n}\n\nexport function getSentryDefaultUnderscoreErrorPage() {\n return `import * as Sentry from \"@sentry/nextjs\";\nimport Error from \"next/error\";\n\nconst CustomErrorComponent = (props) => {\n return <Error statusCode={props.statusCode} />;\n};\n\nCustomErrorComponent.getInitialProps = async (contextData) => {\n // In case this is running in a serverless function, await this in order to give Sentry\n // time to send the error before the lambda exits\n await Sentry.captureUnderscoreErrorException(contextData);\n\n // This will contain the status code of the response\n return Error.getInitialProps(contextData);\n};\n\nexport default CustomErrorComponent;\n`;\n}\n\nexport function getSimpleUnderscoreErrorCopyPasteSnippet() {\n return `\n${chalk.green(`import * as Sentry from '@sentry/nextjs';`)}\n${chalk.green(`import Error from \"next/error\";`)}\n\n${chalk.dim(\n '// Replace \"YourCustomErrorComponent\" with your custom error component!',\n)}\nYourCustomErrorComponent.getInitialProps = async (${chalk.green(\n 'contextData',\n )}) => {\n ${chalk.green('await Sentry.captureUnderscoreErrorException(contextData);')}\n\n ${chalk.dim('// ...other getInitialProps code')}\n\n return Error.getInitialProps(contextData);\n};\n`;\n}\n\nexport function getFullUnderscoreErrorCopyPasteSnippet(isTs: boolean) {\n return `\nimport * as Sentry from '@sentry/nextjs';${\n isTs ? '\\nimport type { NextPageContext } from \"next\";' : ''\n }\nimport Error from \"next/error\";\n\n${chalk.dim(\n '// Replace \"YourCustomErrorComponent\" with your custom error component!',\n)}\nYourCustomErrorComponent.getInitialProps = async (contextData${\n isTs ? ': NextPageContext' : ''\n }) => {\n await Sentry.captureUnderscoreErrorException(contextData);\n\n return Error.getInitialProps(contextData);\n};\n`;\n}\n\nexport function getInstrumentationHookContent(\n instrumentationHookLocation: 'src' | 'root',\n) {\n return `import * as Sentry from '@sentry/nextjs';\n\nexport async function register() {\n if (process.env.NEXT_RUNTIME === 'nodejs') {\n await import('${\n instrumentationHookLocation === 'root' ? '.' : '..'\n }/sentry.server.config');\n }\n\n if (process.env.NEXT_RUNTIME === 'edge') {\n await import('${\n instrumentationHookLocation === 'root' ? '.' : '..'\n }/sentry.edge.config');\n }\n}\n\nexport const onRequestError = Sentry.captureRequestError;\n`;\n}\n\nexport function getInstrumentationHookCopyPasteSnippet(\n instrumentationHookLocation: 'src' | 'root',\n) {\n return makeCodeSnippet(true, (unchanged, plus) => {\n return unchanged(`${plus(\"import * as Sentry from '@sentry/nextjs';\")}\n\nexport ${plus('async')} function register() {\n ${plus(`if (process.env.NEXT_RUNTIME === 'nodejs') {\n await import('${\n instrumentationHookLocation === 'root' ? '.' : '..'\n }/sentry.server.config');\n }\n\n if (process.env.NEXT_RUNTIME === 'edge') {\n await import('${\n instrumentationHookLocation === 'root' ? '.' : '..'\n }/sentry.edge.config');\n }`)}\n}\n\n${plus('export const onRequestError = Sentry.captureRequestError;')}\n`);\n });\n}\n\nexport function getSentryDefaultGlobalErrorPage(isTs: boolean) {\n return isTs\n ? `\"use client\";\n\nimport * as Sentry from \"@sentry/nextjs\";\nimport NextError from \"next/error\";\nimport { useEffect } from \"react\";\n\nexport default function GlobalError({ error }: { error: Error & { digest?: string } }) {\n useEffect(() => {\n Sentry.captureException(error);\n }, [error]);\n\n return (\n <html>\n <body>\n {/* \\`NextError\\` is the default Next.js error page component. Its type\n definition requires a \\`statusCode\\` prop. However, since the App Router\n does not expose status codes for errors, we simply pass 0 to render a\n generic error message. */}\n <NextError statusCode={0} />\n </body>\n </html>\n );\n}`\n : `\"use client\";\n\nimport * as Sentry from \"@sentry/nextjs\";\nimport NextError from \"next/error\";\nimport { useEffect } from \"react\";\n\nexport default function GlobalError({ error }) {\n useEffect(() => {\n Sentry.captureException(error);\n }, [error]);\n\n return (\n <html>\n <body>\n {/* \\`NextError\\` is the default Next.js error page component. Its type\n definition requires a \\`statusCode\\` prop. However, since the App Router\n does not expose status codes for errors, we simply pass 0 to render a\n generic error message. */}\n <NextError statusCode={0} />\n </body>\n </html>\n );\n}\n`;\n}\n\nexport function getGlobalErrorCopyPasteSnippet(isTs: boolean) {\n if (isTs) {\n return `\"use client\";\n\n${chalk.green('import * as Sentry from \"@sentry/nextjs\";')}\n${chalk.green('import Error from \"next/error\";')}\n${chalk.green('import { useEffect } from \"react\";')}\n\nexport default function GlobalError(${chalk.green(\n '{ error }: { error: Error }',\n )}) {\n ${chalk.green(`useEffect(() => {\n Sentry.captureException(error);\n }, [error]);`)}\n\n return (\n <html>\n <body>\n {/* Your Error component here... */}\n </body>\n </html>\n );\n}\n`;\n } else {\n return `\"use client\";\n\n${chalk.green('import * as Sentry from \"@sentry/nextjs\";')}\n${chalk.green('import Error from \"next/error\";')}\n${chalk.green('import { useEffect } from \"react\";')}\n\nexport default function GlobalError(${chalk.green('{ error }')}) {\n ${chalk.green(`useEffect(() => {\n Sentry.captureException(error);\n }, [error]);`)}\n\n return (\n <html>\n <body>\n {/* Your Error component here... */}\n </body>\n </html>\n );\n}\n`;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/nextjs/templates.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,sDAAuD;AAWvD,SAAgB,kCAAkC,CAAC,EACjD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AA2B,KAAK,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IACjD;;;;oBAKE,2BAA2B,KAAK,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IACjD;IACA,CAAC;;;EAGH,IAAI,CAAC,2DAA2D,CAAC;CAClE,CAAC,CAAC;IACD,CAAC,CAAC,CAAC;AACL,CAAC;AAvBD,wFAuBC;AAED,SAAgB,+BAA+B,CAAC,IAAa;IAC3D,OAAO,IAAI;QACT,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;EAsBJ;QACE,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;CAuBL,CAAC;AACF,CAAC;AAjDD,0EAiDC;AAED,SAAgB,8BAA8B,CAAC,IAAa;IAC1D,IAAI,IAAI,EAAE;QACR,OAAO;;EAET,eAAK,CAAC,KAAK,CAAC,2CAA2C,CAAC;EACxD,eAAK,CAAC,KAAK,CAAC,iCAAiC,CAAC;EAC9C,eAAK,CAAC,KAAK,CAAC,oCAAoC,CAAC;;sCAEb,eAAK,CAAC,KAAK,CAC3C,6BAA6B,CAC9B;IACD,eAAK,CAAC,KAAK,CAAC;;eAED,CAAC;;;;;;;;;;CAUf,CAAC;KACC;IACD,OAAO;;EAEP,eAAK,CAAC,KAAK,CAAC,2CAA2C,CAAC;EACxD,eAAK,CAAC,KAAK,CAAC,iCAAiC,CAAC;EAC9C,eAAK,CAAC,KAAK,CAAC,oCAAoC,CAAC;;sCAEb,eAAK,CAAC,KAAK,CAAC,WAAW,CAAC;IAC1D,eAAK,CAAC,KAAK,CAAC;;eAED,CAAC;;;;;;;;;;CAUf,CAAC;AACF,CAAC;AA7CD,wEA6CC","sourcesContent":["import chalk from 'chalk';\nimport { makeCodeSnippet } from '../utils/clack-utils';\n\ntype WithSentryConfigOptions = {\n orgSlug: string;\n projectSlug: string;\n selfHosted: boolean;\n sentryUrl: string;\n tunnelRoute: boolean;\n reactComponentAnnotation: boolean;\n};\n\nexport function getWithSentryConfigOptionsTemplate({\n orgSlug,\n projectSlug,\n selfHosted,\n tunnelRoute,\n reactComponentAnnotation,\n sentryUrl,\n}: WithSentryConfigOptions): string {\n return `{\n // For all available options, see:\n // https://github.com/getsentry/sentry-webpack-plugin#options\n\n org: \"${orgSlug}\",\n project: \"${projectSlug}\",${\n selfHosted ? `\\n sentryUrl: \"${sentryUrl}\",` : ''\n }\n\n // Only print logs for uploading source maps in CI\n silent: !process.env.CI,\n\n // For all available options, see:\n // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/\n\n // Upload a larger set of source maps for prettier stack traces (increases build time)\n widenClientFileUpload: true,${\n reactComponentAnnotation\n ? `\\n\n // Automatically annotate React components to show their full name in breadcrumbs and session replay\n reactComponentAnnotation: {\n enabled: true,\n },`\n : ''\n }\n\n // ${\n tunnelRoute ? 'Route' : 'Uncomment to route'\n } browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.\n // This can increase your server load as well as your hosting bill.\n // Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-\n // side errors will fail.\n ${tunnelRoute ? '' : '// '}tunnelRoute: \"/monitoring\",\n\n // Automatically tree-shake Sentry logger statements to reduce bundle size\n disableLogger: true,\n\n // Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)\n // See the following for more information:\n // https://docs.sentry.io/product/crons/\n // https://vercel.com/docs/cron-jobs\n automaticVercelMonitors: true,\n }`;\n}\n\nexport function getNextjsConfigCjsTemplate(\n withSentryConfigOptionsTemplate: string,\n): string {\n return `const { withSentryConfig } = require(\"@sentry/nextjs\");\n\n/** @type {import('next').NextConfig} */\nconst nextConfig = {};\n\nmodule.exports = withSentryConfig(\n nextConfig,\n ${withSentryConfigOptionsTemplate}\n);\n`;\n}\n\nexport function getNextjsConfigMjsTemplate(\n withSentryConfigOptionsTemplate: string,\n): string {\n return `import { withSentryConfig } from \"@sentry/nextjs\";\n\n/** @type {import('next').NextConfig} */\nconst nextConfig = {};\n\nexport default withSentryConfig(\n nextConfig,\n ${withSentryConfigOptionsTemplate}\n);\n`;\n}\n\nexport function getNextjsConfigCjsAppendix(\n withSentryConfigOptionsTemplate: string,\n): string {\n return `\n\n// Injected content via Sentry wizard below\n\nconst { withSentryConfig } = require(\"@sentry/nextjs\");\n\nmodule.exports = withSentryConfig(\n module.exports,\n ${withSentryConfigOptionsTemplate}\n);\n`;\n}\n\nexport function getNextjsConfigEsmCopyPasteSnippet(\n withSentryConfigOptionsTemplate: string,\n): string {\n return `\n\n// next.config.mjs\nimport { withSentryConfig } from \"@sentry/nextjs\";\n\nexport default withSentryConfig(\n yourNextConfig,\n ${withSentryConfigOptionsTemplate}\n);\n`;\n}\n\nfunction getClientIntegrationsSnippet(features: { replay: boolean }) {\n if (features.replay) {\n return `\n\n // Add optional integrations for additional features\n integrations: [\n Sentry.replayIntegration(),\n ],`;\n }\n\n return '';\n}\n\nexport function getSentryConfigContents(\n dsn: string,\n config: 'server' | 'client' | 'edge',\n selectedFeaturesMap: {\n replay: boolean;\n performance: boolean;\n },\n): string {\n let primer;\n if (config === 'server') {\n primer = `// This file configures the initialization of Sentry on the server.\n// The config you add here will be used whenever the server handles a request.\n// https://docs.sentry.io/platforms/javascript/guides/nextjs/`;\n } else if (config === 'client') {\n primer = `// This file configures the initialization of Sentry on the client.\n// The config you add here will be used whenever a users loads a page in their browser.\n// https://docs.sentry.io/platforms/javascript/guides/nextjs/`;\n } else if (config === 'edge') {\n primer = `// This file configures the initialization of Sentry for edge features (middleware, edge routes, and so on).\n// The config you add here will be used whenever one of the edge features is loaded.\n// Note that this config is unrelated to the Vercel Edge Runtime and is also required when running locally.\n// https://docs.sentry.io/platforms/javascript/guides/nextjs/`;\n }\n\n const integrationsOptions = getClientIntegrationsSnippet({\n replay: config === 'client' && selectedFeaturesMap.replay,\n });\n\n let replayOptions = '';\n if (config === 'client') {\n if (selectedFeaturesMap.replay) {\n replayOptions += `\n\n // Define how likely Replay events are sampled.\n // This sets the sample rate to be 10%. You may want this to be 100% while\n // in development and sample at a lower rate in production\n replaysSessionSampleRate: 0.1,\n\n // Define how likely Replay events are sampled when an error occurs.\n replaysOnErrorSampleRate: 1.0,`;\n }\n }\n\n let performanceOptions = '';\n if (selectedFeaturesMap.performance) {\n performanceOptions += `\n\n // Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.\n tracesSampleRate: 1,`;\n }\n\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n return `${primer}\n\nimport * as Sentry from \"@sentry/nextjs\";\n\nSentry.init({\n dsn: \"${dsn}\",${integrationsOptions}${performanceOptions}${replayOptions}\n\n // Setting this option to true will print useful information to the console while you're setting up Sentry.\n debug: false,\n});\n`;\n}\n\nexport function getSentryExamplePageContents(options: {\n selfHosted: boolean;\n sentryUrl: string;\n orgSlug: string;\n projectId: string;\n useClient: boolean;\n}): string {\n const issuesPageLink = options.selfHosted\n ? `${options.sentryUrl}organizations/${options.orgSlug}/issues/?project=${options.projectId}`\n : `https://${options.orgSlug}.sentry.io/issues/?project=${options.projectId}`;\n\n return `${\n options.useClient ? '\"use client\";\\n\\n' : ''\n }import Head from \"next/head\";\nimport * as Sentry from \"@sentry/nextjs\";\n\nexport default function Page() {\n return (\n <div>\n <Head>\n <title>Sentry Onboarding</title>\n <meta name=\"description\" content=\"Test Sentry for your Next.js app!\" />\n </Head>\n\n <main\n style={{\n minHeight: \"100vh\",\n display: \"flex\",\n flexDirection: \"column\",\n justifyContent: \"center\",\n alignItems: \"center\",\n }}\n >\n <h1 style={{ fontSize: \"4rem\", margin: \"14px 0\" }}>\n <svg\n style={{\n height: \"1em\",\n }}\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 200 44\"\n >\n <path\n fill=\"currentColor\"\n d=\"M124.32,28.28,109.56,9.22h-3.68V34.77h3.73V15.19l15.18,19.58h3.26V9.22h-3.73ZM87.15,23.54h13.23V20.22H87.14V12.53h14.93V9.21H83.34V34.77h18.92V31.45H87.14ZM71.59,20.3h0C66.44,19.06,65,18.08,65,15.7c0-2.14,1.89-3.59,4.71-3.59a12.06,12.06,0,0,1,7.07,2.55l2-2.83a14.1,14.1,0,0,0-9-3c-5.06,0-8.59,3-8.59,7.27,0,4.6,3,6.19,8.46,7.52C74.51,24.74,76,25.78,76,28.11s-2,3.77-5.09,3.77a12.34,12.34,0,0,1-8.3-3.26l-2.25,2.69a15.94,15.94,0,0,0,10.42,3.85c5.48,0,9-2.95,9-7.51C79.75,23.79,77.47,21.72,71.59,20.3ZM195.7,9.22l-7.69,12-7.64-12h-4.46L186,24.67V34.78h3.84V24.55L200,9.22Zm-64.63,3.46h8.37v22.1h3.84V12.68h8.37V9.22H131.08ZM169.41,24.8c3.86-1.07,6-3.77,6-7.63,0-4.91-3.59-8-9.38-8H154.67V34.76h3.8V25.58h6.45l6.48,9.2h4.44l-7-9.82Zm-10.95-2.5V12.6h7.17c3.74,0,5.88,1.77,5.88,4.84s-2.29,4.86-5.84,4.86Z M29,2.26a4.67,4.67,0,0,0-8,0L14.42,13.53A32.21,32.21,0,0,1,32.17,40.19H27.55A27.68,27.68,0,0,0,12.09,17.47L6,28a15.92,15.92,0,0,1,9.23,12.17H4.62A.76.76,0,0,1,4,39.06l2.94-5a10.74,10.74,0,0,0-3.36-1.9l-2.91,5a4.54,4.54,0,0,0,1.69,6.24A4.66,4.66,0,0,0,4.62,44H19.15a19.4,19.4,0,0,0-8-17.31l2.31-4A23.87,23.87,0,0,1,23.76,44H36.07a35.88,35.88,0,0,0-16.41-31.8l4.67-8a.77.77,0,0,1,1.05-.27c.53.29,20.29,34.77,20.66,35.17a.76.76,0,0,1-.68,1.13H40.6q.09,1.91,0,3.81h4.78A4.59,4.59,0,0,0,50,39.43a4.49,4.49,0,0,0-.62-2.28Z\"\n ></path>\n </svg>\n </h1>\n\n <p>Get started by sending us a sample error:</p>\n <button\n type=\"button\"\n style={{\n padding: \"12px\",\n cursor: \"pointer\",\n backgroundColor: \"#AD6CAA\",\n borderRadius: \"4px\",\n border: \"none\",\n color: \"white\",\n fontSize: \"14px\",\n margin: \"18px\",\n }}\n onClick={async () => {\n await Sentry.startSpan({\n name: 'Example Frontend Span',\n op: 'test'\n }, async () => {\n const res = await fetch(\"/api/sentry-example-api\");\n if (!res.ok) {\n throw new Error(\"Sentry Example Frontend Error\");\n }\n });\n }}\n >\n Throw error!\n </button>\n\n <p>\n Next, look for the error on the{\" \"}\n <a href=\"${issuesPageLink}\">Issues Page</a>.\n </p>\n <p style={{ marginTop: \"24px\" }}>\n For more information, see{\" \"}\n <a href=\"https://docs.sentry.io/platforms/javascript/guides/nextjs/\">\n https://docs.sentry.io/platforms/javascript/guides/nextjs/\n </a>\n </p>\n </main>\n </div>\n );\n}\n`;\n}\n\nexport function getSentryExamplePagesDirApiRoute() {\n return `// A faulty API route to test Sentry's error monitoring\nexport default function handler(_req, res) {\n throw new Error(\"Sentry Example API Route Error\");\n res.status(200).json({ name: \"John Doe\" });\n}\n`;\n}\n\nexport function getSentryExampleAppDirApiRoute() {\n return `import { NextResponse } from \"next/server\";\n\nexport const dynamic = \"force-dynamic\";\n\n// A faulty API route to test Sentry's error monitoring\nexport function GET() {\n throw new Error(\"Sentry Example API Route Error\");\n return NextResponse.json({ data: \"Testing Sentry Error...\" });\n}\n`;\n}\n\nexport function getSentryDefaultUnderscoreErrorPage() {\n return `import * as Sentry from \"@sentry/nextjs\";\nimport Error from \"next/error\";\n\nconst CustomErrorComponent = (props) => {\n return <Error statusCode={props.statusCode} />;\n};\n\nCustomErrorComponent.getInitialProps = async (contextData) => {\n // In case this is running in a serverless function, await this in order to give Sentry\n // time to send the error before the lambda exits\n await Sentry.captureUnderscoreErrorException(contextData);\n\n // This will contain the status code of the response\n return Error.getInitialProps(contextData);\n};\n\nexport default CustomErrorComponent;\n`;\n}\n\nexport function getSimpleUnderscoreErrorCopyPasteSnippet() {\n return `\n${chalk.green(`import * as Sentry from '@sentry/nextjs';`)}\n${chalk.green(`import Error from \"next/error\";`)}\n\n${chalk.dim(\n '// Replace \"YourCustomErrorComponent\" with your custom error component!',\n)}\nYourCustomErrorComponent.getInitialProps = async (${chalk.green(\n 'contextData',\n )}) => {\n ${chalk.green('await Sentry.captureUnderscoreErrorException(contextData);')}\n\n ${chalk.dim('// ...other getInitialProps code')}\n\n return Error.getInitialProps(contextData);\n};\n`;\n}\n\nexport function getFullUnderscoreErrorCopyPasteSnippet(isTs: boolean) {\n return `\nimport * as Sentry from '@sentry/nextjs';${\n isTs ? '\\nimport type { NextPageContext } from \"next\";' : ''\n }\nimport Error from \"next/error\";\n\n${chalk.dim(\n '// Replace \"YourCustomErrorComponent\" with your custom error component!',\n)}\nYourCustomErrorComponent.getInitialProps = async (contextData${\n isTs ? ': NextPageContext' : ''\n }) => {\n await Sentry.captureUnderscoreErrorException(contextData);\n\n return Error.getInitialProps(contextData);\n};\n`;\n}\n\nexport function getInstrumentationHookContent(\n instrumentationHookLocation: 'src' | 'root',\n) {\n return `import * as Sentry from '@sentry/nextjs';\n\nexport async function register() {\n if (process.env.NEXT_RUNTIME === 'nodejs') {\n await import('${\n instrumentationHookLocation === 'root' ? '.' : '..'\n }/sentry.server.config');\n }\n\n if (process.env.NEXT_RUNTIME === 'edge') {\n await import('${\n instrumentationHookLocation === 'root' ? '.' : '..'\n }/sentry.edge.config');\n }\n}\n\nexport const onRequestError = Sentry.captureRequestError;\n`;\n}\n\nexport function getInstrumentationHookCopyPasteSnippet(\n instrumentationHookLocation: 'src' | 'root',\n) {\n return makeCodeSnippet(true, (unchanged, plus) => {\n return unchanged(`${plus(\"import * as Sentry from '@sentry/nextjs';\")}\n\nexport ${plus('async')} function register() {\n ${plus(`if (process.env.NEXT_RUNTIME === 'nodejs') {\n await import('${\n instrumentationHookLocation === 'root' ? '.' : '..'\n }/sentry.server.config');\n }\n\n if (process.env.NEXT_RUNTIME === 'edge') {\n await import('${\n instrumentationHookLocation === 'root' ? '.' : '..'\n }/sentry.edge.config');\n }`)}\n}\n\n${plus('export const onRequestError = Sentry.captureRequestError;')}\n`);\n });\n}\n\nexport function getSentryDefaultGlobalErrorPage(isTs: boolean) {\n return isTs\n ? `\"use client\";\n\nimport * as Sentry from \"@sentry/nextjs\";\nimport NextError from \"next/error\";\nimport { useEffect } from \"react\";\n\nexport default function GlobalError({ error }: { error: Error & { digest?: string } }) {\n useEffect(() => {\n Sentry.captureException(error);\n }, [error]);\n\n return (\n <html>\n <body>\n {/* \\`NextError\\` is the default Next.js error page component. Its type\n definition requires a \\`statusCode\\` prop. However, since the App Router\n does not expose status codes for errors, we simply pass 0 to render a\n generic error message. */}\n <NextError statusCode={0} />\n </body>\n </html>\n );\n}`\n : `\"use client\";\n\nimport * as Sentry from \"@sentry/nextjs\";\nimport NextError from \"next/error\";\nimport { useEffect } from \"react\";\n\nexport default function GlobalError({ error }) {\n useEffect(() => {\n Sentry.captureException(error);\n }, [error]);\n\n return (\n <html>\n <body>\n {/* \\`NextError\\` is the default Next.js error page component. Its type\n definition requires a \\`statusCode\\` prop. However, since the App Router\n does not expose status codes for errors, we simply pass 0 to render a\n generic error message. */}\n <NextError statusCode={0} />\n </body>\n </html>\n );\n}\n`;\n}\n\nexport function getGlobalErrorCopyPasteSnippet(isTs: boolean) {\n if (isTs) {\n return `\"use client\";\n\n${chalk.green('import * as Sentry from \"@sentry/nextjs\";')}\n${chalk.green('import Error from \"next/error\";')}\n${chalk.green('import { useEffect } from \"react\";')}\n\nexport default function GlobalError(${chalk.green(\n '{ error }: { error: Error }',\n )}) {\n ${chalk.green(`useEffect(() => {\n Sentry.captureException(error);\n }, [error]);`)}\n\n return (\n <html>\n <body>\n {/* Your Error component here... */}\n </body>\n </html>\n );\n}\n`;\n }\n return `\"use client\";\n\n${chalk.green('import * as Sentry from \"@sentry/nextjs\";')}\n${chalk.green('import Error from \"next/error\";')}\n${chalk.green('import { useEffect } from \"react\";')}\n\nexport default function GlobalError(${chalk.green('{ error }')}) {\n ${chalk.green(`useEffect(() => {\n Sentry.captureException(error);\n }, [error]);`)}\n\n return (\n <html>\n <body>\n {/* Your Error component here... */}\n </body>\n </html>\n );\n}\n`;\n}\n"]}
|