diff --git a/CHANGELOG.md b/CHANGELOG.md index 864c4906..e697d57c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,7 +38,7 @@ _None._ ### New Features -_None._ +- Exposed Sentry's `onCrashedLastRun` to `CrashLoggingDataProvider`. ### Bug Fixes diff --git a/Sources/Remote Logging/Crash Logging/CrashLogging.swift b/Sources/Remote Logging/Crash Logging/CrashLogging.swift index 59962441..d0b64033 100644 --- a/Sources/Remote Logging/Crash Logging/CrashLogging.swift +++ b/Sources/Remote Logging/Crash Logging/CrashLogging.swift @@ -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 diff --git a/Sources/Remote Logging/Crash Logging/CrashLoggingDataProvider.swift b/Sources/Remote Logging/Crash Logging/CrashLoggingDataProvider.swift index 14987803..6e5b0e82 100644 --- a/Sources/Remote Logging/Crash Logging/CrashLoggingDataProvider.swift +++ b/Sources/Remote Logging/Crash Logging/CrashLoggingDataProvider.swift @@ -1,4 +1,5 @@ import Foundation +import Sentry #if SWIFT_PACKAGE import AutomatticTracksModel @@ -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 @@ -94,4 +98,8 @@ public extension CrashLoggingDataProvider { var errorEventsSamplingRate: Double { return 1.0 } + + var onCrashedLastRun: ((Event) -> Void)? { + return nil + } } diff --git a/Tests/Tests/CrashLoggingTests.swift b/Tests/Tests/CrashLoggingTests.swift index aed6076d..e1728ef4 100644 --- a/Tests/Tests/CrashLoggingTests.swift +++ b/Tests/Tests/CrashLoggingTests.swift @@ -196,6 +196,12 @@ class CrashLoggingTests: XCTestCase { XCTAssertTrue(dataProvider.enableUserInteractionTracing) #endif } + + func testOnCrashedLastRunDisabledByDefault() { + let dataProvider = MockCrashLoggingDataProvider() + + XCTAssertNil(dataProvider.onCrashedLastRun) + } } /// Allow throwing Strings as error