.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 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 .NET 10.0 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

After installing, run dotnet clean before building. This is especially important for iOS targets, as stale build artifacts can cause issues. If you encounter dependency resolution problems, run dotnet restore first:

.NET CLI
$dotnet restore
$dotnet clean
$dotnet build
Visual Studio with Android SDK on Windows

Visual Studio on Windows can have issues installing the SDK due to the Android SDK being in a system-protected directory. If you encounter build errors related to Android SDK access, you may need to move the Android SDK to a user-writable location.

For detailed instructions, read the Android SDK relocation guide for Windows.

Then, import the SDK namespaces in your code:

C#
1using LaunchDarkly.SessionReplay;
2using LaunchDarkly.Sdk.Client;
3using LaunchDarkly.Sdk.Client.Integrations;
4using LaunchDarkly.Observability;

Initialize the SDK

Initialize the SDK by registering the ObservabilityPlugin and SessionReplayPlugin as plugins on the LaunchDarkly client configuration. You should call this during your app’s startup, typically in MauiProgram.cs.

The observability and session replay features are registered as plugins using the PluginConfigurationBuilder. This integrates them directly with the LaunchDarkly client lifecycle.

.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;
2using LaunchDarkly.Sdk.Client;
3using LaunchDarkly.Sdk.Client.Integrations;
4using LaunchDarkly.Observability;
5
6public static class MauiProgram
7{
8 public static MauiApp CreateMauiApp()
9 {
10 var builder = MauiApp.CreateBuilder();
11 builder.UseMauiApp<App>();
12
13 var mobileKey = "example-mobile-key";
14
15 var ldConfig = Configuration.Builder(mobileKey, ConfigurationBuilder.AutoEnvAttributes.Enabled)
16 .Plugins(new PluginConfigurationBuilder()
17 .Add(ObservabilityPlugin.Builder(new ObservabilityOptions(
18 isEnabled: true,
19 serviceName: "my-maui-app"
20 )).Build())
21 .Add(SessionReplayPlugin.Builder(new SessionReplayOptions(
22 isEnabled: true
23 )).Build())
24 ).Build();
25
26 var context = LaunchDarkly.Sdk.Context.New("example-user-key");
27 var client = LdClient.Init(ldConfig, context, TimeSpan.FromSeconds(10));
28
29 return builder.Build();
30 }
31}

Configure observability options

You can customize the observability behavior by passing an ObservabilityOptions object to ObservabilityPlugin.Builder().

Here is an example:

Observability options
1var ldConfig = Configuration.Builder(mobileKey, ConfigurationBuilder.AutoEnvAttributes.Enabled)
2 .Plugins(new PluginConfigurationBuilder()
3 .Add(ObservabilityPlugin.Builder(new ObservabilityOptions(
4 isEnabled: true,
5 serviceName: "my-maui-app",
6 serviceVersion: "1.2.0",
7 contextFriendlyName: "Example User"
8 )).Build())
9 .Add(SessionReplayPlugin.Builder(new SessionReplayOptions(
10 isEnabled: true
11 )).Build())
12 ).Build();

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 SessionReplayPlugin.Builder().

Here’s how to configure session replay:

Session replay options
1var ldConfig = Configuration.Builder(mobileKey, ConfigurationBuilder.AutoEnvAttributes.Enabled)
2 .Plugins(new PluginConfigurationBuilder()
3 .Add(ObservabilityPlugin.Builder(new ObservabilityOptions(
4 isEnabled: true,
5 serviceName: "my-maui-app"
6 )).Build())
7 .Add(SessionReplayPlugin.Builder(new SessionReplayOptions(
8 isEnabled: true,
9 privacy: new SessionReplayOptions.PrivacyOptions(
10 maskTextInputs: true,
11 maskWebViews: false,
12 maskLabels: false,
13 maskImages: false
14 )
15 )).Build())
16 ).Build();

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.