Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 —
Expand Down Expand Up @@ -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 |
Expand Down
36 changes: 36 additions & 0 deletions Sources/SkipSentry/SkipSentry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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, _ ->
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions Tests/SkipSentryTests/SkipSentryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading