forked from Stand-With-Crypto/swc-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sentry.client.config.ts
148 lines (130 loc) · 4.91 KB
/
sentry.client.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// This file configures the initialization of Sentry on the client.
// The config you add here will be used whenever a users loads a page in their browser.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
import * as Sentry from '@sentry/nextjs'
import { NEXT_PUBLIC_ENVIRONMENT } from '@/utils/shared/sharedEnv'
import { toBool } from '@/utils/shared/toBool'
import { getIsSupportedBrowser, maybeDetectBrowser } from './maybeDetectBrowser'
const dsn = process.env.NEXT_PUBLIC_SENTRY_DSN
const COMMON_ERROR_MESSAGES_TO_GROUP = [
'No internet connection detected',
"Failed to execute 'removeChild",
'bytecode', // Can't find variable: bytecode
'ResizeObserver loop', // ResizeObserver loop completed with undelivered notifications.
'Load failed',
'Failed to fetch',
"Failed to read the 'localStorage'",
'Converting circular structure to JSON',
"Cannot read properties of undefined (reading 'call')",
'JSON.stringify cannot serialize cyclic structures',
"Cannot read properties of null (reading 'getItem')",
'The operation is insecure',
'The object can not be found here',
'Properties can only be defined on Objects',
'network error',
'localStorage',
'TLS connection',
'Unexpected end of',
'Unknown root exit status',
]
const COMMON_TRANSACTION_NAMES_TO_GROUP = ['node_modules/@thirdweb-dev', 'maps/api/js']
const isSupportedBrowser = getIsSupportedBrowser(maybeDetectBrowser())
Sentry.init({
environment: NEXT_PUBLIC_ENVIRONMENT,
dsn,
tracesSampleRate: NEXT_PUBLIC_ENVIRONMENT === 'production' ? 0.1 : 1.0,
// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,
normalizeDepth: 10,
// replaysOnErrorSampleRate: 1.0,
// // This sets the sample rate to be 10%. You may want this to be 100% while
// // in development and sample at a lower rate in production
// replaysSessionSampleRate: 0.001,
// You can remove this option if you're not planning to use the Sentry Session Replay feature:
integrations: [
Sentry.extraErrorDataIntegration({ depth: 10 }),
Sentry.replayIntegration({
// see https://docs.sentry.io/platforms/javascript/session-replay/configuration/#using-a-custom-compression-worker
// NOTE: when upgrading Sentry major versions we need to manually update this file for compatibility
workerUrl: '/workers/sentry.worker.js',
}),
],
denyUrls: [
/vitals\.vercel-analytics\.com/i,
// Chrome extensions
/chrome-extension:\//i,
/extensions\//i,
/^chrome:\/\//i,
/inject/i,
],
replaysSessionSampleRate: 0,
replaysOnErrorSampleRate: 1.0,
ignoreErrors: [
// `Can't find variable: bytecode`,
'ResizeObserver loop limit exceeded',
'ResizeObserver loop completed with undelivered notifications',
],
beforeSend: (event, hint) => {
// prevent local errors from triggering sentry
if (NEXT_PUBLIC_ENVIRONMENT === 'local') {
const shouldSuppress = toBool(process.env.SUPPRESS_SENTRY_ERRORS_ON_LOCAL) || !dsn
console.error(
`${shouldSuppress ? 'Suppressed ' : ''}Sentry`,
hint?.originalException || hint?.syntheticException,
)
if (shouldSuppress) {
return null
}
}
// prevent legacy browsers from triggering sentry
if (!isSupportedBrowser) {
return null
}
// force group common transaction names
try {
const transaction = event.transaction
console.log('transaction name match against COMMON_TRANSACTION_NAMES_TO_GROUP', transaction)
if (transaction) {
COMMON_TRANSACTION_NAMES_TO_GROUP.forEach(message => {
if (transaction.indexOf(message) !== -1) {
event.fingerprint = [`forceGroupErrorTransaction-${message}`]
console.log(
`Sentry: Forced fingerprint to "${message}" transaction from "${transaction}"`,
)
}
})
}
} catch (e) {
console.error(e)
console.log('Sentry: Failed to force transaction fingerprint')
return event
}
// force group error names
try {
const errorMessage = getErrorMessage(hint.originalException)
console.log('error message to match against COMMON_ERROR_MESSAGES_TO_GROUP', errorMessage)
if (errorMessage) {
COMMON_ERROR_MESSAGES_TO_GROUP.forEach(message => {
if (errorMessage.indexOf(message) !== -1) {
event.fingerprint = [`forceGroupErrorMessage-${message}`]
console.log(`Sentry: Forced fingerprint to "${message}" message from "${errorMessage}"`)
}
})
}
} catch (e) {
console.error(e)
console.log('Sentry: Failed to force error message fingerprint')
return event
}
return event
},
})
function getErrorMessage(error: unknown) {
if (error instanceof Error) {
return error.message
}
if (error instanceof PromiseRejectionEvent) {
return JSON.stringify(error.reason)
}
return JSON.stringify(error)
}