-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsentry.server.config.ts
More file actions
66 lines (54 loc) · 1.66 KB
/
sentry.server.config.ts
File metadata and controls
66 lines (54 loc) · 1.66 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* Sentry Server Configuration
* This file configures the initialization of Sentry on the server side.
*/
import * as Sentry from '@sentry/nextjs';
const SENTRY_DSN = process.env.SENTRY_DSN;
if (SENTRY_DSN) {
Sentry.init({
dsn: SENTRY_DSN,
// Environment
environment: process.env.NODE_ENV,
// Performance Monitoring
tracesSampleRate: process.env.NODE_ENV === 'production' ? 0.1 : 1.0,
// Debug mode in development
debug: process.env.NODE_ENV === 'development',
// Ignore common non-critical errors
ignoreErrors: [
// Network errors
'ECONNREFUSED',
'ECONNRESET',
'ETIMEDOUT',
// Database connection errors (handled separately)
'PrismaClientKnownRequestError',
],
// Sanitize sensitive data before sending
beforeSend(event) {
// Remove sensitive environment variables from context
if (event.contexts?.runtime) {
delete event.contexts.runtime;
}
// Remove sensitive headers
if (event.request?.headers) {
delete event.request.headers['authorization'];
delete event.request.headers['cookie'];
delete event.request.headers['x-api-key'];
}
// Remove sensitive data from extras
if (event.extra) {
const sensitiveKeys = ['password', 'token', 'secret', 'apiKey', 'api_key'];
for (const key of sensitiveKeys) {
if (key in event.extra) {
event.extra[key] = '[REDACTED]';
}
}
}
return event;
},
// Server-specific integrations
integrations: [
// Capture unhandled promise rejections
Sentry.onUnhandledRejectionIntegration(),
],
});
}