Skip to content

Commit ccf1278

Browse files
authored
feat: Update Persistent store and processor to handle multiple data types (#5558)
* feat: Update Persistent store and processor to handle multiple data types * Update tests in SentryScopePersistentStoreTests and SentryWatchdogTerminationFieldsProcessorTests for the new fields * Update changelog * Fix tests on macOS * Rename `SentryWatchdogTerminationFieldsProcessor` to `SentryWatchdogTerminationAttributesProcessor` * Apply suggestions from PR review * Fix typo * Update tests to use fixture * Rename `decoderAux` to `decoderUserHelper`
1 parent d022b1c commit ccf1278

29 files changed

+1301
-795
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
- Removed `APPLICATION_EXTENSION_API_ONLY` requirement (#5524)
1414
- Improve launch profile configuration management (#5318)
15+
- Record user for watchdog termination events (#5558)
1516

1617
## 8.53.1
1718

Sentry.xcodeproj/project.pbxproj

Lines changed: 32 additions & 28 deletions
Large diffs are not rendered by default.

Sources/Sentry/SentryDependencyContainer.m

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,10 @@ - (SentryMXManager *)metricKitManager SENTRY_THREAD_SANITIZER_DOUBLE_CHECKED_LOC
390390

391391
#endif // SENTRY_HAS_METRIC_KIT
392392

393-
- (SentryScopeContextPersistentStore *)
394-
scopeContextPersistentStore SENTRY_THREAD_SANITIZER_DOUBLE_CHECKED_LOCK
393+
- (SentryScopePersistentStore *)scopePersistentStore SENTRY_THREAD_SANITIZER_DOUBLE_CHECKED_LOCK
395394
{
396-
SENTRY_LAZY_INIT(_scopeContextPersistentStore,
397-
[[SentryScopeContextPersistentStore alloc] initWithFileManager:self.fileManager]);
395+
SENTRY_LAZY_INIT(_scopePersistentStore,
396+
[[SentryScopePersistentStore alloc] initWithFileManager:self.fileManager]);
398397
}
399398

400399
- (SentryDebugImageProvider *)debugImageProvider SENTRY_THREAD_SANITIZER_DOUBLE_CHECKED_LOCK
@@ -416,7 +415,7 @@ - (SentryWatchdogTerminationScopeObserver *)getWatchdogTerminationScopeObserverW
416415
initWithBreadcrumbProcessor:
417416
[self
418417
getWatchdogTerminationBreadcrumbProcessorWithMaxBreadcrumbs:options.maxBreadcrumbs]
419-
contextProcessor:self.watchdogTerminationContextProcessor];
418+
attributesProcessor:self.watchdogTerminationAttributesProcessor];
420419
}
421420

422421
- (SentryWatchdogTerminationBreadcrumbProcessor *)
@@ -429,16 +428,16 @@ - (SentryWatchdogTerminationScopeObserver *)getWatchdogTerminationScopeObserverW
429428
fileManager:self.fileManager];
430429
}
431430

432-
- (SentryWatchdogTerminationContextProcessor *)
433-
watchdogTerminationContextProcessor SENTRY_THREAD_SANITIZER_DOUBLE_CHECKED_LOCK
431+
- (SentryWatchdogTerminationAttributesProcessor *)
432+
watchdogTerminationAttributesProcessor SENTRY_THREAD_SANITIZER_DOUBLE_CHECKED_LOCK
434433
{
435-
SENTRY_LAZY_INIT(_watchdogTerminationContextProcessor,
436-
[[SentryWatchdogTerminationContextProcessor alloc]
434+
SENTRY_LAZY_INIT(_watchdogTerminationAttributesProcessor,
435+
[[SentryWatchdogTerminationAttributesProcessor alloc]
437436
initWithDispatchQueueWrapper:
438437
[self.dispatchFactory
439-
createUtilityQueue:"io.sentry.watchdog-termination-tracking.context-processor"
438+
createUtilityQueue:"io.sentry.watchdog-termination-tracking.fields-processor"
440439
relativePriority:0]
441-
scopeContextStore:self.scopeContextPersistentStore])
440+
scopePersistentStore:self.scopePersistentStore])
442441
}
443442
#endif
444443

Sources/Sentry/SentrySDK.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ + (void)startWithOptions:(SentryOptions *)options
241241
[newClient.fileManager moveAppStateToPreviousAppState];
242242
[newClient.fileManager moveBreadcrumbsToPreviousBreadcrumbs];
243243
[SentryDependencyContainer.sharedInstance
244-
.scopeContextPersistentStore moveCurrentFileToPreviousFile];
244+
.scopePersistentStore moveAllCurrentStateToPreviousState];
245245

246246
SentryScope *scope
247247
= options.initialScope([[SentryScope alloc] initWithMaxBreadcrumbs:options.maxBreadcrumbs]);

Sources/Sentry/SentryWatchdogTerminationScopeObserver.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@
1111
@interface SentryWatchdogTerminationScopeObserver ()
1212

