From e258873976cb50f2adf075d243141ae1aec1af3a Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Thu, 22 Feb 2024 15:36:20 +0300 Subject: [PATCH] apps/web: reconfigure sentry --- apps/web/.gitignore | 3 + apps/web/Dockerfile | 2 + apps/web/config/schema/env.js | 2 + apps/web/config/schema/runtime-config.js | 2 + apps/web/next.config.js | 147 +++++++++++++---------- apps/web/pages/_error.jsx | 18 +++ apps/web/sentry.client.config.js | 34 +++--- apps/web/sentry.edge.config.js | 6 +- apps/web/sentry.server.config.js | 7 +- docker-compose.yml | 4 + 10 files changed, 131 insertions(+), 94 deletions(-) create mode 100644 apps/web/.gitignore create mode 100644 apps/web/pages/_error.jsx diff --git a/apps/web/.gitignore b/apps/web/.gitignore new file mode 100644 index 0000000..387b425 --- /dev/null +++ b/apps/web/.gitignore @@ -0,0 +1,3 @@ + +# Sentry Config File +.sentryclirc diff --git a/apps/web/Dockerfile b/apps/web/Dockerfile index ae5b74e..63ed9eb 100644 --- a/apps/web/Dockerfile +++ b/apps/web/Dockerfile @@ -29,6 +29,8 @@ COPY turbo.json turbo.json ARG USE_DEV_COLORS ARG BASE_PATH ARG SENTRY_DSN +ARG SENTRY_AUTH_TOKEN +ARG SENTRY_ENVIRONMENT ARG SENTRYCLI_CDNURL ARG URL_GET_USER_DIRECT ARG URL_CRM_GRAPHQL_DIRECT diff --git a/apps/web/config/schema/env.js b/apps/web/config/schema/env.js index 23b6240..58db832 100644 --- a/apps/web/config/schema/env.js +++ b/apps/web/config/schema/env.js @@ -3,7 +3,9 @@ const { z } = require('zod'); const envSchema = z.object({ BASE_PATH: z.string().optional().default(''), PORT: z.string().optional(), + SENTRY_AUTH_TOKEN: z.string(), SENTRY_DSN: z.string(), + SENTRY_ENVIRONMENT: z.string(), URL_1C_TRANSTAX_DIRECT: z.string(), URL_CORE_CALCULATE_DIRECT: z.string(), URL_CORE_FINGAP_DIRECT: z.string(), diff --git a/apps/web/config/schema/runtime-config.js b/apps/web/config/schema/runtime-config.js index 7cc6559..cc6d691 100644 --- a/apps/web/config/schema/runtime-config.js +++ b/apps/web/config/schema/runtime-config.js @@ -3,6 +3,7 @@ const envSchema = require('./env'); const publicRuntimeConfigSchema = envSchema.pick({ BASE_PATH: true, SENTRY_DSN: true, + SENTRY_ENVIRONMENT: true, USE_DEV_COLORS: true, }); @@ -10,6 +11,7 @@ const serverRuntimeConfigSchema = envSchema.pick({ BASE_PATH: true, PORT: true, SENTRY_DSN: true, + SENTRY_ENVIRONMENT: true, URL_1C_TRANSTAX_DIRECT: true, URL_CORE_CALCULATE_DIRECT: true, URL_CORE_FINGAP_DIRECT: true, diff --git a/apps/web/next.config.js b/apps/web/next.config.js index fd9209f..5039d8c 100644 --- a/apps/web/next.config.js +++ b/apps/web/next.config.js @@ -18,73 +18,92 @@ function buildFaviconRewrite(source) { }; } -module.exports = withSentryConfig({ - basePath: env.BASE_PATH, - compiler: { - styledComponents: true, +module.exports = withSentryConfig( + { + basePath: env.BASE_PATH, + compiler: { + styledComponents: true, + }, + eslint: { + ignoreDuringBuilds: true, + }, + experimental: { + outputFileTracingRoot: path.join(__dirname, '../../'), + }, + images: { + deviceSizes: devices, + }, + output: 'standalone', + publicRuntimeConfig: publicRuntimeConfigSchema.parse(env), + reactStrictMode: true, + async rewrites() { + return [ + { + destination: env.URL_CRM_GRAPHQL_PROXY + '/:path*', + source: urls.URL_CRM_GRAPHQL_PROXY + '/:path*', + }, + { + destination: env.URL_CRM_DOWNLOADKP_BASE + '/:path*', + source: urls.URL_CRM_DOWNLOADKP_PROXY + '/:path*', + }, + { + destination: env.URL_GET_USER_DIRECT, + source: urls.URL_GET_USER_PROXY, + }, + { + destination: env.URL_CORE_FINGAP_DIRECT, + source: urls.URL_CORE_FINGAP_PROXY, + }, + { + destination: env.URL_1C_TRANSTAX_DIRECT, + source: urls.URL_1C_TRANSTAX_PROXY, + }, + { + destination: env.URL_ELT_KASKO_DIRECT, + source: urls.URL_ELT_KASKO_PROXY, + }, + { + destination: env.URL_ELT_OSAGO_DIRECT, + source: urls.URL_ELT_OSAGO_PROXY, + }, + ...favicons.map((fileName) => buildFaviconRewrite(`/${fileName}`)), + ]; + }, + sentry: { + disableClientWebpackPlugin: true, + disableServerWebpackPlugin: true, + hideSourceMaps: true, + tunnelRoute: '/track-error', + }, + serverRuntimeConfig: serverRuntimeConfigSchema.parse(env), + swcMinify: true, + transpilePackages: [ + 'ui', + 'tools', + 'antd', + '@ant-design/icons', + 'rc-pagination', + 'rc-picker', + '@ant-design', + '@rc-component', + 'rc-table', + ], }, - eslint: { - ignoreDuringBuilds: true, + { + authToken: env.SENTRY_AUTH_TOKEN, + org: 'sentry', + project: 'calculator-client', + silent: true, + url: 'https://errors.evoleasing.ru/', }, - experimental: { - outputFileTracingRoot: path.join(__dirname, '../../'), - }, - images: { - deviceSizes: devices, - }, - output: 'standalone', - publicRuntimeConfig: publicRuntimeConfigSchema.parse(env), - reactStrictMode: true, - async rewrites() { - return [ - { - destination: env.URL_CRM_GRAPHQL_PROXY + '/:path*', - source: urls.URL_CRM_GRAPHQL_PROXY + '/:path*', - }, - { - destination: env.URL_CRM_DOWNLOADKP_BASE + '/:path*', - source: urls.URL_CRM_DOWNLOADKP_PROXY + '/:path*', - }, - { - destination: env.URL_GET_USER_DIRECT, - source: urls.URL_GET_USER_PROXY, - }, - { - destination: env.URL_CORE_FINGAP_DIRECT, - source: urls.URL_CORE_FINGAP_PROXY, - }, - { - destination: env.URL_1C_TRANSTAX_DIRECT, - source: urls.URL_1C_TRANSTAX_PROXY, - }, - { - destination: env.URL_ELT_KASKO_DIRECT, - source: urls.URL_ELT_KASKO_PROXY, - }, - { - destination: env.URL_ELT_OSAGO_DIRECT, - source: urls.URL_ELT_OSAGO_PROXY, - }, - ...favicons.map((fileName) => buildFaviconRewrite(`/${fileName}`)), - ]; - }, - sentry: { + { + automaticVercelMonitors: true, disableClientWebpackPlugin: true, + disableLogger: true, disableServerWebpackPlugin: true, hideSourceMaps: true, + transpileClientSDK: false, tunnelRoute: '/track-error', - }, - serverRuntimeConfig: serverRuntimeConfigSchema.parse(env), - swcMinify: true, - transpilePackages: [ - 'ui', - 'tools', - 'antd', - '@ant-design/icons', - 'rc-pagination', - 'rc-picker', - '@ant-design', - '@rc-component', - 'rc-table', - ], -}); + widenClientFileUpload: true, + } +); diff --git a/apps/web/pages/_error.jsx b/apps/web/pages/_error.jsx new file mode 100644 index 0000000..22b583e --- /dev/null +++ b/apps/web/pages/_error.jsx @@ -0,0 +1,18 @@ +/* eslint-disable canonical/no-use-extend-native */ +import { captureUnderscoreErrorException } from '@sentry/nextjs'; +import Error from 'next/error'; + +function CustomErrorComponent(props) { + return ; +} + +CustomErrorComponent.getInitialProps = async (contextData) => { + // In case this is running in a serverless function, await this in order to give Sentry + // time to send the error before the lambda exits + await captureUnderscoreErrorException(contextData); + + // This will contain the status code of the response + return Error.getInitialProps(contextData); +}; + +export default CustomErrorComponent; diff --git a/apps/web/sentry.client.config.js b/apps/web/sentry.client.config.js index 62ebc88..37f230b 100644 --- a/apps/web/sentry.client.config.js +++ b/apps/web/sentry.client.config.js @@ -5,33 +5,27 @@ // https://docs.sentry.io/platforms/javascript/guides/nextjs/ import getUrls from './config/urls'; -import { init } from '@sentry/nextjs'; +import { publicRuntimeConfigSchema } from '@/config/schema/runtime-config'; +import { init, replayIntegration } from '@sentry/nextjs'; +import getConfig from 'next/config'; const { SENTRY_DSN } = getUrls(); +const { publicRuntimeConfig } = getConfig(); +const { SENTRY_ENVIRONMENT } = publicRuntimeConfigSchema.parse(publicRuntimeConfig); + init({ + debug: false, dsn: SENTRY_DSN, + environment: SENTRY_ENVIRONMENT, - integrations: [], - - // If the entire session is not sampled, use the below sample rate to sample - - // sessions when an error occurs. + integrations: [ + replayIntegration({ + blockAllMedia: true, + maskAllText: false, + }), + ], replaysOnErrorSampleRate: 1, - - // ... - - // Note: if you want to override the automatic release value, do not set a - - // `release` value here - use the environment variable `SENTRY_RELEASE`, so - - // that it will also get attached to your source maps - - // in development and sample at a lower rate in production - replaysSessionSampleRate: 0.1, - - // Adjust this value in production, or use tracesSampler for greater control - tracesSampleRate: 1, }); diff --git a/apps/web/sentry.edge.config.js b/apps/web/sentry.edge.config.js index dfe1168..686cfd6 100644 --- a/apps/web/sentry.edge.config.js +++ b/apps/web/sentry.edge.config.js @@ -8,11 +8,7 @@ import { init } from '@sentry/nextjs'; const { SENTRY_DSN } = getUrls(); init({ + debug: false, dsn: SENTRY_DSN, - // Adjust this value in production, or use tracesSampler for greater control tracesSampleRate: 1, - // ... - // Note: if you want to override the automatic release value, do not set a - // `release` value here - use the environment variable `SENTRY_RELEASE`, so - // that it will also get attached to your source maps }); diff --git a/apps/web/sentry.server.config.js b/apps/web/sentry.server.config.js index 573036f..b284cc6 100644 --- a/apps/web/sentry.server.config.js +++ b/apps/web/sentry.server.config.js @@ -8,11 +8,8 @@ import { init } from '@sentry/nextjs'; const { SENTRY_DSN } = getUrls(); init({ + debug: false, + dsn: SENTRY_DSN, - // Adjust this value in production, or use tracesSampler for greater control tracesSampleRate: 1, - // ... - // Note: if you want to override the automatic release value, do not set a - // `release` value here - use the environment variable `SENTRY_RELEASE`, so - // that it will also get attached to your source maps }); diff --git a/docker-compose.yml b/docker-compose.yml index a5a885b..8d974d0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,8 @@ services: - BASE_PATH=${BASE_PATH} - SENTRY_DSN=${SENTRY_DSN} - SENTRYCLI_CDNURL=${SENTRYCLI_CDNURL} + - SENTRY_AUTH_TOKEN=${SENTRY_AUTH_TOKEN} + - SENTRY_ENVIRONMENT=${SENTRY_ENVIRONMENT} - URL_GET_USER_DIRECT=${URL_GET_USER_DIRECT} - URL_CRM_GRAPHQL_DIRECT=${URL_CRM_GRAPHQL_DIRECT} - URL_CRM_GRAPHQL_PROXY=${URL_CRM_GRAPHQL_PROXY} @@ -22,6 +24,8 @@ services: - BASE_PATH=${BASE_PATH} - SENTRY_DSN=${SENTRY_DSN} - SENTRYCLI_CDNURL=${SENTRYCLI_CDNURL} + - SENTRY_AUTH_TOKEN=${SENTRY_AUTH_TOKEN} + - SENTRY_ENVIRONMENT=${SENTRY_ENVIRONMENT} - URL_GET_USER_DIRECT=${URL_GET_USER_DIRECT} - URL_CRM_GRAPHQL_DIRECT=${URL_CRM_GRAPHQL_DIRECT} - URL_CRM_GRAPHQL_PROXY=${URL_CRM_GRAPHQL_PROXY}