feat: crashReporter: expose rateLimit and compress options (#23062)

This commit is contained in:
Jeremy Apthorp 2020-04-14 10:36:31 -07:00 committed by GitHub
parent fdf7e288bb
commit aeaccd00a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 58 additions and 21 deletions

View file

@ -48,6 +48,11 @@ The `crashReporter` module has the following methods:
* `productName` String (optional) - Defaults to `app.name`. * `productName` String (optional) - Defaults to `app.name`.
* `uploadToServer` Boolean (optional) - Whether crash reports should be sent to the server. Default is `true`. * `uploadToServer` Boolean (optional) - Whether crash reports should be sent to the server. Default is `true`.
* `ignoreSystemCrashHandler` Boolean (optional) - Default is `false`. * `ignoreSystemCrashHandler` Boolean (optional) - Default is `false`.
* `rateLimit` Boolean (optional) _macOS_ _Windows_ - If true, limit the
number of crashes uploaded to 1/hour. Default is `false`.
* `compress` Boolean (optional) _macOS_ _Windows_ - If true, crash reports
will be compressed and uploaded with `Content-Encoding: gzip`. Not all
collection servers support compressed payloads. Default is `false`.
* `extra` Record<String, String> (optional) - An object you can define that will be sent along with the * `extra` Record<String, String> (optional) - An object you can define that will be sent along with the
report. Only string properties are sent correctly. Nested objects are not report. Only string properties are sent correctly. Nested objects are not
supported. When using Windows, the property names and values must be fewer than 64 characters. supported. When using Windows, the property names and values must be fewer than 64 characters.

View file

@ -21,7 +21,9 @@ class CrashReporter {
extra = {}, extra = {},
ignoreSystemCrashHandler = false, ignoreSystemCrashHandler = false,
submitURL, submitURL,
uploadToServer = true uploadToServer = true,
rateLimit = false,
compress = false
} = options; } = options;
if (companyName == null) throw new Error('companyName is a required option to crashReporter.start'); if (companyName == null) throw new Error('companyName is a required option to crashReporter.start');
@ -39,7 +41,7 @@ class CrashReporter {
if (extra._companyName == null) extra._companyName = companyName; if (extra._companyName == null) extra._companyName = companyName;
if (extra._version == null) extra._version = ret.appVersion; if (extra._version == null) extra._version = ret.appVersion;
binding.start(ret.productName, companyName, submitURL, ret.crashesDirectory, uploadToServer, ignoreSystemCrashHandler, extra); binding.start(ret.productName, companyName, submitURL, ret.crashesDirectory, uploadToServer, ignoreSystemCrashHandler, rateLimit, compress, extra);
} }
getLastCrashReport () { getLastCrashReport () {

View file

@ -52,12 +52,14 @@ void CrashReporter::Start(const std::string& product_name,
const base::FilePath& crashes_dir, const base::FilePath& crashes_dir,
bool upload_to_server, bool upload_to_server,
bool skip_system_crash_handler, bool skip_system_crash_handler,
bool rate_limit,
bool compress,
const StringMap& extra_parameters) { const StringMap& extra_parameters) {
is_initialized_ = true; is_initialized_ = true;
SetUploadParameters(extra_parameters); SetUploadParameters(extra_parameters);
Init(product_name, company_name, submit_url, crashes_dir, upload_to_server, Init(product_name, company_name, submit_url, crashes_dir, upload_to_server,
skip_system_crash_handler); skip_system_crash_handler, rate_limit, compress);
} }
void CrashReporter::SetUploadParameters(const StringMap& parameters) { void CrashReporter::SetUploadParameters(const StringMap& parameters) {
@ -105,7 +107,9 @@ void CrashReporter::Init(const std::string& product_name,
const std::string& submit_url, const std::string& submit_url,
const base::FilePath& crashes_dir, const base::FilePath& crashes_dir,
bool auto_submit, bool auto_submit,
bool skip_system_crash_handler) {} bool skip_system_crash_handler,
bool rate_limit,
bool compress) {}
void CrashReporter::SetUploadParameters() {} void CrashReporter::SetUploadParameters() {}
@ -141,12 +145,20 @@ void CrashReporter::StartInstance(const gin_helper::Dictionary& options) {
options.Get("crashesDirectory", &crashes_dir); options.Get("crashesDirectory", &crashes_dir);
StringMap extra_parameters; StringMap extra_parameters;
options.Get("extra", &extra_parameters); options.Get("extra", &extra_parameters);
bool rate_limit = false;
options.Get("rateLimit", &rate_limit);
bool compress = false;
options.Get("compress", &compress);
extra_parameters["_productName"] = product_name; extra_parameters["_productName"] = product_name;
extra_parameters["_companyName"] = company_name; extra_parameters["_companyName"] = company_name;
reporter->Start(product_name, company_name, submit_url, crashes_dir, true, bool upload_to_server = true;
false, extra_parameters); bool skip_system_crash_handler = false;
reporter->Start(product_name, company_name, submit_url, crashes_dir,
upload_to_server, skip_system_crash_handler, rate_limit,
compress, extra_parameters);
} }
} // namespace crash_reporter } // namespace crash_reporter

View file

