iOS 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 plugin for the iOS SDK.
The iOS SDK supports the observability plugin for error monitoring, logging, and tracing.
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 reference guide assumes that you are somewhat familiar with the LaunchDarkly iOS SDK.
The observability plugin is compatible with the iOS SDK, version 9.14.0 and later, and is only available if you are using Swift.
Get started
Follow these steps to get started:
- Install the plugin
- Initialize the iOS SDK client
- Configure the plugin options
- Explore supported features
- Review observability data in LaunchDarkly
Install the plugin
LaunchDarkly uses a plugin to the iOS SDK to provide observability.
The first step is to make both the SDK and the observability plugin available as dependencies.
Here’s how:
Then, import the plugin into your code:
Initialize the client
Next, initialize the SDK and the plugin.
To initialize, you need your LaunchDarkly environment’s mobile key. This authorizes your application to connect to a particular environment within LaunchDarkly. To learn more, read Initialize the client in the Android SDK reference guide.
Here’s how to initialize the SDK and plugin:
Configure the plugin options
You can configure options for the observability plugin when you initialize the SDK. The plugin constructor takes an optional object with the configuration details.
Here is an example:
Configuration options
The Configuration
struct provides the following parameters:
- serviceName: The service name for the application. Defaults to “App”.
- otlpEndpoint: The endpoint URL for the OTLP exporter. Defaults to LaunchDarkly’s endpoint.
- serviceVersion: The service version for the application. Defaults to “1.0.0”.
- resourceAttributes: Additional OpenTelemetry resource attributes to include in telemetry data.
- customHeaders: Custom headers to include with OTLP exports as key-value tuples.
- sessionTimeout: Session timeout in seconds. Defaults to 30 minutes (1800 seconds).
- isDebug: Enables additional logging for debugging. Defaults to false.
- isErrorTrackingDisabled: Disables automatic error tracking if true. Defaults to false.
- isLogsDisabled: Disables automatic log collection if true. Defaults to false.
- isTracesDisabled: Disables automatic trace collection if true. Defaults to false.
- isMetricsDisabled: Disables automatic metric collection if true. Defaults to false.
For more information on plugin options, read Configuration for client-side observability.
Manual instrumentation
After initializing the observability plugin, you can use the LDObserve
singleton to manually instrument your iOS application with custom metrics, logs, traces, and error reporting.
Recording custom metrics
Recording custom logs
Recording custom errors
Recording custom traces
Using span builder for advanced tracing
Session management
The observability plugin automatically manages sessions and handles application lifecycle events. Sessions are automatically ended when:
- The application is backgrounded for longer than the configured
sessionTimeout
(default: 30 minutes) - The application is terminated
- A new session is explicitly started
Session timeout configuration
You can configure how long the plugin waits before ending a session when the app goes to the background:
Automatic instrumentation
The observability plugin automatically instruments your iOS application to collect:
- Application lifecycle events: App start, foreground, background, and termination
- Session tracking: Automatic session start and end events with timing
- Network requests: HTTP request/response data when enabled
- LaunchDarkly SDK events: Feature flag evaluations and SDK operations
Session Replay
Session Replay is in Early Access
Session Replay is available in Early Access. APIs are subject to change until a 1.x version is released.
Session Replay captures user interactions and screen recordings to help you understand how users interact with your application. Session Replay works as an additional plugin that requires the observability plugin to be configured first.
Install the Session Replay plugin
First, add the Session Replay package as a dependency alongside the observability plugin:
Then, import the Session Replay plugin into your code:
Initialize Session Replay
To enable Session Replay, add the SessionReplay
plugin to your SDK configuration alongside the Observability
plugin. The Observability
plugin must be added before the SessionReplay
plugin:
Configure Session Replay privacy options
The Session Replay plugin provides privacy options to control what data is captured. Configure these options when initializing the plugin:
Privacy configuration options
The PrivacyOptions
struct provides the following parameters:
- maskTextInputs: Mask all text input fields. Defaults to
true
. - maskLabels: Mask all text labels. Defaults to
false
. - maskImages: Mask all images. Defaults to
false
. - maskUIViews: Array of
UIView
classes to automatically mask in recordings. - ignoreUIViews: Array of
UIView
classes to exclude from masking rules. - maskAccessibilityIdentifiers: Array of accessibility identifiers to mask. Use this to mask specific UI elements by their accessibility identifier.
- ignoreAccessibilityIdentifiers: Array of accessibility identifiers to exclude from masking rules.
- minimumAlpha: Minimum alpha value for view visibility in recordings. Views with alpha below this threshold are not captured. Defaults to
0.02
.
Fine-grained masking control
You can override the default privacy settings on individual views using the .ldPrivate()
and .ldUnmask()
methods. This allows precise control over what is captured in session replays.
SwiftUI view masking
Use view modifiers to control masking for SwiftUI views:
UIKit view masking
Use the .ldPrivate()
and .ldUnmask()
methods on UIView instances:
Explore supported features
The observability plugins supports the following features. After the SDK and plugins are initialized, you can access these from within your application:
Review observability data in LaunchDarkly
After you initialize the SDK and observability plugin, your application automatically starts sending observability data back to LaunchDarkly in the form of custom events and OpenTelemetry data. You can review this information in the LaunchDarkly user interface. To learn how, read Observability.
The observability data collected includes:
- Error monitoring: Unhandled exceptions, crashes, and manually recorded errors with stack traces
- Logs: Application logs with configurable severity levels and custom attributes
- Traces: Distributed tracing data including span timing, nested operations, and custom instrumentation
- Metrics: Performance metrics, custom counters, histograms, and gauge measurements
- Session data: User session information including lifecycle events and timing
Specifically, the observability data includes events that LaunchDarkly uses to automatically create the following metrics:
- User error rate and crash frequency
- Application performance metrics (launch time, session duration)
- Feature flag evaluation context and timing
- Custom business metrics recorded through the SDK
To learn more about autogenerated metrics, read Metrics autogenerated from observability events.