forked from firka/flutter
enable crash reporting in flutter_tools (#9039)
* enable crash reporting in flutter_tools * fix analytics text; use relative paths * fix test
This commit is contained in:
@@ -6,8 +6,11 @@ import 'dart:async';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:stack_trace/stack_trace.dart';
|
||||
|
||||
import 'base/io.dart';
|
||||
import 'base/os.dart';
|
||||
import 'base/platform.dart';
|
||||
import 'globals.dart';
|
||||
import 'usage.dart';
|
||||
|
||||
@@ -21,8 +24,7 @@ const String _kDartTypeId = 'DartError';
|
||||
const String _kCrashServerHost = 'clients2.google.com';
|
||||
|
||||
/// Path to the crash servlet.
|
||||
// TODO(yjbanov): switch to non-staging when production is ready.
|
||||
const String _kCrashEndpointPath = '/cr/staging_report';
|
||||
const String _kCrashEndpointPath = '/cr/report';
|
||||
|
||||
/// The field corresponding to the multipart/form-data file attachment where
|
||||
/// crash backend expects to find the Dart stack trace.
|
||||
@@ -34,11 +36,6 @@ const String _kStackTraceFileField = 'DartError';
|
||||
/// it must be supplied in the request.
|
||||
const String _kStackTraceFilename = 'stacktrace_file';
|
||||
|
||||
/// We only send crash reports in testing mode.
|
||||
///
|
||||
/// See [enterTestingMode] and [exitTestingMode].
|
||||
bool _testing = false;
|
||||
|
||||
/// Sends crash reports to Google.
|
||||
class CrashReportSender {
|
||||
static final Uri _baseUri = new Uri(
|
||||
@@ -72,12 +69,6 @@ class CrashReportSender {
|
||||
@required String getFlutterVersion(),
|
||||
}) async {
|
||||
try {
|
||||
// TODO(yjbanov): we only actually send crash reports in tests. When we
|
||||
// iron out the process, we will remove this guard and report crashes
|
||||
// when !flutterUsage.suppressAnalytics.
|
||||
if (!_testing)
|
||||
return null;
|
||||
|
||||
if (_usage.suppressAnalytics)
|
||||
return null;
|
||||
|
||||
@@ -92,14 +83,18 @@ class CrashReportSender {
|
||||
);
|
||||
|
||||
final http.MultipartRequest req = new http.MultipartRequest('POST', uri);
|
||||
req.fields['uuid'] = _usage.clientId;
|
||||
req.fields['product'] = _kProductId;
|
||||
req.fields['version'] = flutterVersion;
|
||||
req.fields['osName'] = platform.operatingSystem;
|
||||
req.fields['osVersion'] = os.name; // this actually includes version
|
||||
req.fields['type'] = _kDartTypeId;
|
||||
req.fields['error_runtime_type'] = '${error.runtimeType}';
|
||||
|
||||
final String stackTraceWithRelativePaths = new Chain.parse(stackTrace.toString()).terse.toString();
|
||||
req.files.add(new http.MultipartFile.fromString(
|
||||
_kStackTraceFileField,
|
||||
stackTrace.toString(),
|
||||
stackTraceWithRelativePaths,
|
||||
filename: _kStackTraceFilename,
|
||||
));
|
||||
|
||||
@@ -122,15 +117,3 @@ class CrashReportSender {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Enables testing mode.
|
||||
@visibleForTesting
|
||||
void enterTestingMode() {
|
||||
_testing = true;
|
||||
}
|
||||
|
||||
/// Disables testing mode.
|
||||
@visibleForTesting
|
||||
void exitTestingMode() {
|
||||
_testing = false;
|
||||
}
|
||||
|
||||
@@ -66,6 +66,10 @@ class Usage {
|
||||
_analytics.enabled = value;
|
||||
}
|
||||
|
||||
/// A stable randomly generated UUID used to deduplicate multiple identical
|
||||
/// reports coming from the same computer.
|
||||
String get clientId => _analytics.clientId;
|
||||
|
||||
void sendCommand(String command) {
|
||||
if (!suppressAnalytics)
|
||||
_analytics.sendScreenView(command);
|
||||
@@ -114,12 +118,18 @@ class Usage {
|
||||
╔════════════════════════════════════════════════════════════════════════════╗
|
||||
║ Welcome to Flutter! - https://flutter.io ║
|
||||
║ ║
|
||||
║ The Flutter tool anonymously reports feature usage statistics and basic ║
|
||||
║ crash reports to Google in order to help Google contribute improvements to ║
|
||||
║ Flutter over time. See Google's privacy policy: ║
|
||||
║ The Flutter tool anonymously reports feature usage statistics and crash ║
|
||||
║ reports to Google in order to help Google contribute improvements to ║
|
||||
║ Flutter over time. ║
|
||||
║ ║
|
||||
║ Read about data we send with crash reports: ║
|
||||
║ https://github.com/flutter/flutter/wiki/Flutter-CLI-crash-reporting ║
|
||||
║ ║
|
||||
║ See Google's privacy policy: ║
|
||||
║ https://www.google.com/intl/en/policies/privacy/ ║
|
||||
║ ║
|
||||
║ Use "flutter config --no-analytics" to disable analytics reporting. ║
|
||||
║ Use "flutter config --no-analytics" to disable analytics and crash ║
|
||||
║ reporting. ║
|
||||
╚════════════════════════════════════════════════════════════════════════════╝
|
||||
''', emphasis: true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user