Android Native Options

Configure the embedded Sentry Android SDK when using .NET for Android.

When you use the .NET for Android integration, Sentry embeds the Sentry Android SDK to provide native crash reporting and other Android-specific features. The options.Native property exposes configuration for this embedded SDK.

Copied
SentrySdk.Init(options =>
{
    options.Dsn = "___PUBLIC_DSN___";

    // Native Android SDK options:
    options.Native.AnrEnabled = true;
    options.Native.EnableNdk = true;
});

These options are also available in MAUI when targeting Android.

Native.AnrEnabled

Typebool
Defaulttrue

Enables detection of Application Not Responding (ANR) events where the main thread is blocked for too long. Enabled by default.

Native.AnrReportInDebug

Typebool
Defaultfalse

Whether ANR events are reported in debug builds. Disabled by default to avoid noise during development.

Native.AnrTimeoutInterval

TypeTimeSpan
DefaultTimeSpan.FromSeconds(5)

How long the main thread must be unresponsive before an ANR event is captured. Default is 5 seconds.

The Android SDK automatically captures breadcrumbs for various system events. Each category can be enabled or disabled independently.

Native.EnableActivityLifecycleBreadcrumbs

Typebool
Defaulttrue

Adds breadcrumbs for Activity lifecycle events (created, started, resumed, paused, stopped, destroyed).

See Automatic Breadcrumbs.

Native.EnableAppComponentBreadcrumbs

Typebool
Defaulttrue

Adds breadcrumbs for App component events.

See Automatic Breadcrumbs.

Native.EnableAppLifecycleBreadcrumbs

Typebool
Defaulttrue

Adds breadcrumbs for App lifecycle events (foregrounded, backgrounded).

See Automatic Breadcrumbs.

Native.EnableNetworkEventBreadcrumbs

Typebool
Defaulttrue

Adds breadcrumbs when network connectivity changes.

See Automatic Breadcrumbs.

Native.EnableSystemEventBreadcrumbs

Typebool
Defaulttrue

Adds breadcrumbs for system events such as battery state changes, low memory warnings, and timezone changes.

See Automatic Breadcrumbs.

Native.EnableUserInteractionBreadcrumbs

Typebool
Defaulttrue

Adds breadcrumbs when the user interacts with UI elements (taps, swipes, etc.).

See Automatic Breadcrumbs.

Native.EnableAutoActivityLifecycleTracing

Typebool
Defaulttrue

Automatically creates transactions for Activity lifecycle events. Requires TracesSampleRate or TracesSampler to be configured.

See Activity Instrumentation.

Native.EnableActivityLifecycleTracingAutoFinish

Typebool
Defaulttrue

Whether transactions created for Activity lifecycle events finish automatically when the Activity is fully drawn. Requires EnableAutoActivityLifecycleTracing to be enabled.

See Activity Instrumentation.

Native.EnableUserInteractionTracing

Typebool
Defaultfalse

Automatically creates traces for user interaction events (button clicks, etc.). Disabled by default.

See User Interaction Instrumentation.

Native.EnableTracing

Typebool
Defaultfalse

Enables tracing features on the embedded Android SDK. When disabled, the .NET SDK still handles traces for managed code, but the native Android SDK will not create its own traces.

Native.ProfilesSampleRate

Typedouble?
Defaultnull

Profiling sample rate for the native Android SDK, between 0.0 and 1.0. Disabled when null.

Native.AttachScreenshot

Typebool
Defaultfalse

Automatically attaches a screenshot when the native Android SDK captures a Java-based error or exception.

Native.AttachThreads

Typebool
Defaultfalse

Automatically attaches information about all threads to all logged events.

Native.EnableRootCheck

Typebool
Defaulttrue

Checks whether the device has been rooted and includes this in event context. Disable if your app store flags this check as harmful.

Native.EnableNdk

Typebool
Defaulttrue

Enables the Android NDK integration for native C/C++ crash reporting. Disable only if you don't need native crash reports and want to reduce overhead.

Native.ConnectionTimeout

TypeTimeSpan
DefaultTimeSpan.FromSeconds(5)

Connection timeout on the HTTP connection used by the Java SDK when sending events to Sentry.

Native.ReadTimeout

TypeTimeSpan
DefaultTimeSpan.FromSeconds(5)

Read timeout on the HTTP connection used by the Java SDK when sending events to Sentry.

Native.EnableShutdownHook

Typebool
Defaulttrue

Enables a hook that flushes events when the main Java thread shuts down, ensuring events are sent before the process exits.

Native.EnableUncaughtExceptionHandler

Typebool
Defaulttrue

Enables the handler that attaches to Java's Thread.UncaughtExceptionHandler to capture unhandled Java exceptions.

Native.PrintUncaughtStackTrace

Typebool
Defaultfalse

When enabled, prints uncaught Java error stack traces to stderr in addition to sending them to Sentry.

Native.EnableBeforeSend

Typebool
Defaultfalse

When enabled, the BeforeSend callback configured on SentryOptions will also be invoked for events that originate from the embedded Android SDK.

Use these methods to control which Java packages are considered "in-app" in stack traces. Note that these use Java package names, not .NET namespaces.

Native.AddInAppExclude(prefix)

Typemethod

Excludes frames matching the given Java package prefix from being flagged as "in-app" in stack traces.

Copied
options.Native.AddInAppExclude("java.util.");
options.Native.AddInAppExclude("org.apache.logging.log4j.");

See In-App Exclude.

Native.AddInAppInclude(prefix)

Typemethod

Includes frames matching the given Java package prefix as "in-app" in stack traces.

Copied
options.Native.AddInAppInclude("io.sentry.samples.");

See In-App Include.

Session Replay for Android is currently experimental and must be opted into.

Native.ExperimentalOptions.SessionReplay.SessionSampleRate

Typedouble?
Defaultnull

Sample rate for all sessions, between 0.0 and 1.0. Set to 0.0 or leave as null to disable session replay for regular sessions.

Native.ExperimentalOptions.SessionReplay.OnErrorSampleRate

Typedouble?
Defaultnull

Sample rate for buffered replays that are triggered when an error occurs. The SDK keeps the previous minute of activity and continues until the session ends when an error is sampled.

Native.ExperimentalOptions.SessionReplay.MaskAllText

Typebool
Defaulttrue

Masks all text content in session replay recordings to protect user privacy. Enabled by default.

Native.ExperimentalOptions.SessionReplay.MaskAllImages

Typebool
Defaulttrue

Masks all images in session replay recordings to protect user privacy. Enabled by default.

For finer-grained control of masking, you can mask or unmask entire classes of VisualElement:

Copied
// Unmask all Buttons (override the default mask-all behaviour)
options.Native.ExperimentalOptions.SessionReplay.UnmaskControlsOfType<Button>();

// Or mask a specific control type that isn't masked by default
options.Native.ExperimentalOptions.SessionReplay.MaskControlsOfType<MyCustomView>();
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").