diff --git a/CHANGELOG.md b/CHANGELOG.md index c3eb26ae4d9..28531f5055b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,15 +2,19 @@ ## Unreleased -This version introduces a dependency on Swift, which only impacts you if you don't use Swift. If your project uses Swift already, this change will not affect you. +This version adds a dependency on Swift. ### Features - Properly demangle Swift class name (#2162) -### Breaking changes +### Breaking Changes -- Bump minimum supported OS versions: macOS 10.13, iOS 11, tvOS 11, and watchOS 4 are now supported (#2414) +- Remove `- [SentryOptions initWithDict:didFailWithError:]` (#2404) +- Rename `- [SentrySDK startWithOptionsObject:]` to `- [SentrySDK startWithOptions:]` (#2404) +- Remove `- [SentryOptions sdkInfo]` (#2404) +- Mark `- [SpanProtocol setExtraValue:forKey:]` as deprecated (#2413) +- Bump minimum supported OS versions to macOS 10.13, iOS 11, tvOS 11, and watchOS 4 (#2414) ## 7.31.2 diff --git a/Package.swift b/Package.swift index 4f552855c72..b9e1d96e388 100644 --- a/Package.swift +++ b/Package.swift @@ -3,7 +3,7 @@ import PackageDescription let package = Package( name: "Sentry", - platforms: [.iOS(.v9), .macOS(.v10_10), .tvOS(.v9), .watchOS(.v2)], + platforms: [.iOS(.v11), .macOS(.v10_13), .tvOS(.v11), .watchOS(.v4)], products: [ .library(name: "Sentry", targets: ["Sentry"]), .library(name: "Sentry-Dynamic", type: .dynamic, targets: ["Sentry"]) diff --git a/Sentry.xcodeproj/project.pbxproj b/Sentry.xcodeproj/project.pbxproj index f61802427a3..ebed49bdc3c 100644 --- a/Sentry.xcodeproj/project.pbxproj +++ b/Sentry.xcodeproj/project.pbxproj @@ -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 */; }; @@ -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 = ""; }; 0A1B497228E597DD00D7BFA3 /* TestLogOutput.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestLogOutput.swift; sourceTree = ""; }; - 0A1C3591287D7107007D01E3 /* SentryMetaTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryMetaTests.swift; sourceTree = ""; }; 0A283E78291A67E000EF4126 /* SentryUIDeviceWrapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryUIDeviceWrapperTests.swift; sourceTree = ""; }; 0A2D7BB929152CBF008727AF /* SentryOutOfMemoryScopeObserverTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryOutOfMemoryScopeObserverTests.swift; sourceTree = ""; }; 0A2D8D5A289815C0008720F6 /* SentryBaseIntegration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryBaseIntegration.m; sourceTree = ""; }; @@ -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 */, @@ -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 */, diff --git a/SentryPrivate.podspec b/SentryPrivate.podspec index 022795d122b..e3acc64c32d 100644 --- a/SentryPrivate.podspec +++ b/SentryPrivate.podspec @@ -14,10 +14,10 @@ Pod::Spec.new do |s| Common APIs for internal Sentry usage. DESC - s.ios.deployment_target = "9.0" - s.osx.deployment_target = "10.10" - s.tvos.deployment_target = "9.0" - s.watchos.deployment_target = "2.0" + s.ios.deployment_target = "11.0" + s.osx.deployment_target = "10.13" + s.tvos.deployment_target = "11.0" + s.watchos.deployment_target = "4.0" s.module_name = "SentryPrivate" s.frameworks = 'Foundation' diff --git a/Sources/Sentry/Public/SentryOptions.h b/Sources/Sentry/Public/SentryOptions.h index d8ecbf86bc6..797b546ae93 100644 --- a/Sources/Sentry/Public/SentryOptions.h +++ b/Sources/Sentry/Public/SentryOptions.h @@ -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 *)options - didFailWithError:(NSError *_Nullable *_Nullable)error; +- (_Nullable instancetype)initWithDsn:(NSString *)dsn + didFailWithError:(NSError *_Nullable *_Nullable)error; /** * 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) */ @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"); - /** * The maximum size for each attachment in bytes. Default is 20 MiB / 20 * 1024 * 1024 bytes. * diff --git a/Sources/Sentry/Public/SentrySDK.h b/Sources/Sentry/Public/SentrySDK.h index 88846ff4d3b..20f2caaa319 100644 --- a/Sources/Sentry/Public/SentrySDK.h +++ b/Sources/Sentry/Public/SentrySDK.h @@ -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 *)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 diff --git a/Sources/Sentry/Public/SentrySpanProtocol.h b/Sources/Sentry/Public/SentrySpanProtocol.h index ce206fe8778..45c4906ba93 100644 --- a/Sources/Sentry/Public/SentrySpanProtocol.h +++ b/Sources/Sentry/Public/SentrySpanProtocol.h @@ -68,9 +68,10 @@ NS_SWIFT_NAME(Span) /** * Use setDataValue instead. This method calls setDataValue, was added by mistake, and will be - * deprecated in a future version. + * removed in a future version. */ -- (void)setExtraValue:(nullable id)value forKey:(NSString *)key NS_SWIFT_NAME(setExtra(value:key:)); +- (void)setExtraValue:(nullable id)value + forKey:(NSString *)key DEPRECATED_ATTRIBUTE NS_SWIFT_NAME(setExtra(value:key:)); /** * Removes a data value. diff --git a/Sources/Sentry/SentryClient.m b/Sources/Sentry/SentryClient.m index d2ad4e79ff5..2907110eee8 100644 --- a/Sources/Sentry/SentryClient.m +++ b/Sources/Sentry/SentryClient.m @@ -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" diff --git a/Sources/Sentry/SentryNoOpSpan.h b/Sources/Sentry/SentryNoOpSpan.h index 6056730a2ed..8bbaefd830a 100644 --- a/Sources/Sentry/SentryNoOpSpan.h +++ b/Sources/Sentry/SentryNoOpSpan.h @@ -17,6 +17,7 @@ SENTRY_NO_INIT @property (nullable, readonly) NSDictionary *data; @property (readonly) NSDictionary *tags; +- (void)setExtraValue:(nullable id)value forKey:(NSString *)key DEPRECATED_ATTRIBUTE; @end NS_ASSUME_NONNULL_END diff --git a/Sources/Sentry/SentryOptions.m b/Sources/Sentry/SentryOptions.m index d8fc016fadf..667d05a35bd 100644 --- a/Sources/Sentry/SentryOptions.m +++ b/Sources/Sentry/SentryOptions.m @@ -6,7 +6,6 @@ #import "SentryLog.h" #import "SentryMeta.h" #import "SentrySDK.h" -#import "SentrySdkInfo.h" @interface SentryOptions () @@ -131,14 +130,14 @@ - (instancetype)init return self; } -- (_Nullable instancetype)initWithDict:(NSDictionary *)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; } } @@ -191,237 +190,6 @@ - (void)setDsn:(NSString *)dsn } } -/** - * Populates all `SentryOptions` values from `options` dict using fallbacks/defaults if needed. - */ -- (BOOL)validateOptions:(NSDictionary *)options - 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 *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]; diff --git a/Sources/Sentry/SentrySDK.m b/Sources/Sentry/SentrySDK.m index df3fc7af53b..2d036a9bb16 100644 --- a/Sources/Sentry/SentrySDK.m +++ b/Sources/Sentry/SentrySDK.m @@ -128,20 +128,7 @@ + (void)setStartInvocations:(NSUInteger)value startInvocations = value; } -+ (void)startWithOptions:(NSDictionary *)optionsDict -{ - NSError *error = nil; - SentryOptions *options = [[SentryOptions alloc] initWithDict:optionsDict - didFailWithError:&error]; - if (nil != error) { - SENTRY_LOG_ERROR(@"Error while initializing the SDK"); - SENTRY_LOG_ERROR(@"%@", error); - } else { - [SentrySDK startWithOptionsObject:options]; - } -} - -+ (void)startWithOptionsObject:(SentryOptions *)options ++ (void)startWithOptions:(SentryOptions *)options { startInvocations++; @@ -162,7 +149,7 @@ + (void)startWithConfigureOptions:(void (^)(SentryOptions *options))configureOpt { SentryOptions *options = [[SentryOptions alloc] init]; configureOptions(options); - [SentrySDK startWithOptionsObject:options]; + [SentrySDK startWithOptions:options]; } + (void)captureCrashEvent:(SentryEvent *)event diff --git a/Sources/Sentry/SentryUIEventTracker.m b/Sources/Sentry/SentryUIEventTracker.m index efeb27443f8..1d041d3dd39 100644 --- a/Sources/Sentry/SentryUIEventTracker.m +++ b/Sources/Sentry/SentryUIEventTracker.m @@ -169,13 +169,13 @@ - (NSString *)getOperation:(id)sender */ - (NSString *)getTransactionName:(NSString *)action target:(NSString *)target { - NSArray *componens = [action componentsSeparatedByString:@":"]; - if (componens.count > 2) { + NSArray *components = [action componentsSeparatedByString:@":"]; + if (components.count > 2) { NSMutableString *result = - [[NSMutableString alloc] initWithFormat:@"%@.%@(", target, componens.firstObject]; + [[NSMutableString alloc] initWithFormat:@"%@.%@(", target, components.firstObject]; - for (int i = 1; i < (componens.count - 1); i++) { - [result appendFormat:@"%@:", componens[i]]; + for (int i = 1; i < (components.count - 1); i++) { + [result appendFormat:@"%@:", components[i]]; } [result appendFormat:@")"]; @@ -183,7 +183,7 @@ - (NSString *)getTransactionName:(NSString *)action target:(NSString *)target return result; } - return [NSString stringWithFormat:@"%@.%@", target, componens.firstObject]; + return [NSString stringWithFormat:@"%@.%@", target, components.firstObject]; } NS_ASSUME_NONNULL_END diff --git a/Sources/Sentry/include/SentrySpan.h b/Sources/Sentry/include/SentrySpan.h index c0c9e3ae170..7b7fa04a290 100644 --- a/Sources/Sentry/include/SentrySpan.h +++ b/Sources/Sentry/include/SentrySpan.h @@ -45,6 +45,7 @@ SENTRY_NO_INIT */ - (instancetype)initWithTracer:(SentryTracer *)transaction context:(SentrySpanContext *)context; +- (void)setExtraValue:(nullable id)value forKey:(NSString *)key DEPRECATED_ATTRIBUTE; @end NS_ASSUME_NONNULL_END diff --git a/Sources/Sentry/include/SentryTracer.h b/Sources/Sentry/include/SentryTracer.h index cc113df4a5c..054ea890e20 100644 --- a/Sources/Sentry/include/SentryTracer.h +++ b/Sources/Sentry/include/SentryTracer.h @@ -143,6 +143,8 @@ static NSTimeInterval const SentryTracerDefaultTimeout = 3.0; */ - (void)spanFinished:(id)finishedSpan; +- (void)setExtraValue:(nullable id)value forKey:(NSString *)key DEPRECATED_ATTRIBUTE; + /** * Get the tracer from a span. */ diff --git a/Tests/SentryTests/ClearTestState.swift b/Tests/SentryTests/ClearTestState.swift index 02db84e1294..ac2f1958b51 100644 --- a/Tests/SentryTests/ClearTestState.swift +++ b/Tests/SentryTests/ClearTestState.swift @@ -25,4 +25,6 @@ func clearTestState() { SentryDependencyContainer.reset() Dynamic(SentryGlobalEventProcessor.shared()).removeAllProcessors() SentrySwizzleWrapper.sharedInstance.removeAllCallbacks() + + SentryNSDataTracker.sharedInstance.disable() } diff --git a/Tests/SentryTests/Integrations/Performance/SentrySubClassFinderTests.swift b/Tests/SentryTests/Integrations/Performance/SentrySubClassFinderTests.swift index c50f3128c18..bc4340ba311 100644 --- a/Tests/SentryTests/Integrations/Performance/SentrySubClassFinderTests.swift +++ b/Tests/SentryTests/Integrations/Performance/SentrySubClassFinderTests.swift @@ -57,7 +57,7 @@ class SentrySubClassFinderTests: XCTestCase { assertActOnSubclassesOfViewController(expected: [], imageName: "OtherImage") } - func testGettingSublcasses_DoesNotCallInitializer() { + func testGettingSubclasses_DoesNotCallInitializer() { let sut = SentrySubClassFinder(dispatchQueue: TestSentryDispatchQueueWrapper(), objcRuntimeWrapper: fixture.runtimeWrapper) var actual: [AnyClass] = [] diff --git a/Tests/SentryTests/Integrations/SentryCrash/SentryCrashIntegrationTests.swift b/Tests/SentryTests/Integrations/SentryCrash/SentryCrashIntegrationTests.swift index 1e531017325..ba1cd5a62df 100644 --- a/Tests/SentryTests/Integrations/SentryCrash/SentryCrashIntegrationTests.swift +++ b/Tests/SentryTests/Integrations/SentryCrash/SentryCrashIntegrationTests.swift @@ -77,10 +77,11 @@ class SentryCrashIntegrationTests: NotificationCenterTestCase { let releaseName = "1.0.0" let dist = "14G60" // The start of the SDK installs all integrations - SentrySDK.start(options: ["dsn": SentryCrashIntegrationTests.dsnAsString, - "release": releaseName, - "dist": dist] - ) + SentrySDK.start { options in + options.dsn = SentryCrashIntegrationTests.dsnAsString + options.releaseName = releaseName + options.dist = dist + } // To test this properly we need SentryCrash and SentryCrashIntegration installed and registered on the current hub of the SDK. diff --git a/Tests/SentryTests/Networking/SentryDsnTests.m b/Tests/SentryTests/Networking/SentryDsnTests.m index bd6f7b4d4e5..0d6fed5e14b 100644 --- a/Tests/SentryTests/Networking/SentryDsnTests.m +++ b/Tests/SentryTests/Networking/SentryDsnTests.m @@ -14,8 +14,8 @@ @implementation SentryDsnTests - (void)testMissingUsernamePassword { NSError *error = nil; - SentryOptions *options = [[SentryOptions alloc] initWithDict:@{ @"dsn" : @"https://sentry.io" } - didFailWithError:&error]; + SentryOptions *options = [[SentryOptions alloc] initWithDsn:@"https://sentry.io" + didFailWithError:&error]; XCTAssertEqual(kSentryErrorInvalidDsnError, error.code); XCTAssertNil(options); } @@ -62,8 +62,8 @@ - (void)testDsnHeaderUsername - (void)testMissingScheme { NSError *error = nil; - SentryOptions *options = [[SentryOptions alloc] initWithDict:@{ @"dsn" : @"sentry.io" } - didFailWithError:&error]; + SentryOptions *options = [[SentryOptions alloc] initWithDsn:@"sentry.io" + didFailWithError:&error]; XCTAssertEqual(kSentryErrorInvalidDsnError, error.code); XCTAssertNil(options); } @@ -71,8 +71,8 @@ - (void)testMissingScheme - (void)testMissingHost { NSError *error = nil; - SentryOptions *options = [[SentryOptions alloc] initWithDict:@{ @"dsn" : @"http:///1" } - didFailWithError:&error]; + SentryOptions *options = [[SentryOptions alloc] initWithDsn:@"http:///1" + didFailWithError:&error]; XCTAssertEqual(kSentryErrorInvalidDsnError, error.code); XCTAssertNil(options); } @@ -80,8 +80,8 @@ - (void)testMissingHost - (void)testUnsupportedProtocol { NSError *error = nil; - SentryOptions *options = [[SentryOptions alloc] initWithDict:@{ @"dsn" : @"ftp://sentry.io/1" } - didFailWithError:&error]; + SentryOptions *options = [[SentryOptions alloc] initWithDsn:@"ftp://sentry.io/1" + didFailWithError:&error]; XCTAssertEqual(kSentryErrorInvalidDsnError, error.code); XCTAssertNil(options); } diff --git a/Tests/SentryTests/Networking/SentryTransportInitializerTests.swift b/Tests/SentryTests/Networking/SentryTransportInitializerTests.swift index 6651dcc3e64..d99e307382a 100644 --- a/Tests/SentryTests/Networking/SentryTransportInitializerTests.swift +++ b/Tests/SentryTests/Networking/SentryTransportInitializerTests.swift @@ -20,7 +20,7 @@ class SentryTransportInitializerTests: XCTestCase { } func testDefault() throws { - let options = try Options(dict: ["dsn": SentryTransportInitializerTests.dsnAsString]) + let options = try Options(dsn: SentryTransportInitializerTests.dsnAsString) let result = TransportInitializer.initTransport(options, sentryFileManager: fileManager) diff --git a/Tests/SentryTests/Performance/SentryTracerTests.swift b/Tests/SentryTests/Performance/SentryTracerTests.swift index 5ca92d775b7..69a91a46f41 100644 --- a/Tests/SentryTests/Performance/SentryTracerTests.swift +++ b/Tests/SentryTests/Performance/SentryTracerTests.swift @@ -745,13 +745,13 @@ class SentryTracerTests: XCTestCase { XCTAssertEqual(transactions, fixture.hub.capturedEventsWithScopes.count) - let transactionsWithAppStartMeasrurement = fixture.hub.capturedEventsWithScopes.filter { pair in + let transactionsWithAppStartMeasurement = fixture.hub.capturedEventsWithScopes.filter { pair in let serializedTransaction = pair.event.serialize() let measurements = serializedTransaction["measurements"] as? [String: [String: Int]] return measurements == ["app_start_warm": ["value": 500]] } - XCTAssertEqual(1, transactionsWithAppStartMeasrurement.count) + XCTAssertEqual(1, transactionsWithAppStartMeasurement.count) } #if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst) @@ -804,6 +804,7 @@ class SentryTracerTests: XCTestCase { } #endif + @available(*, deprecated) func testSetExtra_ForwardsToSetData() { let sut = fixture.getSut() sut.setExtra(value: 0, key: "key") diff --git a/Tests/SentryTests/SentryClientTests.swift b/Tests/SentryTests/SentryClientTests.swift index b2dd829ad26..b8ff53a6e60 100644 --- a/Tests/SentryTests/SentryClientTests.swift +++ b/Tests/SentryTests/SentryClientTests.swift @@ -60,9 +60,7 @@ class SentryClientTest: XCTestCase { func getSut(configureOptions: (Options) -> Void = { _ in }) -> Client { var client: Client! do { - let options = try Options(dict: [ - "dsn": SentryClientTest.dsn - ]) + let options = try Options(dsn: SentryClientTest.dsn) configureOptions(options) client = Client( diff --git a/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift b/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift index 0b213b277d1..211c841f90e 100644 --- a/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift +++ b/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift @@ -52,8 +52,8 @@ class SentryCrashReportSinkTests: SentrySDKIntegrationTestsBase { filterReportWithAttachment() let client = getTestClient() - XCTAssertEqual(1, client.flushInvoctions.count) - XCTAssertEqual(5, client.flushInvoctions.first) + XCTAssertEqual(1, client.flushInvocations.count) + XCTAssertEqual(5, client.flushInvocations.first) XCTAssertEqual(0, fixture.dispatchQueue.dispatchAsyncCalled) } @@ -63,8 +63,8 @@ class SentryCrashReportSinkTests: SentrySDKIntegrationTestsBase { filterReportWithAttachment() let client = getTestClient() - XCTAssertEqual(1, client.flushInvoctions.count) - XCTAssertEqual(5, client.flushInvoctions.first) + XCTAssertEqual(1, client.flushInvocations.count) + XCTAssertEqual(5, client.flushInvocations.first) XCTAssertEqual(0, fixture.dispatchQueue.dispatchAsyncCalled) } @@ -74,7 +74,7 @@ class SentryCrashReportSinkTests: SentrySDKIntegrationTestsBase { filterReportWithAttachment() let client = getTestClient() - XCTAssertEqual(0, client.flushInvoctions.count) + XCTAssertEqual(0, client.flushInvocations.count) XCTAssertEqual(1, fixture.dispatchQueue.dispatchAsyncCalled) } @@ -84,7 +84,7 @@ class SentryCrashReportSinkTests: SentrySDKIntegrationTestsBase { filterReportWithAttachment() let client = getTestClient() - XCTAssertEqual(0, client.flushInvoctions.count) + XCTAssertEqual(0, client.flushInvocations.count) XCTAssertEqual(1, fixture.dispatchQueue.dispatchAsyncCalled) } @@ -94,7 +94,7 @@ class SentryCrashReportSinkTests: SentrySDKIntegrationTestsBase { filterReportWithAttachment() let client = getTestClient() - XCTAssertEqual(0, client.flushInvoctions.count) + XCTAssertEqual(0, client.flushInvocations.count) XCTAssertEqual(1, fixture.dispatchQueue.dispatchAsyncCalled) } diff --git a/Tests/SentryTests/SentryCrash/SentryThreadInspectorTests.swift b/Tests/SentryTests/SentryCrash/SentryThreadInspectorTests.swift index 7594ee56e40..416a11ecf79 100644 --- a/Tests/SentryTests/SentryCrash/SentryThreadInspectorTests.swift +++ b/Tests/SentryTests/SentryCrash/SentryThreadInspectorTests.swift @@ -6,10 +6,10 @@ import XCTest var testMachineContextWrapper = TestMachineContextWrapper() var stacktraceBuilder = TestSentryStacktraceBuilder(crashStackEntryMapper: SentryCrashStackEntryMapper(inAppLogic: SentryInAppLogic(inAppIncludes: [], inAppExcludes: []))) - func getSut(testWithRealMachineConextWrapper: Bool = false) -> SentryThreadInspector { + func getSut(testWithRealMachineContextWrapper: Bool = false) -> SentryThreadInspector { - let machineContextWrapper = testWithRealMachineConextWrapper ? SentryCrashDefaultMachineContextWrapper() : testMachineContextWrapper as SentryCrashMachineContextWrapper - let stacktraceBuilder = testWithRealMachineConextWrapper ? SentryStacktraceBuilder(crashStackEntryMapper: SentryCrashStackEntryMapper(inAppLogic: SentryInAppLogic(inAppIncludes: [], inAppExcludes: []))) : self.stacktraceBuilder + let machineContextWrapper = testWithRealMachineContextWrapper ? SentryCrashDefaultMachineContextWrapper() : testMachineContextWrapper as SentryCrashMachineContextWrapper + let stacktraceBuilder = testWithRealMachineContextWrapper ? SentryStacktraceBuilder(crashStackEntryMapper: SentryCrashStackEntryMapper(inAppLogic: SentryInAppLogic(inAppIncludes: [], inAppExcludes: []))) : self.stacktraceBuilder return SentryThreadInspector( stacktraceBuilder: stacktraceBuilder, @@ -31,7 +31,7 @@ import XCTest } func testStacktraceHasFrames() { - let actual = fixture.getSut(testWithRealMachineConextWrapper: true).getCurrentThreads() + let actual = fixture.getSut(testWithRealMachineContextWrapper: true).getCurrentThreads() let stacktrace = actual[0].stacktrace // The stacktrace has usually more than 40 frames. Feel free to change the number if the tests are failing @@ -54,7 +54,7 @@ import XCTest let expect = expectation(description: "Read every thread") expect.expectedFulfillmentCount = 10 - let sut = self.fixture.getSut(testWithRealMachineConextWrapper: true) + let sut = self.fixture.getSut(testWithRealMachineContextWrapper: true) for _ in 0..<10 { queue.async { @@ -81,7 +81,7 @@ import XCTest } func testOnlyCurrentThreadHasStacktrace() { - let actual = fixture.getSut(testWithRealMachineConextWrapper: true).getCurrentThreads() + let actual = fixture.getSut(testWithRealMachineContextWrapper: true).getCurrentThreads() XCTAssertEqual(true, actual[0].current) XCTAssertNotNil(actual[0].stacktrace) @@ -90,7 +90,7 @@ import XCTest } func testOnlyFirstThreadIsCurrent() { - let actual = fixture.getSut(testWithRealMachineConextWrapper: true).getCurrentThreads() + let actual = fixture.getSut(testWithRealMachineContextWrapper: true).getCurrentThreads() let thread0 = actual[0] XCTAssertEqual(true, thread0.current) @@ -102,7 +102,7 @@ import XCTest } func testStacktraceOnlyForCurrentThread() { - let actual = fixture.getSut(testWithRealMachineConextWrapper: true).getCurrentThreads() + let actual = fixture.getSut(testWithRealMachineContextWrapper: true).getCurrentThreads() XCTAssertNotNil(actual[0].stacktrace) @@ -114,7 +114,7 @@ import XCTest } func testCrashedIsFalseForAllThreads() { - let actual = fixture.getSut(testWithRealMachineConextWrapper: true).getCurrentThreads() + let actual = fixture.getSut(testWithRealMachineContextWrapper: true).getCurrentThreads() let threadCount = actual.count for i in 0.. @@ -14,22 +13,8 @@ @implementation SentryOptionsTest - (void)testEmptyDsn { NSError *error = nil; - SentryOptions *options = [[SentryOptions alloc] initWithDict:@{} didFailWithError:&error]; + SentryOptions *options = [[SentryOptions alloc] initWithDsn:@"" didFailWithError:&error]; - [self assertDsnNil:options andError:error]; -} - -- (void)testInvalidDsnBoolean -{ - NSError *error = nil; - SentryOptions *options = [[SentryOptions alloc] initWithDict:@{ @"dsn" : @YES } - didFailWithError:&error]; - - [self assertDsnNil:options andError:error]; -} - -- (void)assertDsnNil:(SentryOptions *)options andError:(NSError *)error -{ XCTAssertNil(options.parsedDsn); XCTAssertEqual(NO, options.debug); XCTAssertEqual(kSentryErrorInvalidDsnError, error.code); @@ -38,353 +23,12 @@ - (void)assertDsnNil:(SentryOptions *)options andError:(NSError *)error - (void)testInvalidDsn { NSError *error = nil; - SentryOptions *options = [[SentryOptions alloc] initWithDict:@{ @"dsn" : @"https://sentry.io" } - didFailWithError:&error]; + SentryOptions *options = [[SentryOptions alloc] initWithDsn:@"https://sentry.io" + didFailWithError:&error]; XCTAssertEqual(kSentryErrorInvalidDsnError, error.code); XCTAssertNil(options); } -- (void)testRelease -{ - SentryOptions *options = [self getValidOptions:@{ @"release" : @"abc" }]; - XCTAssertEqualObjects(options.releaseName, @"abc"); -} - -- (void)testSetEmptyRelease -{ - SentryOptions *options = [self getValidOptions:@{ @"release" : @"" }]; - XCTAssertEqualObjects(options.releaseName, @""); -} - -- (void)testSetReleaseToNonString -{ - SentryOptions *options = [self getValidOptions:@{ @"release" : @2 }]; - XCTAssertEqualObjects(options.releaseName, [self buildDefaultReleaseName]); -} - -- (void)testNoReleaseSetUsesDefault -{ - SentryOptions *options = [self getValidOptions:@{}]; - XCTAssertEqualObjects(options.releaseName, [self buildDefaultReleaseName]); -} - -- (NSString *)buildDefaultReleaseName -{ - NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary]; - return [NSString stringWithFormat:@"%@@%@+%@", infoDict[@"CFBundleIdentifier"], - infoDict[@"CFBundleShortVersionString"], infoDict[@"CFBundleVersion"]]; -} - -- (void)testEnvironment -{ - SentryOptions *options = [self getValidOptions:@{}]; - XCTAssertNil(options.environment); - - options = [self getValidOptions:@{ @"environment" : @"xxx" }]; - XCTAssertEqualObjects(options.environment, @"xxx"); -} - -- (void)testDist -{ - SentryOptions *options = [self getValidOptions:@{}]; - XCTAssertNil(options.dist); - - options = [self getValidOptions:@{ @"dist" : @"hhh" }]; - XCTAssertEqualObjects(options.dist, @"hhh"); -} - -- (void)testValidDebug -{ - [self testDebugWith:@YES expected:YES]; - [self testDebugWith:@"YES" expected:YES]; - [self testDebugWith:@(YES) expected:YES]; -} - -- (void)testInvalidDebug -{ - [self testDebugWith:@"Invalid" expected:NO]; - [self testDebugWith:@NO expected:NO]; - [self testDebugWith:@(NO) expected:NO]; -} - -- (void)testDebugWith:(NSObject *)debugValue expected:(BOOL)expectedDebugValue -{ - NSError *error = nil; - SentryOptions *options = [[SentryOptions alloc] initWithDict:@{ - @"dsn" : @"https://username:password@sentry.io/1", - @"debug" : debugValue - } - didFailWithError:&error]; - - XCTAssertNil(error); - XCTAssertEqual(expectedDebugValue, options.debug); -} - -- (void)testValidDiagnosticLevel -{ - [self testDiagnosticlevelWith:@"none" expected:kSentryLevelNone]; - [self testDiagnosticlevelWith:@"debug" expected:kSentryLevelDebug]; - [self testDiagnosticlevelWith:@"info" expected:kSentryLevelInfo]; - [self testDiagnosticlevelWith:@"warning" expected:kSentryLevelWarning]; - [self testDiagnosticlevelWith:@"error" expected:kSentryLevelError]; - [self testDiagnosticlevelWith:@"fatal" expected:kSentryLevelFatal]; -} - -- (void)testInvalidDiagnosticLevel -{ - [self testDiagnosticlevelWith:@"fatala" expected:kSentryLevelDebug]; - [self testDiagnosticlevelWith:@(YES) expected:kSentryLevelDebug]; -} - -- (void)testDiagnosticlevelWith:(NSObject *)level expected:(SentryLevel)expected -{ - SentryOptions *options = [self getValidOptions:@{ @"diagnosticLevel" : level }]; - - XCTAssertEqual(expected, options.diagnosticLevel); -} - -- (void)testValidEnabled -{ - [self testEnabledWith:@YES expected:YES]; - [self testEnabledWith:@"YES" expected:YES]; - [self testEnabledWith:@(YES) expected:YES]; -} - -- (void)testInvalidEnabled -{ - [self testEnabledWith:@"Invalid" expected:NO]; - [self testEnabledWith:@NO expected:NO]; - [self testEnabledWith:@(NO) expected:NO]; -} - -- (void)testEnabledWith:(NSObject *)enabledValue expected:(BOOL)expectedValue -{ - SentryOptions *options = [self getValidOptions:@{ @"enabled" : enabledValue }]; - - XCTAssertEqual(expectedValue, options.enabled); -} - -- (void)testMaxBreadcrumbs -{ - NSNumber *maxBreadcrumbs = @20; - - SentryOptions *options = [self getValidOptions:@{ @"maxBreadcrumbs" : maxBreadcrumbs }]; - - XCTAssertEqual([maxBreadcrumbs unsignedIntValue], options.maxBreadcrumbs); -} - -- (void)testEnableNetworkBreadcrumbs -{ - [self testBooleanField:@"enableNetworkBreadcrumbs"]; -} - -- (void)testEnableAutoBreadcrumbTracking -{ - [self testBooleanField:@"enableAutoBreadcrumbTracking"]; -} - -- (void)testEnableCoreDataTracking -{ - [self testBooleanField:@"enableCoreDataTracking" defaultValue:NO]; -} - -- (void)testSendClientReports -{ - [self testBooleanField:@"sendClientReports" defaultValue:YES]; -} - -- (void)testDefaultMaxBreadcrumbs -{ - SentryOptions *options = [self getValidOptions:@{}]; - - XCTAssertEqual([@100 unsignedIntValue], options.maxBreadcrumbs); -} - -- (void)testMaxBreadcrumbsGarbage -{ - SentryOptions *options = [self getValidOptions:@{ @"maxBreadcrumbs" : self }]; - - XCTAssertEqual(100, options.maxBreadcrumbs); -} - -- (void)testMaxCacheItems -{ - NSNumber *maxCacheItems = @20; - - SentryOptions *options = [self getValidOptions:@{ @"maxCacheItems" : maxCacheItems }]; - - XCTAssertEqual([maxCacheItems unsignedIntValue], options.maxCacheItems); -} - -- (void)testMaxCacheItemsGarbage -{ - SentryOptions *options = [self getValidOptions:@{ @"maxCacheItems" : self }]; - - XCTAssertEqual(30, options.maxCacheItems); -} - -- (void)testDefaultMaxCacheItems -{ - SentryOptions *options = [self getValidOptions:@{}]; - - XCTAssertEqual([@30 unsignedIntValue], options.maxCacheItems); -} - -- (void)testBeforeSend -{ - SentryBeforeSendEventCallback callback = ^(SentryEvent *event) { return event; }; - SentryOptions *options = [self getValidOptions:@{ @"beforeSend" : callback }]; - - XCTAssertEqual(callback, options.beforeSend); -} - -- (void)testDefaultBeforeSend -{ - SentryOptions *options = [self getValidOptions:@{}]; - - XCTAssertNil(options.beforeSend); -} - -- (void)testGarbageBeforeSend_ReturnsNil -{ - SentryOptions *options = [self getValidOptions:@{ @"beforeSend" : @"fault" }]; - - XCTAssertNil(options.beforeSend); -} - -- (void)testNSNullBeforeSend_ReturnsNil -{ - SentryOptions *options = [self getValidOptions:@{ @"beforeSend" : [NSNull null] }]; - - XCTAssertFalse([options.beforeSend isEqual:[NSNull null]]); -} - -- (void)testBeforeBreadcrumb -{ - SentryBeforeBreadcrumbCallback callback - = ^(SentryBreadcrumb *breadcrumb) { return breadcrumb; }; - SentryOptions *options = [self getValidOptions:@{ @"beforeBreadcrumb" : callback }]; - - XCTAssertEqual(callback, options.beforeBreadcrumb); -} - -- (void)testDefaultBeforeBreadcrumb -{ - SentryOptions *options = [self getValidOptions:@{}]; - - XCTAssertNil(options.beforeBreadcrumb); -} - -- (void)testTracePropagationTargets -{ - SentryOptions *options = - [self getValidOptions:@{ @"tracePropagationTargets" : @[ @"localhost" ] }]; - - XCTAssertEqual(options.tracePropagationTargets.count, 1); - XCTAssertEqual(options.tracePropagationTargets[0], @"localhost"); -} - -- (void)testTracePropagationTargetsInvalidInstanceDoesntCrash -{ - SentryOptions *options = [self getValidOptions:@{ @"tracePropagationTargets" : @[ @YES ] }]; - - XCTAssertEqual(options.tracePropagationTargets.count, 1); - XCTAssertEqual(options.tracePropagationTargets[0], @YES); -} - -- (void)testFailedRequestTargets -{ - SentryOptions *options = - [self getValidOptions:@{ @"failedRequestTargets" : @[ @"localhost" ] }]; - - XCTAssertEqual(options.failedRequestTargets.count, 1); - XCTAssertEqual(options.failedRequestTargets[0], @"localhost"); -} - -- (void)testFailedRequestTargetsInvalidInstanceDoesntCrash -{ - SentryOptions *options = [self getValidOptions:@{ @"failedRequestTargets" : @[ @YES ] }]; - - XCTAssertEqual(options.failedRequestTargets.count, 1); - XCTAssertEqual(options.failedRequestTargets[0], @YES); -} - -- (void)testEnableCaptureFailedRequests -{ - [self testBooleanField:@"enableCaptureFailedRequests" defaultValue:NO]; -} - -- (void)testFailedRequestStatusCodes -{ - SentryHttpStatusCodeRange *httpStatusCodeRange = - [[SentryHttpStatusCodeRange alloc] initWithMin:400 max:599]; - SentryOptions *options = - [self getValidOptions:@{ @"failedRequestStatusCodes" : @[ httpStatusCodeRange ] }]; - - XCTAssertEqual(options.failedRequestStatusCodes.count, 1); - XCTAssertEqual(options.failedRequestStatusCodes[0].min, 400); - XCTAssertEqual(options.failedRequestStatusCodes[0].max, 599); -} - -- (void)testGarbageBeforeBreadcrumb_ReturnsNil -{ - SentryOptions *options = [self getValidOptions:@{ @"beforeBreadcrumb" : @"fault" }]; - - XCTAssertEqual(nil, options.beforeBreadcrumb); -} - -- (void)testOnCrashedLastRun -{ - __block BOOL onCrashedLastRunCalled = NO; - SentryOnCrashedLastRunCallback callback = ^(SentryEvent *event) { - onCrashedLastRunCalled = YES; - XCTAssertNotNil(event); - }; - SentryOptions *options = [self getValidOptions:@{ @"onCrashedLastRun" : callback }]; - - options.onCrashedLastRun([[SentryEvent alloc] init]); - - XCTAssertEqual(callback, options.onCrashedLastRun); - XCTAssertTrue(onCrashedLastRunCalled); -} - -- (void)testDefaultOnCrashedLastRun -{ - SentryOptions *options = [self getValidOptions:@{}]; - - XCTAssertNil(options.onCrashedLastRun); -} - -- (void)testGarbageOnCrashedLastRun_ReturnsNil -{ - SentryOptions *options = [self getValidOptions:@{ @"onCrashedLastRun" : @"fault" }]; - - XCTAssertNil(options.onCrashedLastRun); -} - -- (void)testIntegrations -{ - NSArray *integrations = @[ @"integration1", @"integration2" ]; - SentryOptions *options = [self getValidOptions:@{ @"integrations" : integrations }]; - - [self assertArrayEquals:integrations actual:options.integrations]; -} - -- (void)testDefaultIntegrations -{ - SentryOptions *options = [self getValidOptions:@{}]; - - XCTAssertTrue([[SentryOptions defaultIntegrations] isEqualToArray:options.integrations], - @"Default integrations are not set correctly"); -} - -- (void)testSampleRateWithDict -{ - NSNumber *sampleRate = @0.1; - SentryOptions *options = [self getValidOptions:@{ @"sampleRate" : sampleRate }]; - XCTAssertEqual(sampleRate, options.sampleRate); -} - - (void)testSampleRate_SetToNil { SentryOptions *options = [[SentryOptions alloc] init]; @@ -424,54 +68,6 @@ - (void)testSampleRateUpperBound XCTAssertEqual(@1, options.sampleRate); } -- (void)testSampleRateNotSet -{ - SentryOptions *options = [self getValidOptions:@{}]; - - XCTAssertEqual(@1, options.sampleRate); -} - -- (void)testEnableAutoSessionTracking -{ - [self testBooleanField:@"enableAutoSessionTracking"]; -} - -- (void)testEnableOutOfMemoryTracking -{ - [self testBooleanField:@"enableOutOfMemoryTracking"]; -} - -- (void)testSessionTrackingIntervalMillis -{ - NSNumber *sessionTracking = @2000; - SentryOptions *options = - [self getValidOptions:@{ @"sessionTrackingIntervalMillis" : sessionTracking }]; - - XCTAssertEqual([sessionTracking unsignedIntValue], options.sessionTrackingIntervalMillis); -} - -- (void)testDefaultSessionTrackingIntervalMillis -{ - SentryOptions *options = [self getValidOptions:@{}]; - - XCTAssertEqual([@30000 unsignedIntValue], options.sessionTrackingIntervalMillis); -} - -- (void)testAttachStackTrace -{ - [self testBooleanField:@"attachStacktrace"]; -} - -- (void)testStitchAsyncCodeDisabledPerDefault -{ - [self testBooleanField:@"stitchAsyncCode" defaultValue:NO]; -} - -- (void)testEnableIOTracking -{ - [self testBooleanField:@"enableFileIOTracking" defaultValue:NO]; -} - - (void)testEmptyConstructorSetsDefaultValues { SentryOptions *options = [[SentryOptions alloc] init]; @@ -479,57 +75,6 @@ - (void)testEmptyConstructorSetsDefaultValues [self assertDefaultValues:options]; } -- (void)testNSNull_SetsDefaultValue -{ - SentryOptions *options = [[SentryOptions alloc] initWithDict:@{ - @"dsn" : [NSNull null], - @"enabled" : [NSNull null], - @"debug" : [NSNull null], - @"diagnosticLevel" : [NSNull null], - @"release" : [NSNull null], - @"environment" : [NSNull null], - @"dist" : [NSNull null], - @"maxBreadcrumbs" : [NSNull null], - @"enableNetworkBreadcrumbs" : [NSNull null], - @"maxCacheItems" : [NSNull null], - @"beforeSend" : [NSNull null], - @"beforeBreadcrumb" : [NSNull null], - @"onCrashedLastRun" : [NSNull null], - @"integrations" : [NSNull null], - @"sampleRate" : [NSNull null], - @"enableAutoSessionTracking" : [NSNull null], - @"enableOutOfMemoryTracking" : [NSNull null], - @"sessionTrackingIntervalMillis" : [NSNull null], - @"attachStacktrace" : [NSNull null], - @"stitchAsyncCode" : [NSNull null], - @"maxAttachmentSize" : [NSNull null], - @"sendDefaultPii" : [NSNull null], - @"enableAutoPerformanceTracking" : [NSNull null], -#if SENTRY_HAS_UIKIT - @"enableUIViewControllerTracking" : [NSNull null], - @"attachScreenshot" : [NSNull null], -#endif - @"enableAppHangTracking" : [NSNull null], - @"appHangTimeoutInterval" : [NSNull null], - @"enableNetworkTracking" : [NSNull null], - @"enableAutoBreadcrumbTracking" : [NSNull null], - @"tracesSampleRate" : [NSNull null], - @"tracesSampler" : [NSNull null], - @"inAppIncludes" : [NSNull null], - @"inAppExcludes" : [NSNull null], - @"urlSessionDelegate" : [NSNull null], - @"enableSwizzling" : [NSNull null], - @"enableIOTracking" : [NSNull null], - @"sdk" : [NSNull null], - @"enableCaptureFailedRequests" : [NSNull null], - @"failedRequestStatusCodes" : [NSNull null], - } - didFailWithError:nil]; - - XCTAssertNotNil(options.parsedDsn); - [self assertDefaultValues:options]; -} - - (void)assertDefaultValues:(SentryOptions *)options { XCTAssertEqual(YES, options.enabled); @@ -591,12 +136,6 @@ - (void)assertDefaultValues:(SentryOptions *)options XCTAssertNil(options.profilesSampleRate); XCTAssertNil(options.profilesSampler); #endif - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - XCTAssertEqual(SentryMeta.sdkName, options.sdkInfo.name); - XCTAssertEqual(SentryMeta.versionString, options.sdkInfo.version); -#pragma clang diagnostic pop } - (void)testSetValidDsn @@ -633,175 +172,6 @@ - (void)testSetInvalidValidDsn XCTAssertEqual(YES, options.enabled); } -- (void)testSdkInfo -{ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - SentryOptions *options = [[SentryOptions alloc] init]; - XCTAssertEqual(SentryMeta.sdkName, options.sdkInfo.name); - XCTAssertEqual(SentryMeta.versionString, options.sdkInfo.version); -#pragma clang diagnostic pop -} - -- (void)testSetCustomSdkInfo -{ - NSDictionary *dict = @{ @"name" : @"custom.sdk", @"version" : @"1.2.3-alpha.0" }; - - NSError *error = nil; - SentryOptions *options = - [[SentryOptions alloc] initWithDict:@{ @"sdk" : dict, @"dsn" : @"https://a:b@c.d/1" } - didFailWithError:&error]; - - XCTAssertNil(error); - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - XCTAssertEqual(dict[@"name"], options.sdkInfo.name); - XCTAssertEqual(dict[@"version"], options.sdkInfo.version); -#pragma clang diagnostic pop - - NSDictionary *info = [[NSBundle bundleForClass:[SentryClient class]] infoDictionary]; - NSString *version = [NSString stringWithFormat:@"%@", info[@"CFBundleShortVersionString"]]; - SentryMeta.versionString = version; -} - -- (void)testSetCustomSdkName -{ - NSDictionary *dict = @{ @"name" : @"custom.sdk" }; - NSString *originalVersion = SentryMeta.versionString; - - NSError *error = nil; - SentryOptions *options = - [[SentryOptions alloc] initWithDict:@{ @"sdk" : dict, @"dsn" : @"https://a:b@c.d/1" } - didFailWithError:&error]; - - XCTAssertNil(error); - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - XCTAssertEqual(dict[@"name"], options.sdkInfo.name); - // version stays unchanged - XCTAssertEqual(SentryMeta.versionString, options.sdkInfo.version); - XCTAssertEqual(SentryMeta.versionString, originalVersion); -#pragma clang diagnostic pop -} - -- (void)testSetCustomSdkVersion -{ - NSDictionary *dict = @{ @"version" : @"1.2.3-alpha.0" }; - NSString *originalName = SentryMeta.sdkName; - - NSError *error = nil; - SentryOptions *options = - [[SentryOptions alloc] initWithDict:@{ @"sdk" : dict, @"dsn" : @"https://a:b@c.d/1" } - didFailWithError:&error]; - - XCTAssertNil(error); - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - XCTAssertEqual(dict[@"version"], options.sdkInfo.version); - // name stays unchanged - XCTAssertEqual(SentryMeta.sdkName, options.sdkInfo.name); - XCTAssertEqual(SentryMeta.sdkName, originalName); -#pragma clang diagnostic pop - - NSDictionary *info = [[NSBundle bundleForClass:[SentryClient class]] infoDictionary]; - NSString *version = [NSString stringWithFormat:@"%@", info[@"CFBundleShortVersionString"]]; - SentryMeta.versionString = version; -} - -- (void)testMaxAttachmentSize -{ - NSNumber *maxAttachmentSize = @21; - SentryOptions *options = [self getValidOptions:@{ @"maxAttachmentSize" : maxAttachmentSize }]; - - XCTAssertEqual([maxAttachmentSize unsignedIntValue], options.maxAttachmentSize); -} - -- (void)testDefaultMaxAttachmentSize -{ - SentryOptions *options = [self getValidOptions:@{}]; - - XCTAssertEqual(20 * 1024 * 1024, options.maxAttachmentSize); -} - -- (void)testSendDefaultPii -{ - [self testBooleanField:@"sendDefaultPii" defaultValue:NO]; -} - -- (void)testEnableAutoPerformanceTracking -{ - [self testBooleanField:@"enableAutoPerformanceTracking"]; -} - -#if SENTRY_HAS_UIKIT -- (void)testEnableUIViewControllerTracking -{ - [self testBooleanField:@"enableUIViewControllerTracking"]; -} - -- (void)testAttachScreenshot -{ - [self testBooleanField:@"attachScreenshot" defaultValue:NO]; -} - -- (void)testEnableUserInteractionTracking -{ - [self testBooleanField:@"enableUserInteractionTracing" defaultValue:NO]; -} - -- (void)testIdleTimeout -{ - NSNumber *idleTimeout = @2.1; - SentryOptions *options = [self getValidOptions:@{ @"idleTimeout" : idleTimeout }]; - - XCTAssertEqual([idleTimeout doubleValue], options.idleTimeout); -} - -- (void)testEnablePreWarmedAppStartTracking -{ - [self testBooleanField:@"enablePreWarmedAppStartTracking" defaultValue:NO]; -} - -#endif - -- (void)testEnableAppHangTracking -{ - [self testBooleanField:@"enableAppHangTracking" defaultValue:NO]; -} - -- (void)testDefaultAppHangsTimeout -{ - SentryOptions *options = [self getValidOptions:@{}]; - XCTAssertEqual(2, options.appHangTimeoutInterval); -} - -- (void)testEnableNetworkTracking -{ - [self testBooleanField:@"enableNetworkTracking"]; -} - -- (void)testEnableSwizzling -{ - [self testBooleanField:@"enableSwizzling"]; -} - -- (void)testTracesSampleRate -{ - SentryOptions *options = [self getValidOptions:@{ @"tracesSampleRate" : @0.1 }]; - - XCTAssertEqual(options.tracesSampleRate.doubleValue, 0.1); -} - -- (void)testDefaultTracesSampleRate -{ - SentryOptions *options = [self getValidOptions:@{}]; - - XCTAssertNil(options.tracesSampleRate); -} - - (void)testTracesSampleRate_SetToNil { SentryOptions *options = [[SentryOptions alloc] init]; @@ -841,36 +211,6 @@ - (void)testTracesSampleRateUpperBound XCTAssertNil(options.tracesSampleRate); } -- (double)tracesSamplerCallback:(NSDictionary *)context -{ - return 0.1; -} - -- (void)testTracesSampler -{ - SentryTracesSamplerCallback sampler = ^(SentrySamplingContext *context) { - XCTAssertNotNil(context); - return @1.0; - }; - - SentryOptions *options = [self getValidOptions:@{ @"tracesSampler" : sampler }]; - - SentrySamplingContext *context = [[SentrySamplingContext alloc] init]; - XCTAssertEqual(options.tracesSampler(context), @1.0); -} - -- (void)testDefaultTracesSampler -{ - SentryOptions *options = [self getValidOptions:@{}]; - XCTAssertNil(options.tracesSampler); -} - -- (void)testGarbageTracesSampler_ReturnsNil -{ - SentryOptions *options = [self getValidOptions:@{ @"tracesSampler" : @"fault" }]; - XCTAssertNil(options.tracesSampler); -} - - (void)testIsTracingEnabled_NothingSet_IsDisabled { SentryOptions *options = [[SentryOptions alloc] init]; @@ -902,25 +242,6 @@ - (void)testIsTracingEnabled_TracesSamplerSet_IsEnabled } #if SENTRY_TARGET_PROFILING_SUPPORTED -- (void)testEnableProfiling -{ - [self testBooleanField:@"enableProfiling" defaultValue:NO]; -} - -- (void)testProfilesSampleRate -{ - SentryOptions *options = [self getValidOptions:@{ @"profilesSampleRate" : @0.1 }]; - - XCTAssertEqual(options.profilesSampleRate.doubleValue, 0.1); -} - -- (void)testDefaultProfilesSampleRate -{ - SentryOptions *options = [self getValidOptions:@{}]; - - XCTAssertNil(options.profilesSampleRate); -} - - (void)testProfilesSampleRate_SetToNil { SentryOptions *options = [[SentryOptions alloc] init]; @@ -999,182 +320,8 @@ - (void)testIsProfilingEnabled_EnableProfilingSet_IsEnabled # pragma clang diagnostic pop XCTAssertTrue(options.isProfilingEnabled); } - -- (double)profilesSamplerCallback:(NSDictionary *)context -{ - return 0.1; -} - -- (void)testProfilesSampler -{ - SentryTracesSamplerCallback sampler = ^(SentrySamplingContext *context) { - XCTAssertNotNil(context); - return @1.0; - }; - - SentryOptions *options = [self getValidOptions:@{ @"profilesSampler" : sampler }]; - - SentrySamplingContext *context = [[SentrySamplingContext alloc] init]; - XCTAssertEqual(options.profilesSampler(context), @1.0); -} - -- (void)testDefaultProfilesSampler -{ - SentryOptions *options = [self getValidOptions:@{}]; - XCTAssertNil(options.profilesSampler); -} - -- (void)testGarbageProfilesSampler_ReturnsNil -{ - SentryOptions *options = [self getValidOptions:@{ @"profilesSampler" : @"fault" }]; - XCTAssertNil(options.profilesSampler); -} #endif -- (void)testInAppIncludes -{ - NSArray *expected = @[ @"iOS-Swift", @"BusinessLogic" ]; - NSArray *inAppIncludes = @[ @"iOS-Swift", @"BusinessLogic", @1 ]; - SentryOptions *options = [self getValidOptions:@{ @"inAppIncludes" : inAppIncludes }]; - - NSString *bundleExecutable = [self getBundleExecutable]; - if (nil != bundleExecutable) { - expected = [expected arrayByAddingObject:bundleExecutable]; - } - - [self assertArrayEquals:expected actual:options.inAppIncludes]; -} - -- (void)testAddInAppIncludes -{ - SentryOptions *options = [self getValidOptions:@{}]; - [options addInAppInclude:@"App"]; - - NSArray *expected = @[ @"App" ]; - NSString *bundleExecutable = [self getBundleExecutable]; - if (nil != bundleExecutable) { - expected = [expected arrayByAddingObject:bundleExecutable]; - } - - [self assertArrayEquals:expected actual:options.inAppIncludes]; -} - -- (NSString *)getBundleExecutable -{ - NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary]; - return infoDict[@"CFBundleExecutable"]; -} - -- (void)testDefaultInAppIncludes -{ - SentryOptions *options = [self getValidOptions:@{}]; - XCTAssertEqualObjects([self getDefaultInAppIncludes], options.inAppIncludes); -} - -- (void)testInAppExcludes -{ - NSArray *expected = @[ @"Sentry" ]; - NSArray *inAppExcludes = @[ @"Sentry", @2 ]; - - SentryOptions *options = [self getValidOptions:@{ @"inAppExcludes" : inAppExcludes }]; - - XCTAssertEqualObjects(expected, options.inAppExcludes); -} - -- (void)testAddInAppExcludes -{ - SentryOptions *options = [self getValidOptions:@{}]; - [options addInAppExclude:@"App"]; - XCTAssertEqualObjects(@[ @"App" ], options.inAppExcludes); -} - -- (void)testDefaultInAppExcludes -{ - SentryOptions *options = [self getValidOptions:@{}]; - XCTAssertEqualObjects(@[], options.inAppExcludes); -} - -- (SentryOptions *)getValidOptions:(NSDictionary *)dict -{ - NSError *error = nil; - - NSMutableDictionary *options = [[NSMutableDictionary alloc] init]; - options[@"dsn"] = @"https://username:password@sentry.io/1"; - - [options addEntriesFromDictionary:dict]; - - SentryOptions *sentryOptions = [[SentryOptions alloc] initWithDict:options - didFailWithError:&error]; - XCTAssertNil(error); - return sentryOptions; -} - -- (void)testUrlSessionDelegate -{ - id urlSessionDelegate = [[UrlSessionDelegateSpy alloc] init]; - - SentryOptions *options = [self getValidOptions:@{ @"urlSessionDelegate" : urlSessionDelegate }]; - - XCTAssertNotNil(options.urlSessionDelegate); -} - -- (void)testSdkInfoChanges -{ - SentryOptions *options = [self getValidOptions:@{}]; - SentryMeta.sdkName = @"new name"; - SentryMeta.versionString = @"0.0.6"; - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - XCTAssertEqual(options.sdkInfo.name, SentryMeta.sdkName); - XCTAssertEqual(options.sdkInfo.version, SentryMeta.versionString); -#pragma clang diagnostic pop -} - -- (void)assertArrayEquals:(NSArray *)expected actual:(NSArray *)actual -{ - XCTAssertEqualObjects([expected sortedArrayUsingSelector:@selector(compare:)], - [actual sortedArrayUsingSelector:@selector(compare:)]); -} - -- (void)testBooleanField:(NSString *)property -{ - [self testBooleanField:property defaultValue:YES]; -} - -- (void)testBooleanField:(NSString *)property defaultValue:(BOOL)defaultValue -{ - // Opposite of default - SentryOptions *options = [self getValidOptions:@{ property : @(!defaultValue) }]; - XCTAssertEqual(!defaultValue, [self getProperty:property of:options]); - - // Default - options = [self getValidOptions:@{}]; - XCTAssertEqual(defaultValue, [self getProperty:property of:options]); - - // Garbage - options = [self getValidOptions:@{ property : @"" }]; - XCTAssertEqual(NO, [self getProperty:property of:options]); -} - -- (BOOL)getProperty:(NSString *)property of:(SentryOptions *)options -{ - SEL selector = NSSelectorFromString(property); - NSAssert( - [options respondsToSelector:selector], @"Options doesn't have a property '%@'", property); - - NSInvocation *invocation = [NSInvocation - invocationWithMethodSignature:[[options class] - instanceMethodSignatureForSelector:selector]]; - [invocation setSelector:selector]; - [invocation setTarget:options]; - [invocation invoke]; - BOOL result; - [invocation getReturnValue:&result]; - - return result; -} - - (NSArray *)getDefaultInAppIncludes { NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary]; diff --git a/Tests/SentryTests/SentryTests.m b/Tests/SentryTests/SentryTests.m index c3116499191..b1907268b03 100644 --- a/Tests/SentryTests/SentryTests.m +++ b/Tests/SentryTests/SentryTests.m @@ -45,9 +45,9 @@ - (void)testVersion - (void)testSharedClient { NSError *error = nil; - SentryOptions *options = [[SentryOptions alloc] - initWithDict:@{ @"dsn" : @"https://username:password@app.getsentry.com/12345" } - didFailWithError:&error]; + SentryOptions *options = + [[SentryOptions alloc] initWithDsn:@"https://username:password@app.getsentry.com/12345" + didFailWithError:&error]; SentryClient *client = [[SentryClient alloc] initWithOptions:options]; XCTAssertNil(error); @@ -59,14 +59,18 @@ - (void)testSharedClient - (void)testSDKDefaultHub { - [SentrySDK startWithOptions:@{ @"dsn" : @"https://username:password@app.getsentry.com/12345" }]; + [SentrySDK startWithConfigureOptions:^(SentryOptions *_Nonnull options) { + options.dsn = @"https://username:password@app.getsentry.com/12345"; + }]; XCTAssertNotNil([SentrySDK.currentHub getClient]); [SentrySDK.currentHub bindClient:nil]; } - (void)testSDKBreadCrumbAdd { - [SentrySDK startWithOptions:@{ @"dsn" : @"https://username:password@app.getsentry.com/12345" }]; + [SentrySDK startWithConfigureOptions:^(SentryOptions *_Nonnull options) { + options.dsn = @"https://username:password@app.getsentry.com/12345"; + }]; SentryBreadcrumb *crumb = [[SentryBreadcrumb alloc] initWithLevel:kSentryLevelInfo category:@"testCategory"]; @@ -79,7 +83,9 @@ - (void)testSDKBreadCrumbAdd - (void)testSDKCaptureEvent { - [SentrySDK startWithOptions:@{ @"dsn" : @"https://username:password@app.getsentry.com/12345" }]; + [SentrySDK startWithConfigureOptions:^(SentryOptions *_Nonnull options) { + options.dsn = @"https://username:password@app.getsentry.com/12345"; + }]; SentryEvent *event = [[SentryEvent alloc] initWithLevel:kSentryLevelFatal]; @@ -91,7 +97,9 @@ - (void)testSDKCaptureEvent - (void)testSDKCaptureError { - [SentrySDK startWithOptions:@{ @"dsn" : @"https://username:password@app.getsentry.com/12345" }]; + [SentrySDK startWithConfigureOptions:^(SentryOptions *_Nonnull options) { + options.dsn = @"https://username:password@app.getsentry.com/12345"; + }]; NSError *error = [NSError errorWithDomain:@"testworld" diff --git a/Tests/SentryTests/TestClient.swift b/Tests/SentryTests/TestClient.swift index a8b4c8804b6..8e04ba8e6dd 100644 --- a/Tests/SentryTests/TestClient.swift +++ b/Tests/SentryTests/TestClient.swift @@ -130,9 +130,9 @@ class TestClient: Client { recordLostEvents.record((category, reason)) } - var flushInvoctions = Invocations() + var flushInvocations = Invocations() override func flush(timeout: TimeInterval) { - flushInvoctions.record(timeout) + flushInvocations.record(timeout) } } diff --git a/Tests/SentryTests/TestUtils/SentryTestObserver.m b/Tests/SentryTests/TestUtils/SentryTestObserver.m index c9fd968b437..c34b08da32d 100644 --- a/Tests/SentryTests/TestUtils/SentryTestObserver.m +++ b/Tests/SentryTests/TestUtils/SentryTestObserver.m @@ -48,7 +48,7 @@ - (instancetype)init // The SentryCrashIntegration enriches the scope. We need to install the integration // once to get the scope data. - [SentrySDK startWithOptionsObject:options]; + [SentrySDK startWithOptions:options]; self.scope = [[SentryScope alloc] init]; [SentryCrashIntegration enrichScope:self.scope diff --git a/Tests/SentryTests/Transaction/SentryNoOpSpanTests.swift b/Tests/SentryTests/Transaction/SentryNoOpSpanTests.swift index db1d0600cf0..73875e4ef63 100644 --- a/Tests/SentryTests/Transaction/SentryNoOpSpanTests.swift +++ b/Tests/SentryTests/Transaction/SentryNoOpSpanTests.swift @@ -27,7 +27,6 @@ class SentryNoOpSpanTests: XCTestCase { let sut = SentryNoOpSpan.shared() XCTAssertNil(sut.data) sut.setData(value: "tet", key: "key") - sut.setExtra(value: "tet", key: "key") sut.removeData(key: "any") XCTAssertNil(sut.data) } diff --git a/Tests/SentryTests/Transaction/SentrySpanTests.swift b/Tests/SentryTests/Transaction/SentrySpanTests.swift index 8c8f74a511f..214ae819e06 100644 --- a/Tests/SentryTests/Transaction/SentrySpanTests.swift +++ b/Tests/SentryTests/Transaction/SentrySpanTests.swift @@ -185,10 +185,10 @@ class SentrySpanTests: XCTestCase { XCTAssertFalse(logOutput.loggedMessages.filter({ $0.contains(" Starting a child on a finished span is not supported; it won\'t be sent to Sentry.") }).isEmpty) } - func testAddAndRemoveExtras() { + func testAddAndRemoveData() { let span = fixture.getSut() - span.setExtra(value: fixture.extraValue, key: fixture.extraKey) + span.setData(value: fixture.extraValue, key: fixture.extraKey) XCTAssertEqual(span.data!.count, 1) XCTAssertEqual(span.data![fixture.extraKey] as! String, fixture.extraValue) @@ -214,7 +214,7 @@ class SentrySpanTests: XCTestCase { func testSerialization() { let span = fixture.getSut() - span.setExtra(value: fixture.extraValue, key: fixture.extraKey) + span.setData(value: fixture.extraValue, key: fixture.extraKey) span.setTag(value: fixture.extraValue, key: fixture.extraKey) span.finish() @@ -234,7 +234,7 @@ class SentrySpanTests: XCTestCase { func testSanitizeData() { let span = fixture.getSut() - span.setExtra(value: Date(timeIntervalSince1970: 10), key: "date") + span.setData(value: Date(timeIntervalSince1970: 10), key: "date") span.finish() let serialization = span.serialize() @@ -244,7 +244,7 @@ class SentrySpanTests: XCTestCase { func testSanitizeDataSpan() { let span = SentrySpan(tracer: fixture.tracer, context: SpanContext(operation: fixture.someOperation, sampled: .undecided)) - span.setExtra(value: Date(timeIntervalSince1970: 10), key: "date") + span.setData(value: Date(timeIntervalSince1970: 10), key: "date") span.finish() let serialization = span.serialize() @@ -305,13 +305,14 @@ class SentrySpanTests: XCTestCase { XCTAssertEqual(header.value(), "\(span.context.traceId)-\(span.context.spanId)") } + @available(*, deprecated) func testSetExtra_ForwardsToSetData() { let sut = SentrySpan(tracer: fixture.tracer, context: SpanContext(operation: "test")) sut.setExtra(value: 0, key: "key") XCTAssertEqual(["key": 0], sut.data as! [String: Int]) } - + func testSpanWithoutTracer_StartChild_ReturnsNoOpSpan() { // Span has a weak reference to tracer. If we don't keep a reference // to the tracer ARC will deallocate the tracer. @@ -346,7 +347,7 @@ class SentrySpanTests: XCTestCase { queue.async { for j in 0.. +- (void)setExtraValue:(nullable id)value forKey:(nonnull NSString *)key DEPRECATED_ATTRIBUTE; + @end NS_ASSUME_NONNULL_END