Skip to content

Commit f18d609

Browse files
authored
feat(build): collect errors + warnings with @sentry/node (#8571)
* feat(build): add @sentry/node Note: This will only capture build errors. * feat(build/sentry): capture console.warn/error/assert() calls * chore(build/sentry): default to dev environment * chore(workflows): enable Sentry in {prod,stage}-build * chore(sentry): set SENTRY_RELEASE
1 parent ebadb3a commit f18d609

File tree

8 files changed

+122
-1
lines changed

8 files changed

+122
-1
lines changed

Diff for: .github/workflows/prod-build.yml

+5
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,11 @@ jobs:
219219
# Placement
220220
REACT_APP_PLACEMENT_ENABLED: true
221221

222+
# Sentry.
223+
SENTRY_DSN_BUILD: ${{ secrets.SENTRY_DSN_BUILD }}
224+
SENTRY_ENVIRONMENT: prod
225+
SENTRY_RELEASE: ${{ github.sha }}
226+
222227
run: |
223228
224229
# Info about which CONTENT_* environment variables were set and to what.

Diff for: .github/workflows/stage-build.yml

+5
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ jobs:
213213
# Placement
214214
REACT_APP_PLACEMENT_ENABLED: true
215215

216+
# Sentry.
217+
SENTRY_DSN_BUILD: ${{ secrets.SENTRY_DSN_BUILD }}
218+
SENTRY_ENVIRONMENT: stage
219+
SENTRY_RELEASE: ${{ github.sha }}
220+
216221
run: |
217222
218223
# Info about which CONTENT_* environment variables were set and to what.

Diff for: build/cli.ts

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
CONTENT_ROOT,
1515
CONTENT_TRANSLATED_ROOT,
1616
BUILD_OUT_ROOT,
17+
SENTRY_DSN_BUILD,
1718
} from "../libs/env/index.js";
1819
import { VALID_LOCALES } from "../libs/constants/index.js";
1920
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -29,6 +30,7 @@ import { DocMetadata, Flaws } from "../libs/types/document.js";
2930
import SearchIndex from "./search-index.js";
3031
import { makeSitemapXML, makeSitemapIndexXML } from "./sitemaps.js";
3132
import { humanFileSize } from "./utils.js";
33+
import { initSentry } from "./sentry.js";
3234

3335
const { program } = caporal;
3436
const { prompt } = inquirer;
@@ -341,6 +343,10 @@ interface BuildArgsAndOptions {
341343
};
342344
}
343345

