-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathsentry.server.config.ts
More file actions
68 lines (55 loc) · 1.98 KB
/
Copy pathsentry.server.config.ts
File metadata and controls
68 lines (55 loc) · 1.98 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
67
68
// This file configures the initialization of Sentry on the server.
// The config you add here will be used whenever the server handles a request.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
import * as Sentry from "@sentry/nextjs";
/**
* Scrubs sensitive data from events before sending to Sentry
*/
function beforeSend(
event: Sentry.ErrorEvent,
_hint: Sentry.EventHint,
): Sentry.ErrorEvent | null {
// Scrub sensitive headers
if (event.request?.headers) {
delete event.request.headers.cookie;
delete event.request.headers.authorization;
delete event.request.headers.Cookie;
delete event.request.headers.Authorization;
}
// Remove user IP and sensitive user fields
if (event.user) {
event.user.ip_address = null;
delete event.user.email;
}
return event;
}
/**
* Scrubs sensitive data from logs before sending to Sentry
*/
function beforeSendLog(log: Sentry.Log): Sentry.Log | null {
// Remove any sensitive data from log attributes
if (log.attributes) {
delete log.attributes.password;
delete log.attributes.token;
delete log.attributes.apiKey;
delete log.attributes.secret;
}
return log;
}
Sentry.init({
dsn: process.env.SENTRY_DSN,
// Fully disabled in dev — no events queued or sent.
enabled: process.env.NODE_ENV === "production",
// Only trace and log in production — dev sessions would burn free quota fast.
tracesSampleRate: process.env.NODE_ENV === "production" ? 0.1 : 0,
// Enable logs to be sent to Sentry
enableLogs: process.env.NODE_ENV === "production",
// Disable sending user PII (Personally Identifiable Information) by default
// Only enable in non-production environments when explicitly approved
// https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/options/#sendDefaultPii
sendDefaultPii: process.env.NODE_ENV !== "production",
// Scrub sensitive data before sending events
beforeSend,
// Scrub sensitive data before sending logs
beforeSendLog,
});