diff --git a/README.md b/README.md index 3be2c8a..0e95f78 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,20 @@ SkipSentry.start { options in } ``` +### Session Replay + +Session Replay is off until you set a sample rate. Text and images are masked by default. + +```swift +SkipSentry.start { options in + options.dsn = "https://examplePublicKey@o0.ingest.sentry.io/0" + options.sessionReplay.sessionSampleRate = 0.1 // record 10% of sessions + options.sessionReplay.onErrorSampleRate = 1.0 // record every session that hits an error + options.sessionReplay.maskAllText = true + options.sessionReplay.maskAllImages = true +} +``` + ### Filtering Events Before They're Sent Use `beforeSend` to inspect each event on-device and decide whether to drop it — @@ -252,8 +266,18 @@ All methods are static on the `SkipSentry` class. | `sessionTrackingIntervalMillis` | `Int?` | `nil` | Session tracking interval (ms) | | `attachStacktrace` | `Bool` | `true` | Attach stack traces to events | | `enableAppHangTracking` | `Bool` | `true` | Detect app hangs (iOS only) | +| `sessionReplay` | `SkipSentryReplayOptions` | all rates `nil` | Session Replay settings, see below | | `beforeSend` | `((SkipSentryEvent) -> SkipSentryEvent?)?` | `nil` | Inspect each event and drop it (return `nil`) or send it (return the event) | +### SkipSentryReplayOptions + +| Property | Type | Default | Description | +|---|---|---|---| +| `sessionSampleRate` | `Double?` | `nil` | Fraction of all sessions recorded (0.0–1.0) | +| `onErrorSampleRate` | `Double?` | `nil` | Fraction of sessions recorded when an error occurs (0.0–1.0) | +| `maskAllText` | `Bool` | `true` | Mask all text in recordings | +| `maskAllImages` | `Bool` | `true` | Mask all images in recordings | + ### SkipSentryLevel | Case | Description | diff --git a/Sources/SkipSentry/SkipSentry.swift b/Sources/SkipSentry/SkipSentry.swift index f0f9eae..2eb2928 100644 --- a/Sources/SkipSentry/SkipSentry.swift +++ b/Sources/SkipSentry/SkipSentry.swift @@ -91,6 +91,17 @@ public class SkipSentry { options.enableAppHangTracking = opts.enableAppHangTracking options.enableLogs = opts.enableLogs options.enableMetrics = opts.enableMetrics + // Session Replay only exists in sentry-cocoa on iOS and tvOS. + #if os(iOS) || os(tvOS) + if let rate = opts.sessionReplay.sessionSampleRate { + options.sessionReplay.sessionSampleRate = Float(rate) + } + if let rate = opts.sessionReplay.onErrorSampleRate { + options.sessionReplay.onErrorSampleRate = Float(rate) + } + options.sessionReplay.maskAllText = opts.sessionReplay.maskAllText + options.sessionReplay.maskAllImages = opts.sessionReplay.maskAllImages + #endif if let targets = opts.tracePropagationTargets { options.tracePropagationTargets = targets } let droppedHosts = opts.droppedFailedRequestHosts if !droppedHosts.isEmpty || opts.beforeSend != nil { @@ -663,6 +674,10 @@ public class SkipSentry { // SKIP INSERT: options.isReportHistoricalTombstones = opts.isReportHistoricalTombstones // SKIP INSERT: options.logs.isEnabled = opts.enableLogs // SKIP INSERT: options.metrics.isEnabled = opts.enableMetrics + // SKIP INSERT: opts.sessionReplay.sessionSampleRate?.let { options.sessionReplay.setSessionSampleRate(it) } + // SKIP INSERT: opts.sessionReplay.onErrorSampleRate?.let { options.sessionReplay.setOnErrorSampleRate(it) } + // SKIP INSERT: options.sessionReplay.setMaskAllText(opts.sessionReplay.maskAllText) + // SKIP INSERT: options.sessionReplay.setMaskAllImages(opts.sessionReplay.maskAllImages) // SKIP INSERT: opts.tracePropagationTargets?.let { options.setTracePropagationTargets(it.kotlin(nocopy = true).map { t -> t as String }) } // SKIP INSERT: if (hasDroppedHosts || opts.beforeSend != null) { // SKIP INSERT: options.setBeforeSend { event, _ -> @@ -716,6 +731,8 @@ public class SkipSentryOptions { /// `europe-west1-project.cloudfunctions.net`. Use for endpoints whose failures the app /// already reports itself, so Sentry doesn't receive a second, unstructured copy. public var droppedFailedRequestHosts: [String] = [] + /// Session Replay configuration. Replay stays off until at least one sample rate is set. + public var sessionReplay = SkipSentryReplayOptions() /// A hook invoked for each event just before it is sent to Sentry, letting you /// inspect the event and decide whether to drop it (client-side noise filtering). @@ -747,6 +764,25 @@ public class SkipSentryOptions { public init() { } } +// MARK: - SkipSentryReplayOptions + +/// Session Replay options, available as ``SkipSentryOptions/sessionReplay``. +/// +/// Mirrors iOS `SentryReplayOptions` and Android `SentryReplayOptions`. Both sample rates default +/// to `nil`, which leaves replay disabled. Text and images are masked unless you opt out. +public class SkipSentryReplayOptions { + /// Fraction of all sessions that are recorded (0.0 to 1.0). + public var sessionSampleRate: Double? + /// Fraction of sessions that are recorded from the moment an error occurs (0.0 to 1.0). + public var onErrorSampleRate: Double? + /// Whether all text is masked in recordings. + public var maskAllText: Bool = true + /// Whether all images are masked in recordings. + public var maskAllImages: Bool = true + + public init() { } +} + // MARK: - SkipSentryEvent /// A lightweight, cross-platform, read-only projection of a Sentry event, diff --git a/Tests/SkipSentryTests/SkipSentryTests.swift b/Tests/SkipSentryTests/SkipSentryTests.swift index aee46f1..4781784 100644 --- a/Tests/SkipSentryTests/SkipSentryTests.swift +++ b/Tests/SkipSentryTests/SkipSentryTests.swift @@ -121,6 +121,22 @@ final class SkipSentryTests: XCTestCase { } } + func testSkipSentryReplayOptions() throws { + let opts = SkipSentryOptions() + XCTAssertNil(opts.sessionReplay.sessionSampleRate) + XCTAssertNil(opts.sessionReplay.onErrorSampleRate) + XCTAssertTrue(opts.sessionReplay.maskAllText) + XCTAssertTrue(opts.sessionReplay.maskAllImages) + + opts.sessionReplay.sessionSampleRate = 0.1 + opts.sessionReplay.onErrorSampleRate = 1.0 + opts.sessionReplay.maskAllText = false + XCTAssertEqual(opts.sessionReplay.sessionSampleRate, 0.1) + XCTAssertEqual(opts.sessionReplay.onErrorSampleRate, 1.0) + XCTAssertFalse(opts.sessionReplay.maskAllText) + XCTAssertTrue(opts.sessionReplay.maskAllImages) + } + func testSkipSentryExtendedOptions() throws { let opts = SkipSentryOptions() XCTAssertNil(opts.tracesSampleRate)