Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: Remove - [SentryOptions initWithDict:didFailWithError:] #2404

Merged
merged 9 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@

This version adds a dependency on Swift.

### Breaking Changes

- Mark `- [SpanProtocol setExtraValue:forKey:]` as deprecated (#2413)

### Features

- Properly demangle Swift class name (#2162)

### Breaking Changes

- Remove `- [SentryOptions initWithDict:didFailWithError:]` (#2404)
- Rename `- [SentrySDK startWithOptionsObject:]` to `- [SentrySDK startWithOptions:]` (#2404)
- Remove `- [SentryOptions sdkInfo]` (#2404)
- Mark `- [SpanProtocol setExtraValue:forKey:]` as deprecated (#2413)

## 7.31.2

### Fixes
Expand Down
4 changes: 0 additions & 4 deletions Sentry.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
03F84D3827DD4191008FE43F /* SentryBacktrace.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 03F84D3127DD4191008FE43F /* SentryBacktrace.cpp */; };
03F9D37C2819A65C00602916 /* SentryProfilerTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 03F9D37B2819A65C00602916 /* SentryProfilerTests.mm */; };
0A1B497328E597DD00D7BFA3 /* TestLogOutput.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A1B497228E597DD00D7BFA3 /* TestLogOutput.swift */; };
0A1C3592287D7107007D01E3 /* SentryMetaTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A1C3591287D7107007D01E3 /* SentryMetaTests.swift */; };
0A2690B72885C2E000E4432D /* TestSentryPermissionsObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AABE2EF2885C2120057ED69 /* TestSentryPermissionsObserver.swift */; };
0A283E79291A67E000EF4126 /* SentryUIDeviceWrapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A283E78291A67E000EF4126 /* SentryUIDeviceWrapperTests.swift */; };
0A2D7BBA29152CBF008727AF /* SentryOutOfMemoryScopeObserverTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A2D7BB929152CBF008727AF /* SentryOutOfMemoryScopeObserverTests.swift */; };
Expand Down Expand Up @@ -789,7 +788,6 @@
03F84D3127DD4191008FE43F /* SentryBacktrace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SentryBacktrace.cpp; path = Sources/Sentry/SentryBacktrace.cpp; sourceTree = SOURCE_ROOT; };
03F9D37B2819A65C00602916 /* SentryProfilerTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentryProfilerTests.mm; sourceTree = "<group>"; };
0A1B497228E597DD00D7BFA3 /* TestLogOutput.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestLogOutput.swift; sourceTree = "<group>"; };
0A1C3591287D7107007D01E3 /* SentryMetaTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryMetaTests.swift; sourceTree = "<group>"; };
0A283E78291A67E000EF4126 /* SentryUIDeviceWrapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryUIDeviceWrapperTests.swift; sourceTree = "<group>"; };
0A2D7BB929152CBF008727AF /* SentryOutOfMemoryScopeObserverTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryOutOfMemoryScopeObserverTests.swift; sourceTree = "<group>"; };
0A2D8D5A289815C0008720F6 /* SentryBaseIntegration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryBaseIntegration.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1971,7 +1969,6 @@
630C01931EC3402C00C52CEF /* SentryKSCrashReportConverterTests.m */,
63B819131EC352A7002FDF4C /* SentryInterfacesTests.m */,
63EED6C22237989300E02400 /* SentryOptionsTest.m */,
0A1C3591287D7107007D01E3 /* SentryMetaTests.swift */,
632331F52404FFA8008D91D6 /* SentryScopeTests.m */,
7B569DFE2590EEF600B653FC /* SentryScope+Equality.h */,
7B569DFF2590EEF600B653FC /* SentryScope+Equality.m */,
Expand Down Expand Up @@ -3737,7 +3734,6 @@
7BBD18992449DE9D00427C76 /* TestRateLimits.swift in Sources */,
8E4A038625F76A7600000D77 /* TypeMapping.swift in Sources */,
7B04A9AB24EA5F8D00E710B1 /* SentryUserTests.swift in Sources */,
0A1C3592287D7107007D01E3 /* SentryMetaTests.swift in Sources */,
7BA61CCF247EB59500C130A8 /* SentryCrashUUIDConversionTests.swift in Sources */,
7BBD188D2448453600427C76 /* SentryHttpDateParserTests.swift in Sources */,
7B72D23A28D074BC0014798A /* TestExtensions.swift in Sources */,
Expand Down
18 changes: 3 additions & 15 deletions Sources/Sentry/Public/SentryOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@

NS_ASSUME_NONNULL_BEGIN

