Skip to content

Commit 397b93b

Browse files
Merge 8c9360f into d975745
2 parents d975745 + 8c9360f commit 397b93b

File tree

11 files changed

+42
-1151
lines changed

11 files changed

+42
-1151
lines changed

Sources/Sentry/Public/SentryOptions.h

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,13 @@
33

44
NS_ASSUME_NONNULL_BEGIN
55

6-
@class SentryDsn, SentrySdkInfo, SentryMeasurementValue, SentryHttpStatusCodeRange;
6+
@class SentryDsn, SentryMeasurementValue, SentryHttpStatusCodeRange;
77

88
NS_SWIFT_NAME(Options)
99
@interface SentryOptions : NSObject
1010

11-
/**
12-
* Init SentryOptions.
13-
* @param options Options dictionary
14-
* @return SentryOptions
15-
*/
16-
- (_Nullable instancetype)initWithDict:(NSDictionary<NSString *, id> *)options
17-
didFailWithError:(NSError *_Nullable *_Nullable)error;
11+
- (_Nullable instancetype)initWithDsn:(NSString *)dsn
12+
didFailWithError:(NSError *_Nullable *_Nullable)error;
1813

1914
/**
2015
* The DSN tells the SDK where to send the events to. If this value is not provided, the SDK will
@@ -164,13 +159,6 @@ NS_SWIFT_NAME(Options)
164159
*/
165160
@property (nonatomic, assign) BOOL stitchAsyncCode;
166161

167-
/**
168-
* Describes the Sentry SDK and its configuration used to capture and transmit an event.
169-
* This is reserved for internal use, and will be removed in a future version of the SDK.
170-
*/
171-
@property (nonatomic, readonly, strong) SentrySdkInfo *sdkInfo DEPRECATED_MSG_ATTRIBUTE(
172-
"This property will be removed in a future version of the SDK");
173-
174162
/**
175163
* The maximum size for each attachment in bytes. Default is 20 MiB / 20 * 1024 * 1024 bytes.
176164
*

Sources/Sentry/Public/SentrySDK.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ SENTRY_NO_INIT
2525
*/
2626
@property (class, nonatomic, readonly) BOOL isEnabled;
2727

28-
/**
29-
* Inits and configures Sentry (SentryHub, SentryClient) and sets up all integrations.
30-
*/
31-
+ (void)startWithOptions:(NSDictionary<NSString *, id> *)optionsDict NS_SWIFT_NAME(start(options:));
32-
3328
/**
3429
* Inits and configures Sentry (SentryHub, SentryClient) and sets up all integrations.
3530
*/

Sources/Sentry/SentryClient.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#import "SentryPermissionsObserver.h"
3434
#import "SentrySDK+Private.h"
3535
#import "SentryScope+Private.h"
36-
#import "SentrySdkInfo.h"
3736
#import "SentryStacktraceBuilder.h"
3837
#import "SentryThreadInspector.h"
3938
#import "SentryTraceContext.h"

Sources/Sentry/SentryOptions.m

Lines changed: 6 additions & 238 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#import "SentryLog.h"
77
#import "SentryMeta.h"
88
#import "SentrySDK.h"
9-
#import "SentrySdkInfo.h"
109

1110
@interface
1211
SentryOptions ()
@@ -131,14 +130,14 @@ - (instancetype)init
131130
return self;
132131
}
133132

134-
- (_Nullable instancetype)initWithDict:(NSDictionary<NSString *, id> *)options
135-
didFailWithError:(NSError *_Nullable *_Nullable)error
133+
- (_Nullable instancetype)initWithDsn:(NSString *)dsn
134+
didFailWithError:(NSError *_Nullable *_Nullable)error
136135
{
137136
if (self = [self init]) {
138-
if (![self validateOptions:options didFailWithError:error]) {
139-
[SentryLog
140-
logWithMessage:[NSString stringWithFormat:@"Failed to initialize: %@", *error]
141-
andLevel:kSentryLevelError];
137+
self.parsedDsn = [[SentryDsn alloc] initWithString:dsn didFailWithError:error];
138+
self.dsn = dsn;
139+
140+
if (error != nil && *error != nil) {
142141
return nil;
143142
}
144143
}
@@ -191,237 +190,6 @@ - (void)setDsn:(NSString *)dsn
191190
}
192191
}
193192

