.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:

ResourceLocation
GitHub repository

LaunchDarkly.SessionReplay

Published packageNuGet

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

Add the LaunchDarkly.SessionReplay NuGet package to your MAUI project:

$dotnet add package LaunchDarkly.SessionReplay

Then, import the SDK namespace in your code:

C#
1using LaunchDarkly.SessionReplay;

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:

MauiProgram.cs
1using LaunchDarkly.SessionReplay;
2
3public static class MauiProgram
4{
5 public static MauiApp CreateMauiApp()
6 {
7 var builder = MauiApp.CreateBuilder();
8 builder.UseMauiApp<App>();
9
10 var app = builder.Build();
11
12 var mobileKey = "example-mobile-key";
13
14 LDNative.Start(
15 mobileKey: mobileKey,
16 observability: new ObservabilityOptions(
17 serviceName: "my-maui-app"
18 ),
19 replay: new SessionReplayOptions(
20 isEnabled: true
21 )
22 );
23
24 return app;
25 }
26}

Configure observability options

You can customize the observability behavior by passing an ObservabilityOptions object when initializing the SDK.

Here is an example:

Observability options
1LDNative.Start(
2 mobileKey: "example-mobile-key",
3 observability: new ObservabilityOptions(
4 serviceName: "my-maui-app",
5 serviceVersion: "1.2.0",
6 contextFriendlyName: "Example User"
7 ),
8 replay: new SessionReplayOptions()
9);

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:

Session replay options
1LDNative.Start(
2 mobileKey: "example-mobile-key",
3 observability: new ObservabilityOptions(
4 serviceName: "my-maui-app"
5 ),
6 replay: new SessionReplayOptions(
7 isEnabled: true,
8 privacy: new SessionReplayOptions.PrivacyOptions(
9 maskTextInputs: true,
10 maskWebViews: false,
11 maskLabels: false,
12 maskImages: false
13 )
14 )
15);

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:

Privacy options
1var replay = new SessionReplayOptions(
2 isEnabled: true,
3 privacy: new SessionReplayOptions.PrivacyOptions(
4 maskTextInputs: true,
5 maskWebViews: false,
6 maskLabels: false,
7 maskImages: false,
8 minimumAlpha: 0.02
9 )
10);

The available privacy options are:

  • MaskTextInputs: When true, masks all text input fields. Defaults to true.
  • MaskWebViews: When true, masks the contents of web views. Web views are rendered as blank rectangles in session replays. Defaults to false.
  • MaskLabels: When true, masks all text labels. Defaults to false.
  • MaskImages: When true, masks all images. Defaults to false.
  • 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):

Maximum privacy
1var privacy = new SessionReplayOptions.PrivacyOptions(
2 maskTextInputs: true,
3 maskWebViews: true,
4 maskLabels: true,
5 maskImages: true
6);

For debugging or development, you can turn masking off:

No masking
1var privacy = new SessionReplayOptions.PrivacyOptions(
2 maskTextInputs: false,
3 maskWebViews: false,
4 maskLabels: false,
5 maskImages: false
6);

For selective masking, you can mask inputs but show regular text and images:

Selective masking
1var privacy = new SessionReplayOptions.PrivacyOptions(
2 maskTextInputs: true,
3 maskWebViews: true,
4 maskLabels: false,
5 maskImages: false
6);

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.

Masking individual views
1using LaunchDarkly.SessionReplay;
2
3// Mask a sensitive field in session replay
4var passwordEntry = new Entry { Placeholder = "Password", IsPassword = true };
5passwordEntry.LDMask();
6
7// Unmask a field that would otherwise be masked by privacy settings
8var publicInfoLabel = new Label { Text = "Public information" };
9publicInfoLabel.LDUnmask();
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.