@class SentryDsn, SentrySdkInfo, SentryMeasurementValue, SentryHttpStatusCodeRange;
@class SentryDsn, SentryMeasurementValue, SentryHttpStatusCodeRange;

NS_SWIFT_NAME(Options)
@interface SentryOptions : NSObject

/**
* Init SentryOptions.
* @param options Options dictionary
* @return SentryOptions
*/
- (_Nullable instancetype)initWithDict:(NSDictionary<NSString *, id> *)options
didFailWithError:(NSError *_Nullable *_Nullable)error;
- (_Nullable instancetype)initWithDsn:(NSString *)dsn
didFailWithError:(NSError *_Nullable *_Nullable)error;
philipphofmann marked this conversation as resolved.
Show resolved Hide resolved

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

/**
* Describes the Sentry SDK and its configuration used to capture and transmit an event.
* This is reserved for internal use, and will be removed in a future version of the SDK.
*/
@property (nonatomic, readonly, strong) SentrySdkInfo *sdkInfo DEPRECATED_MSG_ATTRIBUTE(
"This property will be removed in a future version of the SDK");
philipphofmann marked this conversation as resolved.
Show resolved Hide resolved

/**
* The maximum size for each attachment in bytes. Default is 20 MiB / 20 * 1024 * 1024 bytes.
*
Expand Down
10 changes: 3 additions & 7 deletions Sources/Sentry/Public/SentrySDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,10 @@ SENTRY_NO_INIT
@property (class, nonatomic, readonly) BOOL isEnabled;

/**
* Inits and configures Sentry (SentryHub, SentryClient) and sets up all integrations.
*/
+ (void)startWithOptions:(NSDictionary<NSString *, id> *)optionsDict NS_SWIFT_NAME(start(options:));

/**
* Inits and configures Sentry (SentryHub, SentryClient) and sets up all integrations.
* Inits and configures Sentry (SentryHub, SentryClient) and sets up all integrations. Make sure to
* set a valid DSN.
*/
+ (void)startWithOptionsObject:(SentryOptions *)options NS_SWIFT_NAME(start(options:));
+ (void)startWithOptions:(SentryOptions *)options NS_SWIFT_NAME(start(options:));

