Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps(sentry): move from raven to @sentry/node #9325

Merged
merged 15 commits into from
Feb 16, 2022
Merged
65 changes: 44 additions & 21 deletions lighthouse-core/lib/sentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

const log = require('lighthouse-logger');

/** @typedef {import('raven').CaptureOptions} CaptureOptions */
/** @typedef {import('raven').ConstructorOptions} ConstructorOptions */
/** @typedef {import('@sentry/node').Breadcrumb} Breadcrumb */
/** @typedef {import('@sentry/node').NodeClient} NodeClient */
/** @typedef {import('@sentry/node').NodeOptions} NodeOptions */
/** @typedef {import('@sentry/node').Severity} Severity */

const SENTRY_URL = 'https://a6bb0da87ee048cc9ae2a345fc09ab2e:63a7029f46f74265981b7e005e0f69f8@sentry.io/174697';

Expand All @@ -21,30 +23,30 @@ const SAMPLED_ERRORS = [
// e.g.: {pattern: /No.*node with given id/, rate: 0.01},
];

const noop = () => {};
const noop = () => { };

/**
* A delegate for sentry so that environments without error reporting enabled will use
* noop functions and environments with error reporting will call the actual Sentry methods.
*/
const sentryDelegate = {
init,
/** @type {(message: string, options?: CaptureOptions) => void} */
/** @type {(message: string, level?: Severity) => void} */
captureMessage: noop,
/** @type {(breadcrumb: any) => void} */
/** @type {(breadcrumb: Breadcrumb) => void} */
captureBreadcrumb: noop,
/** @type {() => any} */
getContext: noop,
/** @type {(error: Error, options?: CaptureOptions) => Promise<void>} */
captureException: async () => {},
/** @type {(error: Error, options: {level?: string, tags?: {[key: string]: any}, extra?: {[key: string]: any}}) => Promise<void>} */
captureException: async () => { },
_shouldSample() {
return SAMPLE_RATE >= Math.random();
},
};

/**
* When called, replaces noops with actual Sentry implementation.
* @param {{url: string, flags: LH.CliFlags, environmentData: ConstructorOptions}} opts
* @param {{url: string, flags: LH.CliFlags, environmentData: NodeOptions}} opts
*/
function init(opts) {
// If error reporting is disabled, leave the functions as a noop
Expand All @@ -58,15 +60,27 @@ function init(opts) {
}

try {
const Sentry = require('raven');
const Sentry = require('@sentry/node');
const sentryConfig = Object.assign({}, opts.environmentData,
{captureUnhandledRejections: true});
Sentry.config(SENTRY_URL, sentryConfig).install();
{
dsn: SENTRY_URL,
captureUnhandledRejections: true,
});
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
Sentry.init(sentryConfig);

const context = Object.assign({},
opts.environmentData.extra,
{
url: opts.url,
emulatedFormFactor: opts.flags.emulatedFormFactor,
throttlingMethod: opts.flags.throttlingMethod,
},
opts.flags.throttling);

// Have each delegate function call the corresponding sentry function by default
sentryDelegate.captureMessage = (...args) => Sentry.captureMessage(...args);
sentryDelegate.captureBreadcrumb = (...args) => Sentry.captureBreadcrumb(...args);
sentryDelegate.getContext = () => Sentry.getContext();
sentryDelegate.captureBreadcrumb = (...args) => Sentry.addBreadcrumb(...args);
sentryDelegate.getContext = () => context;

// Keep a record of exceptions per audit/gatherer so we can just report once
const sentryExceptionCache = new Map();
Expand Down Expand Up @@ -104,20 +118,29 @@ function init(opts) {
}

return new Promise(resolve => {
Sentry.captureException(err, opts, () => resolve());
Sentry.withScope(scope => {
if (opts.level) {
// @ts-ignore - allow any string.
scope.setLevel(opts.level);
}
if (opts.tags) {
scope.setTags(opts.tags);
}
if (opts.extra) {
scope.setExtras(opts.extra);
}
Sentry.captureException(err);
resolve(); // TODO: idk ??
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: i believe this is all synchronous now

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right. We never await Sentry.captureException either (with the exception of tests)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L85 suggests it's necessary.

// Special case captureException to return a Promise so we don't process.exit too early

Let's just keep it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure it was just because the previous api was a callback one, and relied on some sort of event shenanigans which may not happen before the process closes (and Node will wait for a pending Promise to resolve before closing ... probably?)

changed to just have the function be async w/o using any promise stuff directly, just in case.

});
});
};

