Skip to content

Commit

Permalink
feat(docs): Document flutter autoInitializeNativeSdk (#5029)
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase authored and adinauer committed Jun 9, 2022
1 parent 27f4bbe commit ef27279
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/platforms/common/configuration/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -571,25 +571,37 @@ An optional property that configures which downstream services receive the `sent

</PlatformSection>

<PlatformSection supported={["react-native", "javascript.cordova", "javascript.capacitor"]}>
<PlatformSection supported={["react-native", "javascript.cordova", "javascript.capacitor", "flutter"]}>

## Hybrid SDK Options

<ConfigKey name="enableNative">
<ConfigKey name="enableNative" supported={["react-native", "javascript.cordova", "javascript.capacitor"]}>

Set this boolean to `false` to disable the native SDK. This will disable all native crash and error handling and, instead, the SDK will only capture errors on the upper layer.

</ConfigKey>

<ConfigKey name="autoInitializeNativeSdk" supported={["react-native"]}>
<ConfigKey name="autoInitializeNativeSdk">

Set this boolean to `false` to disable the auto initialization of the native layer SDK. Doing so means you will need to initialize the native SDK manually. Do not use this to disable the native layer.

<PlatformSection supported={["react-native", "javascript.cordova", "javascript.capacitor"]}>

Set this boolean to `false` to disable the auto initialization of the native layer SDK. Doing so means you will need to initialize the native SDK manually. Do not use this to disable the native layer, but instead use [enableNative](#enableNative).
To disable the native layer, use [enableNative](#enableNative).

You should follow the [guide to native initialization](/platforms/react-native/manual-setup/native-init/) if you chose to use this option.

</PlatformSection>

<PlatformSection supported={["flutter"]}>

You should follow the [guide to native initialization](/platforms/flutter/native-init/) if you chose to use this option.

</PlatformSection>

</ConfigKey>

<ConfigKey name="enableNativeCrashHandling" supported={["react-native", "javascript.capacitor"]}>
<ConfigKey name="enableNativeCrashHandling" supported={["react-native", "javascript.capacitor", "flutter"]}>

Set this boolean to `false` to disable hard crash handling from the native layer. Doing so means that the SDK won't capture events for hard crashes on Android and iOS if the error was caused by native code.

Expand Down Expand Up @@ -622,7 +634,6 @@ Set this boolean to `false` to disable the scope sync from Java to NDK on Androi
<ConfigKey name="attachThreads">

Set this boolean to `true` to automatically attach all threads to all logged events on Android.

</ConfigKey>

<ConfigKey name="enableAutoPerformanceTracking" supported={["react-native"]}>
Expand All @@ -631,7 +642,7 @@ Set this boolean to `false` to disable auto [performance monitoring](/product/pe

</ConfigKey>

<ConfigKey name="enableOutOfMemoryTracking" supported={["react-native"]}>
<ConfigKey name="enableOutOfMemoryTracking" supported={["react-native", "flutter"]}>

Set this boolean to `false` to disable [out of memory](/platforms/apple/guides/ios/configuration/out-of-memory/) tracking on iOS.

Expand Down
27 changes: 27 additions & 0 deletions src/platforms/flutter/native-init.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: Native Initialization
sidebar_order: 900
description: "Learn how to manually initialize the native SDKs."
---

By default, the Flutter SDK initializes the native SDK underneath the `init` method called on the Flutter layer. As a result, the SDK currenty has a limitation of not capturing native crashes that occur prior to the `init` method being called on the Flutter layer. You can initialize the native SDKs yourself to overcome this limitation or if you want to provide custom options above what the Flutter SDK currently provides.

To do this, set [autoInitializeNativeSdk](/platforms/flutter/configuration/options/#autoInitializeNativeSdk) to `false` in the init options:

```dart
import 'package:flutter/widgets.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
Future<void> main() async {
await SentryFlutter.init(
(options) => options
..dsn = '___PUBLIC_DSN___'
..autoInitializeNativeSdk = false,
appRunner: () => runApp(MyApp()),
);
}
```

This will prevent the Flutter SDK from initializing the native SDKs automatically.

Next, initialize the [Android](/platforms/android/configuration/manual-init/) and [iOS (using the configuration guide to initialize the Sentry Cocoa SDK)](/platforms/apple/guides/ios/#configure) native SDKs. Note that you do not need to install the native SDKs as they are already packaged with the Flutter SDK.

0 comments on commit ef27279

Please sign in to comment.