Skip to content

Commit e5d8bd3

Browse files
committed
chore: always init sentry, dont send in dev mode, add debug logs to sentry
1 parent 33a9022 commit e5d8bd3

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

frontend/src/ts/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ function addToGlobal(items: Record<string, unknown>): void {
5757
void loadFromLocalStorage();
5858
void VersionButton.update();
5959
Focus.set(true, true);
60+
Sentry.init();
6061

6162
addToGlobal({
6263
snapshot: DB.getSnapshot,
@@ -70,6 +71,7 @@ addToGlobal({
7071
toggleUnsmoothedRaw: Result.toggleUnsmoothedRaw,
7172
egVideoListener: egVideoListener,
7273
toggleDebugLogs: Logger.toggleDebugLogs,
74+
toggleSentryDebug: Sentry.toggleDebug,
7375
});
7476

7577
if (isDevEnvironment()) {
@@ -79,6 +81,4 @@ if (isDevEnvironment()) {
7981
void getDevOptionsModal().then((module) => {
8082
module.appendButton();
8183
});
82-
} else {
83-
Sentry.init();
8484
}

frontend/src/ts/sentry.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import * as Sentry from "@sentry/browser";
22
import { envConfig } from "./constants/env-config";
33

4+
let debug = false;
5+
46
export function init(): void {
57
Sentry.init({
68
release: envConfig.clientVersion,
79
dsn: "https://f50c25dc9dd75304a63776063896a39b@o4509236448133120.ingest.us.sentry.io/4509237217394688",
810
// Setting this option to true will send default PII data to Sentry.
911
// For example, automatic IP address collection on events
1012
sendDefaultPii: true,
13+
environment: envConfig.isDevelopment ? "development" : "production",
1114
integrations: [
1215
Sentry.browserTracingIntegration(),
1316
Sentry.replayIntegration({
@@ -31,7 +34,6 @@ export function init(): void {
3134
// Session Replay
3235
replaysSessionSampleRate: 0, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production.
3336
replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.
34-
allowUrls: ["https://*.monkeytype.com"],
3537
ignoreErrors: [
3638
/**
3739
* Thrown when firefox prevents an add-on from refrencing a DOM element that has been removed.
@@ -45,7 +47,46 @@ export function init(): void {
4547
"NotFoundError: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.",
4648
"NotFoundError: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.",
4749
"Error: There is no clipping info for given tab",
50+
"Non-Error promise rejection captured",
51+
"Object captured as promise rejection",
4852
],
53+
beforeSend(event) {
54+
if (envConfig.isDevelopment) {
55+
console.debug(
56+
"Sentry beforeSend, not sending in development mode",
57+
event
58+
);
59+
return null;
60+
} else {
61+
if (debug) {
62+
console.debug("Sentry beforeSend", event);
63+
}
64+
}
65+
66+
return event;
67+
68+
// console.log(
69+
// "BEFORE SEND FRAMES",
70+
// event.exception?.values?.[0]?.stacktrace?.frames
71+
// );
72+
// if (
73+
// event.exception !== undefined &&
74+
// event.exception.values !== undefined &&
75+
// event.exception.values.length > 0
76+
// ) {
77+
// const exception = event.exception.values[0];
78+
// if (exception && exception.stacktrace) {
79+
// console.log(exception);
80+
// const frames = exception.stacktrace.frames;
81+
// for (const frame of frames ?? []) {
82+
// if (frame.filename && frame.filename.includes("monkeytype")) {
83+
// // return event;
84+
// }
85+
// }
86+
// }
87+
// }
88+
// return null;
89+
},
4990
beforeBreadcrumb(breadcrumb, _hint) {
5091
if (breadcrumb.category === "console" && breadcrumb.level === "debug") {
5192
return null;
@@ -69,3 +110,8 @@ export function clearUser(): void {
69110
export function captureException(error: Error): void {
70111
Sentry.captureException(error);
71112
}
113+
114+
export function toggleDebug(): void {
115+
debug = !debug;
116+
console.debug("Sentry debug mode:", debug);
117+
}

0 commit comments

Comments
 (0)