194-
/**
195-
* Populates all `SentryOptions` values from `options` dict using fallbacks/defaults if needed.
196-
*/
197-
- (BOOL)validateOptions:(NSDictionary<NSString *, id> *)options
198-
didFailWithError:(NSError *_Nullable *_Nullable)error
199-
{
200-
NSPredicate *isNSString = [NSPredicate predicateWithBlock:^BOOL(
201-
id object, NSDictionary *bindings) { return [object isKindOfClass:[NSString class]]; }];
202-
203-
[self setBool:options[@"debug"] block:^(BOOL value) { self->_debug = value; }];
204-
205-
if ([options[@"diagnosticLevel"] isKindOfClass:[NSString class]]) {
206-
for (SentryLevel level = 0; level <= kSentryLevelFatal; level++) {
207-
if ([nameForSentryLevel(level) isEqualToString:options[@"diagnosticLevel"]]) {
208-
self.diagnosticLevel = level;
209-
break;
210-
}
211-
}
212-
}
213-
214-
NSString *dsn = @"";
215-
if (nil != options[@"dsn"] && [options[@"dsn"] isKindOfClass:[NSString class]]) {
216-
dsn = options[@"dsn"];
217-
}
218-
219-
self.parsedDsn = [[SentryDsn alloc] initWithString:dsn didFailWithError:error];
220-
221-
if ([options[@"release"] isKindOfClass:[NSString class]]) {
222-
self.releaseName = options[@"release"];
223-
}
224-
225-
if ([options[@"environment"] isKindOfClass:[NSString class]]) {
226-
self.environment = options[@"environment"];
227-
}
228-
229-
if ([options[@"dist"] isKindOfClass:[NSString class]]) {
230-
self.dist = options[@"dist"];
231-
}
232-
233-
[self setBool:options[@"enabled"] block:^(BOOL value) { self->_enabled = value; }];
234-
235-
[self setBool:options[@"enableCrashHandler"]
236-
block:^(BOOL value) { self->_enableCrashHandler = value; }];
237-
238-
if ([options[@"maxBreadcrumbs"] isKindOfClass:[NSNumber class]]) {
239-
self.maxBreadcrumbs = [options[@"maxBreadcrumbs"] unsignedIntValue];
240-
}
241-
242-
[self setBool:options[@"enableNetworkBreadcrumbs"]
243-
block:^(BOOL value) { self->_enableNetworkBreadcrumbs = value; }];
244-
245-
if ([options[@"maxCacheItems"] isKindOfClass:[NSNumber class]]) {
246-
self.maxCacheItems = [options[@"maxCacheItems"] unsignedIntValue];
247-
}
248-
249-
if ([self isBlock:options[@"beforeSend"]]) {
250-
self.beforeSend = options[@"beforeSend"];
251-
}
252-
253-
if ([self isBlock:options[@"beforeBreadcrumb"]]) {
254-
self.beforeBreadcrumb = options[@"beforeBreadcrumb"];
255-
}
256-
257-
if ([self isBlock:options[@"onCrashedLastRun"]]) {
258-
self.onCrashedLastRun = options[@"onCrashedLastRun"];
259-
}
260-
261-
if ([options[@"integrations"] isKindOfClass:[NSArray class]]) {
262-
self.integrations = [options[@"integrations"] filteredArrayUsingPredicate:isNSString];
263-
}
264-
265-
if ([options[@"sampleRate"] isKindOfClass:[NSNumber class]]) {
266-
self.sampleRate = options[@"sampleRate"];
267-
}
268-
269-
[self setBool:options[@"enableAutoSessionTracking"]
270-
block:^(BOOL value) { self->_enableAutoSessionTracking = value; }];
271-
272-
[self setBool:options[@"enableOutOfMemoryTracking"]
273-
block:^(BOOL value) { self->_enableOutOfMemoryTracking = value; }];
274-
275-
if ([options[@"sessionTrackingIntervalMillis"] isKindOfClass:[NSNumber class]]) {
276-
self.sessionTrackingIntervalMillis =
277-
[options[@"sessionTrackingIntervalMillis"] unsignedIntValue];
278-
}
279-
280-
[self setBool:options[@"attachStacktrace"]
281-
block:^(BOOL value) { self->_attachStacktrace = value; }];
282-
283-
[self setBool:options[@"stitchAsyncCode"]
284-
block:^(BOOL value) { self->_stitchAsyncCode = value; }];
285-
286-
if ([options[@"maxAttachmentSize"] isKindOfClass:[NSNumber class]]) {
287-
self.maxAttachmentSize = [options[@"maxAttachmentSize"] unsignedIntValue];
288-
}
289-
290-
[self setBool:options[@"sendDefaultPii"]
291-
block:^(BOOL value) { self->_sendDefaultPii = value; }];
292-
293-
[self setBool:options[@"enableAutoPerformanceTracking"]
294-
block:^(BOOL value) { self->_enableAutoPerformanceTracking = value; }];
295-
296-
[self setBool:options[@"enableCaptureFailedRequests"]
297-
block:^(BOOL value) { self->_enableCaptureFailedRequests = value; }];
298-
299-
#if SENTRY_HAS_UIKIT
300-
[self setBool:options[@"enableUIViewControllerTracking"]
301-
block:^(BOOL value) { self->_enableUIViewControllerTracking = value; }];
302-
303-
[self setBool:options[@"attachScreenshot"]
304-
block:^(BOOL value) { self->_attachScreenshot = value; }];
305-
306-
[self setBool:options[@"attachViewHierarchy"]
307-
block:^(BOOL value) { self->_attachViewHierarchy = value; }];
308-
309-
[self setBool:options[@"enableUserInteractionTracing"]
310-
block:^(BOOL value) { self->_enableUserInteractionTracing = value; }];
311-
312-
if ([options[@"idleTimeout"] isKindOfClass:[NSNumber class]]) {
313-
self.idleTimeout = [options[@"idleTimeout"] doubleValue];
314-
}
315-
316-
[self setBool:options[@"enablePreWarmedAppStartTracking"]
317-
block:^(BOOL value) { self->_enablePreWarmedAppStartTracking = value; }];
318-
#endif
319-
320-
[self setBool:options[@"enableAppHangTracking"]
321-
block:^(BOOL value) { self->_enableAppHangTracking = value; }];
322-
323-
if ([options[@"appHangTimeoutInterval"] isKindOfClass:[NSNumber class]]) {
324-
self.appHangTimeoutInterval = [options[@"appHangTimeoutInterval"] doubleValue];
325-
}
326-
327-
[self setBool:options[@"enableNetworkTracking"]
328-
block:^(BOOL value) { self->_enableNetworkTracking = value; }];
329-
330-
[self setBool:options[@"enableFileIOTracking"]
331-
block:^(BOOL value) { self->_enableFileIOTracking = value; }];
332-
333-
if ([options[@"tracesSampleRate"] isKindOfClass:[NSNumber class]]) {
334-
self.tracesSampleRate = options[@"tracesSampleRate"];
335-
}
336-
337-
if ([self isBlock:options[@"tracesSampler"]]) {
338-
self.tracesSampler = options[@"tracesSampler"];
339-
}
340-
341-
if ([options[@"inAppIncludes"] isKindOfClass:[NSArray class]]) {
342-
NSArray<NSString *> *inAppIncludes =
343-
[options[@"inAppIncludes"] filteredArrayUsingPredicate:isNSString];
344-
_inAppIncludes = [_inAppIncludes arrayByAddingObjectsFromArray:inAppIncludes];
345-
}
346-
347-
if ([options[@"inAppExcludes"] isKindOfClass:[NSArray class]]) {
348-
_inAppExcludes = [options[@"inAppExcludes"] filteredArrayUsingPredicate:isNSString];
349-
}
350-
351-
if ([options[@"urlSessionDelegate"] conformsToProtocol:@protocol(NSURLSessionDelegate)]) {
352-
self.urlSessionDelegate = options[@"urlSessionDelegate"];
353-
}
354-
355-
[self setBool:options[@"enableSwizzling"]
356-
block:^(BOOL value) { self->_enableSwizzling = value; }];
357-
358-
[self setBool:options[@"enableCoreDataTracking"]
359-
block:^(BOOL value) { self->_enableCoreDataTracking = value; }];
360-
361-
#if SENTRY_TARGET_PROFILING_SUPPORTED
362-
if ([options[@"profilesSampleRate"] isKindOfClass:[NSNumber class]]) {
363-
self.profilesSampleRate = options[@"profilesSampleRate"];
364-
}
365-
366-
if ([self isBlock:options[@"profilesSampler"]]) {
367-
self.profilesSampler = options[@"profilesSampler"];
368-
}
369-
370-
[self setBool:options[@"enableProfiling"]
371-
block:^(BOOL value) { self->_enableProfiling = value; }];
372-
#endif
373-
374-
[self setBool:options[@"sendClientReports"]
375-
block:^(BOOL value) { self->_sendClientReports = value; }];
376-
377-
[self setBool:options[@"enableAutoBreadcrumbTracking"]
378-
block:^(BOOL value) { self->_enableAutoBreadcrumbTracking = value; }];
379-
380-
if ([options[@"tracePropagationTargets"] isKindOfClass:[NSArray class]]) {
381-
self.tracePropagationTargets = options[@"tracePropagationTargets"];
382-
}
383-
384-
if ([options[@"failedRequestStatusCodes"] isKindOfClass:[NSArray class]]) {
385-
self.failedRequestStatusCodes = options[@"failedRequestStatusCodes"];
386-
}
387-
388-
if ([options[@"failedRequestTargets"] isKindOfClass:[NSArray class]]) {
389-
self.failedRequestTargets = options[@"failedRequestTargets"];
390-
}
391-
392-
// SentrySdkInfo already expects a dictionary with {"sdk": {"name": ..., "value": ...}}
393-
// so we're passing the whole options object.
394-
// Note: we should remove this code once the hybrid SDKs move over to the new
395-
// PrivateSentrySDKOnly setter functions.
396-
if ([options[@"sdk"] isKindOfClass:[NSDictionary class]]) {
397-
SentrySdkInfo *defaults = [[SentrySdkInfo alloc] initWithName:SentryMeta.sdkName
398-
andVersion:SentryMeta.versionString];
399-
SentrySdkInfo *sdkInfo = [[SentrySdkInfo alloc] initWithDict:options orDefaults:defaults];
400-
SentryMeta.versionString = sdkInfo.version;
401-
SentryMeta.sdkName = sdkInfo.name;
402-
}
403-
404-
if (nil != error && nil != *error) {
405-
return NO;
406-
} else {
407-
return YES;
408-
}
409-
}
410-
411-
- (SentrySdkInfo *)sdkInfo
412-
{
413-
return [[SentrySdkInfo alloc] initWithName:SentryMeta.sdkName
414-
andVersion:SentryMeta.versionString];
415-
}
416-
417-
- (void)setBool:(id)value block:(void (^)(BOOL))block
418-
{
419-
// Entries in the dictionary can be NSNull. Especially, on React-Native, this can happen.
420-
if (value != nil && ![value isEqual:[NSNull null]]) {
421-
block([value boolValue]);
422-
}
423-
}
424-
425193
- (void)addInAppInclude:(NSString *)inAppInclude
426194
{
427195
_inAppIncludes = [self.inAppIncludes arrayByAddingObject:inAppInclude];

Sources/Sentry/SentrySDK.m

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,6 @@ + (void)setStartInvocations:(NSUInteger)value
128128
startInvocations = value;
129129
}
130130