@ -40,6 +40,8 @@ class CrashReporter {
const base::FilePath& crashes_dir, const base::FilePath& crashes_dir,
bool upload_to_server, bool upload_to_server,
bool skip_system_crash_handler, bool skip_system_crash_handler,
bool rate_limit,
bool compress,
const StringMap& extra_parameters); const StringMap& extra_parameters);
virtual std::vector<CrashReporter::UploadReportResult> GetUploadedReports( virtual std::vector<CrashReporter::UploadReportResult> GetUploadedReports(
@ -61,7 +63,9 @@ class CrashReporter {
const std::string& submit_url, const std::string& submit_url,
const base::FilePath& crashes_dir, const base::FilePath& crashes_dir,
bool upload_to_server, bool upload_to_server,
bool skip_system_crash_handler); bool skip_system_crash_handler,
bool rate_limit,
bool compress);
virtual void SetUploadParameters(); virtual void SetUploadParameters();
StringMap upload_parameters_; StringMap upload_parameters_;

View file

@ -61,7 +61,9 @@ void CrashReporterLinux::Init(const std::string& product_name,
const std::string& submit_url, const std::string& submit_url,
const base::FilePath& crashes_dir, const base::FilePath& crashes_dir,
bool upload_to_server, bool upload_to_server,
bool skip_system_crash_handler) { bool skip_system_crash_handler,
bool rate_limit,
bool compress) {
EnableCrashDumping(crashes_dir); EnableCrashDumping(crashes_dir);
upload_url_ = submit_url; upload_url_ = submit_url;

View file

@ -33,7 +33,9 @@ class CrashReporterLinux : public CrashReporter {
const std::string& submit_url, const std::string& submit_url,
const base::FilePath& crashes_dir, const base::FilePath& crashes_dir,
bool upload_to_server, bool upload_to_server,
bool skip_system_crash_handler) override; bool skip_system_crash_handler,
bool rate_limit,
bool compress) override;
void SetUploadToServer(bool upload_to_server) override; void SetUploadToServer(bool upload_to_server) override;
void SetUploadParameters() override; void SetUploadParameters() override;
bool GetUploadToServer() override; bool GetUploadToServer() override;

View file

@ -26,7 +26,9 @@ class CrashReporterMac : public CrashReporterCrashpad {
const std::string& submit_url, const std::string& submit_url,
const base::FilePath& crashes_dir, const base::FilePath& crashes_dir,
bool upload_to_server, bool upload_to_server,
bool skip_system_crash_handler) override; bool skip_system_crash_handler,
bool rate_limit,
bool compress) override;
void SetUploadParameters() override; void SetUploadParameters() override;
private: private:

View file

@ -27,7 +27,9 @@ void CrashReporterMac::Init(const std::string& product_name,
const std::string& submit_url, const std::string& submit_url,
const base::FilePath& crashes_dir, const base::FilePath& crashes_dir,
bool upload_to_server, bool upload_to_server,
bool skip_system_crash_handler) { bool skip_system_crash_handler,
bool rate_limit,
bool compress) {
// check whether crashpad has been initialized. // check whether crashpad has been initialized.
// Only need to initialize once. // Only need to initialize once.
if (simple_string_dictionary_) if (simple_string_dictionary_)
@ -39,10 +41,11 @@ void CrashReporterMac::Init(const std::string& product_name,
base::FilePath handler_path = base::FilePath handler_path =
framework_bundle_path.Append("Resources").Append("crashpad_handler"); framework_bundle_path.Append("Resources").Append("crashpad_handler");
std::vector<std::string> args = { std::vector<std::string> args;
"--no-rate-limit", if (!rate_limit)
"--no-upload-gzip", // not all servers accept gzip args.emplace_back("--no-rate-limit");
}; if (!compress)
args.emplace_back("--no-upload-gzip");
crashpad::CrashpadClient crashpad_client; crashpad::CrashpadClient crashpad_client;
crashpad_client.StartHandler(handler_path, crashes_dir, crashes_dir, crashpad_client.StartHandler(handler_path, crashes_dir, crashes_dir,

View file

@ -62,7 +62,9 @@ void CrashReporterWin::Init(const std::string& product_name,
const std::string& submit_url, const std::string& submit_url,
const base::FilePath& crashes_dir, const base::FilePath& crashes_dir,
bool upload_to_server, bool upload_to_server,
bool skip_system_crash_handler) { bool skip_system_crash_handler,
bool rate_limit,
bool compress) {
// check whether crashpad has been initialized. // check whether crashpad has been initialized.
// Only need to initialize once. // Only need to initialize once.
if (simple_string_dictionary_) if (simple_string_dictionary_)
@ -71,10 +73,11 @@ void CrashReporterWin::Init(const std::string& product_name,
base::FilePath handler_path; base::FilePath handler_path;
base::PathService::Get(base::FILE_EXE, &handler_path); base::PathService::Get(base::FILE_EXE, &handler_path);
std::vector<std::string> args = { std::vector<std::string> args;
"--no-rate-limit", if (!rate_limit)
"--no-upload-gzip", // not all servers accept gzip args.emplace_back("--no-rate-limit");
}; if (!compress)
args.emplace_back("--no-upload-gzip");
args.push_back(base::StringPrintf("--type=%s", kCrashpadProcess)); args.push_back(base::StringPrintf("--type=%s", kCrashpadProcess));
args.push_back( args.push_back(
base::StringPrintf("--%s=%s", kCrashesDirectoryKey, base::StringPrintf("--%s=%s", kCrashesDirectoryKey,

View file

@ -30,7 +30,9 @@ class CrashReporterWin : public CrashReporterCrashpad {
const std::string& submit_url, const std::string& submit_url,
const base::FilePath& crashes_dir, const base::FilePath& crashes_dir,
bool upload_to_server, bool upload_to_server,
bool skip_system_crash_handler) override; bool skip_system_crash_handler,
bool rate_limit,
bool compress) override;
void SetUploadParameters() override; void SetUploadParameters() override;
crashpad::CrashpadClient& GetCrashpadClient(); crashpad::CrashpadClient& GetCrashpadClient();