346+
if (SENTRY_DSN_BUILD) {
347+
initSentry(SENTRY_DSN_BUILD);
348+
}
349+
344350
program
345351
.name("build")
346352
.option("-i, --interactive", "Ask what to do when encountering flaws", {

Diff for: build/sentry.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Sentry from "@sentry/node";
2+
import { CaptureConsole } from "@sentry/integrations";
3+
4+
export function initSentry(
5+
dsn: string,
6+
options?: Omit<Sentry.NodeOptions, "dsn" | "environment" | "integrations">
7+
) {
8+
Sentry.init({
9+
dsn,
10+
environment: process.env.SENTRY_ENVIRONMENT || "dev",
11+
integrations: [new CaptureConsole({ levels: ["warn", "error", "assert"] })],
12+
tracesSampleRate: 1.0,
13+
...options,
14+
});
15+
}

Diff for: libs/env/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ export const PROXY_HOSTNAME: string;
2727
export const CONTENT_HOSTNAME: string;
2828
export const OFFLINE_CONTENT: boolean;
2929
export const FAKE_V1_API: boolean;
30+
export const SENTRY_DSN_BUILD: string;

Diff for: libs/env/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ export const ALWAYS_ALLOW_ROBOTS = JSON.parse(
6464
process.env.BUILD_ALWAYS_ALLOW_ROBOTS || "false"
6565
);
6666

67+
export const SENTRY_DSN_BUILD = process.env.SENTRY_DSN_BUILD || "";
68+
6769
// -------
6870
// content
6971
// -------

Diff for: package.json

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
"@mdn/bcd-utils-api": "^0.0.4",
6464
"@mdn/browser-compat-data": "^5.2.57",
6565
"@mozilla/glean": "1.4.0",
66+
"@sentry/integrations": "^7.51.2",
67+
"@sentry/node": "^7.51.2",
6668
"@use-it/interval": "^1.0.0",
6769
"@vscode/ripgrep": "^1.15.2",
6870
"@webref/css": "^5.4.4",

Diff for: yarn.lock

+86-1
Original file line numberDiff line numberDiff line change
@@ -1950,6 +1950,62 @@
19501950
resolved "https://registry.yarnpkg.com/@rushstack/eslint-patch/-/eslint-patch-1.2.0.tgz#8be36a1f66f3265389e90b5f9c9962146758f728"
19511951
integrity sha512-sXo/qW2/pAcmT43VoRKOJbDOfV3cYpq3szSVfIThQXNt+E4DfKj361vaAt3c88U5tPUxzEswam7GW48PJqtKAg==
19521952

1953+
"@sentry-internal/[email protected]":
1954+
version "7.51.2"
1955+
resolved "https://registry.yarnpkg.com/@sentry-internal/tracing/-/tracing-7.51.2.tgz#17833047646426ca71445327018ffcb33506a699"
1956+
integrity sha512-OBNZn7C4CyocmlSMUPfkY9ORgab346vTHu5kX35PgW5XR51VD2nO5iJCFbyFcsmmRWyCJcZzwMNARouc2V4V8A==
1957+
dependencies:
1958+
"@sentry/core" "7.51.2"
1959+
"@sentry/types" "7.51.2"
1960+
"@sentry/utils" "7.51.2"
1961+
tslib "^1.9.3"
1962+
1963+
1964+
version "7.51.2"
1965+
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-7.51.2.tgz#f2c938de334f9bf26f4416079168275832423964"
1966+
integrity sha512-p8ZiSBxpKe+rkXDMEcgmdoyIHM/1bhpINLZUFPiFH8vzomEr7sgnwRhyrU8y/ADnkPeNg/2YF3QpDpk0OgZJUA==
1967+
dependencies:
1968+
"@sentry/types" "7.51.2"
1969+
"@sentry/utils" "7.51.2"
1970+
tslib "^1.9.3"
1971+
1972+
"@sentry/integrations@^7.51.2":
1973+
version "7.51.2"
1974+
resolved "https://registry.yarnpkg.com/@sentry/integrations/-/integrations-7.51.2.tgz#fce58b9ced601c7f93344b508c67c69a9c883f3d"
1975+
integrity sha512-ZnSptbuDQOoQ13mFX9vvLDfXlbMGjenW2fMIssi9+08B7fD6qxmetkYnWmBK+oEipjoGA//0240Fj8FUvZr0Qg==
1976+
dependencies:
1977+
"@sentry/types" "7.51.2"
1978+
"@sentry/utils" "7.51.2"
1979+
localforage "^1.8.1"
1980+
tslib "^1.9.3"
1981+
1982+
"@sentry/node@^7.51.2":
1983+
version "7.51.2"
1984+
resolved "https://registry.yarnpkg.com/@sentry/node/-/node-7.51.2.tgz#3aa8177699a66265081f711f73652b5e37d0dc53"
1985+
integrity sha512-qtZ2xNVR0ZW+OZWb0Xw0Cdh2QJXOJkXjK84CGC2P4Y6jWrt+GVvwMANPItLT6mAh+ITszTJ5Gk5HHFRpYme5EA==
1986+
dependencies:
1987+
"@sentry-internal/tracing" "7.51.2"
1988+
"@sentry/core" "7.51.2"
1989+
"@sentry/types" "7.51.2"
1990+
"@sentry/utils" "7.51.2"
1991+
cookie "^0.4.1"
1992+
https-proxy-agent "^5.0.0"
1993+
lru_map "^0.3.3"
1994+
tslib "^1.9.3"
1995+
1996+
1997+
version "7.51.2"
1998+
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-7.51.2.tgz#cb742f374d9549195f62c462c915adeafed31d65"
1999+
integrity sha512-/hLnZVrcK7G5BQoD/60u9Qak8c9AvwV8za8TtYPJDUeW59GrqnqOkFji7RVhI7oH1OX4iBxV+9pAKzfYE6A6SA==
2000+
2001+
2002+
version "7.51.2"
2003+
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-7.51.2.tgz#2a52ac2cfb00ffd128248981279c0a561b39eccb"
2004+
integrity sha512-EcjBU7qG4IG+DpIPvdgIBcdIofROMawKoRUNKraeKzH/waEYH9DzCaqp/mzc5/rPBhpDB4BShX9xDDSeH+8c0A==
2005+
dependencies:
2006+
"@sentry/types" "7.51.2"
2007+
tslib "^1.9.3"
2008+
19532009
"@sidvind/better-ajv-errors@^2.0.0":
19542010
version "2.1.0"
19552011
resolved "https://registry.yarnpkg.com/@sidvind/better-ajv-errors/-/better-ajv-errors-2.1.0.tgz#54f4216d2200d60e90ec25c6a27c1ea3afdc6cdf"
@@ -4358,6 +4414,11 @@ [email protected], cookie@^0.5.0:
43584414
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.5.0.tgz#d1f5d71adec6558c58f389987c366aa47e994f8b"
43594415
integrity sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==
43604416

4417+
cookie@^0.4.1:
4418+
version "0.4.2"
4419+
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.4.2.tgz#0e41f24de5ecf317947c82fc789e06a884824432"
4420+
integrity sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==
4421+
43614422
core-js-compat@^3.25.1:
43624423
version "3.25.5"
43634424
resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.25.5.tgz#0016e8158c904f7b059486639e6e82116eafa7d9"
@@ -7296,6 +7357,11 @@ imagemin@^8.0.1:
72967357
replace-ext "^2.0.0"
72977358
slash "^3.0.0"
72987359

7360+
immediate@~3.0.5:
7361+
version "3.0.6"
7362+
resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.0.6.tgz#9db1dbd0faf8de6fbe0f5dd5e56bb606280de69b"
7363+
integrity sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==
7364+
72997365
immer@^9.0.7:
73007366
version "9.0.15"
73017367
resolved "https://registry.yarnpkg.com/immer/-/immer-9.0.15.tgz#0b9169e5b1d22137aba7d43f8a81a495dd1b62dc"
@@ -8611,6 +8677,13 @@ levn@~0.3.0:
86118677
prelude-ls "~1.1.2"
86128678
type-check "~0.3.2"
86138679

8680+
8681+
version "3.1.1"
8682+
resolved "https://registry.yarnpkg.com/lie/-/lie-3.1.1.tgz#9a436b2cc7746ca59de7a41fa469b3efb76bd87e"
8683+
integrity sha512-RiNhHysUjhrDQntfYSfY4MU24coXXdEOgw9WGcKHNeEwffDYbF//u87M1EWaMGzuFoSbqW0C9C6lEEhDOAswfw==
8684+
dependencies:
8685+
immediate "~3.0.5"
8686+
86148687
[email protected], lilconfig@^2.0.5, lilconfig@^2.1.0:
86158688
version "2.1.0"
86168689
resolved "https://registry.yarnpkg.com/lilconfig/-/lilconfig-2.1.0.tgz#78e23ac89ebb7e1bfbf25b18043de756548e7f52"
@@ -8680,6 +8753,13 @@ loader-utils@^3.2.0:
86808753
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-3.2.0.tgz#bcecc51a7898bee7473d4bc6b845b23af8304d4f"
86818754
integrity sha512-HVl9ZqccQihZ7JM85dco1MvO9G+ONvxoGa9rkhzFsneGLKSUg1gJf9bWzhRhcvm2qChhWpebQhP44qxjKIUCaQ==
86828755

8756+
localforage@^1.8.1:
8757+
version "1.10.0"
8758+
resolved "https://registry.yarnpkg.com/localforage/-/localforage-1.10.0.tgz#5c465dc5f62b2807c3a84c0c6a1b1b3212781dd4"
8759+
integrity sha512-14/H1aX7hzBBmmh7sGPd+AOMkkIrHM3Z1PAyGgZigA1H1p5O5ANnMyWzvpAETtG68/dC4pC0ncy3+PPGzXZHPg==
8760+
dependencies:
8761+
lie "3.1.1"
8762+
86838763
locate-path@^3.0.0:
86848764
version "3.0.0"
86858765
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-3.0.0.tgz#dbec3b3ab759758071b58fe59fc41871af21400e"
@@ -8857,6 +8937,11 @@ lru-cache@^9.0.0, lru-cache@^9.1.1:
88578937
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-9.1.1.tgz#c58a93de58630b688de39ad04ef02ef26f1902f1"
88588938
integrity sha512-65/Jky17UwSb0BuB9V+MyDpsOtXKmYwzhyl+cOa9XUiI4uV2Ouy/2voFP3+al0BjZbJgMBD8FojMpAf+Z+qn4A==
88598939

8940+
lru_map@^0.3.3:
8941+
version "0.3.3"
8942+
resolved "https://registry.yarnpkg.com/lru_map/-/lru_map-0.3.3.tgz#b5c8351b9464cbd750335a79650a0ec0e56118dd"
8943+
integrity sha512-Pn9cox5CsMYngeDbmChANltQl+5pi6XmTrraMSzhPmMBbmgcxmqWry0U3PGapCU1yB4/LqCcom7qhHZiF/jGfQ==
8944+
88608945
lz-string@^1.4.4:
88618946
version "1.4.4"
88628947
resolved "https://registry.yarnpkg.com/lz-string/-/lz-string-1.4.4.tgz#c0d8eaf36059f705796e1e344811cf4c498d3a26"
@@ -13217,7 +13302,7 @@ tsconfig-paths@^3.14.1:
1321713302
minimist "^1.2.6"
1321813303
strip-bom "^3.0.0"
1321913304

13220-
tslib@^1.8.1, tslib@^1.9.0:
13305+
tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3:
1322113306
version "1.14.1"
1322213307
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
1322313308
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==

0 commit comments

Comments
 (0)