start method

Future<void> start({
  1. String? apiKey,
  2. BugsnagUser? user,
  3. bool persistUser = true,
  4. String? context,
  5. String? appType,
  6. String? appVersion,
  7. String? bundleVersion,
  8. String? releaseStage,
  9. BugsnagEnabledErrorTypes enabledErrorTypes = BugsnagEnabledErrorTypes.all,
  10. BugsnagEndpointConfiguration endpoints = BugsnagEndpointConfiguration.bugsnag,
  11. int maxBreadcrumbs = 50,
  12. int maxPersistedSessions = 128,
  13. int maxPersistedEvents = 32,
  14. int maxStringValueLength = 10000,
  15. bool autoTrackSessions = true,
  16. bool autoDetectErrors = true,
  17. BugsnagThreadSendPolicy sendThreads = BugsnagThreadSendPolicy.always,
  18. int launchDurationMillis = 5000,
  19. bool sendLaunchCrashesSynchronously = true,
  20. int appHangThresholdMillis = appHangThresholdFatalOnly,
  21. Set<String> redactedKeys = const {'password'},
  22. Set<String> discardClasses = const {},
  23. Set<String>? enabledReleaseStages,
  24. Set<BugsnagEnabledBreadcrumbType>? enabledBreadcrumbTypes,
  25. BugsnagProjectPackages projectPackages = const BugsnagProjectPackages.withDefaults({}),
  26. Map<String, Map<String, Object>>? metadata,
  27. List<BugsnagFeatureFlag>? featureFlags,
  28. List<BugsnagOnErrorCallback> onError = const [],
  29. BugsnagTelemetryTypes telemetry = BugsnagTelemetryTypes.all,
  30. Directory? persistenceDirectory,
  31. 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);
  }
}