1313
@property (nonatomic, strong) SentryWatchdogTerminationBreadcrumbProcessor *breadcrumbProcessor;
14-
@property (nonatomic, strong) SentryWatchdogTerminationContextProcessor *contextProcessor;
14+
@property (nonatomic, strong) SentryWatchdogTerminationAttributesProcessor *attributesProcessor;
1515

1616
@end
1717

1818
@implementation SentryWatchdogTerminationScopeObserver
1919

2020
- (instancetype)
2121
initWithBreadcrumbProcessor:(SentryWatchdogTerminationBreadcrumbProcessor *)breadcrumbProcessor
22-
contextProcessor:(SentryWatchdogTerminationContextProcessor *)contextProcessor;
22+
attributesProcessor:(SentryWatchdogTerminationAttributesProcessor *)attributesProcessor;
2323
{
2424
if (self = [super init]) {
2525
self.breadcrumbProcessor = breadcrumbProcessor;
26-
self.contextProcessor = contextProcessor;
26+
self.attributesProcessor = attributesProcessor;
2727
}
2828

2929
return self;
@@ -34,7 +34,7 @@ @implementation SentryWatchdogTerminationScopeObserver
3434
- (void)clear
3535
{
3636
[self.breadcrumbProcessor clear];
37-
[self.contextProcessor clear];
37+
[self.attributesProcessor clear];
3838
}
3939

4040
- (void)addSerializedBreadcrumb:(NSDictionary *)crumb
@@ -49,7 +49,7 @@ - (void)clearBreadcrumbs
4949

5050
- (void)setContext:(nullable NSDictionary<NSString *, id> *)context
5151
{
52-
[self.contextProcessor setContext:context];
52+
[self.attributesProcessor setContext:context];
5353
}
5454

5555
- (void)setDist:(nullable NSString *)dist
@@ -84,7 +84,7 @@ - (void)setTags:(nullable NSDictionary<NSString *, NSString *> *)tags
8484

8585
- (void)setUser:(nullable SentryUser *)user
8686
{
87-
// Left blank on purpose
87+
[self.attributesProcessor setUser:user];
8888
}
8989

9090
- (void)setTraceContext:(nullable NSDictionary<NSString *, id> *)traceContext

Sources/Sentry/SentryWatchdogTerminationTracker.m

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ @interface SentryWatchdogTerminationTracker ()
2222
@property (nonatomic, strong) SentryDispatchQueueWrapper *dispatchQueue;
2323
@property (nonatomic, strong) SentryAppStateManager *appStateManager;
2424
@property (nonatomic, strong) SentryFileManager *fileManager;
25-
@property (nonatomic, strong) SentryScopeContextPersistentStore *scopeContextStore;
25+
@property (nonatomic, strong) SentryScopePersistentStore *scopePersistentStore;
2626

2727
@end
2828

@@ -33,15 +33,15 @@ - (instancetype)initWithOptions:(SentryOptions *)options
3333
appStateManager:(SentryAppStateManager *)appStateManager
3434
dispatchQueueWrapper:(SentryDispatchQueueWrapper *)dispatchQueueWrapper
3535
fileManager:(SentryFileManager *)fileManager
36-
scopeContextStore:(SentryScopeContextPersistentStore *)scopeContextStore
36+
scopePersistentStore:(SentryScopePersistentStore *)scopePersistentStore
3737
{
3838
if (self = [super init]) {
3939
self.options = options;
4040
self.watchdogTerminationLogic = watchdogTerminationLogic;
4141
self.appStateManager = appStateManager;
4242
self.dispatchQueue = dispatchQueueWrapper;
4343
self.fileManager = fileManager;
44-
self.scopeContextStore = scopeContextStore;
44+
self.scopePersistentStore = scopePersistentStore;
4545
}
4646
return self;
4747
}
@@ -57,6 +57,7 @@ - (void)start
5757

5858
[self addBreadcrumbsToEvent:event];
5959
[self addContextToEvent:event];
60+
event.user = [self.scopePersistentStore readPreviousUserFromDisk];
6061

6162
SentryException *exception =
6263
[[SentryException alloc] initWithValue:SentryWatchdogTerminationExceptionValue
@@ -105,7 +106,7 @@ - (void)addContextToEvent:(SentryEvent *)event
105106
{
106107
// Load the previous context from disk, or create an empty one if it doesn't exist
107108
NSDictionary<NSString *, NSDictionary<NSString *, id> *> *previousContext =
108-
[self.scopeContextStore readPreviousContextFromDisk];
109+
[self.scopePersistentStore readPreviousContextFromDisk];
109110
NSMutableDictionary *context =
110111
[[NSMutableDictionary alloc] initWithDictionary:previousContext ?: @{}];
111112

Sources/Sentry/SentryWatchdogTerminationTrackingIntegration.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ - (BOOL)installWithOptions:(SentryOptions *)options
6666
[[SentryWatchdogTerminationLogic alloc] initWithOptions:options
6767
crashAdapter:crashWrapper
6868
appStateManager:appStateManager];
69-
SentryScopeContextPersistentStore *scopeContextStore =
70-
[SentryDependencyContainer.sharedInstance scopeContextPersistentStore];
69+
SentryScopePersistentStore *scopeStore =
70+
[SentryDependencyContainer.sharedInstance scopePersistentStore];
7171

7272
self.tracker = [[SentryWatchdogTerminationTracker alloc] initWithOptions:options
7373
watchdogTerminationLogic:logic
7474
appStateManager:appStateManager
7575
dispatchQueueWrapper:dispatchQueueWrapper
7676
fileManager:fileManager
77-
scopeContextStore:scopeContextStore];
77+
scopePersistentStore:scopeStore];
7878

7979
[self.tracker start];
8080

@@ -96,6 +96,7 @@ - (BOOL)installWithOptions:(SentryOptions *)options
9696
// Sync the current context to the observer to capture context modifications that happened
9797
// before installation.
9898
[scopeObserver setContext:outerScope.contextDictionary];
99+
[scopeObserver setUser:outerScope.userObject];
99100
}];
100101

