-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
core(lib): add error reporting #2420
Changes from all commits
fbd724e
528286d
062fee6
b7f89f6
94f6f54
5ebc608
80f2040
140ac9e
eea3f67
40c0506
2624082
011a77d
14a833a
7ba93f4
37718c2
2891e64
58e186d
7d83585
38c9630
49c061c
cf0e640
637b124
d77270a
6b4f9ea
1aac5a2
a4c982d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Error Reporting Explained | ||
|
||
## What's going on? | ||
|
||
The Lighthouse team is constantly trying to improve the reliability of our tools, so we've added error tracking functionality to the CLI. Given your consent, we would like to anonymously report runtime exceptions using [Sentry](https://sentry.io/welcome/). We will use this information to detect new bugs and avoid regressions. | ||
|
||
Only CLI users are currently impacted. DevTools, extension, and node module users will not have errors reported. | ||
|
||
## What will happen if I opt-in? | ||
Runtime exceptions will be reported to the team along with information on your environment such as the URL you tested, your OS, and Chrome version. See [what data gets reported](#what-data-gets-reported). | ||
|
||
## What will happen if I do not opt-in? | ||
Runtime exceptions will not be reported to the team. Your ability to use Lighthouse will not be affected in any way. | ||
|
||
## What data gets reported? | ||
|
||
* The URL you tested | ||
* The runtime settings used (throttling enabled/disabled, emulation, etc) | ||
* The message, stack trace, and associated data of the error | ||
* The file path of Lighthouse node module on your machine | ||
* Your Lighthouse version | ||
* Your Chrome version | ||
* Your operating system | ||
|
||
## How do I opt-in? | ||
The first time you run the CLI you will be prompted with a message asking you if Lighthouse can anonymously report runtime exceptions. You can give a direct response of `yes` or `no` (`y`, `n`, and pressing enter which defaults to `no` are also acceptable responses), and you will not be prompted again. If no response is given within 20 seconds, a `no` response will be assumed, and you will not be prompted again. Non-interactive terminal sessions and invocations with the `CI` environment variable set will automatically not be prompted and will not opt-in by default. | ||
|
||
The CLI also has two flags to control error reporting that will override the saved preference. Running Lighthouse with `--enable-error-reporting` will report errors regardless of the saved preference, and running Lighthouse with `--no-enable-error-reporting` will *not* report errors regardless of the saved preferences. | ||
|
||
## How do I change my opt-in preference? | ||
Your response to the prompt will be saved to your home directory `~/.config/configstore/lighthouse.json` and used on future runs. To trigger a re-prompt, simply delete this file and Lighthouse will ask again on the next run. You can also edit this json file directly or run Lighthouse with the `--[no-]enable-error-reporting` flags. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* @license Copyright 2017 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
import {Configstore, inquirer} from './shim-modules'; | ||
|
||
const log = require('lighthouse-logger'); | ||
|
||
const MAXIMUM_WAIT_TIME = 20 * 1000; | ||
// clang-format off | ||
const MESSAGE = | ||
`${log.reset}We're constantly trying to improve Lighthouse and its reliability.\n ` + | ||
`May we anonymously report runtime exceptions to improve the tool over time?\n ` + | ||
`${log.reset}Learn more: https://github.com/GoogleChrome/lighthouse/blob/master/docs/error-reporting.md`; | ||
// clang-format on | ||
|
||
async function prompt() { | ||
if (!process.stdout.isTTY || process.env.CI) { | ||
// Default non-interactive sessions to false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wdyt about defaulting CI to true? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm I'm definitely against in our CI so an opt-out env variable seems good. It'd be nice to gather errors from folks running Lighthouse in CI, but silently opting them in seems bad. Can always use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do like the idea of enabling this for our smoke tests on master though 👍 followup work There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok sg |
||
return false; | ||
} | ||
|
||
let timeout: NodeJS.Timer; | ||
|
||
const prompt = inquirer.prompt([ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm strange, I can't repro, it happens every time? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
type: 'confirm', | ||
name: 'isErrorReportingEnabled', | ||
default: false, | ||
message: MESSAGE, | ||
}, | ||
]); | ||
|
||
const timeoutPromise = new Promise((resolve: (a: boolean) => {}) => { | ||
timeout = setTimeout(() => { | ||
prompt.ui.close(); | ||
process.stdout.write('\n'); | ||
log.warn('CLI', 'No response to error logging preference, errors will not be reported.'); | ||
resolve(false); | ||
}, MAXIMUM_WAIT_TIME); | ||
}); | ||
|
||
return Promise.race([ | ||
prompt.then((result: {isErrorReportingEnabled: boolean}) => { | ||
clearTimeout(timeout); | ||
return result.isErrorReportingEnabled; | ||
}), | ||
timeoutPromise, | ||
]); | ||
} | ||
|
||
export async function askPermission() { | ||
const configstore = new Configstore('lighthouse'); | ||
let isErrorReportingEnabled = configstore.get('isErrorReportingEnabled'); | ||
if (typeof isErrorReportingEnabled === 'boolean') { | ||
return isErrorReportingEnabled; | ||
} | ||
|
||
isErrorReportingEnabled = await prompt(); | ||
configstore.set('isErrorReportingEnabled', isErrorReportingEnabled); | ||
return isErrorReportingEnabled; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should add this to the readme.
We probably also want to add a note to the readme that the CLI will ask you one time if you want to opt in to sending analytics about errors LH runs into. Opting out will opt out permanently, or you can pass in
--enable-error-reporting false
, or if theCI
environment variable is set to true.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done