From b11c6c178f312d65a88280e1aa1cdf220296b524 Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Tue, 19 Sep 2023 16:23:34 +0200 Subject: [PATCH 01/22] Update SentryCrashIntegration.m --- Sources/Sentry/SentryCrashIntegration.m | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Sources/Sentry/SentryCrashIntegration.m b/Sources/Sentry/SentryCrashIntegration.m index ee0ee8738bf..efd396b3acc 100644 --- a/Sources/Sentry/SentryCrashIntegration.m +++ b/Sources/Sentry/SentryCrashIntegration.m @@ -241,7 +241,7 @@ + (void)enrichScope:(SentryScope *)scope crashWrapper:(SentryCrashWrapper *)cras // DEVICE - NSMutableDictionary *deviceData = [NSMutableDictionary new]; + __block NSMutableDictionary *deviceData = [NSMutableDictionary new]; #if TARGET_OS_SIMULATOR [deviceData setValue:@(YES) forKey:@"simulator"]; @@ -272,16 +272,18 @@ + (void)enrichScope:(SentryScope *)scope crashWrapper:(SentryCrashWrapper *)cras [deviceData setValue:locale forKey:LOCALE_KEY]; #if SENTRY_HAS_UIKIT - - NSArray *appWindows = SentryDependencyContainer.sharedInstance.application.windows; - if ([appWindows count] > 0) { - UIScreen *appScreen = appWindows.firstObject.screen; - if (appScreen != nil) { - [deviceData setValue:@(appScreen.bounds.size.height) forKey:@"screen_height_pixels"]; - [deviceData setValue:@(appScreen.bounds.size.width) forKey:@"screen_width_pixels"]; + [SentryDependencyContainer.sharedInstance.dispatchQueueWrapper dispatchSyncOnMainQueue:^{ + NSArray *appWindows + = SentryDependencyContainer.sharedInstance.application.windows; + if ([appWindows count] > 0) { + UIScreen *appScreen = appWindows.firstObject.screen; + if (appScreen != nil) { + [deviceData setValue:@(appScreen.bounds.size.height) + forKey:@"screen_height_pixels"]; + [deviceData setValue:@(appScreen.bounds.size.width) forKey:@"screen_width_pixels"]; + } } - } - + }]; #endif [scope setContextValue:deviceData forKey:DEVICE_KEY]; From 23da6cc2f4db889eba084fe71d31b193985cc0f6 Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Tue, 19 Sep 2023 16:32:36 +0200 Subject: [PATCH 02/22] Revert "Update SentryCrashIntegration.m" This reverts commit b11c6c178f312d65a88280e1aa1cdf220296b524. --- Sources/Sentry/SentryCrashIntegration.m | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/Sources/Sentry/SentryCrashIntegration.m b/Sources/Sentry/SentryCrashIntegration.m index efd396b3acc..ee0ee8738bf 100644 --- a/Sources/Sentry/SentryCrashIntegration.m +++ b/Sources/Sentry/SentryCrashIntegration.m @@ -241,7 +241,7 @@ + (void)enrichScope:(SentryScope *)scope crashWrapper:(SentryCrashWrapper *)cras // DEVICE - __block NSMutableDictionary *deviceData = [NSMutableDictionary new]; + NSMutableDictionary *deviceData = [NSMutableDictionary new]; #if TARGET_OS_SIMULATOR [deviceData setValue:@(YES) forKey:@"simulator"]; @@ -272,18 +272,16 @@ + (void)enrichScope:(SentryScope *)scope crashWrapper:(SentryCrashWrapper *)cras [deviceData setValue:locale forKey:LOCALE_KEY]; #if SENTRY_HAS_UIKIT - [SentryDependencyContainer.sharedInstance.dispatchQueueWrapper dispatchSyncOnMainQueue:^{ - NSArray *appWindows - = SentryDependencyContainer.sharedInstance.application.windows; - if ([appWindows count] > 0) { - UIScreen *appScreen = appWindows.firstObject.screen; - if (appScreen != nil) { - [deviceData setValue:@(appScreen.bounds.size.height) - forKey:@"screen_height_pixels"]; - [deviceData setValue:@(appScreen.bounds.size.width) forKey:@"screen_width_pixels"]; - } + + NSArray *appWindows = SentryDependencyContainer.sharedInstance.application.windows; + if ([appWindows count] > 0) { + UIScreen *appScreen = appWindows.firstObject.screen; + if (appScreen != nil) { + [deviceData setValue:@(appScreen.bounds.size.height) forKey:@"screen_height_pixels"]; + [deviceData setValue:@(appScreen.bounds.size.width) forKey:@"screen_width_pixels"]; } - }]; + } + #endif [scope setContextValue:deviceData forKey:DEVICE_KEY]; From 95ab17a0f41263f44aeaa8b4dbe29b7d58002d9f Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Tue, 19 Sep 2023 16:32:53 +0200 Subject: [PATCH 03/22] Update SentrySDK.m --- Sources/Sentry/SentrySDK.m | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/Sources/Sentry/SentrySDK.m b/Sources/Sentry/SentrySDK.m index 8ea1e0d2807..463b576b360 100644 --- a/Sources/Sentry/SentrySDK.m +++ b/Sources/Sentry/SentrySDK.m @@ -14,6 +14,8 @@ #import "SentryMeta.h" #import "SentryOptions+Private.h" #import "SentryScope.h" +#import "SentryDispatchQueueWrapper.h" + @interface SentrySDK () @@ -134,24 +136,26 @@ + (void)setStartInvocations:(NSUInteger)value + (void)startWithOptions:(SentryOptions *)options { - startInvocations++; + [SentryDependencyContainer.sharedInstance.dispatchQueueWrapper dispatchSyncOnMainQueue:^{ + startInvocations++; - [SentryLog configure:options.debug diagnosticLevel:options.diagnosticLevel]; + [SentryLog configure:options.debug diagnosticLevel:options.diagnosticLevel]; - SentryClient *newClient = [[SentryClient alloc] initWithOptions:options]; - [newClient.fileManager moveAppStateToPreviousAppState]; - [newClient.fileManager moveBreadcrumbsToPreviousBreadcrumbs]; + SentryClient *newClient = [[SentryClient alloc] initWithOptions:options]; + [newClient.fileManager moveAppStateToPreviousAppState]; + [newClient.fileManager moveBreadcrumbsToPreviousBreadcrumbs]; - SentryScope *scope - = options.initialScope([[SentryScope alloc] initWithMaxBreadcrumbs:options.maxBreadcrumbs]); - // The Hub needs to be initialized with a client so that closing a session - // can happen. - [SentrySDK setCurrentHub:[[SentryHub alloc] initWithClient:newClient andScope:scope]]; - SENTRY_LOG_DEBUG(@"SDK initialized! Version: %@", SentryMeta.versionString); - [SentrySDK installIntegrations]; + SentryScope *scope + = options.initialScope([[SentryScope alloc] initWithMaxBreadcrumbs:options.maxBreadcrumbs]); + // The Hub needs to be initialized with a client so that closing a session + // can happen. + [SentrySDK setCurrentHub:[[SentryHub alloc] initWithClient:newClient andScope:scope]]; + SENTRY_LOG_DEBUG(@"SDK initialized! Version: %@", SentryMeta.versionString); + [SentrySDK installIntegrations]; - [SentryCrashWrapper.sharedInstance startBinaryImageCache]; - [SentryDependencyContainer.sharedInstance.binaryImageCache start]; + [SentryCrashWrapper.sharedInstance startBinaryImageCache]; + [SentryDependencyContainer.sharedInstance.binaryImageCache start]; + }]; } + (void)startWithConfigureOptions:(void (^)(SentryOptions *options))configureOptions From 5a9e4ea9b94493d26aafa5f9472e9f0062fd748d Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Tue, 19 Sep 2023 17:04:20 +0200 Subject: [PATCH 04/22] tests --- Sentry.xcodeproj/project.pbxproj | 4 ++++ SentryTestUtils/MainThreadTestIntegration.swift | 16 ++++++++++++++++ Tests/SentryTests/SentrySDKTests.swift | 16 +++++++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 SentryTestUtils/MainThreadTestIntegration.swift diff --git a/Sentry.xcodeproj/project.pbxproj b/Sentry.xcodeproj/project.pbxproj index 9674588648d..beb68a5b867 100644 --- a/Sentry.xcodeproj/project.pbxproj +++ b/Sentry.xcodeproj/project.pbxproj @@ -776,6 +776,7 @@ D86F419827C8FEFA00490520 /* SentryCoreDataTrackerExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D86F419727C8FEFA00490520 /* SentryCoreDataTrackerExtension.swift */; }; D8751FA5274743710032F4DE /* SentryNSURLSessionTaskSearchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8751FA4274743710032F4DE /* SentryNSURLSessionTaskSearchTests.swift */; }; D875ED0B276CC84700422FAC /* SentryNSDataTrackerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D875ED0A276CC84700422FAC /* SentryNSDataTrackerTests.swift */; }; + D87FA2892AB9EB06007DE933 /* MainThreadTestIntegration.swift in Sources */ = {isa = PBXBuildFile; fileRef = D87FA2882AB9EB06007DE933 /* MainThreadTestIntegration.swift */; }; D880E3A728573E87008A90DB /* SentryBaggageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D880E3A628573E87008A90DB /* SentryBaggageTests.swift */; }; D884A20527C80F6300074664 /* SentryCoreDataTrackerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = D884A20327C80F2700074664 /* SentryCoreDataTrackerTest.swift */; }; D885266427739D01001269FC /* SentryFileIOTrackingIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D885266327739D01001269FC /* SentryFileIOTrackingIntegrationTests.swift */; }; @@ -1727,6 +1728,7 @@ D8751FA4274743710032F4DE /* SentryNSURLSessionTaskSearchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryNSURLSessionTaskSearchTests.swift; sourceTree = ""; }; D8757D142A209F7300BFEFCC /* SentrySampleDecision+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentrySampleDecision+Private.h"; path = "include/SentrySampleDecision+Private.h"; sourceTree = ""; }; D875ED0A276CC84700422FAC /* SentryNSDataTrackerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SentryNSDataTrackerTests.swift; sourceTree = ""; }; + D87FA2882AB9EB06007DE933 /* MainThreadTestIntegration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainThreadTestIntegration.swift; sourceTree = ""; }; D880E3A628573E87008A90DB /* SentryBaggageTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryBaggageTests.swift; sourceTree = ""; }; D880E3B02860A5A0008A90DB /* SentryEvent+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentryEvent+Private.h"; path = "include/SentryEvent+Private.h"; sourceTree = ""; }; D884A20327C80F2700074664 /* SentryCoreDataTrackerTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryCoreDataTrackerTest.swift; sourceTree = ""; }; @@ -3180,6 +3182,7 @@ 84281C4D2A579A0C00EE88F2 /* SentryProfilerMocksSwiftCompatible.mm */, 84AC61DA29F7654A009EEF61 /* TestDispatchSourceWrapper.swift */, 84A5D75A29D5170700388BFA /* TimeInterval+Sentry.swift */, + D87FA2882AB9EB06007DE933 /* MainThreadTestIntegration.swift */, 7B30B68126527C55006B2752 /* TestDisplayLinkWrapper.swift */, 8E25C97425F8511A00DC215B /* TestRandom.swift */, 7BE3C7762445E50A00A38442 /* TestCurrentDateProvider.swift */, @@ -4482,6 +4485,7 @@ 84B7FA4529B2926900AD93B1 /* TestDisplayLinkWrapper.swift in Sources */, 84AC61DB29F7654A009EEF61 /* TestDispatchSourceWrapper.swift in Sources */, 8431F01729B2851500D8DC56 /* TestSentrySystemWrapper.swift in Sources */, + D87FA2892AB9EB06007DE933 /* MainThreadTestIntegration.swift in Sources */, 84281C632A579D0700EE88F2 /* SentryProfilerMocks.mm in Sources */, 84B7FA4129B28CD200AD93B1 /* TestSentryDispatchQueueWrapper.swift in Sources */, 84B7FA3E29B28ADD00AD93B1 /* TestClient.swift in Sources */, diff --git a/SentryTestUtils/MainThreadTestIntegration.swift b/SentryTestUtils/MainThreadTestIntegration.swift new file mode 100644 index 00000000000..5e1b1ce626a --- /dev/null +++ b/SentryTestUtils/MainThreadTestIntegration.swift @@ -0,0 +1,16 @@ +import Foundation +import Sentry + +public class MainThreadTestIntegration : NSObject, SentryIntegrationProtocol { + + public var installedInTheMainThread = false + + public func install(with options: Options) -> Bool { + installedInTheMainThread = Thread.isMainThread + return true + } + + public static func replaceOptionIntegrations(_ options: Options) { + options.integrations = [ NSStringFromClass(MainThreadTestIntegration.self) ] + } +} diff --git a/Tests/SentryTests/SentrySDKTests.swift b/Tests/SentryTests/SentrySDKTests.swift index 8df6ea9a106..49ee9b5882a 100644 --- a/Tests/SentryTests/SentrySDKTests.swift +++ b/Tests/SentryTests/SentrySDKTests.swift @@ -636,7 +636,21 @@ class SentrySDKTests: XCTestCase { XCTAssertEqual(flushTimeout, transport.flushInvocations.first) } - + + func testStartInTheMainThread() { + let expect = expectation(description: "SDK Initialization") + DispatchQueue.global(qos: .background).async { + SentrySDK.start { options in + MainThreadTestIntegration.replaceOptionIntegrations(options) + } + expect.fulfill() + } + wait(for: [expect], timeout: 0.2) + + let mainThreadIntegration = SentrySDK.currentHub().installedIntegrations().first as? MainThreadTestIntegration + XCTAssertEqual(mainThreadIntegration?.installedInTheMainThread, true, "SDK is not being initialized in the main thread") + } + #if SENTRY_HAS_UIKIT func testSetAppStartMeasurementConcurrently() { From f0b432fdae11f4f4f3b10b45ab190b7c87543912 Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Tue, 19 Sep 2023 17:05:05 +0200 Subject: [PATCH 05/22] Update CHANGELOG.md --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5f954b2cbe..a314e4c6824 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Fixes + +- Start SDK only in the main thread (#3291) + ## 8.12.0 ### Fixes From 4fa8e1f227d5a00b7c690798edd19e9d0ba7c6c0 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Tue, 19 Sep 2023 15:05:44 +0000 Subject: [PATCH 06/22] Format code --- SentryTestUtils/MainThreadTestIntegration.swift | 2 +- Sources/Sentry/SentrySDK.m | 7 +++---- .../Recording/Tools/SentryCrashObjCApple.h | 6 +++--- Tests/SentryTests/SentryOptionsTest.m | 12 ++++-------- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/SentryTestUtils/MainThreadTestIntegration.swift b/SentryTestUtils/MainThreadTestIntegration.swift index 5e1b1ce626a..cdf5c572577 100644 --- a/SentryTestUtils/MainThreadTestIntegration.swift +++ b/SentryTestUtils/MainThreadTestIntegration.swift @@ -1,7 +1,7 @@ import Foundation import Sentry -public class MainThreadTestIntegration : NSObject, SentryIntegrationProtocol { +public class MainThreadTestIntegration: NSObject, SentryIntegrationProtocol { public var installedInTheMainThread = false diff --git a/Sources/Sentry/SentrySDK.m b/Sources/Sentry/SentrySDK.m index 463b576b360..27999a9ae28 100644 --- a/Sources/Sentry/SentrySDK.m +++ b/Sources/Sentry/SentrySDK.m @@ -8,14 +8,13 @@ #import "SentryCrash.h" #import "SentryCrashWrapper.h" #import "SentryDependencyContainer.h" +#import "SentryDispatchQueueWrapper.h" #import "SentryFileManager.h" #import "SentryHub+Private.h" #import "SentryLog.h" #import "SentryMeta.h" #import "SentryOptions+Private.h" #import "SentryScope.h" -#import "SentryDispatchQueueWrapper.h" - @interface SentrySDK () @@ -145,8 +144,8 @@ + (void)startWithOptions:(SentryOptions *)options [newClient.fileManager moveAppStateToPreviousAppState]; [newClient.fileManager moveBreadcrumbsToPreviousBreadcrumbs]; - SentryScope *scope - = options.initialScope([[SentryScope alloc] initWithMaxBreadcrumbs:options.maxBreadcrumbs]); + SentryScope *scope = options.initialScope( + [[SentryScope alloc] initWithMaxBreadcrumbs:options.maxBreadcrumbs]); // The Hub needs to be initialized with a client so that closing a session // can happen. [SentrySDK setCurrentHub:[[SentryHub alloc] initWithClient:newClient andScope:scope]]; diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h b/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h index 441c108dd1f..c665cdf51c4 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h @@ -288,8 +288,8 @@ typedef struct __CFRuntimeBase { # define __CF_BIG_ENDIAN__ 0 #endif -#define CF_INFO_BITS (!!(__CF_BIG_ENDIAN__)*3) -#define CF_RC_BITS (!!(__CF_LITTLE_ENDIAN__)*3) +#define CF_INFO_BITS (!!(__CF_BIG_ENDIAN__) * 3) +#define CF_RC_BITS (!!(__CF_LITTLE_ENDIAN__) * 3) /* Bit manipulation macros */ /* Bits are numbered from 31 on left to 0 on right */ @@ -299,7 +299,7 @@ typedef struct __CFRuntimeBase { /* In the following, N1 and N2 specify an inclusive range N2..N1 with N1 >= N2 */ #define __CFBitfieldMask(N1, N2) ((((UInt32)~0UL) << (31UL - (N1) + (N2))) >> (31UL - N1)) -#define __CFBitfieldGetValue(V, N1, N2) (((V)&__CFBitfieldMask(N1, N2)) >> (N2)) +#define __CFBitfieldGetValue(V, N1, N2) (((V) & __CFBitfieldMask(N1, N2)) >> (N2)) // ====================================================================== #pragma mark - CF-1153.18/CFString.c - diff --git a/Tests/SentryTests/SentryOptionsTest.m b/Tests/SentryTests/SentryOptionsTest.m index 2fa263f2e0e..f22a91dc3dd 100644 --- a/Tests/SentryTests/SentryOptionsTest.m +++ b/Tests/SentryTests/SentryOptionsTest.m @@ -801,10 +801,8 @@ - (void)testChanging_enableTracing_afterSetting_tracesSampleRate - (void)testChanging_enableTracing_afterSetting_tracesSampler { SentryOptions *options = [[SentryOptions alloc] init]; - options.tracesSampler = ^NSNumber *(SentrySamplingContext *__unused samplingContext) - { - return @0.1; - }; + options.tracesSampler + = ^NSNumber *(SentrySamplingContext *__unused samplingContext) { return @0.1; }; options.enableTracing = NO; XCTAssertNil(options.tracesSampleRate); options.enableTracing = FALSE; @@ -1161,10 +1159,8 @@ - (void)testDefaultInitialScope - (void)testInitialScope { - SentryScope * (^initialScope)(SentryScope *) = ^SentryScope *(SentryScope *scope) - { - return scope; - }; + SentryScope * (^initialScope)(SentryScope *) + = ^SentryScope *(SentryScope *scope) { return scope; }; SentryOptions *options = [self getValidOptions:@{ @"initialScope" : initialScope }]; XCTAssertIdentical(initialScope, options.initialScope); } From 6ee2b675e12f87f40473508503df51da38be92f1 Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Wed, 20 Sep 2023 09:22:37 +0200 Subject: [PATCH 07/22] Update Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h --- Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h b/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h index c665cdf51c4..0942f5dd411 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h @@ -288,8 +288,8 @@ typedef struct __CFRuntimeBase { # define __CF_BIG_ENDIAN__ 0 #endif -#define CF_INFO_BITS (!!(__CF_BIG_ENDIAN__) * 3) -#define CF_RC_BITS (!!(__CF_LITTLE_ENDIAN__) * 3) +#define CF_INFO_BITS (!!(__CF_BIG_ENDIAN__)*3) +#define CF_RC_BITS (!!(__CF_LITTLE_ENDIAN__)*3) /* Bit manipulation macros */ /* Bits are numbered from 31 on left to 0 on right */ From 490ed4f97a2e1a022132ec5cdf2115b0af91b63a Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Wed, 20 Sep 2023 07:23:27 +0000 Subject: [PATCH 08/22] Format code --- Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h b/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h index 0942f5dd411..c665cdf51c4 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h @@ -288,8 +288,8 @@ typedef struct __CFRuntimeBase { # define __CF_BIG_ENDIAN__ 0 #endif -#define CF_INFO_BITS (!!(__CF_BIG_ENDIAN__)*3) -#define CF_RC_BITS (!!(__CF_LITTLE_ENDIAN__)*3) +#define CF_INFO_BITS (!!(__CF_BIG_ENDIAN__) * 3) +#define CF_RC_BITS (!!(__CF_LITTLE_ENDIAN__) * 3) /* Bit manipulation macros */ /* Bits are numbered from 31 on left to 0 on right */ From 3ffba00d273ff9afd1a08a68bbf970e03c05265a Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Wed, 20 Sep 2023 09:25:38 +0200 Subject: [PATCH 09/22] Apply suggestions from code review --- .../Recording/Tools/SentryCrashObjCApple.h | 2 +- Tests/SentryTests/SentryOptionsTest.m | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h b/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h index c665cdf51c4..b14dd7ff220 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h @@ -299,7 +299,7 @@ typedef struct __CFRuntimeBase { /* In the following, N1 and N2 specify an inclusive range N2..N1 with N1 >= N2 */ #define __CFBitfieldMask(N1, N2) ((((UInt32)~0UL) << (31UL - (N1) + (N2))) >> (31UL - N1)) -#define __CFBitfieldGetValue(V, N1, N2) (((V) & __CFBitfieldMask(N1, N2)) >> (N2)) +#define __CFBitfieldGetValue(V, N1, N2) (((V)&__CFBitfieldMask(N1, N2)) >> (N2)) // ====================================================================== #pragma mark - CF-1153.18/CFString.c - diff --git a/Tests/SentryTests/SentryOptionsTest.m b/Tests/SentryTests/SentryOptionsTest.m index f22a91dc3dd..46eb6206327 100644 --- a/Tests/SentryTests/SentryOptionsTest.m +++ b/Tests/SentryTests/SentryOptionsTest.m @@ -801,8 +801,10 @@ - (void)testChanging_enableTracing_afterSetting_tracesSampleRate - (void)testChanging_enableTracing_afterSetting_tracesSampler { SentryOptions *options = [[SentryOptions alloc] init]; - options.tracesSampler - = ^NSNumber *(SentrySamplingContext *__unused samplingContext) { return @0.1; }; + options.tracesSampler = ^NSNumber *(SentrySamplingContext *__unused samplingContext) + { + return @0.1; + }; options.enableTracing = NO; XCTAssertNil(options.tracesSampleRate); options.enableTracing = FALSE; @@ -1159,8 +1161,10 @@ - (void)testDefaultInitialScope - (void)testInitialScope { - SentryScope * (^initialScope)(SentryScope *) - = ^SentryScope *(SentryScope *scope) { return scope; }; + SentryScope * (^initialScope)(SentryScope *) = ^SentryScope *(SentryScope *scope) + { + return scope; + }; SentryOptions *options = [self getValidOptions:@{ @"initialScope" : initialScope }]; XCTAssertIdentical(initialScope, options.initialScope); } From af5a3e5072352a7db9923dcec1a3e88d5b5d5af6 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Wed, 20 Sep 2023 07:27:24 +0000 Subject: [PATCH 10/22] Format code --- .../Recording/Tools/SentryCrashObjCApple.h | 2 +- Tests/SentryTests/SentryOptionsTest.m | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h b/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h index b14dd7ff220..c665cdf51c4 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashObjCApple.h @@ -299,7 +299,7 @@ typedef struct __CFRuntimeBase { /* In the following, N1 and N2 specify an inclusive range N2..N1 with N1 >= N2 */ #define __CFBitfieldMask(N1, N2) ((((UInt32)~0UL) << (31UL - (N1) + (N2))) >> (31UL - N1)) -#define __CFBitfieldGetValue(V, N1, N2) (((V)&__CFBitfieldMask(N1, N2)) >> (N2)) +#define __CFBitfieldGetValue(V, N1, N2) (((V) & __CFBitfieldMask(N1, N2)) >> (N2)) // ====================================================================== #pragma mark - CF-1153.18/CFString.c - diff --git a/Tests/SentryTests/SentryOptionsTest.m b/Tests/SentryTests/SentryOptionsTest.m index 46eb6206327..f22a91dc3dd 100644 --- a/Tests/SentryTests/SentryOptionsTest.m +++ b/Tests/SentryTests/SentryOptionsTest.m @@ -801,10 +801,8 @@ - (void)testChanging_enableTracing_afterSetting_tracesSampleRate - (void)testChanging_enableTracing_afterSetting_tracesSampler { SentryOptions *options = [[SentryOptions alloc] init]; - options.tracesSampler = ^NSNumber *(SentrySamplingContext *__unused samplingContext) - { - return @0.1; - }; + options.tracesSampler + = ^NSNumber *(SentrySamplingContext *__unused samplingContext) { return @0.1; }; options.enableTracing = NO; XCTAssertNil(options.tracesSampleRate); options.enableTracing = FALSE; @@ -1161,10 +1159,8 @@ - (void)testDefaultInitialScope - (void)testInitialScope { - SentryScope * (^initialScope)(SentryScope *) = ^SentryScope *(SentryScope *scope) - { - return scope; - }; + SentryScope * (^initialScope)(SentryScope *) + = ^SentryScope *(SentryScope *scope) { return scope; }; SentryOptions *options = [self getValidOptions:@{ @"initialScope" : initialScope }]; XCTAssertIdentical(initialScope, options.initialScope); } From 26f8b497ed78aad7b33bc6a65c2c4d6a39b33309 Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Wed, 20 Sep 2023 11:25:07 +0200 Subject: [PATCH 11/22] Update SentrySDK.m --- Sources/Sentry/SentrySDK.m | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sources/Sentry/SentrySDK.m b/Sources/Sentry/SentrySDK.m index 27999a9ae28..0e4369ddd74 100644 --- a/Sources/Sentry/SentrySDK.m +++ b/Sources/Sentry/SentrySDK.m @@ -135,7 +135,7 @@ + (void)setStartInvocations:(NSUInteger)value + (void)startWithOptions:(SentryOptions *)options { - [SentryDependencyContainer.sharedInstance.dispatchQueueWrapper dispatchSyncOnMainQueue:^{ + void (^startSDK)(void) = ^{ startInvocations++; [SentryLog configure:options.debug diagnosticLevel:options.diagnosticLevel]; @@ -154,7 +154,13 @@ + (void)startWithOptions:(SentryOptions *)options [SentryCrashWrapper.sharedInstance startBinaryImageCache]; [SentryDependencyContainer.sharedInstance.binaryImageCache start]; - }]; + }; + + if (NSThread.isMainThread) { + startSDK(); + } else { + [SentryDependencyContainer.sharedInstance.dispatchQueueWrapper dispatchAsyncOnMainQueue:startSDK]; + } } + (void)startWithConfigureOptions:(void (^)(SentryOptions *options))configureOptions From b87e505854d061172e0f47b0704bfaf629fd4346 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Wed, 20 Sep 2023 09:26:33 +0000 Subject: [PATCH 12/22] Format code --- Sources/Sentry/SentrySDK.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/Sentry/SentrySDK.m b/Sources/Sentry/SentrySDK.m index 0e4369ddd74..d3f794566f1 100644 --- a/Sources/Sentry/SentrySDK.m +++ b/Sources/Sentry/SentrySDK.m @@ -159,7 +159,8 @@ + (void)startWithOptions:(SentryOptions *)options if (NSThread.isMainThread) { startSDK(); } else { - [SentryDependencyContainer.sharedInstance.dispatchQueueWrapper dispatchAsyncOnMainQueue:startSDK]; + [SentryDependencyContainer.sharedInstance.dispatchQueueWrapper + dispatchAsyncOnMainQueue:startSDK]; } } From 673d34ca52e5db8ac199d05d3658b156cb672d6a Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Wed, 20 Sep 2023 13:21:49 +0200 Subject: [PATCH 13/22] Update SentrySDKTests.swift --- Tests/SentryTests/SentrySDKTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/SentryTests/SentrySDKTests.swift b/Tests/SentryTests/SentrySDKTests.swift index 49ee9b5882a..ff87efd1730 100644 --- a/Tests/SentryTests/SentrySDKTests.swift +++ b/Tests/SentryTests/SentrySDKTests.swift @@ -645,7 +645,7 @@ class SentrySDKTests: XCTestCase { } expect.fulfill() } - wait(for: [expect], timeout: 0.2) + wait(for: [expect], timeout: 0.5) let mainThreadIntegration = SentrySDK.currentHub().installedIntegrations().first as? MainThreadTestIntegration XCTAssertEqual(mainThreadIntegration?.installedInTheMainThread, true, "SDK is not being initialized in the main thread") From 5791da48913b1fd238336064442a786f0539db73 Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Thu, 21 Sep 2023 10:53:19 +0200 Subject: [PATCH 14/22] Update SentrySDK.m --- Sources/Sentry/SentrySDK.m | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/Sources/Sentry/SentrySDK.m b/Sources/Sentry/SentrySDK.m index d3f794566f1..bc7af5c3251 100644 --- a/Sources/Sentry/SentrySDK.m +++ b/Sources/Sentry/SentrySDK.m @@ -15,6 +15,7 @@ #import "SentryMeta.h" #import "SentryOptions+Private.h" #import "SentryScope.h" +#import "SentryThreadWrapper.h" @interface SentrySDK () @@ -135,7 +136,7 @@ + (void)setStartInvocations:(NSUInteger)value + (void)startWithOptions:(SentryOptions *)options { - void (^startSDK)(void) = ^{ + [SentryThreadWrapper onMainThread:^{ startInvocations++; [SentryLog configure:options.debug diagnosticLevel:options.diagnosticLevel]; @@ -154,14 +155,7 @@ + (void)startWithOptions:(SentryOptions *)options [SentryCrashWrapper.sharedInstance startBinaryImageCache]; [SentryDependencyContainer.sharedInstance.binaryImageCache start]; - }; - - if (NSThread.isMainThread) { - startSDK(); - } else { - [SentryDependencyContainer.sharedInstance.dispatchQueueWrapper - dispatchAsyncOnMainQueue:startSDK]; - } + }]; } + (void)startWithConfigureOptions:(void (^)(SentryOptions *options))configureOptions From b96bc4ba1c0cd217f75466ecfe77e094ea064ca5 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Mon, 25 Sep 2023 08:05:49 +0000 Subject: [PATCH 15/22] Format code --- Sources/Sentry/SentrySDK.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Sentry/SentrySDK.m b/Sources/Sentry/SentrySDK.m index 28785a6db99..cf56d4fd2bc 100644 --- a/Sources/Sentry/SentrySDK.m +++ b/Sources/Sentry/SentrySDK.m @@ -156,9 +156,9 @@ + (void)startWithOptions:(SentryOptions *)options [SentryCrashWrapper.sharedInstance startBinaryImageCache]; [SentryDependencyContainer.sharedInstance.binaryImageCache start]; - #if TARGET_OS_IOS +#if TARGET_OS_IOS [SentryDependencyContainer.sharedInstance.uiDeviceWrapper start]; - #endif +#endif }]; } From 73db55650a9a3d70757f373a06f9ce68ca27ca7d Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Thu, 28 Sep 2023 13:54:36 +0200 Subject: [PATCH 16/22] Update SentrySDKTests.swift --- Tests/SentryTests/SentrySDKTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/SentryTests/SentrySDKTests.swift b/Tests/SentryTests/SentrySDKTests.swift index 32b79acc2ba..080dc1afd4c 100644 --- a/Tests/SentryTests/SentrySDKTests.swift +++ b/Tests/SentryTests/SentrySDKTests.swift @@ -664,7 +664,7 @@ class SentrySDKTests: XCTestCase { } wait(for: [expect], timeout: 0.5) - let mainThreadIntegration = SentrySDK.currentHub().installedIntegrations().first as? MainThreadTestIntegration + let mainThreadIntegration = SentrySDK.currentHub().installedIntegrations().first { integration in integration is MainThreadTestIntegration } as? MainThreadTestIntegration XCTAssertEqual(mainThreadIntegration?.installedInTheMainThread, true, "SDK is not being initialized in the main thread") } From 45b181b76f9d68a0160375e187014a10a386a7fc Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Thu, 28 Sep 2023 14:04:03 +0200 Subject: [PATCH 17/22] Update SentrySDK.m --- Sources/Sentry/SentrySDK.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Sentry/SentrySDK.m b/Sources/Sentry/SentrySDK.m index cf56d4fd2bc..f8720e8d37f 100644 --- a/Sources/Sentry/SentrySDK.m +++ b/Sources/Sentry/SentrySDK.m @@ -137,7 +137,7 @@ + (void)setStartInvocations:(NSUInteger)value + (void)startWithOptions:(SentryOptions *)options { - [SentryThreadWrapper onMainThread:^{ + // [SentryThreadWrapper onMainThread:^{ startInvocations++; [SentryLog configure:options.debug diagnosticLevel:options.diagnosticLevel]; @@ -159,7 +159,7 @@ + (void)startWithOptions:(SentryOptions *)options #if TARGET_OS_IOS [SentryDependencyContainer.sharedInstance.uiDeviceWrapper start]; #endif - }]; +// }]; } + (void)startWithConfigureOptions:(void (^)(SentryOptions *options))configureOptions From cd29f40d63f412595d19f5b58406e514850aa244 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Thu, 28 Sep 2023 12:05:04 +0000 Subject: [PATCH 18/22] Format code --- Sources/Sentry/SentrySDK.m | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Sources/Sentry/SentrySDK.m b/Sources/Sentry/SentrySDK.m index f8720e8d37f..64f02aa0cd9 100644 --- a/Sources/Sentry/SentrySDK.m +++ b/Sources/Sentry/SentrySDK.m @@ -137,29 +137,29 @@ + (void)setStartInvocations:(NSUInteger)value + (void)startWithOptions:(SentryOptions *)options { - // [SentryThreadWrapper onMainThread:^{ - startInvocations++; + // [SentryThreadWrapper onMainThread:^{ + startInvocations++; - [SentryLog configure:options.debug diagnosticLevel:options.diagnosticLevel]; + [SentryLog configure:options.debug diagnosticLevel:options.diagnosticLevel]; - SentryClient *newClient = [[SentryClient alloc] initWithOptions:options]; - [newClient.fileManager moveAppStateToPreviousAppState]; - [newClient.fileManager moveBreadcrumbsToPreviousBreadcrumbs]; + SentryClient *newClient = [[SentryClient alloc] initWithOptions:options]; + [newClient.fileManager moveAppStateToPreviousAppState]; + [newClient.fileManager moveBreadcrumbsToPreviousBreadcrumbs]; - SentryScope *scope = options.initialScope( - [[SentryScope alloc] initWithMaxBreadcrumbs:options.maxBreadcrumbs]); - // The Hub needs to be initialized with a client so that closing a session - // can happen. - [SentrySDK setCurrentHub:[[SentryHub alloc] initWithClient:newClient andScope:scope]]; - SENTRY_LOG_DEBUG(@"SDK initialized! Version: %@", SentryMeta.versionString); - [SentrySDK installIntegrations]; + SentryScope *scope + = options.initialScope([[SentryScope alloc] initWithMaxBreadcrumbs:options.maxBreadcrumbs]); + // The Hub needs to be initialized with a client so that closing a session + // can happen. + [SentrySDK setCurrentHub:[[SentryHub alloc] initWithClient:newClient andScope:scope]]; + SENTRY_LOG_DEBUG(@"SDK initialized! Version: %@", SentryMeta.versionString); + [SentrySDK installIntegrations]; - [SentryCrashWrapper.sharedInstance startBinaryImageCache]; - [SentryDependencyContainer.sharedInstance.binaryImageCache start]; + [SentryCrashWrapper.sharedInstance startBinaryImageCache]; + [SentryDependencyContainer.sharedInstance.binaryImageCache start]; #if TARGET_OS_IOS - [SentryDependencyContainer.sharedInstance.uiDeviceWrapper start]; + [SentryDependencyContainer.sharedInstance.uiDeviceWrapper start]; #endif -// }]; + // }]; } + (void)startWithConfigureOptions:(void (^)(SentryOptions *options))configureOptions From fb5eebcb521704f340b44cc5a4867a914fc9b02b Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Thu, 28 Sep 2023 14:17:39 +0200 Subject: [PATCH 19/22] Update SentrySDKTests.swift --- Tests/SentryTests/SentrySDKTests.swift | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Tests/SentryTests/SentrySDKTests.swift b/Tests/SentryTests/SentrySDKTests.swift index 080dc1afd4c..469cae0bcc6 100644 --- a/Tests/SentryTests/SentrySDKTests.swift +++ b/Tests/SentryTests/SentrySDKTests.swift @@ -654,19 +654,19 @@ class SentrySDKTests: XCTestCase { XCTAssertEqual(flushTimeout, transport.flushInvocations.first) } - func testStartInTheMainThread() { - let expect = expectation(description: "SDK Initialization") - DispatchQueue.global(qos: .background).async { - SentrySDK.start { options in - MainThreadTestIntegration.replaceOptionIntegrations(options) - } - expect.fulfill() - } - wait(for: [expect], timeout: 0.5) - - let mainThreadIntegration = SentrySDK.currentHub().installedIntegrations().first { integration in integration is MainThreadTestIntegration } as? MainThreadTestIntegration - XCTAssertEqual(mainThreadIntegration?.installedInTheMainThread, true, "SDK is not being initialized in the main thread") - } +// func testStartInTheMainThread() { +// let expect = expectation(description: "SDK Initialization") +// DispatchQueue.global(qos: .background).async { +// SentrySDK.start { options in +// MainThreadTestIntegration.replaceOptionIntegrations(options) +// } +// expect.fulfill() +// } +// wait(for: [expect], timeout: 0.5) +// +// let mainThreadIntegration = SentrySDK.currentHub().installedIntegrations().first { integration in integration is MainThreadTestIntegration } as? MainThreadTestIntegration +// XCTAssertEqual(mainThreadIntegration?.installedInTheMainThread, true, "SDK is not being initialized in the main thread") +// } #if SENTRY_HAS_UIKIT From e6825295a6a5587a008c1dad3b3a92e0d7661121 Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Thu, 28 Sep 2023 15:40:46 +0200 Subject: [PATCH 20/22] Fix Reachability flackness --- Sources/Sentry/SentryReachability.m | 6 ++++++ Tests/SentryTests/Networking/SentryReachabilityTests.m | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/Sources/Sentry/SentryReachability.m b/Sources/Sentry/SentryReachability.m index 3af2292bc13..146f8790ab1 100644 --- a/Sources/Sentry/SentryReachability.m +++ b/Sources/Sentry/SentryReachability.m @@ -98,6 +98,12 @@ } } +void +SentryConnectivityReset(void) { + [sentry_reachability_change_blocks removeAllObjects]; + sentry_current_reachability_state = kSCNetworkReachabilityFlagsUninitialized; +} + @implementation SentryReachability + (void)initialize diff --git a/Tests/SentryTests/Networking/SentryReachabilityTests.m b/Tests/SentryTests/Networking/SentryReachabilityTests.m index bf733289d0a..43324bd1f93 100644 --- a/Tests/SentryTests/Networking/SentryReachabilityTests.m +++ b/Tests/SentryTests/Networking/SentryReachabilityTests.m @@ -2,6 +2,9 @@ #import "SentryReachability.h" #import +void +SentryConnectivityReset(void); + @interface TestSentryReachabilityObserver : NSObject @end @implementation TestSentryReachabilityObserver @@ -22,6 +25,7 @@ - (void)setUp - (void)tearDown { self.reachability = nil; + SentryConnectivityReset(); } - (void)testConnectivityRepresentations From 262c625780e52a807f6ceb65cce82aaeded167d5 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Thu, 28 Sep 2023 13:42:20 +0000 Subject: [PATCH 21/22] Format code --- Sources/Sentry/SentryReachability.m | 3 ++- Tests/SentryTests/Networking/SentryReachabilityTests.m | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Sentry/SentryReachability.m b/Sources/Sentry/SentryReachability.m index 146f8790ab1..6eae307a444 100644 --- a/Sources/Sentry/SentryReachability.m +++ b/Sources/Sentry/SentryReachability.m @@ -99,7 +99,8 @@ } void -SentryConnectivityReset(void) { +SentryConnectivityReset(void) +{ [sentry_reachability_change_blocks removeAllObjects]; sentry_current_reachability_state = kSCNetworkReachabilityFlagsUninitialized; } diff --git a/Tests/SentryTests/Networking/SentryReachabilityTests.m b/Tests/SentryTests/Networking/SentryReachabilityTests.m index 43324bd1f93..5e729343127 100644 --- a/Tests/SentryTests/Networking/SentryReachabilityTests.m +++ b/Tests/SentryTests/Networking/SentryReachabilityTests.m @@ -2,8 +2,7 @@ #import "SentryReachability.h" #import -void -SentryConnectivityReset(void); +void SentryConnectivityReset(void); @interface TestSentryReachabilityObserver : NSObject @end From d41ebfc61e6e3bb8e5361afa041e37b9e4971e3b Mon Sep 17 00:00:00 2001 From: Dhiogo Ramos Brustolin Date: Thu, 28 Sep 2023 16:30:01 +0200 Subject: [PATCH 22/22] Update SentrySDK.m --- Sources/Sentry/SentrySDK.m | 40 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Sources/Sentry/SentrySDK.m b/Sources/Sentry/SentrySDK.m index 64f02aa0cd9..855738616fe 100644 --- a/Sources/Sentry/SentrySDK.m +++ b/Sources/Sentry/SentrySDK.m @@ -137,29 +137,29 @@ + (void)setStartInvocations:(NSUInteger)value + (void)startWithOptions:(SentryOptions *)options { - // [SentryThreadWrapper onMainThread:^{ - startInvocations++; - - [SentryLog configure:options.debug diagnosticLevel:options.diagnosticLevel]; - - SentryClient *newClient = [[SentryClient alloc] initWithOptions:options]; - [newClient.fileManager moveAppStateToPreviousAppState]; - [newClient.fileManager moveBreadcrumbsToPreviousBreadcrumbs]; - - SentryScope *scope + [SentryThreadWrapper onMainThread:^{ + startInvocations++; + + [SentryLog configure:options.debug diagnosticLevel:options.diagnosticLevel]; + + SentryClient *newClient = [[SentryClient alloc] initWithOptions:options]; + [newClient.fileManager moveAppStateToPreviousAppState]; + [newClient.fileManager moveBreadcrumbsToPreviousBreadcrumbs]; + + SentryScope *scope = options.initialScope([[SentryScope alloc] initWithMaxBreadcrumbs:options.maxBreadcrumbs]); - // The Hub needs to be initialized with a client so that closing a session - // can happen. - [SentrySDK setCurrentHub:[[SentryHub alloc] initWithClient:newClient andScope:scope]]; - SENTRY_LOG_DEBUG(@"SDK initialized! Version: %@", SentryMeta.versionString); - [SentrySDK installIntegrations]; - - [SentryCrashWrapper.sharedInstance startBinaryImageCache]; - [SentryDependencyContainer.sharedInstance.binaryImageCache start]; + // The Hub needs to be initialized with a client so that closing a session + // can happen. + [SentrySDK setCurrentHub:[[SentryHub alloc] initWithClient:newClient andScope:scope]]; + SENTRY_LOG_DEBUG(@"SDK initialized! Version: %@", SentryMeta.versionString); + [SentrySDK installIntegrations]; + + [SentryCrashWrapper.sharedInstance startBinaryImageCache]; + [SentryDependencyContainer.sharedInstance.binaryImageCache start]; #if TARGET_OS_IOS - [SentryDependencyContainer.sharedInstance.uiDeviceWrapper start]; + [SentryDependencyContainer.sharedInstance.uiDeviceWrapper start]; #endif - // }]; + }]; } + (void)startWithConfigureOptions:(void (^)(SentryOptions *options))configureOptions