const context = Object.assign({
url: opts.url,
emulatedFormFactor: opts.flags.emulatedFormFactor,
throttlingMethod: opts.flags.throttlingMethod,
}, opts.flags.throttling);
Sentry.mergeContext({extra: Object.assign({}, opts.environmentData.extra, context)});
// TODO: verify.
Sentry.setExtras(context);
} catch (e) {
log.warn(
'sentry',
'Could not load raven library, errors will not be reported.'
'Could not load Sentry, errors will not be reported.'
);
}
}
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class Runner {
Sentry.captureBreadcrumb({
message: 'Run started',
category: 'lifecycle',
data: sentryContext && sentryContext.extra,
// TODO is this really needed? the 'extra' data is already set at the end of sentry.js ... why put in breadcrumb?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previously you got a few nice UI perks while traversing the history of events but not sure if that's how it works with the new sdk and/or if they've changed things on the server UI

data: sentryContext,
});

// User can run -G solo, -A solo, or -GA together
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
"@types/mkdirp": "^0.5.2",
"@types/node": "*",
"@types/opn": "^3.0.28",
"@types/raven": "^2.5.1",
"@types/resize-observer-browser": "^0.1.1",
"@types/rimraf": "^2.0.2",
"@types/semver": "^5.5.0",
Expand Down Expand Up @@ -137,6 +136,7 @@
"zone.js": "^0.7.3"
},
"dependencies": {
"@sentry/node": "^5.4.3",
"axe-core": "3.2.2",
"chrome-launcher": "^0.10.7",
"configstore": "^3.1.1",
Expand All @@ -159,7 +159,6 @@
"mkdirp": "0.5.1",
"opn": "4.0.2",
"parse-cache-control": "1.0.1",
"raven": "^2.2.1",
"rimraf": "^2.6.1",
"robots-parser": "^2.0.1",
"semver": "^5.3.0",
Expand Down
102 changes: 67 additions & 35 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,62 @@
resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-1.1.2.tgz#54c5a964462be3d4d78af631363c18d6fa91ac26"
integrity sha512-yprFYuno9FtNsSHVlSWd+nRlmGoAbqbeCwOryP6sC/zoCjhpArcRMYp19EvpSUSizJAlsXEwJv+wcWS9XaXdMw==

"@sentry/core@5.4.3":
version "5.4.3"
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-5.4.3.tgz#c9e3a6cc9f5e296c5a5e19a7a925d9ee9125a95f"
integrity sha512-VjRv9BXip2BtCSohi/WQra+Ep4B8ajer1nU1VpKy5tUCjpVfXRpitY23EdEl+MVJH7h6YPZ45JsuFiKGgrtaFQ==
dependencies:
"@sentry/hub" "5.4.3"
"@sentry/minimal" "5.4.3"
"@sentry/types" "5.4.2"
"@sentry/utils" "5.4.2"
tslib "^1.9.3"

"@sentry/hub@5.4.3":
version "5.4.3"
resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-5.4.3.tgz#d6936f976435dd552e06a6a3e9f8cd643e9b9b3f"
integrity sha512-97bnk2dDuCdFv2xhujogqPiDDpKOsHxBXH1jOJ5ezr3/uZNsMRr450FDxxJJYDLuSx+qZ/+vUFfdVNjprBsuSg==
dependencies:
"@sentry/types" "5.4.2"
"@sentry/utils" "5.4.2"
tslib "^1.9.3"

"@sentry/minimal@5.4.3":
version "5.4.3"
resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-5.4.3.tgz#afaa8f7a3b5074efa8d70a2edac920b2e0cdbe15"
integrity sha512-xSCcKDtVtlmJIGmnlNH2fL++4l7iORJ+pOOfTz1Yjm/Il7Tz9wLVodbEfplXmAbOvgG/x9oilbW0MBSnrwKPfQ==
dependencies:
"@sentry/hub" "5.4.3"
"@sentry/types" "5.4.2"
tslib "^1.9.3"

"@sentry/node@^5.4.3":
version "5.4.3"
resolved "https://registry.yarnpkg.com/@sentry/node/-/node-5.4.3.tgz#3de5b050b8c7ca44d25e3b1d6b0cf9b76833d937"
integrity sha512-QdLj1Po+94Ns9y5Z4orvA/febJV8i1uwSVK/cj61FISdb2DXlCWRFV9OYvm0I0EIHr9xAORpOCmyy0JbO1lE8w==
dependencies:
"@sentry/core" "5.4.3"
"@sentry/hub" "5.4.3"
"@sentry/types" "5.4.2"
"@sentry/utils" "5.4.2"
cookie "0.3.1"
https-proxy-agent "2.2.1"
lru_map "0.3.3"
tslib "^1.9.3"

"@sentry/types@5.4.2":
version "5.4.2"
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-5.4.2.tgz#4ab327bced2cfd961dc7a29f0ff43398f913f6a6"
integrity sha512-yh1fd7x5lLOIZ8W3A1I792B3jowJVCWp4HcTRikjTsjbF8lcURY62m+hiLYUFPTIX99AlFRIPiApDkWiwMGYMA==

"@sentry/utils@5.4.2":
version "5.4.2"
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-5.4.2.tgz#c88c6c08d635e1744a443cfefe9e2ed7fa250e4e"
integrity sha512-AW7/TGt2HiPQB8lJ8NgMgaFAIDQpKDF+wV8nENRbC1CP1zzcvb1QBF4zBL2auDT4fhkhVa817064s7vlDiJVLQ==
dependencies:
"@sentry/types" "5.4.2"
tslib "^1.9.3"

"@types/archiver@^2.1.2":
version "2.1.2"
resolved "https://registry.yarnpkg.com/@types/archiver/-/archiver-2.1.2.tgz#e84960d4872570d7c826589cd57f2c076bf198c5"
Expand Down Expand Up @@ -584,14 +640,6 @@
dependencies:
"@types/node" "*"

"@types/raven@^2.5.1":
version "2.5.1"
resolved "https://registry.yarnpkg.com/@types/raven/-/raven-2.5.1.tgz#62ef0a59e29691945e1f295b62ed199619cbd9b6"
integrity sha512-pWEyOzD1VUXqVpDaZGsa1LnhZqXwTjMwVftNVU+nj7QOvRj+HvwUc4aVtljoj3CWGiBPUZyCTOHrtzvx56IQRQ==
dependencies:
"@types/events" "*"
"@types/node" "*"

"@types/resize-observer-browser@^0.1.1":
version "0.1.1"
resolved "https://registry.yarnpkg.com/@types/resize-observer-browser/-/resize-observer-browser-0.1.1.tgz#9b7cdae9cdc8b1a7020ca7588018dac64c770866"
Expand Down Expand Up @@ -3808,7 +3856,7 @@ https-browserify@^1.0.0:
resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-1.0.0.tgz#ec06c10e0a34c0f2faf199f7fd7fc78fffd03c73"
integrity sha1-7AbBDgo0wPL68Zn3/X/Hj//QPHM=

https-proxy-agent@^2.2.1:
https-proxy-agent@2.2.1, https-proxy-agent@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-2.2.1.tgz#51552970fa04d723e04c56d04178c3f92592bbc0"
integrity sha512-HPCTS1LW51bcyMYbxUIOO4HEOlQ1/1qRaFWcyxvwaqUS9TY88aoEuHUY33kuAh1YhVVaDQhLZsnPd+XNARWZlQ==
Expand Down Expand Up @@ -5216,10 +5264,10 @@ lru-cache@^4.0.1:
pseudomap "^1.0.2"
yallist "^2.1.2"

lsmod@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/lsmod/-/lsmod-1.0.0.tgz#9a00f76dca36eb23fa05350afe1b585d4299e64b"
integrity sha1-mgD3bco26yP6BTUK/htYXUKZ5ks=
lru_map@0.3.3:
version "0.3.3"
resolved "https://registry.yarnpkg.com/lru_map/-/lru_map-0.3.3.tgz#b5c8351b9464cbd750335a79650a0ec0e56118dd"
integrity sha1-tcg1G5Rky9dQM1p5ZQoOwOVhGN0=

magic-string@^0.22.4:
version "0.22.5"
Expand Down Expand Up @@ -6354,17 +6402,6 @@ randomfill@^1.0.3:
randombytes "^2.0.5"
safe-buffer "^5.1.0"

raven@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/raven/-/raven-2.2.1.tgz#57c7fbe68a80147ec527def3d7c01575cf948fe3"
integrity sha1-V8f75oqAFH7FJ97z18AVdc+Uj+M=
dependencies:
cookie "0.3.1"
lsmod "1.0.0"
stack-trace "0.0.9"
timed-out "4.0.1"
uuid "3.0.0"

rc@^1.0.1, rc@^1.1.6, rc@^1.2.7:
version "1.2.8"
resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.8.tgz#cd924bf5200a075b83c188cd6b9e211b7fc0d3ed"
Expand Down Expand Up @@ -7048,11 +7085,6 @@ sshpk@^1.7.0:
safer-buffer "^2.0.2"
tweetnacl "~0.14.0"

stack-trace@0.0.9:
version "0.0.9"
resolved "https://registry.yarnpkg.com/stack-trace/-/stack-trace-0.0.9.tgz#a8f6eaeca90674c333e7c43953f275b451510695"
integrity sha1-qPbq7KkGdMMz58Q5U/J1tFFRBpU=

stack-trace@0.0.x:
version "0.0.10"
resolved "https://registry.yarnpkg.com/stack-trace/-/stack-trace-0.0.10.tgz#547c70b347e8d32b4e108ea1a2a159e5fdde19c0"
Expand Down Expand Up @@ -7412,7 +7444,7 @@ through@2, "through@>=2.2.7 <3", through@^2.3.6:
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
integrity sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=

timed-out@4.0.1, timed-out@^4.0.0:
timed-out@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/timed-out/-/timed-out-4.0.1.tgz#f32eacac5a175bea25d7fab565ab3ed8741ef56f"
integrity sha1-8y6srFoXW+ol1/q1Zas+2HQe9W8=
Expand Down Expand Up @@ -7552,6 +7584,11 @@ tslib@1.9.0:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.0.tgz#e37a86fda8cbbaf23a057f473c9f4dc64e5fc2e8"
integrity sha512-f/qGG2tUkrISBlQZEjEqoZ3B2+npJjIf04H1wuAv9iA8i04Icp+61KRXxFdha22670NJopsZCIjhC3SnjPRKrQ==

tslib@^1.9.3:
version "1.10.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a"
integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==

tty-browserify@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.1.tgz#3f05251ee17904dfd0677546670db9651682b811"
Expand Down Expand Up @@ -7753,11 +7790,6 @@ util@~0.10.1:
dependencies:
inherits "2.0.3"

uuid@3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.0.0.tgz#6728fc0459c450d796a99c31837569bdf672d728"
integrity sha1-Zyj8BFnEUNeWqZwxg3VpvfZy1yg=

uuid@^2.0.1:
version "2.0.3"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-2.0.3.tgz#67e2e863797215530dff318e5bf9dcebfd47b21a"
Expand Down