Skip to content

Commit 0db87ad

Browse files
committed
chore: move sentry to its own file, call set user
1 parent b0ad7f7 commit 0db87ad

File tree

4 files changed

+45
-22
lines changed

4 files changed

+45
-22
lines changed

frontend/src/ts/controllers/account-controller.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import * as PSA from "../elements/psa";
5050
import defaultResultFilters from "../constants/default-result-filters";
5151
import { getActiveFunboxesWithFunction } from "../test/funbox/list";
5252
import { Snapshot } from "../constants/default-snapshot";
53+
import * as Sentry from "../sentry";
5354

5455
export const gmailProvider = new GoogleAuthProvider();
5556
export const githubProvider = new GithubAuthProvider();
@@ -88,7 +89,10 @@ async function getDataAndInit(): Promise<boolean> {
8889
}
8990
LoadingPage.updateText("Downloading user data...");
9091
await LoadingPage.showBar();
91-
await DB.initSnapshot();
92+
const snapshot = await DB.initSnapshot();
93+
if (snapshot !== false) {
94+
Sentry.setUser(snapshot.uid, snapshot.name);
95+
}
9296
} catch (error) {
9397
console.error(error);
9498
AccountButton.loading(false);
@@ -234,6 +238,7 @@ async function readyFunction(
234238
if (window.location.pathname === "/account") {
235239
window.history.replaceState("", "", "/login");
236240
}
241+
Sentry.clearUser();
237242
PageTransition.set(false);
238243
navigate();
239244
}
@@ -242,6 +247,7 @@ async function readyFunction(
242247
if (window.location.pathname === "/account") {
243248
window.history.replaceState("", "", "/login");
244249
}
250+
Sentry.clearUser();
245251
PageTransition.set(false);
246252
navigate();
247253
}
@@ -465,6 +471,7 @@ export function signOut(): void {
465471
Notifications.add("Signed out", 0, {
466472
duration: 2,
467473
});
474+
Sentry.clearUser();
468475
Settings.hideAccountSection();
469476
AccountButton.update(undefined);
470477
navigate("/login");

frontend/src/ts/db.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export function setSnapshot(newSnapshot: Snapshot | undefined): void {
7171
}
7272
}
7373

74-
export async function initSnapshot(): Promise<Snapshot | number | boolean> {
74+
export async function initSnapshot(): Promise<Snapshot | false> {
7575
//send api request with token that returns tags, presets, and data needed for snap
7676
const snap = getDefaultSnapshot();
7777
try {

frontend/src/ts/index.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ import { isDevEnvironment } from "./utils/misc";
4545
import * as VersionButton from "./elements/version-button";
4646
import * as Focus from "./test/focus";
4747
import { getDevOptionsModal } from "./utils/async-modules";
48-
import * as Sentry from "@sentry/browser";
49-
import { envConfig } from "./constants/env-config";
48+
import * as Sentry from "./sentry";
5049

5150
function addToGlobal(items: Record<string, unknown>): void {
5251
for (const [name, item] of Object.entries(items)) {
@@ -81,22 +80,5 @@ if (isDevEnvironment()) {
8180
module.appendButton();
8281
});
8382
} else {
84-
Sentry.init({
85-
release: envConfig.clientVersion,
86-
dsn: "https://f50c25dc9dd75304a63776063896a39b@o4509236448133120.ingest.us.sentry.io/4509237217394688",
87-
// Setting this option to true will send default PII data to Sentry.
88-
// For example, automatic IP address collection on events
89-
sendDefaultPii: true,
90-
integrations: [
91-
Sentry.browserTracingIntegration(),
92-
Sentry.replayIntegration(),
93-
],
94-
// Tracing
95-
tracesSampleRate: 1.0, // Capture 100% of the transactions
96-
// Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
97-
tracePropagationTargets: ["localhost", /^https:\/\/api\.monkeytype\.com/],
98-
// Session Replay
99-
replaysSessionSampleRate: 0.1, // 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.
100-
replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.
101-
});
83+
Sentry.init();
10284
}

frontend/src/ts/sentry.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import * as Sentry from "@sentry/browser";
2+
import { envConfig } from "./constants/env-config";
3+
4+
export function init(): void {
5+
Sentry.init({
6+
release: envConfig.clientVersion,
7+
dsn: "https://f50c25dc9dd75304a63776063896a39b@o4509236448133120.ingest.us.sentry.io/4509237217394688",
8+
// Setting this option to true will send default PII data to Sentry.
9+
// For example, automatic IP address collection on events
10+
sendDefaultPii: true,
11+
integrations: [
12+
Sentry.browserTracingIntegration(),
13+
Sentry.replayIntegration(),
14+
],
15+
// Tracing
16+
tracesSampleRate: 1.0, // Capture 100% of the transactions
17+
// Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
18+
tracePropagationTargets: ["localhost", /^https:\/\/api\.monkeytype\.com/],
19+
// Session Replay
20+
replaysSessionSampleRate: 0.1, // 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.
21+
replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.
22+
});
23+
}
24+
25+
export function setUser(uid: string, name: string): void {
26+
Sentry.setUser({
27+
id: uid,
28+
username: name,
29+
});
30+
}
31+
32+
export function clearUser(): void {
33+
Sentry.setUser(null);
34+
}

0 commit comments

Comments
 (0)