Skip to content

Commit

Permalink
Expose onCrashedLastRun (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
1Conan authored Jun 21, 2024
2 parents 948c764 + bef803b commit b11b8be
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ _None._

### New Features

_None._
- Exposed Sentry's `onCrashedLastRun` to `CrashLoggingDataProvider`.

### Bug Fixes

Expand Down
2 changes: 2 additions & 0 deletions Sources/Remote Logging/Crash Logging/CrashLogging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public class CrashLogging {
options.enableUserInteractionTracing = self.dataProvider.enableUserInteractionTracing
options.enableUIViewControllerTracing = self.dataProvider.enableUIViewControllerTracking
#endif

options.onCrashedLastRun = self.dataProvider.onCrashedLastRun
}

Internals.crashLogging = self
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import Sentry

#if SWIFT_PACKAGE
import AutomatticTracksModel
Expand All @@ -17,6 +18,9 @@ public protocol CrashLoggingDataProvider {
var enableAppHangTracking: Bool { get }
/// Whether HTTP client errors are captured.
var enableCaptureFailedRequests: Bool { get }

/// A closure that will run shortly after the crash logging is initialized in case a crash was detected during the previous run.
var onCrashedLastRun: ((Event) -> Void)? { get }
}

/// Default implementations of common protocol properties
Expand Down Expand Up @@ -94,4 +98,8 @@ public extension CrashLoggingDataProvider {
var errorEventsSamplingRate: Double {
return 1.0
}

var onCrashedLastRun: ((Event) -> Void)? {
return nil
}
}
6 changes: 6 additions & 0 deletions Tests/Tests/CrashLoggingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ class CrashLoggingTests: XCTestCase {
XCTAssertTrue(dataProvider.enableUserInteractionTracing)
#endif
}

func testOnCrashedLastRunDisabledByDefault() {
let dataProvider = MockCrashLoggingDataProvider()

XCTAssertNil(dataProvider.onCrashedLastRun)
}
}

/// Allow throwing Strings as error
Expand Down

0 comments on commit b11b8be

Please sign in to comment.