Set Up Session Replay for Kotlin Multiplatform

Enable Session Replay for Android and iOS apps from shared Kotlin Multiplatform code.

Session Replay helps you understand what a user was doing before and after an error. Configure it in shared Kotlin code to record replays through the Sentry Android and Cocoa SDKs.

Use Sentry Kotlin Multiplatform SDK 0.12.0 or later. Follow the installation guide if you haven't set up the SDK yet.

Session Replay is supported on Android and iOS. Android recording requires Android 8 (API level 26) or newer.

Add Replay sampling to your existing shared initializer:

commonMain/SentrySetup.kt
Copied
import io.sentry.kotlin.multiplatform.Sentry

fun initializeSentry() {
    Sentry.init { options ->
        options.dsn = "___PUBLIC_DSN___"
        options.sessionReplay.sessionSampleRate = 0.1
        options.sessionReplay.onErrorSampleRate = 1.0
    }
}

Call the initializer early in each app's lifecycle, as described in Initialization Options.

Temporarily set sessionSampleRate to 1.0 to record every session. Launch your app, interact with a few screens, and look for the recording on Sentry's Replays page. Inspect text and images in the recording to verify masking. Lower the sample rate before releasing your app.

To test error-only recording, set sessionSampleRate to 0.0 and onErrorSampleRate to 1.0, then restart the app. Interact with the app before capturing a test error:

Copied
Sentry.captureException(Exception("Test error with Session Replay"))

Open the error event in Sentry and check for its linked replay.

Both sample rates accept values from 0.0 to 1.0 and default to null (disabled):

OptionBehavior
sessionReplay.sessionSampleRateSamples sessions for recording from the start. For example, 0.1 records approximately 10% of sessions.
sessionReplay.onErrorSampleRateSamples sessions that weren't selected for full recording when an error occurs. The native SDK buffers up to 30 seconds before the error and continues recording afterward.

These settings control Replay sampling independently of error-event sampling.

Session duration and lifecycle behavior follow the native SDK. See the Android and iOS guides for details.

The shared options expose these defaults:

OptionDefaultPurpose
sessionReplay.maskAllTexttrueMasks text in supported UI elements.
sessionReplay.maskAllImagestrueMasks images in supported UI elements.
sessionReplay.qualitySentryReplayOptions.Quality.MEDIUMSets recording quality to LOW, MEDIUM, or HIGH. Higher quality increases data transfer and processing cost.

Keep masking enabled unless you have reviewed the content your app can display. Masking behavior depends on the native SDK and UI framework. Review the Android privacy guide or iOS custom redaction guide before customizing it.

To change recording quality, import io.sentry.kotlin.multiplatform.SentryReplayOptions and set options.sessionReplay.quality inside your initializer.

For options beyond the shared sampling, masking, and quality settings, use native platform options and the native Android configuration or iOS configuration guide. Available options depend on the native SDK version used by your KMP SDK.

If a replay is missing, confirm that sampling is enabled, initialization runs early, and the device uses a supported platform. Use the native guides for platform-specific diagnostics and performance information:

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").