Skip to content

Commit 8d5a5ce

Browse files
committed
ref: move SentryCrash singleton to SentryDependencyContainer
1 parent 01a28a9 commit 8d5a5ce

16 files changed

+50
-46
lines changed

SentryTestUtils/ClearTestState.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,7 @@ class TestCleanup: NSObject {
4747
PrivateSentrySDKOnly.onAppStartMeasurementAvailable = nil
4848
SentrySDK.setAppStartMeasurement(nil)
4949
#endif // os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
50+
51+
sentrycrash_scopesync_reset()
5052
}
5153
}

SentryTestUtils/SentryTestUtils-ObjC-BridgingHeader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#import "SentryRandom.h"
3636
#import "SentrySDK+Private.h"
3737
#import "SentrySDK+Tests.h"
38+
#import "SentryScopeSyncC.h"
3839
#import "SentrySession.h"
3940
#import "SentrySwizzleWrapper.h"
4041
#import "SentrySystemWrapper.h"

Sources/Sentry/SentryCrashIntegration.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ - (void)configureScope
185185
userInfo[@"release"] = self.options.releaseName;
186186
userInfo[@"dist"] = self.options.dist;
187187

188-
[SentryCrash.sharedInstance setUserInfo:userInfo];
188+
[SentryDependencyContainer.sharedInstance.crashReporter setUserInfo:userInfo];
189189

190190
[outerScope addObserver:self.scopeObserver];
191191
}];

Sources/Sentry/SentryCrashWrapper.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#import <SentryCrashCachedData.h>
88
#import <SentryCrashDebug.h>
99
#import <SentryCrashMonitor_System.h>
10+
#import <SentryDependencyContainer.h>
1011
#include <mach/mach.h>
1112

1213
NS_ASSUME_NONNULL_BEGIN
@@ -23,7 +24,7 @@ + (instancetype)sharedInstance
2324

2425
- (BOOL)crashedLastLaunch
2526
{
26-
return SentryCrash.sharedInstance.crashedLastLaunch;
27+
return SentryDependencyContainer.sharedInstance.crashReporter.crashedLastLaunch;
2728
}
2829

2930
- (NSTimeInterval)durationFromCrashStateInitToLastCrash
@@ -33,7 +34,7 @@ - (NSTimeInterval)durationFromCrashStateInitToLastCrash
3334

3435
- (NSTimeInterval)activeDurationSinceLastCrash
3536
{
36-
return SentryCrash.sharedInstance.activeDurationSinceLastCrash;
37+
return SentryDependencyContainer.sharedInstance.crashReporter.activeDurationSinceLastCrash;
3738
}
3839

3940
- (BOOL)isBeingTraced
@@ -55,7 +56,8 @@ - (NSDictionary *)systemInfo
5556
{
5657
static NSDictionary *sharedInfo = nil;
5758
static dispatch_once_t onceToken;
58-
dispatch_once(&onceToken, ^{ sharedInfo = SentryCrash.sharedInstance.systemInfo; });
59+
dispatch_once(&onceToken,
60+
^{ sharedInfo = SentryDependencyContainer.sharedInstance.crashReporter.systemInfo; });
5961
return sharedInfo;
6062
}
6163

Sources/Sentry/SentryDependencyContainer.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#import "SentryUIApplication.h"
1111
#import <SentryAppStateManager.h>
1212
#import <SentryClient+Private.h>
13+
#import <SentryCrash.h>
1314
#import <SentryCrashWrapper.h>
1415
#import <SentryDebugImageProvider.h>
1516
#import <SentryDependencyContainer.h>
@@ -95,6 +96,18 @@ - (SentryCrashWrapper *)crashWrapper
9596
return _crashWrapper;
9697
}
9798

