diff --git a/Sources/Sentry/Public/SentryClient.h b/Sources/Sentry/Public/SentryClient.h index 8bb0cc24d4d..d6e09f48a18 100644 --- a/Sources/Sentry/Public/SentryClient.h +++ b/Sources/Sentry/Public/SentryClient.h @@ -113,7 +113,10 @@ SENTRY_NO_INIT - (void)captureEnvelope:(SentryEnvelope *)envelope NS_SWIFT_NAME(capture(envelope:)); -- (SentryFileManager *)fileManager; +/** + * Needed by hybrid SDKs as react-native to synchronously store an envelope to disk. + */ +- (void)storeEnvelope:(SentryEnvelope *)envelope; @end diff --git a/Sources/Sentry/SentryClient.m b/Sources/Sentry/SentryClient.m index 2f1b9452557..e6e17d8c594 100644 --- a/Sources/Sentry/SentryClient.m +++ b/Sources/Sentry/SentryClient.m @@ -268,6 +268,11 @@ - (void)captureUserFeedback:(SentryUserFeedback *)userFeedback [self.transport sendUserFeedback:userFeedback]; } +- (void)storeEnvelope:(SentryEnvelope *)envelope +{ + [self.fileManager storeEnvelope:envelope]; +} + /** * returns BOOL chance of YES is defined by sampleRate. * if sample rate isn't within 0.0 - 1.0 it returns YES (like if sampleRate diff --git a/Sources/Sentry/SentrySessionCrashedHandler.m b/Sources/Sentry/SentrySessionCrashedHandler.m index ed48ac0dc0c..ad5ab205693 100644 --- a/Sources/Sentry/SentrySessionCrashedHandler.m +++ b/Sources/Sentry/SentrySessionCrashedHandler.m @@ -1,4 +1,5 @@ #import "SentrySessionCrashedHandler.h" +#import "SentryClient+Private.h" #import "SentryClient.h" #import "SentryCrashAdapter.h" #import "SentryCurrentDate.h" diff --git a/Sources/Sentry/SentrySessionTracker.m b/Sources/Sentry/SentrySessionTracker.m index 2deabf42d54..a17c8a9c347 100644 --- a/Sources/Sentry/SentrySessionTracker.m +++ b/Sources/Sentry/SentrySessionTracker.m @@ -1,4 +1,5 @@ #import "SentrySessionTracker.h" +#import "SentryClient+Private.h" #import "SentryClient.h" #import "SentryFileManager.h" #import "SentryHub.h" diff --git a/Sources/Sentry/include/SentryClient+Private.h b/Sources/Sentry/include/SentryClient+Private.h index 75f56503dcc..a02b7729c1e 100644 --- a/Sources/Sentry/include/SentryClient+Private.h +++ b/Sources/Sentry/include/SentryClient+Private.h @@ -7,6 +7,8 @@ NS_ASSUME_NONNULL_BEGIN @interface SentryClient (Private) +- (SentryFileManager *)fileManager; + - (SentryId *)captureError:(NSError *)error withSession:(SentrySession *)session withScope:(SentryScope *)scope; diff --git a/Tests/SentryTests/SentryClientTests.swift b/Tests/SentryTests/SentryClientTests.swift index 76b8b935d4f..16ffc82e979 100644 --- a/Tests/SentryTests/SentryClientTests.swift +++ b/Tests/SentryTests/SentryClientTests.swift @@ -23,6 +23,7 @@ class SentryClientTest: XCTestCase { let message: SentryMessage let user: User + let fileManager: SentryFileManager init() { session = SentrySession(releaseName: "release") @@ -35,6 +36,8 @@ class SentryClientTest: XCTestCase { user = User() user.email = "someone@sentry.io" + + fileManager = try! SentryFileManager(dsn: TestConstants.dsn, andCurrentDateProvider: TestCurrentDateProvider()) } func getSut(configureOptions: (Options) -> Void = { _ in }) -> Client { @@ -45,7 +48,7 @@ class SentryClientTest: XCTestCase { ]) configureOptions(options) - client = Client(options: options, andTransport: transport, andFileManager: try SentryFileManager(dsn: TestConstants.dsn, andCurrentDateProvider: TestCurrentDateProvider())) + client = Client(options: options, andTransport: transport, andFileManager: fileManager) } catch { XCTFail("Options could not be created") } @@ -84,6 +87,7 @@ class SentryClientTest: XCTestCase { override func setUp() { super.setUp() fixture = Fixture() + fixture.fileManager.deleteAllEnvelopes() } func testCaptureMessage() { @@ -606,6 +610,11 @@ class SentryClientTest: XCTestCase { } } + func testStoreEnvelope_StoresEnvelopeToDisk() { + fixture.getSut().store(SentryEnvelope(event: Event())) + XCTAssertEqual(1, fixture.fileManager.getAllEnvelopes().count) + } + private func givenEventWithDebugMeta() -> Event { let event = Event(level: SentryLevel.fatal) let debugMeta = DebugMeta()