Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/add-sentry-to-yari' into bundles…
Browse files Browse the repository at this point in the history
…ize-compare-add-sentry-to-yari
  • Loading branch information
LeoMcA committed Sep 17, 2024
2 parents 23ec4a1 + bfff095 commit 9352601
Show file tree
Hide file tree
Showing 11 changed files with 218 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/prod-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ jobs:
REACT_APP_OBSERVATORY_API_URL: https://observatory-api.mdn.mozilla.net

# Sentry.
REACT_APP_SENTRY_DSN: ${{ secrets.SENTRY_DSN_CLIENT }}
REACT_APP_SENTRY_ENVIRONMENT: prod
REACT_APP_SENTRY_RELEASE: ${{ github.sha }}
SENTRY_DSN_BUILD: ${{ secrets.SENTRY_DSN_BUILD }}
SENTRY_ENVIRONMENT: prod
SENTRY_RELEASE: ${{ github.sha }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/stage-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ jobs:
REACT_APP_OBSERVATORY_API_URL: https://observatory-api.mdn.allizom.net

# Sentry.
REACT_APP_SENTRY_DSN: ${{ secrets.SENTRY_DSN_CLIENT }}
REACT_APP_SENTRY_ENVIRONMENT: stage
REACT_APP_SENTRY_RELEASE: ${{ github.sha }}
SENTRY_DSN_BUILD: ${{ secrets.SENTRY_DSN_BUILD }}
SENTRY_ENVIRONMENT: stage
SENTRY_RELEASE: ${{ github.sha }}
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ jobs:

# Observatory
REACT_APP_OBSERVATORY_API_URL: https://observatory-api.mdn.allizom.net

# Sentry.
REACT_APP_SENTRY_DSN: ${{ secrets.SENTRY_DSN_CLIENT }}
REACT_APP_SENTRY_ENVIRONMENT: test
REACT_APP_SENTRY_RELEASE: ${{ github.sha }}

run: |
set -eo pipefail
Expand Down
9 changes: 6 additions & 3 deletions build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import path from "node:path";

import chalk from "chalk";
import * as cheerio from "cheerio";
import * as Sentry from "@sentry/node";
import {
setContext as setSentryContext,
setTags as setSentryTags,
} from "@sentry/node";

import {
MacroInvocationError,
Expand Down Expand Up @@ -182,12 +185,12 @@ export async function buildDocument(
document,
documentOptions: DocumentOptions = {}
): Promise<BuiltDocument> {
Sentry.setContext("doc", {
setSentryContext("doc", {
path: document?.fileInfo?.path,
title: document?.metadata?.title,
url: document?.url,
});
Sentry.setTags({
setSentryTags({
doc_slug: document?.metadata?.slug,
doc_locale: document?.metadata?.locale,
});
Expand Down
8 changes: 8 additions & 0 deletions client/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,14 @@ function config(webpackEnv) {
// during a production build.
// Otherwise React will be compiled in the very slow development mode.
new webpack.DefinePlugin(env.stringified),
// Treeshake Sentry (saves about 12 kB on the chunk).
new webpack.DefinePlugin({
__SENTRY_DEBUG__: false,
__SENTRY_TRACING__: false,
__RRWEB_EXCLUDE_IFRAME__: true,
__RRWEB_EXCLUDE_SHADOW_DOM__: true,
__SENTRY_EXCLUDE_REPLAY_WORKER__: true,
}),
// Experimental hot reloading for React .
// https://github.com/facebook/react/tree/main/packages/react-refresh
isEnvDevelopment &&
Expand Down
5 changes: 5 additions & 0 deletions client/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ export const GLEAN_LOG_CLICK = Boolean(
JSON.parse(process.env.REACT_APP_GLEAN_LOG_CLICK || "false")
);

export const SENTRY_DSN = process.env.REACT_APP_SENTRY_DSN || "";
export const SENTRY_ENVIRONMENT =
process.env.REACT_APP_SENTRY_ENVIRONMENT || "";
export const SENTRY_RELEASE = process.env.REACT_APP_SENTRY_RELEASE || "";

export const AI_FEEDBACK_GITHUB_REPO =
process.env.REACT_APP_AI_FEEDBACK_GITHUB_REPO || "mdn/private-ai-feedback";

Expand Down
2 changes: 2 additions & 0 deletions client/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import { UserDataProvider } from "./user-context";
import { UIProvider } from "./ui-context";
import { GleanProvider } from "./telemetry/glean-context";
import { PlacementProvider } from "./placement-context";
import { initSentry } from "./telemetry/sentry";

// import * as serviceWorker from './serviceWorker';
initSentry();

const container = document.getElementById("root");
if (!container) {
Expand Down
41 changes: 41 additions & 0 deletions client/src/telemetry/sentry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { SENTRY_DSN, SENTRY_ENVIRONMENT, SENTRY_RELEASE } from "../env";

let sentryPromise: Promise<any> | null = null;

function loadSentry(): Promise<any> {
if (!sentryPromise) {
sentryPromise = import(
/* webpackChunkName: "sentry" */ "@sentry/react"
).then((Sentry) => {
Sentry.init({
dsn: SENTRY_DSN,
release: SENTRY_RELEASE || "dev",
environment: SENTRY_ENVIRONMENT || "dev",
});
return Sentry;
});
}
return sentryPromise;
}

export function initSentry() {
if (!SENTRY_DSN) {
return;
}
let removeEventListener: (() => void) | null = null;
const capturedMessages = new Set<string>();
const errorHandler = (event: ErrorEvent) => {
loadSentry().then((Sentry) => {
if (removeEventListener) {
removeEventListener();
removeEventListener = null;
}
if (!capturedMessages.has(event.message)) {
Sentry.captureException(event);
capturedMessages.add(event.message);
}
});
};
window.addEventListener("error", errorHandler);
removeEventListener = () => window.removeEventListener("error", errorHandler);
}
1 change: 1 addition & 0 deletions libs/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export const CSP_DIRECTIVES = {
"https://observatory-api.mdn.mozilla.net",

"stats.g.doubleclick.net",
"*.sentry.io",
"https://api.stripe.com",
],
"font-src": ["'self'"],
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@
"@mdn/bcd-utils-api": "^0.0.7",
"@mdn/browser-compat-data": "^5.6.0",
"@mozilla/glean": "5.0.3",
"@sentry/browser": "^8.30.0",
"@sentry/node": "^8.29.0",
"@sentry/react": "^8.29.0",
"@stripe/stripe-js": "^4.5.0",
"@use-it/interval": "^1.0.0",
"@vscode/ripgrep": "^1.15.9",
Expand Down
142 changes: 141 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2577,6 +2577,116 @@
resolved "https://registry.yarnpkg.com/@sec-ant/readable-stream/-/readable-stream-0.4.1.tgz#60de891bb126abfdc5410fdc6166aca065f10a0c"
integrity sha512-831qok9r2t8AlxLko40y2ebgSDhenenCatLVeW/uBtnHPyhHOvG0C7TvfgecV+wHzIm5KUICgzmVpWS+IMEAeg==

"@sentry-internal/[email protected]":
version "8.29.0"
resolved "https://registry.yarnpkg.com/@sentry-internal/browser-utils/-/browser-utils-8.29.0.tgz#c84e8d8a08170dbf52968e6b563775949c2ac532"
integrity sha512-6HpyQkaqPvK6Lnigjlarq/LDYgXT2OBNf24RK7z0ipJSxSIpmtelfzHbnwWYnypNDXfTDdPm97fZEenQHryYJA==
dependencies:
"@sentry/core" "8.29.0"
"@sentry/types" "8.29.0"
"@sentry/utils" "8.29.0"

"@sentry-internal/[email protected]":
version "8.30.0"
resolved "https://registry.yarnpkg.com/@sentry-internal/browser-utils/-/browser-utils-8.30.0.tgz#eb68c79556ffb864eb5924a53affde52f2b77362"
integrity sha512-pwX+awNWaxSOAsBLVLqc1+Hw+Fm1Nci9mbKFA6Ed5YzCG049PnBVQwugpmx2dcyyCqJpORhcIqb9jHdCkYmCiA==
dependencies:
"@sentry/core" "8.30.0"
"@sentry/types" "8.30.0"
"@sentry/utils" "8.30.0"

"@sentry-internal/[email protected]":
version "8.29.0"
resolved "https://registry.yarnpkg.com/@sentry-internal/feedback/-/feedback-8.29.0.tgz#9c562f7d13794131b6ac87860cda5492ed538e37"
integrity sha512-yAL5YMEFk4XaeVRUGEguydahRzaQrNPAaWRv6k+XRzCv9CGBhxb14KXQc9X/penlauMFcDfgelCPKcTqcf6wDw==
dependencies:
"@sentry/core" "8.29.0"
"@sentry/types" "8.29.0"
"@sentry/utils" "8.29.0"

"@sentry-internal/[email protected]":
version "8.30.0"
resolved "https://registry.yarnpkg.com/@sentry-internal/feedback/-/feedback-8.30.0.tgz#6f78a245298502e4cc5ce77313dde6965abfecfe"
integrity sha512-ParFRxQY6helxkwUDmro77Wc5uSIC6rZos88jYMrYwFmoTJaNWf4lDzPyECfdSiSYyzSMZk4dorSUN85Ul7DCg==
dependencies:
"@sentry/core" "8.30.0"
"@sentry/types" "8.30.0"
"@sentry/utils" "8.30.0"

"@sentry-internal/[email protected]":
version "8.29.0"
resolved "https://registry.yarnpkg.com/@sentry-internal/replay-canvas/-/replay-canvas-8.29.0.tgz#57a08adec35641607b53ea079f7a6ef539e98c00"
integrity sha512-W2YbZRvp2lYC50V51fNLcnoIiK1Km4vSc+v6SL7c//lv2qpyumoUAAIDKY+14s8Lgt1RsR6rfZhfheD4O/6WSQ==
dependencies:
"@sentry-internal/replay" "8.29.0"
"@sentry/core" "8.29.0"
"@sentry/types" "8.29.0"
"@sentry/utils" "8.29.0"

"@sentry-internal/[email protected]":
version "8.30.0"
resolved "https://registry.yarnpkg.com/@sentry-internal/replay-canvas/-/replay-canvas-8.30.0.tgz#3630eec14d23b1fd368d8c331ee695aa5bb41425"
integrity sha512-y/QqcvchhtMlVA6eOZicIfTxtZarazQZJuFW0018ynPxBTiuuWSxMCLqduulXUYsFejfD8/eKHb3BpCIFdDYjg==
dependencies:
"@sentry-internal/replay" "8.30.0"
"@sentry/core" "8.30.0"
"@sentry/types" "8.30.0"
"@sentry/utils" "8.30.0"

"@sentry-internal/[email protected]":
version "8.29.0"
resolved "https://registry.yarnpkg.com/@sentry-internal/replay/-/replay-8.29.0.tgz#d704ad5a137c3dd6fe398e0c9856c4fc043be707"
integrity sha512-Xgv/eYucsm7GaGKms2ClQ02NpD07MxjoTjp1/vYZm0H4Q08dVphVZrQp7hL1oX/VD9mb5SFyyKuuIRqIu7S8RA==
dependencies:
"@sentry-internal/browser-utils" "8.29.0"
"@sentry/core" "8.29.0"
"@sentry/types" "8.29.0"
"@sentry/utils" "8.29.0"

"@sentry-internal/[email protected]":
version "8.30.0"
resolved "https://registry.yarnpkg.com/@sentry-internal/replay/-/replay-8.30.0.tgz#6a4a8bd551a16ea5f77f913acbccd88061868c84"
integrity sha512-/KFre+BrovPCiovgAu5N1ErJtkDVzkJA5hV3Jw011AlxRWxrmPwu6+9sV9/rn3tqYAGyq6IggYqeIOHhLh1Ihg==
dependencies:
"@sentry-internal/browser-utils" "8.30.0"
"@sentry/core" "8.30.0"
"@sentry/types" "8.30.0"
"@sentry/utils" "8.30.0"

"@sentry/[email protected]":
version "8.29.0"
resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-8.29.0.tgz#d60a754a26c5235fab05fe2e675ced07209aaa88"
integrity sha512-aKTy4H/3RI0q9LIeepesjWGlGNeh4HGFfwQjzHME8gcWCQ5LSlzYX4U+hu2yp7r1Jfd9MUTFfOuuLih2HGLGsQ==
dependencies:
"@sentry-internal/browser-utils" "8.29.0"
"@sentry-internal/feedback" "8.29.0"
"@sentry-internal/replay" "8.29.0"
"@sentry-internal/replay-canvas" "8.29.0"
"@sentry/core" "8.29.0"
"@sentry/types" "8.29.0"
"@sentry/utils" "8.29.0"

"@sentry/browser@^8.30.0":
version "8.30.0"
resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-8.30.0.tgz#3c6d5ef62d7daca2873b47f59b136c33941b56de"
integrity sha512-M+tKqawH9S3CqlAIcqdZcHbcsNQkEa9MrPqPCYvXco3C4LRpNizJP2XwBiGQY2yK+fOSvbaWpPtlI938/wuRZQ==
dependencies:
"@sentry-internal/browser-utils" "8.30.0"
"@sentry-internal/feedback" "8.30.0"
"@sentry-internal/replay" "8.30.0"
"@sentry-internal/replay-canvas" "8.30.0"
"@sentry/core" "8.30.0"
"@sentry/types" "8.30.0"
"@sentry/utils" "8.30.0"

"@sentry/[email protected]":
version "8.29.0"
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-8.29.0.tgz#52032ece2d7b60f3775f10189c27e26b1cebdbca"
integrity sha512-scMbZaJ0Ov8NPgWn86EdjhyTLrhvRVbTxjg0imJAvhIvRbblH3xyqye/17Qnk2fOp8TNDOl7TBZHi0NCFQ5HUw==
dependencies:
"@sentry/types" "8.29.0"
"@sentry/utils" "8.29.0"

"@sentry/[email protected]":
version "8.30.0"
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-8.30.0.tgz#f929e42e9a537bfa3eb6024082714e9ab98d822b"
Expand Down Expand Up @@ -2632,11 +2742,34 @@
"@sentry/types" "8.30.0"
"@sentry/utils" "8.30.0"

"@sentry/react@^8.29.0":
version "8.29.0"
resolved "https://registry.yarnpkg.com/@sentry/react/-/react-8.29.0.tgz#f69b87a7947213dcaabdd18bafb6ac818d30f0a2"
integrity sha512-ux+9rNHx2ZyWC94OBb5K1HFQU/v64gL/n3co9e/3cD9nUnqXMJuw/IofiwD1fv6nfdWECLU50A1OtXhA9/c+XQ==
dependencies:
"@sentry/browser" "8.29.0"
"@sentry/core" "8.29.0"
"@sentry/types" "8.29.0"
"@sentry/utils" "8.29.0"
hoist-non-react-statics "^3.3.2"

"@sentry/[email protected]":
version "8.29.0"
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-8.29.0.tgz#c19e43524b8e7766028f4da8f02eddcc33518541"
integrity sha512-j4gX3ctzgD4xVWllXAhm6M+kHFEvrFoUPFq60X/pgkjsWCocGuhtNfB0rW43ICG8hCnlz8IYl7O7b8V8qY7SPg==

"@sentry/[email protected]":
version "8.30.0"
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-8.30.0.tgz#5f5011f5b16bafd30a039ca5e8c337e948c703fb"
integrity sha512-kgWW2BCjBmVlSQRG32GonHEVyeDbys74xf9mLPvynwHTgw3+NUlNAlEdu05xnb2ow4bCTHfbkS5G1zRgyv5k4Q==

"@sentry/[email protected]":
version "8.29.0"
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-8.29.0.tgz#d4a36643369e30ba62ef8f40f149420a100f64bb"
integrity sha512-nb93/m3SjQChQJFqJj3oNW3Rz/12yrT7jypTCire3c2hpYWG2uR5n8VY9UUMTA6HLNvdom6tckK7p3bXGXlF0w==
dependencies:
"@sentry/types" "8.29.0"

"@sentry/[email protected]":
version "8.30.0"
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-8.30.0.tgz#2343dd8593ea83890b3e0d792ed3fa257955a26b"
Expand Down Expand Up @@ -7982,6 +8115,13 @@ history@^5.2.0:
dependencies:
"@babel/runtime" "^7.7.6"

hoist-non-react-statics@^3.3.2:
version "3.3.2"
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz#ece0acaf71d62c2969c2ec59feff42a4b1a85b45"
integrity sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==
dependencies:
react-is "^16.7.0"

hoopy@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/hoopy/-/hoopy-0.1.4.tgz#609207d661100033a9a9402ad3dea677381c1b1d"
Expand Down Expand Up @@ -12449,7 +12589,7 @@ react-dom@^18.3.1:
loose-envify "^1.1.0"
scheduler "^0.23.2"

react-is@^16.13.1:
react-is@^16.13.1, react-is@^16.7.0:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==
Expand Down

0 comments on commit 9352601

Please sign in to comment.