forked from babylonlabs-io/simple-staking
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsentry.client.config.ts
More file actions
105 lines (83 loc) · 3.43 KB
/
sentry.client.config.ts
File metadata and controls
105 lines (83 loc) · 3.43 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
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
// 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/react/
/**
* Extra notes:
* This file is manually imported in the main entry point for Vite builds.
* Source maps are handled by the Sentry Vite plugin during build time.
* Reference: https://docs.sentry.io/platforms/javascript/sourcemaps/uploading/vite/
*/
import * as Sentry from "@sentry/react";
import { v4 as uuidv4 } from "uuid";
import { isProductionEnv } from "@/ui/common/config";
import { REPLAYS_ON_ERROR_RATE } from "@/ui/common/constants";
import { getCommitHash } from "@/ui/common/utils/version";
const SENTRY_DEVICE_ID_KEY = "sentry_device_id";
Sentry.init({
enabled: Boolean(
process.env.NEXT_PUBLIC_SIDECAR_API_URL &&
process.env.NEXT_PUBLIC_SENTRY_DSN,
),
// This is pointing to the DSN (Data Source Name) for my local instance.
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
// Tunnel endpoint for proxying Sentry events through our own server
// This helps avoid ad-blockers and CSP issues
tunnel: process.env.NEXT_PUBLIC_SIDECAR_API_URL
? `${process.env.NEXT_PUBLIC_SIDECAR_API_URL}/sentry-tunnel`
: "http://localhost:8092/sentry-tunnel",
// This environment variable is provided in the CI
environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT ?? "local",
// Ensure this release ID matches the one used during 'vite build' for source map uploads
// It's passed via NEXT_PUBLIC_RELEASE_ID in the build environment (e.g., GitHub Actions)
release: process.env.NEXT_PUBLIC_RELEASE_ID ?? "local-dev",
// Ensure this dist ID matches the one used during 'vite build' for source map uploads
// It's passed via NEXT_PUBLIC_DIST_ID in the build environment (e.g., GitHub Actions)
dist: process.env.NEXT_PUBLIC_DIST_ID ?? "local",
// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1,
tracesSampler: (samplingContext) => {
const hasErrorTag = samplingContext.tags?.error === "true";
// Only sample at 100% if it's an error transaction with the error tag
if (hasErrorTag) {
return 1.0;
}
// Default sampling rate for everything else
return 0.01;
},
enableTracing: true,
// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,
replaysOnErrorSampleRate: REPLAYS_ON_ERROR_RATE,
replaysSessionSampleRate: 0,
integrations: [
Sentry.replayIntegration({
// Additional Replay configuration goes in here, for example:
maskAllText: isProductionEnv(),
blockAllMedia: true,
}),
// Browser tracing for performance monitoring and React component annotation
// (matching reactComponentAnnotation: { enabled: true } from original Next.js config)
Sentry.browserTracingIntegration(),
],
beforeSend(event, hint) {
event.extra = {
...(event.extra || {}),
version: getCommitHash(),
};
const exception = hint?.originalException as any;
if (exception?.code) {
event.fingerprint = ["{{ default }}", exception?.code];
}
return event;
},
});
try {
let deviceId = localStorage.getItem(SENTRY_DEVICE_ID_KEY);
if (!deviceId) {
deviceId = uuidv4();
localStorage.setItem(SENTRY_DEVICE_ID_KEY, deviceId);
}
Sentry.setUser({ id: deviceId });
} catch (e) {
Sentry.setUser({ id: uuidv4() });
}