chore: move sentry to its own file, call set user

This commit is contained in:
Miodec 2025-04-29 18:28:20 +02:00
parent b0ad7f7c6e
commit 0db87ad422
4 changed files with 45 additions and 22 deletions

View file

@ -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<boolean> {
}
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");

View file

@ -71,7 +71,7 @@ export function setSnapshot(newSnapshot: Snapshot | undefined): void {
}
}
export async function initSnapshot(): Promise<Snapshot | number | boolean> {
export async function initSnapshot(): Promise<Snapshot | false> {
//send api request with token that returns tags, presets, and data needed for snap
const snap = getDefaultSnapshot();
try {

View file

@ -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<string, unknown>): 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();
}

34
frontend/src/ts/sentry.ts Normal file
View file

@ -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);
}