-
Notifications
You must be signed in to change notification settings - Fork 6
/
sentry.server.config.ts
45 lines (42 loc) · 1.78 KB
/
sentry.server.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import * as Sentry from '@sentry/nextjs';
const DEFAULT_SENTRY_ENVIRONMENT = 'local';
const USER_AGENT_BLACKLIST = process.env.NEXT_PUBLIC_SENTRY_USER_AGENT_BLACKLIST?.split(',');
const SENTRY_ENVIRONMENTS_ENABLE_SEND_DATA = ['recette', 'production', 'review_app'];
const SENTRY_ENVIRONMENTS_ENABLE_DEBUG = ['local', 'review_app'];
const SEND_DATA = SENTRY_ENVIRONMENTS_ENABLE_SEND_DATA.includes(process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT || '');
const DEBUG_DATA = SENTRY_ENVIRONMENTS_ENABLE_DEBUG.includes(process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT || '');
const RELEASE_NAME_SUFFIX = 'server';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { name, version } = require('./package.json');
const releaseName = (environnement = process.env) => {
if(environnement.NEXT_PUBLIC_SENTRY_ENVIRONMENT === 'review_app') {
return `${name}@review+${version}-${RELEASE_NAME_SUFFIX}`;
}
return `${name}@${version}-${RELEASE_NAME_SUFFIX}`;
};
process.env.NODE_ENV === 'production' && Sentry.init({
beforeSend(event) {
if(!SEND_DATA) {
return null;
}
if (!event.request?.headers) {
return event;
}
const userAgent: string | undefined = event.request.headers['user-agent'];
const userAgentDuBot = USER_AGENT_BLACKLIST?.find((botUserAgent) => userAgent?.includes(botUserAgent));
if (userAgentDuBot !== undefined) {
return null; // Don't send this event to Sentry
}
return event;
},
debug: DEBUG_DATA,
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
enabled: true,
environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT || DEFAULT_SENTRY_ENVIRONMENT,
initialScope: {
level: process.env.NEXT_PUBLIC_SENTRY_LOG_LEVEL as Sentry.SeverityLevel,
},
release: releaseName(),
sendClientReports: SEND_DATA,
tracesSampleRate: Number(process.env.NEXT_PUBLIC_SENTRY_TRACES_SAMPLE_RATE),
});