From 109947493647f1626152825b764c7664680f5482 Mon Sep 17 00:00:00 2001 From: 1Conan Date: Thu, 20 Jun 2024 00:49:00 +0800 Subject: [PATCH 1/3] expose onCrashedLastRun --- Sources/Remote Logging/Crash Logging/CrashLogging.swift | 2 ++ .../Crash Logging/CrashLoggingDataProvider.swift | 7 +++++++ Tests/Tests/CrashLoggingTests.swift | 6 ++++++ 3 files changed, 15 insertions(+) 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..59cdee3c 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,8 @@ public protocol CrashLoggingDataProvider { var enableAppHangTracking: Bool { get } /// Whether HTTP client errors are captured. var enableCaptureFailedRequests: Bool { get } + + var onCrashedLastRun: ((Event) -> Void)? { get } } /// Default implementations of common protocol properties @@ -94,4 +97,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 From 47e11f977d4b1594d12015afa8752a3f94349ae7 Mon Sep 17 00:00:00 2001 From: 1Conan Date: Thu, 20 Jun 2024 01:03:21 +0800 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From bef803b38f0c210ac6a290f421798024cb74a0cf Mon Sep 17 00:00:00 2001 From: Conan Date: Thu, 20 Jun 2024 21:25:36 -0700 Subject: [PATCH 3/3] Update Sources/Remote Logging/Crash Logging/CrashLoggingDataProvider.swift Co-authored-by: Gio Lodi --- .../Remote Logging/Crash Logging/CrashLoggingDataProvider.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/Remote Logging/Crash Logging/CrashLoggingDataProvider.swift b/Sources/Remote Logging/Crash Logging/CrashLoggingDataProvider.swift index 59cdee3c..6e5b0e82 100644 --- a/Sources/Remote Logging/Crash Logging/CrashLoggingDataProvider.swift +++ b/Sources/Remote Logging/Crash Logging/CrashLoggingDataProvider.swift @@ -19,6 +19,7 @@ public protocol CrashLoggingDataProvider { /// 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 } }