99+
- (SentryCrash *)crashReporter
100+
{
101+
if (_crashReporter == nil) {
102+
@synchronized(sentryDependencyContainerLock) {
103+
if (_crashReporter == nil) {
104+
_crashReporter = [[SentryCrash alloc] init];
105+
}
106+
}
107+
}
108+
return _crashReporter;
109+
}
110+
98111
- (SentryThreadWrapper *)threadWrapper
99112
{
100113
if (_threadWrapper == nil) {

Sources/Sentry/SentrySDK.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ + (void)setUser:(SentryUser *_Nullable)user
322322

323323
+ (BOOL)crashedLastRun
324324
{
325-
return SentryCrash.sharedInstance.crashedLastLaunch;
325+
return SentryDependencyContainer.sharedInstance.crashReporter.crashedLastLaunch;
326326
}
327327

328328
+ (void)startSession

Sources/Sentry/include/HybridPublic/SentryDependencyContainer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
@class SentryANRTracker;
44
@class SentryAppStateManager;
5+
@class SentryCrash;
56
@class SentryCrashWrapper;
67
@class SentryCurrentDateProvider;
78
@class SentryDebugImageProvider;
@@ -42,6 +43,7 @@ SENTRY_NO_INIT
4243
@property (nonatomic, strong) SentryFileManager *fileManager;
4344
@property (nonatomic, strong) SentryAppStateManager *appStateManager;
4445
@property (nonatomic, strong) SentryCrashWrapper *crashWrapper;
46+
@property (nonatomic, strong) SentryCrash *crashReporter;
4547
@property (nonatomic, strong) SentryThreadWrapper *threadWrapper;
4648
@property (nonatomic, strong) id<SentryRandom> random;
4749
@property (nonatomic, strong) SentrySwizzleWrapper *swizzleWrapper;

Sources/SentryCrash/Installations/SentryCrashInstallation.m

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#import "SentryCrashJSONCodecObjC.h"
3434
#import "SentryCrashLogger.h"
3535
#import "SentryCrashReportFilterBasic.h"
36+
#import "SentryDependencyContainer.h"
3637
#import <objc/runtime.h>
3738

3839
/** Max number of properties that can be defined for writing to the report */
@@ -175,7 +176,7 @@ - (id)initWithRequiredProperties:(NSArray *)requiredProperties
175176

176177
- (void)dealloc
177178
{
178-
SentryCrash *handler = [SentryCrash sharedInstance];
179+
SentryCrash *handler = SentryDependencyContainer.sharedInstance.crashReporter;
179180
@synchronized(handler) {
180181
if (g_crashHandlerData == self.crashHandlerData) {
181182
g_crashHandlerData = NULL;
@@ -260,7 +261,7 @@ - (void)setOnCrash:(SentryCrashReportWriteCallback)onCrash
260261

261262
- (void)install
262263
{
263-
SentryCrash *handler = [SentryCrash sharedInstance];
264+
SentryCrash *handler = SentryDependencyContainer.sharedInstance.crashReporter;
264265
@synchronized(handler) {
265266
g_crashHandlerData = self.crashHandlerData;
266267
handler.onCrash = crashCallback;
@@ -270,7 +271,7 @@ - (void)install
270271

271272
- (void)uninstall
272273
{
273-
SentryCrash *handler = [SentryCrash sharedInstance];
274+
SentryCrash *handler = SentryDependencyContainer.sharedInstance.crashReporter;
274275
@synchronized(handler) {
275276
if (g_crashHandlerData == self.crashHandlerData) {
276277
g_crashHandlerData = NULL;
@@ -302,7 +303,7 @@ - (void)sendAllReportsWithCompletion:(SentryCrashReportFilterCompletion)onComple
302303

303304
sink = [SentryCrashReportFilterPipeline filterWithFilters:self.prependedFilters, sink, nil];
304305

305-
SentryCrash *handler = [SentryCrash sharedInstance];
306+
SentryCrash *handler = SentryDependencyContainer.sharedInstance.crashReporter;
306307
handler.sink = sink;
307308
[handler sendAllReportsWithCompletion:onCompletion];
308309
}

Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_NSException.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "SentryCrashMonitorContext.h"
3232
#import "SentryCrashStackCursor_Backtrace.h"
3333
#include "SentryCrashThread.h"
34+
#import "SentryDependencyContainer.h"
3435

3536
// #define SentryCrashLogger_LocalLevel TRACE
3637
#import "SentryCrashLogger.h"
@@ -128,7 +129,8 @@
128129

129130
SentryCrashLOG_DEBUG(@"Setting new handler.");
130131
NSSetUncaughtExceptionHandler(&handleUncaughtException);
131-
SentryCrash.sharedInstance.uncaughtExceptionHandler = &handleUncaughtException;
132+
SentryDependencyContainer.sharedInstance.crashReporter.uncaughtExceptionHandler
133+
= &handleUncaughtException;
132134
} else {
133135
SentryCrashLOG_DEBUG(@"Restoring original handler.");
134136
NSSetUncaughtExceptionHandler(g_previousUncaughtExceptionHandler);

Sources/SentryCrash/Recording/SentryCrash.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,6 @@ static NSString *const SENTRYCRASH_REPORT_ATTACHMENTS_ITEM = @"attachments";
182182

183183
#pragma mark - API -
184184

185-
/** Get the singleton instance of the crash reporter.
186-
*/
187-
+ (SentryCrash *)sharedInstance;
188-
189185
/** Install the crash reporter.
190186
* The reporter will record crashes, but will not send any crash reports unless
191187
* sink is set.

0 commit comments

Comments
 (0)