|
6 | 6 | #import "SentryLog.h" |
7 | 7 | #import "SentryMeta.h" |
8 | 8 | #import "SentrySDK.h" |
9 | | -#import "SentrySdkInfo.h" |
10 | 9 |
|
11 | 10 | @interface |
12 | 11 | SentryOptions () |
@@ -131,14 +130,14 @@ - (instancetype)init |
131 | 130 | return self; |
132 | 131 | } |
133 | 132 |
|
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 |
136 | 135 | { |
137 | 136 | 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) { |
142 | 141 | return nil; |
143 | 142 | } |
144 | 143 | } |
@@ -191,237 +190,6 @@ - (void)setDsn:(NSString *)dsn |
191 | 190 | } |
192 | 191 | } |
193 | 192 |
|
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 | | - |
425 | 193 | - (void)addInAppInclude:(NSString *)inAppInclude |
426 | 194 | { |
427 | 195 | _inAppIncludes = [self.inAppIncludes arrayByAddingObject:inAppInclude]; |
|
0 commit comments