Skip to content

Commit 71e7300

Browse files
zhyd1997zomars
andauthored
build(apps/web): enabled client code Sentry source maps uploading. (calcom#21108)
Co-authored-by: Omar López <zomars@me.com>
1 parent bccffb3 commit 71e7300

13 files changed

Lines changed: 230 additions & 3487 deletions

File tree

.env.example

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,12 @@ SENDGRID_EMAIL=
159159
NEXT_PUBLIC_SENDGRID_SENDER_NAME=
160160

161161
# Sentry
162+
SENTRY_ORG=
163+
SENTRY_PROJECT=
164+
SENTRY_AUTH_TOKEN=
162165
# Used for capturing exceptions and logging messages
163166
NEXT_PUBLIC_SENTRY_DSN=
164167
SENTRY_DEBUG=
165-
SENTRY_DISABLE_CLIENT_SOURCE_MAPS=
166-
SENTRY_DISABLE_SERVER_SOURCE_MAPS=
167168
SENTRY_MAX_SPANS=
168169
SENTRY_TRACES_SAMPLE_RATE=
169170

@@ -363,9 +364,6 @@ E2E_TEST_OIDC_USER_PASSWORD=
363364

364365
# ***********************************************************************************************************
365366

366-
# disable setry server source maps
367-
SENTRY_DISABLE_SERVER_WEBPACK_PLUGIN=1
368-
369367
# api v2
370368
NEXT_PUBLIC_API_V2_URL="http://localhost:5555/api/v2"
371369

apps/web/app/api/version/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { defaultResponderForAppDir } from "app/api/defaultResponderForAppDir";
22
import { NextResponse } from "next/server";
3-
import * as pjson from "package.json";
3+
import packageJson from "package.json";
44

55
async function getHandler() {
6-
return NextResponse.json({ version: pjson.version });
6+
return NextResponse.json({ version: packageJson.version });
77
}
88

99
export const GET = defaultResponderForAppDir(getHandler);

apps/web/instrumentation-client.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// This file configures the initialization of Sentry on the client.
2+
// The added config here will be used whenever a users loads a page in their browser.
3+
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
4+
import * as Sentry from "@sentry/nextjs";
5+
6+
Sentry.init({
7+
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
8+
9+
// Add optional integrations for additional features
10+
integrations: [Sentry.replayIntegration()],
11+
12+
// Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
13+
tracesSampleRate: 1,
14+
15+
// Define how likely Replay events are sampled.
16+
// This sets the sample rate to be 10%. You may want this to be 100% while
17+
// in development and sample at a lower rate in production
18+
replaysSessionSampleRate: 0.1,
19+
20+
// Define how likely Replay events are sampled when an error occurs.
21+
replaysOnErrorSampleRate: 1.0,
22+
23+
// Setting this option to true will print useful information to the console while you're setting up Sentry.
24+
debug: false,
25+
});
26+
27+
export const onRouterTransitionStart = Sentry.captureRouterTransitionStart;

apps/web/instrumentation.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as Sentry from "@sentry/nextjs";
2+
13
export async function register() {
24
if (process.env.NEXT_PUBLIC_SENTRY_DSN && process.env.NEXT_RUNTIME === "nodejs") {
35
await import("./sentry.server.config");
@@ -7,3 +9,5 @@ export async function register() {
79
await import("./sentry.edge.config");
810
}
911
}
12+
13+
export const onRequestError = Sentry.captureRequestError;

apps/web/modules/maintenance/maintenance-view.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default function MaintenancePage() {
99
return (
1010
<div className="bg-subtle flex h-screen">
1111
<div className="bg-default m-auto rounded-md p-10 text-right ltr:text-left">
12-
<h1 className="text-emphasis text-2xl font-medium">{t("down_for_maintenance")}</h1>
12+
<h1 className="text-emphasis text-2xl font-medium">{t("under_maintenance")}</h1>
1313
<p className="text-default mb-6 mt-4 max-w-2xl text-sm">{t("maintenance_message")}</p>
1414
<Button href={`${WEBSITE_URL}/support`}>{t("contact_support")}</Button>
1515
</div>

apps/web/next.config.js

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
require("dotenv").config({ path: "../../.env" });
22
const englishTranslation = require("./public/static/locales/en/common.json");
33
const { withAxiom } = require("next-axiom");
4-
const { withSentryConfig } = require("@sentry/nextjs");
54
const { version } = require("./package.json");
65
const {
76
i18n: { locales },
@@ -188,9 +187,8 @@ const nextConfig = {
188187
experimental: {
189188
// externalize server-side node_modules with size > 1mb, to improve dev mode performance/RAM usage
190189
optimizePackageImports: ["@calcom/ui"],
191-
turbo: {},
192190
},
193-
productionBrowserSourceMaps: process.env.SENTRY_DISABLE_CLIENT_SOURCE_MAPS === "0",
191+
productionBrowserSourceMaps: true,
194192
/* We already do type check on GH actions */
195193
typescript: {
196194
ignoreBuildErrors: !!process.env.CI,
@@ -226,10 +224,6 @@ const nextConfig = {
226224
},
227225
webpack: (config, { webpack, buildId, isServer }) => {
228226
if (isServer) {
229-
if (process.env.SENTRY_DISABLE_SERVER_SOURCE_MAPS === "1") {
230-
config.devtool = false;
231-
}
232-
233227
// Module not found fix @see https://github.com/boxyhq/jackson/issues/1535#issuecomment-1704381612
234228
config.plugins.push(
235229
new webpack.IgnorePlugin({
@@ -691,19 +685,4 @@ const nextConfig = {
691685
},
692686
};
693687

694-
if (!!process.env.NEXT_PUBLIC_SENTRY_DSN) {
695-
plugins.push((nextConfig) =>
696-
withSentryConfig(nextConfig, {
697-
autoInstrumentServerFunctions: false,
698-
hideSourceMaps: true,
699-
// disable source map generation for the server code
700-
disableServerWebpackPlugin: !!process.env.SENTRY_DISABLE_SERVER_WEBPACK_PLUGIN,
701-
silent: false,
702-
sourcemaps: {
703-
disable: process.env.SENTRY_DISABLE_SERVER_SOURCE_MAPS === "1",
704-
},
705-
})
706-
);
707-
}
708-
709688
module.exports = () => plugins.reduce((acc, next) => next(acc), nextConfig);

apps/web/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
"test-codegen": "yarn playwright codegen http://localhost:3000",
1515
"type-check": "tsc --pretty --noEmit",
1616
"type-check:ci": "tsc-absolute --pretty --noEmit",
17+
"sentry:release": "NODE_OPTIONS='--max-old-space-size=6144' node scripts/create-sentry-release.js",
1718
"copy-static": "node scripts/copy-app-store-static.js",
18-
"build": "yarn copy-static && next build",
19+
"build": "yarn copy-static && next build && yarn sentry:release",
1920
"start": "next start",
2021
"lint": "eslint . --ignore-path .gitignore",
2122
"lint:fix": "eslint . --ext .ts,.js,.tsx,.jsx --fix",
@@ -70,7 +71,7 @@
7071
"@radix-ui/react-switch": "^1.0.0",
7172
"@radix-ui/react-toggle-group": "^1.0.0",
7273
"@radix-ui/react-tooltip": "^1.0.0",
73-
"@sentry/nextjs": "^9.8.0",
74+
"@sentry/nextjs": "^9.15.0",
7475
"@stripe/react-stripe-js": "^1.10.0",
7576
"@stripe/stripe-js": "^1.35.0",
7677
"@tanstack/react-query": "^5.17.15",

apps/web/public/static/locales/en/common.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3141,7 +3141,6 @@
31413141
"user_team": "User/Team",
31423142
"client_id_copied": "Client ID copied!",
31433143
"client_secret_copied": "Client secret copied!",
3144-
"down_for_maintenance": "Down for maintenance",
31453144
"maintenance_message": "The Cal.com team are performing scheduled maintenance. If you have any questions, please contact support.",
31463145
"your_payment_failed": "Your payment failed",
31473146
"payment_successful": "Payment successful!",
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const { execSync } = require("child_process");
2+
3+
const CLIENT_FILES_PATH = ".next/static/chunks";
4+
5+
try {
6+
// Continue if required any env vars are not set
7+
const requiredEnvVars = ["SENTRY_AUTH_TOKEN", "SENTRY_ORG", "SENTRY_PROJECT"];
8+
const missingEnvVars = requiredEnvVars.filter((envVar) => !process.env[envVar]);
9+
if (missingEnvVars.length > 0) {
10+
console.log(
11+
`Skipping release creation as required environment variables are not set: ${missingEnvVars.join(", ")}`
12+
);
13+
process.exit(0);
14+
}
15+
16+
const release = execSync("git rev-parse HEAD").toString().trim();
17+
18+
// Add release
19+
execSync(`sentry-cli releases new ${release}`, { stdio: "inherit" });
20+
21+
// Add git commits
22+
execSync(`sentry-cli releases set-commits ${release} --auto`, {
23+
stdio: "inherit",
24+
});
25+
26+
// Inject Debug IDs
27+
execSync(`sentry-cli sourcemaps inject ${CLIENT_FILES_PATH}`, { stdio: "inherit" });
28+
29+
// Upload with release flag
30+
execSync(
31+
`sentry-cli sourcemaps upload ${CLIENT_FILES_PATH} --validate --ext=js --ext=map --release=${release}`,
32+
{
33+
stdio: "inherit",
34+
env: process.env,
35+
}
36+
);
37+
38+
// Finalize the release
39+
execSync(`sentry-cli releases finalize ${release}`, { stdio: "inherit" });
40+
} catch (err) {
41+
console.error("Sentry cli execution failed:", err);
42+
process.exit(1);
43+
}

apps/web/sentry.client.config.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)