diff --git a/frontend/src/ts/controllers/account-controller.ts b/frontend/src/ts/controllers/account-controller.ts index f1d9b81ee..5d5120b30 100644 --- a/frontend/src/ts/controllers/account-controller.ts +++ b/frontend/src/ts/controllers/account-controller.ts @@ -50,6 +50,7 @@ import * as PSA from "../elements/psa"; import defaultResultFilters from "../constants/default-result-filters"; import { getActiveFunboxesWithFunction } from "../test/funbox/list"; import { Snapshot } from "../constants/default-snapshot"; +import * as Sentry from "../sentry"; export const gmailProvider = new GoogleAuthProvider(); export const githubProvider = new GithubAuthProvider(); @@ -88,7 +89,10 @@ async function getDataAndInit(): Promise { } LoadingPage.updateText("Downloading user data..."); await LoadingPage.showBar(); - await DB.initSnapshot(); + const snapshot = await DB.initSnapshot(); + if (snapshot !== false) { + Sentry.setUser(snapshot.uid, snapshot.name); + } } catch (error) { console.error(error); AccountButton.loading(false); @@ -234,6 +238,7 @@ async function readyFunction( if (window.location.pathname === "/account") { window.history.replaceState("", "", "/login"); } + Sentry.clearUser(); PageTransition.set(false); navigate(); } @@ -242,6 +247,7 @@ async function readyFunction( if (window.location.pathname === "/account") { window.history.replaceState("", "", "/login"); } + Sentry.clearUser(); PageTransition.set(false); navigate(); } @@ -465,6 +471,7 @@ export function signOut(): void { Notifications.add("Signed out", 0, { duration: 2, }); + Sentry.clearUser(); Settings.hideAccountSection(); AccountButton.update(undefined); navigate("/login"); diff --git a/frontend/src/ts/db.ts b/frontend/src/ts/db.ts index fa71b7a1b..952d7d48b 100644 --- a/frontend/src/ts/db.ts +++ b/frontend/src/ts/db.ts @@ -71,7 +71,7 @@ export function setSnapshot(newSnapshot: Snapshot | undefined): void { } } -export async function initSnapshot(): Promise { +export async function initSnapshot(): Promise { //send api request with token that returns tags, presets, and data needed for snap const snap = getDefaultSnapshot(); try { diff --git a/frontend/src/ts/index.ts b/frontend/src/ts/index.ts index f55f66e78..b973b67c6 100644 --- a/frontend/src/ts/index.ts +++ b/frontend/src/ts/index.ts @@ -45,8 +45,7 @@ import { isDevEnvironment } from "./utils/misc"; import * as VersionButton from "./elements/version-button"; import * as Focus from "./test/focus"; import { getDevOptionsModal } from "./utils/async-modules"; -import * as Sentry from "@sentry/browser"; -import { envConfig } from "./constants/env-config"; +import * as Sentry from "./sentry"; function addToGlobal(items: Record): void { for (const [name, item] of Object.entries(items)) { @@ -81,22 +80,5 @@ if (isDevEnvironment()) { module.appendButton(); }); } else { - Sentry.init({ - release: envConfig.clientVersion, - dsn: "https://f50c25dc9dd75304a63776063896a39b@o4509236448133120.ingest.us.sentry.io/4509237217394688", - // Setting this option to true will send default PII data to Sentry. - // For example, automatic IP address collection on events - sendDefaultPii: true, - integrations: [ - Sentry.browserTracingIntegration(), - Sentry.replayIntegration(), - ], - // Tracing - tracesSampleRate: 1.0, // Capture 100% of the transactions - // Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled - tracePropagationTargets: ["localhost", /^https:\/\/api\.monkeytype\.com/], - // Session Replay - 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. - replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur. - }); + Sentry.init(); } diff --git a/frontend/src/ts/sentry.ts b/frontend/src/ts/sentry.ts new file mode 100644 index 000000000..74b9a32c2 --- /dev/null +++ b/frontend/src/ts/sentry.ts @@ -0,0 +1,34 @@ +import * as Sentry from "@sentry/browser"; +import { envConfig } from "./constants/env-config"; + +export function init(): void { + Sentry.init({ + release: envConfig.clientVersion, + dsn: "https://f50c25dc9dd75304a63776063896a39b@o4509236448133120.ingest.us.sentry.io/4509237217394688", + // Setting this option to true will send default PII data to Sentry. + // For example, automatic IP address collection on events + sendDefaultPii: true, + integrations: [ + Sentry.browserTracingIntegration(), + Sentry.replayIntegration(), + ], + // Tracing + tracesSampleRate: 1.0, // Capture 100% of the transactions + // Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled + tracePropagationTargets: ["localhost", /^https:\/\/api\.monkeytype\.com/], + // Session Replay + 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. + replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur. + }); +} + +export function setUser(uid: string, name: string): void { + Sentry.setUser({ + id: uid, + username: name, + }); +} + +export function clearUser(): void { + Sentry.setUser(null); +}