Skip to content

Commit 511d8d1

Browse files
committed
chore: add sentry
1 parent c666d13 commit 511d8d1

File tree

6 files changed

+1950
-901
lines changed

6 files changed

+1950
-901
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,4 @@ frontend/src/webfonts-generated
127127
frontend/static/webfonts-preview
128128

129129
.turbo
130+
frontend/.env.sentry-build-plugin

frontend/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"gulp-eslint-new": "1.9.1",
5757
"happy-dom": "15.10.2",
5858
"madge": "8.0.0",
59+
"magic-string": "0.30.17",
5960
"normalize.css": "8.0.1",
6061
"oxlint": "0.16.7",
6162
"postcss": "8.4.31",
@@ -66,7 +67,7 @@
6667
"vite": "6.3.0",
6768
"vite-bundle-visualizer": "1.0.1",
6869
"vite-plugin-checker": "0.7.2",
69-
"vite-plugin-filter-replace": "0.1.13",
70+
"vite-plugin-filter-replace": "0.1.14",
7071
"vite-plugin-html-inject": "1.1.2",
7172
"vite-plugin-inspect": "11.0.0",
7273
"vite-plugin-minify": "2.1.0",
@@ -79,6 +80,8 @@
7980
"@monkeytype/contracts": "workspace:*",
8081
"@monkeytype/funbox": "workspace:*",
8182
"@monkeytype/util": "workspace:*",
83+
"@sentry/browser": "9.14.0",
84+
"@sentry/vite-plugin": "3.3.1",
8285
"@ts-rest/core": "3.51.0",
8386
"balloon-css": "1.2.0",
8487
"canvas-confetti": "1.5.1",

frontend/src/ts/index.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ 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";
4850

4951
function addToGlobal(items: Record<string, unknown>): void {
5052
for (const [name, item] of Object.entries(items)) {
@@ -78,4 +80,23 @@ if (isDevEnvironment()) {
7880
void getDevOptionsModal().then((module) => {
7981
module.appendButton();
8082
});
83+
} 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+
});
81102
}

frontend/vite.config.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import autoprefixer from "autoprefixer";
44
import "dotenv/config";
55
import PROD_CONFIG from "./vite.config.prod";
66
import DEV_CONFIG from "./vite.config.dev";
7+
import MagicString from "magic-string";
78

89
/** @type {import("vite").UserConfig} */
910
const BASE_CONFIG = {
@@ -14,15 +15,19 @@ const BASE_CONFIG = {
1415
if (id.endsWith(".ts")) {
1516
//check if file has a jQuery or $() call
1617
if (/(?:jQuery|\$)\([^)]*\)/.test(src)) {
18+
const s = new MagicString(src);
19+
1720
//if file has "use strict"; at the top, add it below that line, if not, add it at the very top
1821
if (src.startsWith(`"use strict";`)) {
19-
return src.replace(
20-
/("use strict";)/,
21-
`$1import $ from "jquery";`
22-
);
22+
s.appendRight(12, `\nimport $ from "jquery";`);
2323
} else {
24-
return `import $ from "jquery";${src}`;
24+
s.prepend(`import $ from "jquery";`);
2525
}
26+
27+
return {
28+
code: s.toString(),
29+
map: s.generateMap({ hires: true, source: id }),
30+
};
2631
}
2732
}
2833
},

frontend/vite.config.prod.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { writeFileSync } from "fs";
1212
import UnpluginInjectPreload from "unplugin-inject-preload/vite";
1313
import { readdirSync, readFileSync, statSync } from "node:fs";
1414
import { ViteMinifyPlugin } from "vite-plugin-minify";
15+
import { sentryVitePlugin } from "@sentry/vite-plugin";
1516

1617
function pad(numbers, maxLength, fillString) {
1718
return numbers.map((number) =>
@@ -140,6 +141,11 @@ export default {
140141
],
141142
},
142143
}),
144+
sentryVitePlugin({
145+
authToken: process.env.SENTRY_AUTH_TOKEN,
146+
org: "monkeytype",
147+
project: "frontend",
148+
}),
143149
replace([
144150
{
145151
filter: /firebase\.ts$/,
@@ -236,6 +242,7 @@ export default {
236242
},
237243
],
238244
build: {
245+
sourcemap: true,
239246
emptyOutDir: true,
240247
outDir: "../dist",
241248
assetsInlineLimit: 0, //dont inline small files as data

0 commit comments

Comments
 (0)