-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsentry.client.config.ts
65 lines (55 loc) · 1.85 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
// 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'
const SENTRY_DSN = process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN
const replay = Sentry.replayIntegration({
maskAllText: false,
blockAllMedia: false,
})
function handleNavigation(url: URL) {
try {
if (url.pathname.startsWith('/overlay')) {
replay.stop()
} else {
replay.start()
}
} catch (e) {
// Sentry.captureException(e)
}
}
if (SENTRY_DSN) {
Sentry.init({
dsn: SENTRY_DSN,
// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1,
// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,
/**
* Initialize the Sentry SDK as normal.
*
* `replaysSessionSampleRate` and `replaysOnErrorSampleRate` are both set to
* "0" so that we have manual control over session-based replays
*/
replaysSessionSampleRate: 0,
replaysOnErrorSampleRate: 0,
integrations: [replay],
})
if (typeof window !== 'undefined') {
if (window.navigation) {
// Use the Navigation API if available
window.navigation.addEventListener('navigate', (event) => {
const url = new URL(event.destination.url)
handleNavigation(url)
})
} else {
// Fallback for browsers that do not support the Navigation API
const handleFallbackNavigation = () => {
const url = new URL(window.location.href)
handleNavigation(url)
}
window.addEventListener('popstate', handleFallbackNavigation)
window.addEventListener('hashchange', handleFallbackNavigation)
}
}
}