apps/web: reconfigure sentry

This commit is contained in:
vchikalkin 2024-02-22 15:36:20 +03:00
parent 59e45ddc63
commit e258873976
10 changed files with 131 additions and 94 deletions

3
apps/web/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Sentry Config File
.sentryclirc

View File

@ -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

View File

@ -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(),

View File

@ -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,

View File

@ -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,
}
);

18
apps/web/pages/_error.jsx Normal file
View File

@ -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 <Error statusCode={props.statusCode} />;
}
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;

View File

@ -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,
});

View File

@ -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
});

View File

@ -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
});

View File

@ -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}