Skip to content

Commit bdb8eb1

Browse files
test: Use initialScope in sample apps (#3001)
1 parent 2b4a663 commit bdb8eb1

File tree

7 files changed

+51
-36
lines changed

7 files changed

+51
-36
lines changed

Samples/iOS-ObjectiveC/iOS-ObjectiveC/AppDelegate.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ - (BOOL)application:(UIApplication *)application
2626
SentryHttpStatusCodeRange *httpStatusCodeRange =
2727
[[SentryHttpStatusCodeRange alloc] initWithMin:400 max:599];
2828
options.failedRequestStatusCodes = @[ httpStatusCodeRange ];
29+
30+
options.initialScope = ^(SentryScope *scope) {
31+
[scope setTagValue:@"" forKey:@""];
32+
return scope;
33+
};
2934
}];
3035

3136
return YES;

Samples/iOS-Swift/iOS-Swift/AppDelegate.swift

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,22 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
5050
NotificationCenter.default.post(name: .init("io.sentry.newbreadcrumb"), object: breadcrumb)
5151
return breadcrumb
5252
}
53-
}
54-
55-
SentrySDK.configureScope { (scope) in
56-
scope.setEnvironment("debug")
57-
scope.setTag(value: "swift", key: "language")
58-
59-
let user = User(userId: "1")
60-
user.email = "[email protected]"
61-
scope.setUser(user)
53+
54+
options.initialScope = { scope in
55+
scope.setEnvironment("debug")
56+
scope.setTag(value: "swift", key: "language")
57+
58+
let user = User(userId: "1")
59+
user.email = "[email protected]"
60+
scope.setUser(user)
6261

63-
if let path = Bundle.main.path(forResource: "Tongariro", ofType: "jpg") {
64-
scope.addAttachment(Attachment(path: path, filename: "Tongariro.jpg", contentType: "image/jpeg"))
65-
}
66-
if let data = "hello".data(using: .utf8) {
67-
scope.addAttachment(Attachment(data: data, filename: "log.txt"))
62+
if let path = Bundle.main.path(forResource: "Tongariro", ofType: "jpg") {
63+
scope.addAttachment(Attachment(path: path, filename: "Tongariro.jpg", contentType: "image/jpeg"))
64+
}
65+
if let data = "hello".data(using: .utf8) {
66+
scope.addAttachment(Attachment(data: data, filename: "log.txt"))
67+
}
68+
return scope
6869
}
6970
}
7071
}

Samples/macOS-Swift/macOS-Swift/AppDelegate.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ class AppDelegate: NSObject, NSApplicationDelegate {
1313
if ProcessInfo.processInfo.arguments.contains("--io.sentry.profiling.enable") {
1414
options.profilesSampleRate = 1
1515
}
16-
}
17-
18-
SentrySDK.configureScope { scope in
19-
if let path = Bundle.main.path(forResource: "Tongariro", ofType: "jpg") {
20-
scope.addAttachment(Attachment(path: path, filename: "Tongariro.jpg", contentType: "image/jpeg"))
21-
}
2216

23-
if let data = "hello".data(using: .utf8) {
24-
scope.addAttachment(Attachment(data: data, filename: "log.txt"))
17+
options.initialScope = { scope in
18+
if let path = Bundle.main.path(forResource: "Tongariro", ofType: "jpg") {
19+
scope.addAttachment(Attachment(path: path, filename: "Tongariro.jpg", contentType: "image/jpeg"))
20+
}
21+
22+
if let data = "hello".data(using: .utf8) {
23+
scope.addAttachment(Attachment(data: data, filename: "log.txt"))
24+
}
25+
26+
return scope
2527
}
2628
}
2729
}

Samples/tvOS-Swift/tvOS-Swift/AppDelegate.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1616
// Sampling 100% - In Production you probably want to adjust this
1717
options.tracesSampleRate = 1.0
1818
options.enableAppHangTracking = true
19-
}
20-
21-
SentrySDK.configureScope { scope in
22-
if let path = Bundle.main.path(forResource: "Tongariro", ofType: "jpg") {
23-
scope.addAttachment(Attachment(path: path, filename: "Tongariro.jpg", contentType: "image/jpeg"))
24-
}
2519

26-
if let data = "hello".data(using: .utf8) {
27-
scope.addAttachment(Attachment(data: data, filename: "log.txt"))
20+
options.initialScope = { scope in
21+
if let path = Bundle.main.path(forResource: "Tongariro", ofType: "jpg") {
22+
scope.addAttachment(Attachment(path: path, filename: "Tongariro.jpg", contentType: "image/jpeg"))
23+
}
24+
25+
if let data = "hello".data(using: .utf8) {
26+
scope.addAttachment(Attachment(data: data, filename: "log.txt"))
27+
}
28+
return scope
2829
}
2930
}
3031

Sources/Sentry/Public/SentryOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ NS_SWIFT_NAME(Options)
197197
* configure and return this, or create your own scope instead.
198198
* @note The default simply returns the passed in scope.
199199
*/
200-
@property (nonatomic) SentryScope *(^initialScope)(SentryScope *);
200+
@property (nonatomic) SentryScope * (^initialScope)(SentryScope *);
201201

202202
#if SENTRY_HAS_UIKIT
203203
/**

Sources/Sentry/SentrySDK.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ + (void)startWithOptions:(SentryOptions *)options
139139
[newClient.fileManager moveAppStateToPreviousAppState];
140140
[newClient.fileManager moveBreadcrumbsToPreviousBreadcrumbs];
141141

142-
SentryScope *scope = options.initialScope([[SentryScope alloc] initWithMaxBreadcrumbs:options.maxBreadcrumbs]);
142+
SentryScope *scope
143+
= options.initialScope([[SentryScope alloc] initWithMaxBreadcrumbs:options.maxBreadcrumbs]);
143144
// The Hub needs to be initialized with a client so that closing a session
144145
// can happen.
145146
[SentrySDK setCurrentHub:[[SentryHub alloc] initWithClient:newClient andScope:scope]];

Tests/SentryTests/SentryOptionsTest.m

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,15 +1144,20 @@ - (void)testDefaultInAppExcludes
11441144
XCTAssertEqualObjects(@[], options.inAppExcludes);
11451145
}
11461146

1147-
- (void)testDefaultInitialScope {
1147+
- (void)testDefaultInitialScope
1148+
{
11481149
SentryOptions *options = [self getValidOptions:@{}];
11491150
SentryScope *scope = [[SentryScope alloc] init];
11501151
XCTAssertIdentical(scope, options.initialScope(scope));
11511152
}
11521153

1153-
- (void)testInitialScope {
1154-
SentryScope *(^initialScope)(SentryScope *) = ^SentryScope * (SentryScope *scope) { return scope; };
1155-
SentryOptions *options = [self getValidOptions:@{ @"initialScope": initialScope }];
1154+
- (void)testInitialScope
1155+
{
1156+
SentryScope * (^initialScope)(SentryScope *) = ^SentryScope *(SentryScope *scope)
1157+
{
1158+
return scope;
1159+
};
1160+
SentryOptions *options = [self getValidOptions:@{ @"initialScope" : initialScope }];
11561161
XCTAssertIdentical(initialScope, options.initialScope);
11571162
}
11581163

0 commit comments

Comments
 (0)