-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core(lib): add error reporting (#2420)
* refactor(StartUrl): switch from error to debugString object * feat: add error reporting * cave to peer pressure * lint * merge fixes * reduce yarn churn * limit impact to run.ts * clang format * avoid duplicate errors * lint * disable error reporting on test * feedback * remove enableErrorReporting default * update readme * fix yarn.lock * add error reporting doc * doc feedback * move sentry call * more cleanup * remove unused environmentData
- Loading branch information
1 parent
21e25aa
commit de57850
Showing
17 changed files
with
414 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
return false; | ||
} | ||
|
||
let timeout: NodeJS.Timer; | ||
|
||
const prompt = inquirer.prompt([ | ||
{ | ||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.