Skip to content

Commit 04435e6

Browse files
authored
ref: SentryScopeObserver Swift (#6431)
1 parent 466e905 commit 04435e6

File tree

10 files changed

+91
-50
lines changed

10 files changed

+91
-50
lines changed

Sentry.xcodeproj/project.pbxproj

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,8 +1112,9 @@
11121112
FAAB2EE02E4BE97500FE8B7E /* TestSentryNSApplication.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAAB2EDF2E4BE96F00FE8B7E /* TestSentryNSApplication.swift */; };
11131113
FAAB2F972E4D345800FE8B7E /* SentryUIDeviceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAAB2F962E4D344F00FE8B7E /* SentryUIDeviceWrapper.swift */; };
11141114
FAAB30F32E4E8F2C00FE8B7E /* SentryInAppLogic.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAAB30F22E4E8F2C00FE8B7E /* SentryInAppLogic.swift */; };
1115-
FAB007432E9F47E8001C806A /* SessionTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAB007422E9F47E4001C806A /* SessionTracker.swift */; };
1115+
FAAB95C02EA163590030A2DB /* SentryScopeObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAAB95BF2EA163590030A2DB /* SentryScopeObserver.swift */; };
11161116
FAB007362E9EF8D3001C806A /* SentryUIViewControllerPerformanceTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAB007302E9EF8CB001C806A /* SentryUIViewControllerPerformanceTracker.swift */; };
1117+
FAB007432E9F47E8001C806A /* SessionTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAB007422E9F47E4001C806A /* SessionTracker.swift */; };
11171118
FAB007522E9FE2FF001C806A /* SentrySwizzleWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAB0074C2E9FE2FA001C806A /* SentrySwizzleWrapper.swift */; };
11181119
FAB359982E05D7E90083D5E3 /* SentryEventSwiftHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = FAB359972E05D7E90083D5E3 /* SentryEventSwiftHelper.h */; };
11191120
FAB3599A2E05D8080083D5E3 /* SentryEventSwiftHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = FAB359992E05D8080083D5E3 /* SentryEventSwiftHelper.m */; };
@@ -2475,8 +2476,9 @@
24752476
FAAB2EDF2E4BE96F00FE8B7E /* TestSentryNSApplication.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestSentryNSApplication.swift; sourceTree = "<group>"; };
24762477
FAAB2F962E4D344F00FE8B7E /* SentryUIDeviceWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryUIDeviceWrapper.swift; sourceTree = "<group>"; };
24772478
FAAB30F22E4E8F2C00FE8B7E /* SentryInAppLogic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryInAppLogic.swift; sourceTree = "<group>"; };
2478-
FAB007422E9F47E4001C806A /* SessionTracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionTracker.swift; sourceTree = "<group>"; };
2479+
FAAB95BF2EA163590030A2DB /* SentryScopeObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryScopeObserver.swift; sourceTree = "<group>"; };
24792480
FAB007302E9EF8CB001C806A /* SentryUIViewControllerPerformanceTracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryUIViewControllerPerformanceTracker.swift; sourceTree = "<group>"; };
2481+
FAB007422E9F47E4001C806A /* SessionTracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionTracker.swift; sourceTree = "<group>"; };
24802482
FAB0074C2E9FE2FA001C806A /* SentrySwizzleWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySwizzleWrapper.swift; sourceTree = "<group>"; };
24812483
FAB359972E05D7E90083D5E3 /* SentryEventSwiftHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryEventSwiftHelper.h; path = include/SentryEventSwiftHelper.h; sourceTree = "<group>"; };
24822484
FAB359992E05D8080083D5E3 /* SentryEventSwiftHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryEventSwiftHelper.m; sourceTree = "<group>"; };
@@ -4380,6 +4382,7 @@
43804382
D800942328F82E8D005D3943 /* Swift */ = {
43814383
isa = PBXGroup;
43824384
children = (
4385+
FAAB95B92EA1633E0030A2DB /* State */,
43834386
FA560F5A2E8C876A00F2AF7F /* SentryAppStateManager.swift */,
43844387
F429D37E2E8532A300DBF387 /* Networking */,
43854388
F4FE9E062E6248BB0014FED5 /* SentryCrash */,
@@ -4969,6 +4972,14 @@
49694972
path = Core;
49704973
sourceTree = "<group>";
49714974
};
4975+
FAAB95B92EA1633E0030A2DB /* State */ = {
4976+
isa = PBXGroup;
4977+
children = (
4978+
FAAB95BF2EA163590030A2DB /* SentryScopeObserver.swift */,
4979+
);
4980+
path = State;
4981+
sourceTree = "<group>";
4982+
};
49724983
FAB0073C2E9F47DE001C806A /* Session */ = {
49734984
isa = PBXGroup;
49744985
children = (
@@ -6036,6 +6047,7 @@
60366047
63FE710B20DA4C1000CDBAE8 /* SentryCrashMach.c in Sources */,
60376048
63FE707720DA4C1000CDBAE8 /* SentryDictionaryDeepSearch.m in Sources */,
60386049
FACEED132E3179A10007B4AC /* SentyOptionsInternal.m in Sources */,
6050+
FAAB95C02EA163590030A2DB /* SentryScopeObserver.swift in Sources */,
60396051
D48891D02E98F2E700212823 /* SentryInfoPlistError.swift in Sources */,
60406052
8482FA9C2DD7C397000E9283 /* SentryFeedbackAPI.m in Sources */,
60416053
7BC9A20628F41781001E7C4C /* SentryMeasurementUnit.m in Sources */,

Sources/Sentry/SentryCrashIntegration.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
}
4747
}
4848

49+
@interface SentryCrashScopeObserver () <SentryScopeObserver>
50+
@end
51+
4952
@interface SentryCrashIntegration ()
5053

5154
@property (nonatomic, weak) SentryOptions *options;

Sources/Sentry/SentryDependencyContainer.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ @interface SentryDefaultAppStateManager () <SentryAppStateManager>
6464
@end
6565

6666
#if SENTRY_HAS_UIKIT
67+
@interface SentryWatchdogTerminationScopeObserver () <SentryScopeObserver>
68+
@end
69+
6770
@interface SentryDefaultUIViewControllerPerformanceTracker () <
6871
SentryUIViewControllerPerformanceTracker>
6972
@end

Sources/Sentry/SentryScope.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#import "SentryPropagationContext.h"
1111
#import "SentryScope+Private.h"
1212
#import "SentryScope+PrivateSwift.h"
13-
#import "SentryScopeObserver.h"
1413
#import "SentrySpan.h"
1514
#import "SentrySwift.h"
1615
#import "SentryTracer.h"

Sources/Sentry/include/SentryCrashScopeObserver.h

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#import "SentryDefines.h"
2-
#import "SentryScopeObserver.h"
2+
3+
@class SentryUser;
34

45
NS_ASSUME_NONNULL_BEGIN
56

@@ -15,11 +16,35 @@ NS_ASSUME_NONNULL_BEGIN
1516
* thread. This has the downside of the scope not being 100% up to date when a crash happens and, of
1617
* course, lots of CPU overhead.
1718
*/
18-
@interface SentryCrashScopeObserver : NSObject <SentryScopeObserver>
19+
@interface SentryCrashScopeObserver : NSObject
1920
SENTRY_NO_INIT
2021

2122
- (instancetype)initWithMaxBreadcrumbs:(NSInteger)maxBreadcrumbs;
2223

24+
- (void)setUser:(nullable SentryUser *)user;
25+
26+
- (void)setTags:(nullable NSDictionary<NSString *, NSString *> *)tags;
27+
28+
- (void)setExtras:(nullable NSDictionary<NSString *, id> *)extras;
29+
30+
- (void)setContext:(nullable NSDictionary<NSString *, id> *)context;
31+
32+
- (void)setTraceContext:(nullable NSDictionary<NSString *, id> *)traceContext;
33+
34+
- (void)setDist:(nullable NSString *)dist;
35+
36+
- (void)setEnvironment:(nullable NSString *)environment;
37+
38+
- (void)setFingerprint:(nullable NSArray<NSString *> *)fingerprint;
39+
40+
- (void)setLevel:(enum SentryLevel)level;
41+
42+
- (void)addSerializedBreadcrumb:(NSDictionary<NSString *, id> *)crumb;
43+
44+
- (void)clearBreadcrumbs;
45+
46+
- (void)clear;
47+
2348
@end
2449

2550
NS_ASSUME_NONNULL_END

Sources/Sentry/include/SentryScopeObserver.h

Lines changed: 0 additions & 41 deletions
This file was deleted.

Sources/Sentry/include/SentryWatchdogTerminationScopeObserver.h

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
#if SENTRY_HAS_UIKIT
44

5-
# import "SentryScopeObserver.h"
6-
75
@class SentryWatchdogTerminationBreadcrumbProcessor;
86
@class SentryWatchdogTerminationAttributesProcessor;
7+
@class SentryUser;
98

109
NS_ASSUME_NONNULL_BEGIN
1110

@@ -15,13 +14,37 @@ NS_ASSUME_NONNULL_BEGIN
1514
* This class doesn't need to be thread safe as the scope already calls the scope observers in a
1615
* thread safe manner.
1716
*/
18-
@interface SentryWatchdogTerminationScopeObserver : NSObject <SentryScopeObserver>
17+
@interface SentryWatchdogTerminationScopeObserver : NSObject
1918
SENTRY_NO_INIT
2019

2120
- (instancetype)
2221
initWithBreadcrumbProcessor:(SentryWatchdogTerminationBreadcrumbProcessor *)breadcrumbProcessor
2322
attributesProcessor:(SentryWatchdogTerminationAttributesProcessor *)attributesProcessor;
2423

24+
- (void)setUser:(nullable SentryUser *)user;
25+
26+
- (void)setTags:(nullable NSDictionary<NSString *, NSString *> *)tags;
27+
28+
- (void)setExtras:(nullable NSDictionary<NSString *, id> *)extras;
29+
30+
- (void)setContext:(nullable NSDictionary<NSString *, id> *)context;
31+
32+
- (void)setTraceContext:(nullable NSDictionary<NSString *, id> *)traceContext;
33+
34+
- (void)setDist:(nullable NSString *)dist;
35+
36+
- (void)setEnvironment:(nullable NSString *)environment;
37+
38+
- (void)setFingerprint:(nullable NSArray<NSString *> *)fingerprint;
39+
40+
- (void)setLevel:(enum SentryLevel)level;
41+
42+
- (void)addSerializedBreadcrumb:(NSDictionary<NSString *, id> *)crumb;
43+
44+
- (void)clearBreadcrumbs;
45+
46+
- (void)clear;
47+
2548
@end
2649

2750
NS_ASSUME_NONNULL_END
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@_spi(Private) @objc public protocol SentryScopeObserver: NSObjectProtocol {
2+
func setUser(_ user: User?)
3+
func setTags(_ tags: [String: String]?)
4+
func setExtras(_ extras: [String: Any]?)
5+
func setContext(_ context: [String: Any]?)
6+
func setTraceContext(_ traceContext: [String: Any]?)
7+
func setDist(_ dist: String?)
8+
func setEnvironment(_ environment: String?)
9+
func setFingerprint(_ fingerprint: [String]?)
10+
func setLevel(_ level: SentryLevel)
11+
func addSerializedBreadcrumb(_ serializedBreadcrumb: [String: Any])
12+
func clearBreadcrumbs()
13+
func clear()
14+
@objc optional func setCurrentScreen(_ currentScreen: String?)
15+
}

Tests/SentryTests/Integrations/SentryCrash/SentryCrashScopeObserverTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
@_spi(Private) import Sentry
12
import SentryTestUtils
23
import XCTest
34

5+
@_spi(Private) extension SentryCrashScopeObserver: SentryScopeObserver { }
6+
47
class SentryCrashScopeObserverTests: XCTestCase {
58

69
private class Fixture {

Tests/SentryTests/SentryTests-Bridging-Header.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@
155155
#import "SentrySDKInternal+Tests.h"
156156
#import "SentrySampleDecision+Private.h"
157157
#import "SentryScope+Private.h"
158-
#import "SentryScopeObserver.h"
159158
#import "SentryScopeSyncC.h"
160159
#import "SentryScreenshotIntegration.h"
161160
#import "SentrySerialization.h"

0 commit comments

Comments
 (0)