131-
+ (void)startWithOptions:(NSDictionary<NSString *, id> *)optionsDict
132-
{
133-
NSError *error = nil;
134-
SentryOptions *options = [[SentryOptions alloc] initWithDict:optionsDict
135-
didFailWithError:&error];
136-
if (nil != error) {
137-
SENTRY_LOG_ERROR(@"Error while initializing the SDK");
138-
SENTRY_LOG_ERROR(@"%@", error);
139-
} else {
140-
[SentrySDK startWithOptionsObject:options];
141-
}
142-
}
143-
144131
+ (void)startWithOptionsObject:(SentryOptions *)options
145132
{
146133
startInvocations++;

Tests/SentryTests/Integrations/SentryCrash/SentryCrashIntegrationTests.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,11 @@ class SentryCrashIntegrationTests: NotificationCenterTestCase {
7777
let releaseName = "1.0.0"
7878
let dist = "14G60"
7979
// The start of the SDK installs all integrations
80-
SentrySDK.start(options: ["dsn": SentryCrashIntegrationTests.dsnAsString,
81-
"release": releaseName,
82-
"dist": dist]
83-
)
80+
SentrySDK.start { options in
81+
options.dsn = SentryCrashIntegrationTests.dsnAsString
82+
options.releaseName = releaseName
83+
options.dist = dist
84+
}
8485

8586
// To test this properly we need SentryCrash and SentryCrashIntegration installed and registered on the current hub of the SDK.
8687

0 commit comments

Comments
 (0)