.NET MAUI SDK observability reference
The LaunchDarkly observability features are available for early access
Observability features in the LaunchDarkly UI are publicly available in early access.
The observability SDKs, implemented as plugins for LaunchDarkly server-side and client-side SDKs, are designed for use with the in-app observability features. They are currently in available in Early Access, and APIs are subject to change until a 1.x version is released.
If you are interested in participating in the Early Access Program for upcoming observability SDKs, sign up here.
Overview
This topic documents how to get started with the LaunchDarkly observability and session replay SDK for .NET MAUI.
The .NET MAUI SDK supports observability for error monitoring and logging, and session replay for capturing UI snapshots. It provides cross-platform support for both Android and iOS through .NET MAUI’s native platform bindings.
SDK quick links
LaunchDarkly’s SDKs are open source. In addition to this reference guide, we provide source, API reference documentation, and a sample application:
Prerequisites and dependencies
This SDK requires:
- .NET 9.0 or later with the MAUI workload installed
- Android SDK version 24 or higher (Android 7.0, Nougat)
- iOS 13.2 or higher
Get started
Follow these steps to get started:
- Install the SDK
- Initialize the SDK
- Configure observability options
- Configure session replay
- Configure session replay privacy options
- Use custom masking
- Explore supported features
- Review observability data in LaunchDarkly
Install the SDK
Add the LaunchDarkly.SessionReplay NuGet package to your MAUI project:
Then, import the SDK namespace in your code:
Initialize the SDK
Initialize the SDK by calling LDNative.Start() with your LaunchDarkly environment’s mobile key and configuration options. You should call this during your app’s startup, typically in MauiProgram.cs.
.NET MAUI observability SDK credentials
The .NET MAUI observability SDK uses a mobile key. Keys are specific to each project and environment. They are available from Project settings, on the Environments list. To learn more about key types, read Keys.
Mobile keys are not secret and you can expose them in your client-side code without risk. However, never embed a server-side SDK key into a client-side application.
Here’s how to initialize the SDK:
Configure observability options
You can customize the observability behavior by passing an ObservabilityOptions object when initializing the SDK.
Here is an example:
The available ObservabilityOptions configuration options are:
- ServiceName: The service name for the application. Defaults to
"observability-maui". - ServiceVersion: The version of the service. Defaults to
"0.1.0". - OtlpEndpoint: The endpoint URL for the OTLP exporter. Defaults to LaunchDarkly’s endpoint.
- BackendUrl: The backend URL for the observability service. Defaults to LaunchDarkly’s backend.
- ContextFriendlyName: An optional friendly name for the user context, displayed in the LaunchDarkly UI.
For more information on plugin options, read Configuration for client-side observability.
Configure session replay
The .NET MAUI SDK supports session replay, which captures snapshots of your app’s UI at regular intervals. This allows you to visually review user sessions in LaunchDarkly to better understand user behavior and diagnose issues.
Session replay is configured through the SessionReplayOptions object passed to LDNative.Start().
Here’s how to configure session replay:
The available SessionReplayOptions configuration options are:
- IsEnabled: Enables or disables session replay. Defaults to
true. - ServiceName: The service name for session replay telemetry. Defaults to
"sessionreplay-dotnet". - Privacy: Controls how UI elements are masked in the replay. To learn more, read Configure session replay privacy options.
Configure session replay privacy options
The PrivacyOptions class controls how UI elements are masked during session replay. By default, text inputs are masked to protect user privacy.
Here’s how to configure privacy settings:
The available privacy options are:
- MaskTextInputs: When
true, masks all text input fields. Defaults totrue. - MaskWebViews: When
true, masks the contents of web views. Web views are rendered as blank rectangles in session replays. Defaults tofalse. - MaskLabels: When
true, masks all text labels. Defaults tofalse. - MaskImages: When
true, masks all images. Defaults tofalse. - MinimumAlpha: Minimum alpha value for view visibility in recordings. Views with alpha below this threshold are not captured. Defaults to
0.02.
Common privacy configurations
For maximum privacy (recommended for production):
For debugging or development, you can turn masking off:
For selective masking, you can mask inputs but show regular text and images:
For more information on session replay configuration, read Configuration for session replay.
Use custom masking
In addition to the privacy profile settings, you can explicitly mask or unmask individual MAUI views using the LDMask() and LDUnmask() extension methods. This gives you fine-grained control over which UI elements are captured in session replay recordings.
Handler must be attached
The LDMask() and LDUnmask() methods work by accessing the underlying native platform view. The MAUI view’s handler must be attached before calling these methods. Call them after the view has been added to the visual tree, such as in a page’s Appearing event or after Handler is set.
The .LDMask() and .LDUnmask() extension methods work on any MAUI View, and they apply the masking to the underlying native view on both Android and iOS.
Explore supported features
The .NET MAUI observability SDK supports the following features. After the SDK is initialized, you can access these from within your application:
Review observability data in LaunchDarkly
After you initialize the SDK, your application automatically starts sending observability data back to LaunchDarkly, including errors, logs, and session replay recordings. You can review this information in the LaunchDarkly user interface. To learn how, read Observability.