101102
return YES;

Sources/Sentry/include/HybridPublic/SentryDependencyContainer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
@class SentryThreadWrapper;
2323
@class SentryThreadInspector;
2424
@class SentryFileIOTracker;
25-
@class SentryScopeContextPersistentStore;
25+
@class SentryScopePersistentStore;
2626
@class SentryOptions;
2727
@class SentrySessionTracker;
2828
@class SentryGlobalEventProcessor;
@@ -45,7 +45,7 @@
4545
@class SentryViewHierarchyProvider;
4646
@class SentryUIViewControllerPerformanceTracker;
4747
@class SentryWatchdogTerminationScopeObserver;
48-
@class SentryWatchdogTerminationContextProcessor;
48+
@class SentryWatchdogTerminationAttributesProcessor;
4949
@class SentryWatchdogTerminationBreadcrumbProcessor;
5050
#endif // SENTRY_UIKIT_AVAILABLE
5151

@@ -109,7 +109,7 @@ SENTRY_NO_INIT
109109
@property (nonatomic, strong) SentryThreadInspector *threadInspector;
110110
@property (nonatomic, strong) SentryFileIOTracker *fileIOTracker;
111111
@property (nonatomic, strong) SentryCrash *crashReporter;
112-
@property (nonatomic, strong) SentryScopeContextPersistentStore *scopeContextPersistentStore;
112+
@property (nonatomic, strong) SentryScopePersistentStore *scopePersistentStore;
113113
@property (nonatomic, strong) SentryDebugImageProvider *debugImageProvider;
114114

115115
- (id<SentryANRTracker>)getANRTracker:(NSTimeInterval)timeout;
@@ -142,7 +142,7 @@ SENTRY_NO_INIT
142142
- (SentryWatchdogTerminationBreadcrumbProcessor *)
143143
getWatchdogTerminationBreadcrumbProcessorWithMaxBreadcrumbs:(NSInteger)maxBreadcrumbs;
144144
@property (nonatomic, strong)
145-
SentryWatchdogTerminationContextProcessor *watchdogTerminationContextProcessor;
145+
SentryWatchdogTerminationAttributesProcessor *watchdogTerminationAttributesProcessor;
146146
#endif
147147

148148
@property (nonatomic, strong) SentryGlobalEventProcessor *globalEventProcessor;

Sources/Sentry/include/SentryWatchdogTerminationScopeObserver.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# import "SentryScopeObserver.h"
66

77
@class SentryWatchdogTerminationBreadcrumbProcessor;
8-
@class SentryWatchdogTerminationContextProcessor;
8+
@class SentryWatchdogTerminationAttributesProcessor;
99

1010
NS_ASSUME_NONNULL_BEGIN
1111

@@ -20,7 +20,7 @@ SENTRY_NO_INIT
2020

2121
- (instancetype)
2222
initWithBreadcrumbProcessor:(SentryWatchdogTerminationBreadcrumbProcessor *)breadcrumbProcessor
23-
contextProcessor:(SentryWatchdogTerminationContextProcessor *)contextProcessor;
23+
attributesProcessor:(SentryWatchdogTerminationAttributesProcessor *)attributesProcessor;
2424

2525
@end
2626

Sources/Sentry/include/SentryWatchdogTerminationTracker.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
@class SentryFileManager;
66
@class SentryOptions;
77
@class SentryWatchdogTerminationLogic;
8-
@class SentryScopeContextPersistentStore;
8+
@class SentryScopePersistentStore;
99

1010
NS_ASSUME_NONNULL_BEGIN
1111

@@ -28,7 +28,7 @@ SENTRY_NO_INIT
2828
appStateManager:(SentryAppStateManager *)appStateManager
2929
dispatchQueueWrapper:(SentryDispatchQueueWrapper *)dispatchQueueWrapper
3030
fileManager:(SentryFileManager *)fileManager
31-
scopeContextStore:(SentryScopeContextPersistentStore *)scopeContextStore;
31+
scopePersistentStore:(SentryScopePersistentStore *)scopeStore;
3232

3333
- (void)start;
3434
- (void)stop;

0 commit comments

Comments
 (0)