Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docs): Document flutter autoInitializeNativeSdk #5029

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions src/platforms/common/configuration/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -555,25 +555,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 @@ -606,7 +618,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 @@ -615,7 +626,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.