From 138d65036dc89edc6961352ec8bffa2a133c8dfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Ta=C3=AFeb?= Date: Mon, 13 Jan 2025 14:17:41 +0100 Subject: [PATCH] chore: upgrade sentry sdk --- .gitignore | 3 ++ next.config.js | 71 +++++++++++++++++++++-------------------- sentry.client.config.ts | 17 ++++++---- sentry.edge.config.ts | 2 +- sentry.server.config.ts | 2 +- src/instrumentation.ts | 13 ++++++++ 6 files changed, 64 insertions(+), 44 deletions(-) create mode 100644 src/instrumentation.ts diff --git a/.gitignore b/.gitignore index c0fae573..c46d424c 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,6 @@ certificates /scripts/ficheSolution.json /scripts/retourExperience.json /scripts/ficheDiagnostic.json + +# Sentry Config File +.env.sentry-build-plugin diff --git a/next.config.js b/next.config.js index 1a86446a..9c156cb8 100644 --- a/next.config.js +++ b/next.config.js @@ -1,4 +1,4 @@ -/** @type {import('next').NextConfig} */ +/** @type {import("next").NextConfig} */ const nextConfig = { async headers() { @@ -71,44 +71,45 @@ module.exports = nextConfig; // Injected content via Sentry wizard below const { withSentryConfig } = require("@sentry/nextjs"); -module.exports = withSentryConfig( - module.exports, - { - // For all available options, see: - // https://github.com/getsentry/sentry-webpack-plugin#options - errorHandler: (err, invokeErr, compilation) => { - compilation.warnings.push("Sentry CLI Plugin: " + err.message); - }, - - // Suppresses source map uploading logs during build - silent: true, - org: "betagouv", - project: "plusfraichemaville", - url: "https://sentry.incubateur.net/", +module.exports = withSentryConfig(module.exports, { + // For all available options, see: + // https://github.com/getsentry/sentry-webpack-plugin#options + errorHandler: (err, invokeErr, compilation) => { + compilation.warnings.push("Sentry CLI Plugin: " + err.message); }, - { - // For all available options, see: - // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/ + org: "incubateur-ademe", + project: "plusfraichemaville", + sentryUrl: "https://sentry.incubateur.net/", - // Upload a larger set of source maps for prettier stack traces (increases build time) - widenClientFileUpload: true, + // Only print logs for uploading source maps in CI + silent: !process.env.CI, - // Transpiles SDK to be compatible with IE11 (increases bundle size) - transpileClientSDK: true, + // For all available options, see: + // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/ - // Routes browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers (increases server load) - tunnelRoute: "/monitoring", + // Upload a larger set of source maps for prettier stack traces (increases build time) + widenClientFileUpload: true, - // Hides source maps from generated client bundles - hideSourceMaps: true, + // Automatically annotate React components to show their full name in breadcrumbs and session replay + reactComponentAnnotation: { + enabled: true, + }, - // Automatically tree-shake Sentry logger statements to reduce bundle size - disableLogger: true, + // Uncomment to route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers. + // This can increase your server load as well as your hosting bill. + // Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client- + // side errors will fail. + tunnelRoute: "/monitoring", - // Enables automatic instrumentation of Vercel Cron Monitors. - // See the following for more information: - // https://docs.sentry.io/product/crons/ - // https://vercel.com/docs/cron-jobs - automaticVercelMonitors: true, - }, -); + // Hides source maps from generated client bundles + hideSourceMaps: true, + + // Automatically tree-shake Sentry logger statements to reduce bundle size + disableLogger: true, + + // Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.) + // See the following for more information: + // https://docs.sentry.io/product/crons/ + // https://vercel.com/docs/cron-jobs + automaticVercelMonitors: true, +}); diff --git a/sentry.client.config.ts b/sentry.client.config.ts index 879fd495..191148c8 100644 --- a/sentry.client.config.ts +++ b/sentry.client.config.ts @@ -7,18 +7,21 @@ import * as Sentry from "@sentry/nextjs"; Sentry.init({ dsn: "https://8d4940c318ab411f9ce8eb5d095f5373@sentry.incubateur.net/120", - // Adjust this value in production, or use tracesSampler for greater control + // Add optional integrations for additional features + integrations: [Sentry.replayIntegration()], + + // Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control. tracesSampleRate: 0.2, environment: process.env.NEXT_PUBLIC_SENTRY_ENV, - // Setting this option to true will print useful information to the console while you're setting up Sentry. - debug: false, - - replaysOnErrorSampleRate: 1.0, - + // Define how likely Replay events are sampled. // This sets the sample rate to be 10%. You may want this to be 100% while // in development and sample at a lower rate in production replaysSessionSampleRate: 0.1, - integrations: [], + // Define how likely Replay events are sampled when an error occurs. + replaysOnErrorSampleRate: 1.0, + + // Setting this option to true will print useful information to the console while you're setting up Sentry. + debug: false, }); diff --git a/sentry.edge.config.ts b/sentry.edge.config.ts index ab277846..e355b822 100644 --- a/sentry.edge.config.ts +++ b/sentry.edge.config.ts @@ -8,7 +8,7 @@ import * as Sentry from "@sentry/nextjs"; Sentry.init({ dsn: "https://8d4940c318ab411f9ce8eb5d095f5373@sentry.incubateur.net/120", - // Adjust this value in production, or use tracesSampler for greater control + // Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control. tracesSampleRate: 0.2, environment: process.env.NEXT_PUBLIC_SENTRY_ENV, diff --git a/sentry.server.config.ts b/sentry.server.config.ts index 9f47862a..2d624edf 100644 --- a/sentry.server.config.ts +++ b/sentry.server.config.ts @@ -7,7 +7,7 @@ import * as Sentry from "@sentry/nextjs"; Sentry.init({ dsn: "https://8d4940c318ab411f9ce8eb5d095f5373@sentry.incubateur.net/120", - // Adjust this value in production, or use tracesSampler for greater control + // Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control. tracesSampleRate: 0.2, environment: process.env.NEXT_PUBLIC_SENTRY_ENV, diff --git a/src/instrumentation.ts b/src/instrumentation.ts new file mode 100644 index 00000000..ecb65282 --- /dev/null +++ b/src/instrumentation.ts @@ -0,0 +1,13 @@ +import * as Sentry from "@sentry/nextjs"; + +export async function register() { + if (process.env.NEXT_RUNTIME === "nodejs") { + await import("../sentry.server.config"); + } + + if (process.env.NEXT_RUNTIME === "edge") { + await import("../sentry.edge.config"); + } +} + +export const onRequestError = Sentry.captureRequestError;