/**
* Inits and configures Sentry (SentryHub, SentryClient) and sets up all integrations. Make sure to
Expand Down
1 change: 0 additions & 1 deletion Sources/Sentry/SentryClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#import "SentryPermissionsObserver.h"
#import "SentrySDK+Private.h"
#import "SentryScope+Private.h"
#import "SentrySdkInfo.h"
#import "SentryStacktraceBuilder.h"
#import "SentryThreadInspector.h"
#import "SentryTraceContext.h"
Expand Down
244 changes: 6 additions & 238 deletions Sources/Sentry/SentryOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#import "SentryLog.h"
#import "SentryMeta.h"
#import "SentrySDK.h"
#import "SentrySdkInfo.h"

@interface
SentryOptions ()
Expand Down Expand Up @@ -131,14 +130,14 @@ - (instancetype)init
return self;
}

- (_Nullable instancetype)initWithDict:(NSDictionary<NSString *, id> *)options
didFailWithError:(NSError *_Nullable *_Nullable)error
- (_Nullable instancetype)initWithDsn:(NSString *)dsn
didFailWithError:(NSError *_Nullable *_Nullable)error
{
if (self = [self init]) {
if (![self validateOptions:options didFailWithError:error]) {
[SentryLog
logWithMessage:[NSString stringWithFormat:@"Failed to initialize: %@", *error]
andLevel:kSentryLevelError];
self.parsedDsn = [[SentryDsn alloc] initWithString:dsn didFailWithError:error];
self.dsn = dsn;

if (error != nil && *error != nil) {
return nil;
}
}
Expand Down Expand Up @@ -191,237 +190,6 @@ - (void)setDsn:(NSString *)dsn
}
}

/**
* Populates all `SentryOptions` values from `options` dict using fallbacks/defaults if needed.
*/
- (BOOL)validateOptions:(NSDictionary<NSString *, id> *)options
kevinrenskers marked this conversation as resolved.
Show resolved Hide resolved
didFailWithError:(NSError *_Nullable *_Nullable)error
{
NSPredicate *isNSString = [NSPredicate predicateWithBlock:^BOOL(
id object, NSDictionary *bindings) { return [object isKindOfClass:[NSString class]]; }];

[self setBool:options[@"debug"] block:^(BOOL value) { self->_debug = value; }];

if ([options[@"diagnosticLevel"] isKindOfClass:[NSString class]]) {
for (SentryLevel level = 0; level <= kSentryLevelFatal; level++) {
if ([nameForSentryLevel(level) isEqualToString:options[@"diagnosticLevel"]]) {
self.diagnosticLevel = level;
break;
}
}
}

NSString *dsn = @"";
if (nil != options[@"dsn"] && [options[@"dsn"] isKindOfClass:[NSString class]]) {
dsn = options[@"dsn"];
}

self.parsedDsn = [[SentryDsn alloc] initWithString:dsn didFailWithError:error];

if ([options[@"release"] isKindOfClass:[NSString class]]) {
self.releaseName = options[@"release"];
}

if ([options[@"environment"] isKindOfClass:[NSString class]]) {
self.environment = options[@"environment"];
}

if ([options[@"dist"] isKindOfClass:[NSString class]]) {
self.dist = options[@"dist"];
}

[self setBool:options[@"enabled"] block:^(BOOL value) { self->_enabled = value; }];

[self setBool:options[@"enableCrashHandler"]
block:^(BOOL value) { self->_enableCrashHandler = value; }];

if ([options[@"maxBreadcrumbs"] isKindOfClass:[NSNumber class]]) {
self.maxBreadcrumbs = [options[@"maxBreadcrumbs"] unsignedIntValue];
}

[self setBool:options[@"enableNetworkBreadcrumbs"]
block:^(BOOL value) { self->_enableNetworkBreadcrumbs = value; }];

if ([options[@"maxCacheItems"] isKindOfClass:[NSNumber class]]) {
self.maxCacheItems = [options[@"maxCacheItems"] unsignedIntValue];
}

if ([self isBlock:options[@"beforeSend"]]) {
self.beforeSend = options[@"beforeSend"];
}

if ([self isBlock:options[@"beforeBreadcrumb"]]) {
self.beforeBreadcrumb = options[@"beforeBreadcrumb"];
}

if ([self isBlock:options[@"onCrashedLastRun"]]) {
self.onCrashedLastRun = options[@"onCrashedLastRun"];
}

if ([options[@"integrations"] isKindOfClass:[NSArray class]]) {
self.integrations = [options[@"integrations"] filteredArrayUsingPredicate:isNSString];
}

if ([options[@"sampleRate"] isKindOfClass:[NSNumber class]]) {
self.sampleRate = options[@"sampleRate"];
}

[self setBool:options[@"enableAutoSessionTracking"]
block:^(BOOL value) { self->_enableAutoSessionTracking = value; }];

[self setBool:options[@"enableOutOfMemoryTracking"]
block:^(BOOL value) { self->_enableOutOfMemoryTracking = value; }];

if ([options[@"sessionTrackingIntervalMillis"] isKindOfClass:[NSNumber class]]) {
self.sessionTrackingIntervalMillis =
[options[@"sessionTrackingIntervalMillis"] unsignedIntValue];
}

[self setBool:options[@"attachStacktrace"]
block:^(BOOL value) { self->_attachStacktrace = value; }];

[self setBool:options[@"stitchAsyncCode"]
block:^(BOOL value) { self->_stitchAsyncCode = value; }];

if ([options[@"maxAttachmentSize"] isKindOfClass:[NSNumber class]]) {
self.maxAttachmentSize = [options[@"maxAttachmentSize"] unsignedIntValue];
}

[self setBool:options[@"sendDefaultPii"]
block:^(BOOL value) { self->_sendDefaultPii = value; }];

[self setBool:options[@"enableAutoPerformanceTracking"]
block:^(BOOL value) { self->_enableAutoPerformanceTracking = value; }];

[self setBool:options[@"enableCaptureFailedRequests"]
block:^(BOOL value) { self->_enableCaptureFailedRequests = value; }];

#if SENTRY_HAS_UIKIT
[self setBool:options[@"enableUIViewControllerTracking"]
block:^(BOOL value) { self->_enableUIViewControllerTracking = value; }];

[self setBool:options[@"attachScreenshot"]
block:^(BOOL value) { self->_attachScreenshot = value; }];

[self setBool:options[@"attachViewHierarchy"]
block:^(BOOL value) { self->_attachViewHierarchy = value; }];

[self setBool:options[@"enableUserInteractionTracing"]
block:^(BOOL value) { self->_enableUserInteractionTracing = value; }];

if ([options[@"idleTimeout"] isKindOfClass:[NSNumber class]]) {
self.idleTimeout = [options[@"idleTimeout"] doubleValue];
}

[self setBool:options[@"enablePreWarmedAppStartTracking"]
block:^(BOOL value) { self->_enablePreWarmedAppStartTracking = value; }];
#endif

[self setBool:options[@"enableAppHangTracking"]
block:^(BOOL value) { self->_enableAppHangTracking = value; }];

if ([options[@"appHangTimeoutInterval"] isKindOfClass:[NSNumber class]]) {
self.appHangTimeoutInterval = [options[@"appHangTimeoutInterval"] doubleValue];
}

[self setBool:options[@"enableNetworkTracking"]
block:^(BOOL value) { self->_enableNetworkTracking = value; }];

[self setBool:options[@"enableFileIOTracking"]
block:^(BOOL value) { self->_enableFileIOTracking = value; }];

if ([options[@"tracesSampleRate"] isKindOfClass:[NSNumber class]]) {
self.tracesSampleRate = options[@"tracesSampleRate"];
}

if ([self isBlock:options[@"tracesSampler"]]) {
self.tracesSampler = options[@"tracesSampler"];
}

if ([options[@"inAppIncludes"] isKindOfClass:[NSArray class]]) {
NSArray<NSString *> *inAppIncludes =
[options[@"inAppIncludes"] filteredArrayUsingPredicate:isNSString];
_inAppIncludes = [_inAppIncludes arrayByAddingObjectsFromArray:inAppIncludes];
}

if ([options[@"inAppExcludes"] isKindOfClass:[NSArray class]]) {
_inAppExcludes = [options[@"inAppExcludes"] filteredArrayUsingPredicate:isNSString];
}

if ([options[@"urlSessionDelegate"] conformsToProtocol:@protocol(NSURLSessionDelegate)]) {
self.urlSessionDelegate = options[@"urlSessionDelegate"];
}

[self setBool:options[@"enableSwizzling"]
block:^(BOOL value) { self->_enableSwizzling = value; }];

[self setBool:options[@"enableCoreDataTracking"]
block:^(BOOL value) { self->_enableCoreDataTracking = value; }];

#if SENTRY_TARGET_PROFILING_SUPPORTED
if ([options[@"profilesSampleRate"] isKindOfClass:[NSNumber class]]) {
self.profilesSampleRate = options[@"profilesSampleRate"];
}

if ([self isBlock:options[@"profilesSampler"]]) {
self.profilesSampler = options[@"profilesSampler"];
}

[self setBool:options[@"enableProfiling"]
block:^(BOOL value) { self->_enableProfiling = value; }];
#endif

[self setBool:options[@"sendClientReports"]
block:^(BOOL value) { self->_sendClientReports = value; }];

[self setBool:options[@"enableAutoBreadcrumbTracking"]
block:^(BOOL value) { self->_enableAutoBreadcrumbTracking = value; }];

if ([options[@"tracePropagationTargets"] isKindOfClass:[NSArray class]]) {
self.tracePropagationTargets = options[@"tracePropagationTargets"];
}

if ([options[@"failedRequestStatusCodes"] isKindOfClass:[NSArray class]]) {
self.failedRequestStatusCodes = options[@"failedRequestStatusCodes"];
}

if ([options[@"failedRequestTargets"] isKindOfClass:[NSArray class]]) {
self.failedRequestTargets = options[@"failedRequestTargets"];
}

// SentrySdkInfo already expects a dictionary with {"sdk": {"name": ..., "value": ...}}
// so we're passing the whole options object.
// Note: we should remove this code once the hybrid SDKs move over to the new
// PrivateSentrySDKOnly setter functions.
if ([options[@"sdk"] isKindOfClass:[NSDictionary class]]) {
SentrySdkInfo *defaults = [[SentrySdkInfo alloc] initWithName:SentryMeta.sdkName
andVersion:SentryMeta.versionString];
SentrySdkInfo *sdkInfo = [[SentrySdkInfo alloc] initWithDict:options orDefaults:defaults];
SentryMeta.versionString = sdkInfo.version;
SentryMeta.sdkName = sdkInfo.name;
}

if (nil != error && nil != *error) {
return NO;
} else {
return YES;
}
}

- (SentrySdkInfo *)sdkInfo
{
return [[SentrySdkInfo alloc] initWithName:SentryMeta.sdkName
andVersion:SentryMeta.versionString];
}

- (void)setBool:(id)value block:(void (^)(BOOL))block
{
// Entries in the dictionary can be NSNull. Especially, on React-Native, this can happen.
if (value != nil && ![value isEqual:[NSNull null]]) {
block([value boolValue]);
}
}

- (void)addInAppInclude:(NSString *)inAppInclude
{
_inAppIncludes = [self.inAppIncludes arrayByAddingObject:inAppInclude];
Expand Down
Loading