start method
Future<void>
start({
- String? apiKey,
- BugsnagUser? user,
- bool persistUser = true,
- String? context,
- String? appType,
- String? appVersion,
- String? bundleVersion,
- String? releaseStage,
- BugsnagEnabledErrorTypes enabledErrorTypes = BugsnagEnabledErrorTypes.all,
- BugsnagEndpointConfiguration endpoints = BugsnagEndpointConfiguration.bugsnag,
- int maxBreadcrumbs = 50,
- int maxPersistedSessions = 128,
- int maxPersistedEvents = 32,
- int maxStringValueLength = 10000,
- bool autoTrackSessions = true,
- bool autoDetectErrors = true,
- BugsnagThreadSendPolicy sendThreads = BugsnagThreadSendPolicy.always,
- int launchDurationMillis = 5000,
- bool sendLaunchCrashesSynchronously = true,
- int appHangThresholdMillis = appHangThresholdFatalOnly,
- Set<
String> redactedKeys = const {'password'}, - Set<
String> discardClasses = const {}, - Set<
String> ? enabledReleaseStages, - Set<
BugsnagEnabledBreadcrumbType> ? enabledBreadcrumbTypes, - BugsnagProjectPackages projectPackages = const BugsnagProjectPackages.withDefaults({}),
- Map<
String, Map< ? metadata,String, Object> > - List<
BugsnagFeatureFlag> ? featureFlags, - List<
BugsnagOnErrorCallback> onError = const [], - BugsnagTelemetryTypes telemetry = BugsnagTelemetryTypes.all,
- Directory? persistenceDirectory,
- int? versionCode,
Initialize the Bugsnag notifier with the configuration options specified. Use attach if you are building a Hybrid application where Bugsnag is initialised by the Native layer.
start will pick up any native configuration options that are specified.
Typical Flutter-only applications with Bugsnag will start with:
Future<void> main() async {
await bugsnag.start(apiKey: 'your-api-key');
runApp(MyApplication());
}
See also:
Implementation
Future<void> start({
String? apiKey,
BugsnagUser? user,
bool persistUser = true,
String? context,
String? appType,
String? appVersion,
String? bundleVersion,
String? releaseStage,
BugsnagEnabledErrorTypes enabledErrorTypes = BugsnagEnabledErrorTypes.all,
BugsnagEndpointConfiguration endpoints =
BugsnagEndpointConfiguration.bugsnag,
int maxBreadcrumbs = 50,
int maxPersistedSessions = 128,
int maxPersistedEvents = 32,
int maxStringValueLength = 10000,
bool autoTrackSessions = true,
bool autoDetectErrors = true,
BugsnagThreadSendPolicy sendThreads = BugsnagThreadSendPolicy.always,
int launchDurationMillis = 5000,
bool sendLaunchCrashesSynchronously = true,
int appHangThresholdMillis = appHangThresholdFatalOnly,
Set<String> redactedKeys = const {'password'},
Set<String> discardClasses = const {},
Set<String>? enabledReleaseStages,
Set<BugsnagEnabledBreadcrumbType>? enabledBreadcrumbTypes,
BugsnagProjectPackages projectPackages =
const BugsnagProjectPackages.withDefaults({}),
Map<String, Map<String, Object>>? metadata,
List<BugsnagFeatureFlag>? featureFlags,
List<BugsnagOnErrorCallback> onError = const [],
BugsnagTelemetryTypes telemetry = BugsnagTelemetryTypes.all,
Directory? persistenceDirectory,
int? versionCode,
}) async {
final detectDartErrors =
autoDetectErrors && enabledErrorTypes.unhandledDartExceptions;
if (projectPackages._includeDefaults) {
projectPackages += BugsnagProjectPackages.only(_findProjectPackages());
}
// make sure we can use Channels
WidgetsFlutterBinding.ensureInitialized();
await ChannelClient._channel.invokeMethod('start', <String, dynamic>{
if (apiKey != null) 'apiKey': apiKey,
if (user != null) 'user': user,
'persistUser': persistUser,
if (context != null) 'context': context,
if (appType != null) 'appType': appType,
if (appVersion != null) 'appVersion': appVersion,
if (bundleVersion != null) 'bundleVersion': bundleVersion,
if (releaseStage != null) 'releaseStage': releaseStage,
'enabledErrorTypes': enabledErrorTypes,
'endpoints': endpoints,
'maxBreadcrumbs': maxBreadcrumbs,
'maxPersistedSessions': maxPersistedSessions,
'maxPersistedEvents': maxPersistedEvents,
'maxStringValueLength': maxStringValueLength,
'autoTrackSessions': autoTrackSessions,
'autoDetectErrors': autoDetectErrors,
'sendThreads': sendThreads.toName(),
'launchDurationMillis': launchDurationMillis,
'sendLaunchCrashesSynchronously': sendLaunchCrashesSynchronously,
'appHangThresholdMillis': appHangThresholdMillis,
'redactedKeys': List<String>.from(redactedKeys),
'discardClasses': List<String>.from(discardClasses),
if (enabledReleaseStages != null)
'enabledReleaseStages': enabledReleaseStages.toList(),
'enabledBreadcrumbTypes':
(enabledBreadcrumbTypes ?? BugsnagEnabledBreadcrumbType.values)
.map((e) => e.toName())
.toList(),
'projectPackages': projectPackages,
if (metadata != null) 'metadata': BugsnagMetadata(metadata),
'featureFlags': featureFlags,
'notifier': _notifier,
'telemetry': telemetry,
if (persistenceDirectory != null)
'persistenceDirectory': persistenceDirectory.absolute.path,
if (versionCode != null) 'versionCode': versionCode,
});
final client = ChannelClient(detectDartErrors);
client._onErrorCallbacks.addAll(onError);
this.client = client;
if (autoTrackSessions) {
await resumeSession().onError((error, stackTrace) => true);
}
}