diff --git a/CHANGELOG.md b/CHANGELOG.md index 1820d961..2a5ae905 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,10 @@ The change log has moved to this repo's [GitHub Releases Page](https://github.co ## Release Notes +**2.0.0-beta.22** +**2.0.0-beta.21** +- feat: new RollbarAUL module is code complete + **2.0.0-beta.15** - fix: resolve #81 - SPM - Resolving Package Graph Failed diff --git a/Demos/macosAppSwift/macosAppSwift.xcodeproj/project.pbxproj b/Demos/macosAppSwift/macosAppSwift.xcodeproj/project.pbxproj index 227b9bf4..45333629 100644 --- a/Demos/macosAppSwift/macosAppSwift.xcodeproj/project.pbxproj +++ b/Demos/macosAppSwift/macosAppSwift.xcodeproj/project.pbxproj @@ -11,6 +11,8 @@ 55098C6725FA930D0045C180 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55098C6625FA930D0045C180 /* ContentView.swift */; }; 55098C6925FA93110045C180 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 55098C6825FA93110045C180 /* Assets.xcassets */; }; 55098C6C25FA93110045C180 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 55098C6B25FA93110045C180 /* Preview Assets.xcassets */; }; + 552689F12657381B004D6036 /* RollbarAUL in Frameworks */ = {isa = PBXBuildFile; productRef = 552689F02657381B004D6036 /* RollbarAUL */; }; + 552689F326573831004D6036 /* RollbarPLCrashReporter in Frameworks */ = {isa = PBXBuildFile; productRef = 552689F226573831004D6036 /* RollbarPLCrashReporter */; }; 5544A01F25FB074300C710A1 /* RollbarCommon in Frameworks */ = {isa = PBXBuildFile; productRef = 5544A01E25FB074300C710A1 /* RollbarCommon */; }; 5544A02125FB074300C710A1 /* RollbarNotifier in Frameworks */ = {isa = PBXBuildFile; productRef = 5544A02025FB074300C710A1 /* RollbarNotifier */; }; 5544A02325FB074300C710A1 /* RollbarSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 5544A02225FB074300C710A1 /* RollbarSwift */; }; @@ -33,6 +35,8 @@ files = ( 5544A01F25FB074300C710A1 /* RollbarCommon in Frameworks */, 5544A02125FB074300C710A1 /* RollbarNotifier in Frameworks */, + 552689F326573831004D6036 /* RollbarPLCrashReporter in Frameworks */, + 552689F12657381B004D6036 /* RollbarAUL in Frameworks */, 5544A02325FB074300C710A1 /* RollbarSwift in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -105,6 +109,8 @@ 5544A01E25FB074300C710A1 /* RollbarCommon */, 5544A02025FB074300C710A1 /* RollbarNotifier */, 5544A02225FB074300C710A1 /* RollbarSwift */, + 552689F02657381B004D6036 /* RollbarAUL */, + 552689F226573831004D6036 /* RollbarPLCrashReporter */, ); productName = macosAppSwift; productReference = 55098C6125FA930D0045C180 /* macosAppSwift.app */; @@ -352,6 +358,14 @@ /* End XCConfigurationList section */ /* Begin XCSwiftPackageProductDependency section */ + 552689F02657381B004D6036 /* RollbarAUL */ = { + isa = XCSwiftPackageProductDependency; + productName = RollbarAUL; + }; + 552689F226573831004D6036 /* RollbarPLCrashReporter */ = { + isa = XCSwiftPackageProductDependency; + productName = RollbarPLCrashReporter; + }; 5544A01E25FB074300C710A1 /* RollbarCommon */ = { isa = XCSwiftPackageProductDependency; productName = RollbarCommon; diff --git a/Demos/macosAppSwift/macosAppSwift/ContentView.swift b/Demos/macosAppSwift/macosAppSwift/ContentView.swift index 63cb1da6..6df84db4 100644 --- a/Demos/macosAppSwift/macosAppSwift/ContentView.swift +++ b/Demos/macosAppSwift/macosAppSwift/ContentView.swift @@ -8,6 +8,7 @@ import SwiftUI import RollbarNotifier import RollbarSwift +import RollbarAUL struct ContentView: View { @@ -92,7 +93,21 @@ func handleSwiftError() { let config = RollbarConfig(); config.destination.accessToken = "2ffc7997ed864dda94f63e7b7daae0f3"; config.destination.environment = "samples"; - config.developerOptions.transmit = true; + + // AUL capture setup: +// config.developerOptions.transmit = true; +// config.telemetry.enabled = true; +// config.telemetry.captureLog = true; +// +// Rollbar.initWithConfiguration(config); +// RollbarAulStoreMonitor.sharedInstance().configureRollbarLogger(Rollbar.currentLogger()); +// let aulOptions = RollbarAulStoreMonitorOptions(); +// aulOptions.addAulSubsystem("DataAccessLayer"); +// aulOptions.addAulSubsystem("Model"); +// aulOptions.addAulCategory("CompanyOrg"); +// RollbarAulStoreMonitor.sharedInstance().configure(with: aulOptions); +// +// RollbarAulStoreMonitor.sharedInstance().start(); let logger = RollbarLogger(configuration: config); diff --git a/README.md b/README.md index e0ab2c19..d97127d5 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,9 @@ All the active development will be done within this SDK repository. ![CI Build with Unit Tests](https://github.com/rollbar/rollbar-apple/workflows/CI%20Build%20with%20Unit%20Tests/badge.svg) + [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=rollbar-apple&metric=security_rating)](https://sonarcloud.io/dashboard?id=rollbar-apple) [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=rollbar-apple&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=rollbar-apple) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=rollbar-apple&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=rollbar-apple) @@ -44,14 +46,19 @@ All the active development will be done within this SDK repository. [![Platform](https://img.shields.io/cocoapods/p/RollbarNotifier.svg?label=RollbarNotifier)](https://docs.rollbar.com/docs/apple) [![Platform](https://img.shields.io/cocoapods/p/RollbarDeploys.svg?label=RollbarDeploys)](https://docs.rollbar.com/docs/apple) [![Platform](https://img.shields.io/cocoapods/p/RollbarCommon.svg?label=RollbarCommon)](https://docs.rollbar.com/docs/apple) -[![Platform](https://img.shields.io/cocoapods/p/RollbarKSCrash.svg?label=RollbarKSCrash)](https://docs.rollbar.com/docs/apple) +[![Platform](https://img.shields.io/cocoapods/p/RollbarAUL.svg?label=RollbarAUL)](https://docs.rollbar.com/docs/apple) +[![Platform](https://img.shields.io/cocoapods/p/RollbarSwift.svg?label=RollbarSwift)](https://docs.rollbar.com/docs/apple) [![Platform](https://img.shields.io/cocoapods/p/RollbarPLCrashReporter.svg?label=RollbarPLCrashReporter)](https://docs.rollbar.com/docs/apple) +[![Platform](https://img.shields.io/cocoapods/p/RollbarKSCrash.svg?label=RollbarKSCrash)](https://docs.rollbar.com/docs/apple) [![CocoaPods](https://img.shields.io/cocoapods/v/RollbarNotifier?label=RollbarNotifier)](https://cocoapods.org/pods/RollbarNotifier) [![CocoaPods](https://img.shields.io/cocoapods/v/RollbarDeploys?label=RollbarDeploys)](https://cocoapods.org/pods/RollbarDeploys) [![CocoaPods](https://img.shields.io/cocoapods/v/RollbarCommon?label=RollbarCommon)](https://cocoapods.org/pods/RollbarCommon) -[![CocoaPods](https://img.shields.io/cocoapods/v/RollbarKSCrash?label=RollbarKSCrash)](https://cocoapods.org/pods/RollbarKSCrash) +[![CocoaPods](https://img.shields.io/cocoapods/v/RollbarAUL?label=RollbarAUL)](https://cocoapods.org/pods/RollbarAUL) +[![CocoaPods](https://img.shields.io/cocoapods/v/RollbarSwift?label=RollbarSwift)](https://cocoapods.org/pods/RollbarSwift) [![CocoaPods](https://img.shields.io/cocoapods/v/RollbarPLCrashReporter?label=RollbarPLCrashReporter)](https://cocoapods.org/pods/RollbarPLCrashReporter) +[![CocoaPods](https://img.shields.io/cocoapods/v/RollbarKSCrash?label=RollbarKSCrash)](https://cocoapods.org/pods/RollbarKSCrash) + ## Setup Instructions diff --git a/RollbarAUL.podspec b/RollbarAUL.podspec index 5b524ae3..2cfc0212 100644 --- a/RollbarAUL.podspec +++ b/RollbarAUL.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| - s.version = "2.0.0-beta.21" + s.version = "2.0.0-beta.22" s.name = "RollbarAUL" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." s.description = <<-DESC diff --git a/RollbarAUL/README.md b/RollbarAUL/README.md index 21156dae..a5d8073a 100644 --- a/RollbarAUL/README.md +++ b/RollbarAUL/README.md @@ -1,6 +1,6 @@ # RollbarAUL -This is an SDK module implements RollbarNotifier integration with Apple Unified Logging (AUL). +This is an SDK module implements RollbarNotifier integration with Apple Unified Logging (AUL) and allows capture of the AUL entries as corresponding Rollbar Telemetry log events. Main abstractions: diff --git a/RollbarCommon.podspec b/RollbarCommon.podspec index 39ae380b..28ef59f1 100644 --- a/RollbarCommon.podspec +++ b/RollbarCommon.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| - s.version = "2.0.0-beta.21" + s.version = "2.0.0-beta.22" s.name = "RollbarCommon" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." s.description = <<-DESC diff --git a/RollbarCommon/Sources/RollbarCommon/NSJSONSerialization+Rollbar.m b/RollbarCommon/Sources/RollbarCommon/NSJSONSerialization+Rollbar.m index dfa14199..1b2a8e88 100644 --- a/RollbarCommon/Sources/RollbarCommon/NSJSONSerialization+Rollbar.m +++ b/RollbarCommon/Sources/RollbarCommon/NSJSONSerialization+Rollbar.m @@ -13,12 +13,17 @@ + (nullable NSData *)rollbar_dataWithJSONObject:(id)obj safe:(BOOL)safe { if (safe) { + if ([obj isKindOfClass:[NSArray class]]) { + NSMutableArray *newArr = [NSMutableArray array]; for (id item in obj) { + if ([item isKindOfClass:[NSDictionary class]]) { + [newArr addObject:[[self class] rollbar_safeDataFromJSONObject:item]]; } else { + [newArr addObject:item]; } } @@ -26,19 +31,26 @@ + (nullable NSData *)rollbar_dataWithJSONObject:(id)obj options:opt error:error]; } else if ([obj isKindOfClass:[NSDictionary class]]) { + return [NSJSONSerialization dataWithJSONObject:[[self class] rollbar_safeDataFromJSONObject:obj] options:opt error:error]; } } + return [NSJSONSerialization dataWithJSONObject:obj options:opt error:error]; } -+ (NSMutableDictionary *)rollbar_safeDataFromJSONObject:(id)obj { ++ (nonnull NSMutableDictionary *)rollbar_safeDataFromJSONObject:(nullable id)obj { NSMutableDictionary *safeData = [NSMutableDictionary new]; + if (nil == obj) { + + return safeData; + } + [obj enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) { if ([obj isKindOfClass:[NSDictionary class]]) { @@ -73,7 +85,7 @@ + (NSMutableDictionary *)rollbar_safeDataFromJSONObject:(id)obj { } else if ([obj isKindOfClass:[NSError class]] && (nil != [obj userInfo])) { NSDictionary* userInfoData = [[self class] rollbar_safeDataFromJSONObject:[obj userInfo]]; - if (userInfoData) { + if (nil != userInfoData) { [safeData setObject:userInfoData forKey:key]; } @@ -91,6 +103,7 @@ + (NSMutableDictionary *)rollbar_safeDataFromJSONObject:(id)obj { options:(NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves) error:&error]; if ((error == nil) && (nil != json)) { + NSDictionary *jsonData = [[self class] rollbar_safeDataFromJSONObject:json]; if (jsonData) { @@ -106,6 +119,7 @@ + (NSMutableDictionary *)rollbar_safeDataFromJSONObject:(id)obj { NSStringFromClass([obj class])); } }]; + return safeData; } diff --git a/RollbarCommon/Sources/RollbarCommon/include/NSJSONSerialization+Rollbar.h b/RollbarCommon/Sources/RollbarCommon/include/NSJSONSerialization+Rollbar.h index 02fc973b..be04e9e0 100644 --- a/RollbarCommon/Sources/RollbarCommon/include/NSJSONSerialization+Rollbar.h +++ b/RollbarCommon/Sources/RollbarCommon/include/NSJSONSerialization+Rollbar.h @@ -22,7 +22,7 @@ NS_ASSUME_NONNULL_BEGIN /// Turns JSON-like object structure into a valid NSJSONSerialization structure /// @param obj JSON-like object -+ (NSMutableDictionary *)rollbar_safeDataFromJSONObject:(id)obj; ++ (nonnull NSMutableDictionary *)rollbar_safeDataFromJSONObject:(nullable id)obj; /// Byte-length of a NSData representation of a JSON structure /// @param jsonData NSData representation of a JSON structure diff --git a/RollbarDeploys.podspec b/RollbarDeploys.podspec index 4e1bad9b..e8dbfe00 100644 --- a/RollbarDeploys.podspec +++ b/RollbarDeploys.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| - s.version = "2.0.0-beta.21" + s.version = "2.0.0-beta.22" s.name = "RollbarDeploys" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." s.description = <<-DESC diff --git a/RollbarKSCrash.podspec b/RollbarKSCrash.podspec index 4a2a9162..bdb1947d 100644 --- a/RollbarKSCrash.podspec +++ b/RollbarKSCrash.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| - s.version = "2.0.0-beta.21" + s.version = "2.0.0-beta.22" s.name = "RollbarKSCrash" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." s.description = <<-DESC diff --git a/RollbarNotifier.podspec b/RollbarNotifier.podspec index 0668d857..4f896c18 100644 --- a/RollbarNotifier.podspec +++ b/RollbarNotifier.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| - s.version = "2.0.0-beta.21" + s.version = "2.0.0-beta.22" s.name = "RollbarNotifier" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." s.description = <<-DESC diff --git a/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarConfig.m b/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarConfig.m index d1099c55..faaabebd 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarConfig.m +++ b/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarConfig.m @@ -22,7 +22,7 @@ #pragma mark - constants -static NSString * const NOTIFIER_VERSION = @"2.0.0-beta.21"; +static NSString * const NOTIFIER_VERSION = @"2.0.0-beta.22"; static NSString * const NOTIFIER_NAME = @"rollbar-apple"; diff --git a/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarLevel.m b/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarLevel.m index 262b0a2f..c5cc9aaf 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarLevel.m +++ b/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarLevel.m @@ -5,6 +5,7 @@ @implementation RollbarLevelUtil + (NSString *) RollbarLevelToString:(RollbarLevel)value; { + switch (value) { case RollbarLevel_Debug: return @"debug"; @@ -19,21 +20,30 @@ + (NSString *) RollbarLevelToString:(RollbarLevel)value; { } } -+ (RollbarLevel) RollbarLevelFromString:(NSString *)value { ++ (RollbarLevel) RollbarLevelFromString:(nullable NSString *)value { - if (NSOrderedSame == [value caseInsensitiveCompare:@"debug"]) { + if (nil == value) { + + return RollbarLevel_Info; // default case... + } + else if (NSOrderedSame == [value caseInsensitiveCompare:@"debug"]) { + return RollbarLevel_Debug; } else if (NSOrderedSame == [value caseInsensitiveCompare:@"warning"]) { + return RollbarLevel_Warning; } else if (NSOrderedSame == [value caseInsensitiveCompare:@"critical"]) { + return RollbarLevel_Critical; } else if (NSOrderedSame == [value caseInsensitiveCompare:@"error"]) { + return RollbarLevel_Error; } else { + return RollbarLevel_Info; // default case... } } diff --git a/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarSource.m b/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarSource.m index acc4d754..8e1a0301 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarSource.m +++ b/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarSource.m @@ -11,6 +11,7 @@ @implementation RollbarSourceUtil + (NSString *) RollbarSourceToString:(RollbarSource)value { + switch (value) { case RollbarSource_Client: return @"client"; @@ -21,14 +22,22 @@ + (NSString *) RollbarSourceToString:(RollbarSource)value { } } -+ (RollbarSource) RollbarSourceFromString:(NSString *)value { - if (NSOrderedSame == [value caseInsensitiveCompare:@"client"]) { ++ (RollbarSource) RollbarSourceFromString:(nullable NSString *)value { + + if (nil == value) { + + return RollbarSource_Server; // default case... + } + else if (NSOrderedSame == [value caseInsensitiveCompare:@"client"]) { + return RollbarSource_Client; } else if (NSOrderedSame == [value caseInsensitiveCompare:@"server"]) { + return RollbarSource_Server; } else { + return RollbarSource_Server; // default case... } } diff --git a/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarTelemetryEvent.m b/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarTelemetryEvent.m index 0e3836b0..0e41a1cc 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarTelemetryEvent.m +++ b/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarTelemetryEvent.m @@ -66,11 +66,6 @@ - (instancetype)initWithLevel:(RollbarLevel)level return self; } -//- (instancetype)initWithArray:(NSArray *)data { -// -// return [super initWithArray:data]; -//} - - (instancetype)initWithDictionary:(NSDictionary *)data { return [super initWithDictionary:data]; @@ -81,68 +76,52 @@ - (instancetype)initWithDictionary:(NSDictionary *)data { #pragma mark level -(RollbarLevel)level { + NSString *result = [self getDataByKey:DFK_LEVEL]; return [RollbarLevelUtil RollbarLevelFromString:result]; } -//-(void)setLevel:(RollbarLevel)value { -// [self setData:[RollbarLevelUtil RollbarLevelToString:value] -// byKey:DFK_LEVEL]; -//} - #pragma mark type -(RollbarTelemetryType)type { + NSString *result = [self getDataByKey:DFK_TYPE]; return [RollbarTelemetryTypeUtil RollbarTelemetryTypeFromString:result]; } -//-(void)setType:(RollbarTelemetryType)value { -// [self setData:[RollbarTelemetryTypeUtil RollbarTelemetryTypeToString:value] -// byKey:DFK_TYPE]; -//} - #pragma mark source -(RollbarSource)source { + NSString *result = [self getDataByKey:DFK_SOURCE]; return [RollbarSourceUtil RollbarSourceFromString:result]; } -//-(void)setSource:(RollbarSource)value { -// [self setData:[RollbarSourceUtil RollbarSourceToString:value] -// byKey:DFK_SOURCE]; -//} - #pragma mark timestamp -(NSTimeInterval)timestamp { + NSNumber *dateNumber = [self getDataByKey:DFK_TIMESTAMP]; // [sec] if (nil != dateNumber) { + return (NSTimeInterval)(dateNumber.doubleValue / 1000.0); // [msec] } + return 0; } -//-(void)setTimestamp:(NSTimeInterval)value { -// [self setData:[NSNumber numberWithDouble:(value * 1000.0)] // [msec] -// byKey:DFK_TIMESTAMP]; -//} - #pragma mark body - (RollbarTelemetryBody *)body { + id data = [self safelyGetDictionaryByKey:DFK_BODY]; return [RollbarTelemetryEvent createTelemetryBodyWithType:self.type data:data]; } -//- (void)setBody:(RollbarTelemetryBody *)value { -// [self setDataTransferObject:value forKey:DFK_BODY]; -//} - -+ (nullable RollbarTelemetryBody *)createTelemetryBodyWithType:(RollbarTelemetryType)type ++ (RollbarTelemetryBody *)createTelemetryBodyWithType:(RollbarTelemetryType)type data:(NSDictionary *)data { + RollbarTelemetryBody *body = nil; switch(type) { case RollbarTelemetryType_View: @@ -167,39 +146,50 @@ + (nullable RollbarTelemetryBody *)createTelemetryBodyWithType:(RollbarTelemetry body = [RollbarTelemetryConnectivityBody alloc]; break; default: - return nil; + body = [RollbarTelemetryBody alloc]; } - if (!data) { + + if (nil == data) { + data = [NSMutableDictionary dictionary]; } + return [body initWithDictionary:data]; } +(RollbarTelemetryType)deriveTypeFromBody:(nonnull RollbarTelemetryBody *)body { - //TODO: order of type discovery matters (for inhereted body type hierarchies): + //NOTE: order of type discovery matters (for inhereted body type hierarchies): if ([body isKindOfClass:[RollbarTelemetryErrorBody class]]) { + return RollbarTelemetryType_Error; } else if ([body isKindOfClass:[RollbarTelemetryLogBody class]]) { + return RollbarTelemetryType_Log; } else if ([body isKindOfClass:[RollbarTelemetryViewBody class]]) { + return RollbarTelemetryType_View; } else if ([body isKindOfClass:[RollbarTelemetryNavigationBody class]]) { + return RollbarTelemetryType_Navigation; } else if ([body isKindOfClass:[RollbarTelemetryManualBody class]]) { + return RollbarTelemetryType_Manual; } else if ([body isKindOfClass:[RollbarTelemetryNetworkBody class]]) { + return RollbarTelemetryType_Network; } else if ([body isKindOfClass:[RollbarTelemetryConnectivityBody class]]) { + return RollbarTelemetryType_Connectivity; } else { + return RollbarTelemetryType_Manual; } } diff --git a/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarTelemetryType.m b/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarTelemetryType.m index 187c5966..5dea8ac6 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarTelemetryType.m +++ b/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarTelemetryType.m @@ -23,27 +23,38 @@ + (NSString *) RollbarTelemetryTypeToString:(RollbarTelemetryType)value; { } } -+ (RollbarTelemetryType) RollbarTelemetryTypeFromString:(NSString *)value { ++ (RollbarTelemetryType) RollbarTelemetryTypeFromString:(nullable NSString *)value { - if (NSOrderedSame == [value caseInsensitiveCompare:@"dom"]) { + if (nil == value) { + + return RollbarTelemetryType_Manual; // default case... + } + else if (NSOrderedSame == [value caseInsensitiveCompare:@"dom"]) { + return RollbarTelemetryType_View; } else if (NSOrderedSame == [value caseInsensitiveCompare:@"log"]) { + return RollbarTelemetryType_Log; } else if (NSOrderedSame == [value caseInsensitiveCompare:@"error"]) { + return RollbarTelemetryType_Error; } else if (NSOrderedSame == [value caseInsensitiveCompare:@"navigation"]) { + return RollbarTelemetryType_Navigation; } else if (NSOrderedSame == [value caseInsensitiveCompare:@"network"]) { + return RollbarTelemetryType_Network; } else if (NSOrderedSame == [value caseInsensitiveCompare:@"connectivity"]) { + return RollbarTelemetryType_Connectivity; } else { + return RollbarTelemetryType_Manual; // default case... } } diff --git a/RollbarNotifier/Sources/RollbarNotifier/Rollbar.m b/RollbarNotifier/Sources/RollbarNotifier/Rollbar.m index 5fa18056..7d415ba1 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/Rollbar.m +++ b/RollbarNotifier/Sources/RollbarNotifier/Rollbar.m @@ -20,7 +20,9 @@ @implementation Rollbar static RollbarCrashProcessor *crashProcessor = nil; + (void)initialize { + if (self == [Rollbar class]) { + telemetryOptionsObserver = [RollbarTelemetryOptionsObserver new]; } } @@ -62,15 +64,19 @@ + (void)initWithAccessToken:(nullable NSString *)accessToken [RollbarTelemetry sharedInstance]; // Load saved data, if any if (logger) { + RollbarSdkLog(@"Rollbar has already been initialized."); } else { + RollbarConfig *config = configuration ? configuration : [RollbarConfig new]; if (accessToken && accessToken.length > 0) { + config.destination.accessToken = accessToken; } [Rollbar updateConfiguration:config]; if (crashCollector) { + crashProcessor = [[RollbarCrashProcessor alloc] init]; [crashCollector collectCrashReportsWithObserver:crashProcessor]; } @@ -89,10 +95,6 @@ + (RollbarLogger *)currentLogger { + (void)updateConfiguration:(RollbarConfig *)configuration { -// if (logger && logger.configuration && logger.configuration.telemetry) { -// [telemetryOptionsObserver unregisterAsObserverForTelemetryOptions:logger.configuration.telemetry]; -// } - NSUInteger oldReportingRate = 0; if (logger) { @@ -107,10 +109,6 @@ + (void)updateConfiguration:(RollbarConfig *)configuration { [logger updateReportingRate:configuration.loggingOptions.maximumReportsPerMinute]; } -// if (logger && logger.configuration && logger.configuration.telemetry) { -// [telemetryOptionsObserver registerAsObserverForTelemetryOptions:logger.configuration.telemetry]; -// } - if (configuration && configuration.telemetry) { [RollbarTelemetry sharedInstance].enabled = configuration.telemetry.enabled; [RollbarTelemetry sharedInstance].scrubViewInputs = configuration.telemetry.viewInputsScrubber.enabled; @@ -122,7 +120,11 @@ + (void)updateConfiguration:(RollbarConfig *)configuration { } + (void)reapplyConfiguration { - [Rollbar updateConfiguration:Rollbar.currentConfiguration]; + + if (nil != Rollbar.currentConfiguration) { + + [Rollbar updateConfiguration:Rollbar.currentConfiguration]; + } } #pragma mark - Logging methods @@ -225,160 +227,234 @@ + (void)log:(RollbarLevel)level #pragma mark - Convenience logging methods + (void)debugMessage:(NSString *)message { + [Rollbar log:RollbarLevel_Debug message:message data:nil context:nil]; } + + (void)debugException:(NSException *)exception { + [Rollbar log:RollbarLevel_Debug exception:exception data:nil context:nil]; } + + (void)debugError:(NSError *)error { + [Rollbar log:RollbarLevel_Debug error:error data:nil context:nil]; } + (void)debugMessage:(NSString *)message data:(NSDictionary *)data { + [Rollbar log:RollbarLevel_Debug message:message data:data context:nil]; } + + (void)debugException:(NSException *)exception data:(NSDictionary *)data { + [Rollbar log:RollbarLevel_Debug exception:exception data:data context:nil]; } + + (void)debugError:(NSError *)error data:(NSDictionary *)data { + [Rollbar log:RollbarLevel_Debug error:error data:data context:nil]; } + (void)debugMessage:(NSString *)message data:(NSDictionary *)data context:(NSString *)context { + [Rollbar log:RollbarLevel_Debug message:message data:data context:context]; } + (void)debugException:(NSException *)exception data:(NSDictionary *)data context:(NSString *)context { + [Rollbar log:RollbarLevel_Debug exception:exception data:data context:context]; } + + (void)debugError:(NSError *)error data:(NSDictionary *)data context:(NSString *)context { + [Rollbar log:RollbarLevel_Debug error:error data:data context:context]; } + (void)infoMessage:(NSString *)message { + [Rollbar log:RollbarLevel_Info message:message data:nil context:nil]; } + + (void)infoException:(NSException *)exception { + [Rollbar log:RollbarLevel_Info exception:exception data:nil context:nil]; } + + (void)infoError:(NSError *)error { + [Rollbar log:RollbarLevel_Info error:error data:nil context:nil]; } + (void)infoMessage:(NSString *)message data:(NSDictionary *)data { + [Rollbar log:RollbarLevel_Info message:message data:data context:nil]; } + + (void)infoException:(NSException *)exception data:(NSDictionary *)data { + [Rollbar log:RollbarLevel_Info exception:exception data:data context:nil]; } + + (void)infoError:(NSError *)error data:(NSDictionary *)data { + [Rollbar log:RollbarLevel_Info error:error data:data context:nil]; } + (void)infoMessage:(NSString *)message data:(NSDictionary *)data context:(NSString *)context { + [Rollbar log:RollbarLevel_Info message:message data:data context:context]; } + + (void)infoException:(NSException *)exception data:(NSDictionary *)data context:(NSString *)context { + [Rollbar log:RollbarLevel_Info exception:exception data:data context:context]; } + + (void)infoError:(NSError *)error data:(NSDictionary *)data context:(NSString *)context { + [Rollbar log:RollbarLevel_Info error:error data:data context:context]; } + (void)warningMessage:(NSString *)message { + [Rollbar log:RollbarLevel_Warning message:message data:nil context:nil]; } + + (void)warningException:(NSException *)exception { + [Rollbar log:RollbarLevel_Warning exception:exception data:nil context:nil]; } + + (void)warningError:(NSError *)error { + [Rollbar log:RollbarLevel_Warning error:error data:nil context:nil]; } + (void)warningMessage:(NSString *)message data:(NSDictionary *)data { + [Rollbar log:RollbarLevel_Warning message:message data:data context:nil]; } + + (void)warningException:(NSException *)exception data:(NSDictionary *)data { + [Rollbar log:RollbarLevel_Warning exception:exception data:data context:nil]; } + + (void)warningError:(NSError *)error data:(NSDictionary *)data { + [Rollbar log:RollbarLevel_Warning error:error data:data context:nil]; } + (void)warningMessage:(NSString *)message data:(NSDictionary *)data context:(NSString *)context { + [Rollbar log:RollbarLevel_Warning message:message data:data context:context]; } + + (void)warningException:(NSException *)exception data:(NSDictionary *)data context:(NSString *)context { + [Rollbar log:RollbarLevel_Warning exception:exception data:data context:context]; } + + (void)warningError:(NSError *)error data:(NSDictionary *)data context:(NSString *)context { + [Rollbar log:RollbarLevel_Warning error:error data:data context:context]; } + (void)errorMessage:(NSString *)message { + [Rollbar log:RollbarLevel_Error message:message data:nil context:nil]; } + + (void)errorException:(NSException *)exception { + [Rollbar log:RollbarLevel_Error exception:exception data:nil context:nil]; } + + (void)errorError:(NSError *)error { + [Rollbar log:RollbarLevel_Error error:error data:nil context:nil]; } + (void)errorMessage:(NSString *)message data:(NSDictionary *)data { + [Rollbar log:RollbarLevel_Error message:message data:data context:nil]; } + + (void)errorException:(NSException *)exception data:(NSDictionary *)data { + [Rollbar log:RollbarLevel_Error exception:exception data:data context:nil]; } + + (void)errorError:(NSError *)error data:(NSDictionary *)data { + [Rollbar log:RollbarLevel_Error error:error data:data context:nil]; } + (void)errorMessage:(NSString *)message data:(NSDictionary *)data context:(NSString *)context { + [Rollbar log:RollbarLevel_Error message:message data:data context:context]; } + + (void)errorException:(NSException *)exception data:(NSDictionary *)data context:(NSString *)context { + [Rollbar log:RollbarLevel_Error exception:exception data:data context:context]; } + + (void)errorError:(NSError *)error data:(NSDictionary *)data context:(NSString *)context { + [Rollbar log:RollbarLevel_Error error:error data:data context:context]; } + (void)criticalMessage:(NSString *)message { + [Rollbar log:RollbarLevel_Critical message:message data:nil context:nil]; } + + (void)criticalException:(NSException *)exception { + [Rollbar log:RollbarLevel_Critical exception:exception data:nil context:nil]; } + + (void)criticalError:(NSError *)error { + [Rollbar log:RollbarLevel_Critical error:error data:nil context:nil]; } + (void)criticalMessage:(NSString *)message data:(NSDictionary *)data { + [Rollbar log:RollbarLevel_Critical message:message data:data context:nil]; } + + (void)criticalException:(NSException *)exception data:(NSDictionary *)data { + [Rollbar log:RollbarLevel_Critical exception:exception data:data context:nil]; } + + (void)criticalError:(NSError *)error data:(NSDictionary *)data { + [Rollbar log:RollbarLevel_Critical error:error data:data context:nil]; } + (void)criticalMessage:(NSString *)message data:(NSDictionary *)data context:(NSString *)context { + [Rollbar log:RollbarLevel_Critical message:message data:data context:context]; } + + (void)criticalException:(NSException *)exception data:(NSDictionary *)data context:(NSString *)context { + [Rollbar log:RollbarLevel_Critical exception:exception data:data context:context]; } + + (void)criticalError:(NSError *)error data:(NSDictionary *)data context:(NSString *)context { + [Rollbar log:RollbarLevel_Critical error:error data:data context:context]; } @@ -395,6 +471,7 @@ + (void)sendJsonPayload:(NSData *)payload { + (void)recordViewEventForLevel:(RollbarLevel)level element:(NSString *)element { + [self recordViewEventForLevel:level element:element extraData:nil]; @@ -403,6 +480,7 @@ + (void)recordViewEventForLevel:(RollbarLevel)level + (void)recordViewEventForLevel:(RollbarLevel)level element:(NSString *)element extraData:(NSDictionary *)extraData { + [[RollbarTelemetry sharedInstance] recordViewEventForLevel:level element:element extraData:extraData]; @@ -414,6 +492,7 @@ + (void)recordNetworkEventForLevel:(RollbarLevel)level method:(NSString *)method url:(NSString *)url statusCode:(NSString *)statusCode { + [self recordNetworkEventForLevel:level method:method url:url @@ -426,6 +505,7 @@ + (void)recordNetworkEventForLevel:(RollbarLevel)level url:(NSString *)url statusCode:(NSString *)statusCode extraData:(NSDictionary *)extraData { + [[RollbarTelemetry sharedInstance] recordNetworkEventForLevel:level method:method url:url @@ -437,6 +517,7 @@ + (void)recordNetworkEventForLevel:(RollbarLevel)level + (void)recordConnectivityEventForLevel:(RollbarLevel)level status:(NSString *)status { + [self recordConnectivityEventForLevel:level status:status extraData:nil]; @@ -445,6 +526,7 @@ + (void)recordConnectivityEventForLevel:(RollbarLevel)level + (void)recordConnectivityEventForLevel:(RollbarLevel)level status:(NSString *)status extraData:(NSDictionary *)extraData { + [[RollbarTelemetry sharedInstance] recordConnectivityEventForLevel:level status:status extraData:extraData]; @@ -454,6 +536,7 @@ + (void)recordConnectivityEventForLevel:(RollbarLevel)level + (void)recordErrorEventForLevel:(RollbarLevel)level message:(NSString *)message { + [self recordErrorEventForLevel:level message:message extraData:nil]; @@ -461,6 +544,7 @@ + (void)recordErrorEventForLevel:(RollbarLevel)level + (void)recordErrorEventForLevel:(RollbarLevel)level exception:(NSException *)exception { + [self recordErrorEventForLevel:level message:exception.reason extraData:@{@"description": exception.description, @@ -471,6 +555,7 @@ + (void)recordErrorEventForLevel:(RollbarLevel)level + (void)recordErrorEventForLevel:(RollbarLevel)level message:(NSString *)message extraData:(NSDictionary *)extraData { + [[RollbarTelemetry sharedInstance] recordErrorEventForLevel:level message:message extraData:extraData]; @@ -481,6 +566,7 @@ + (void)recordErrorEventForLevel:(RollbarLevel)level + (void)recordNavigationEventForLevel:(RollbarLevel)level from:(NSString *)from to:(NSString *)to { + [self recordNavigationEventForLevel:level from:from to:to @@ -491,6 +577,7 @@ + (void)recordNavigationEventForLevel:(RollbarLevel)level from:(NSString *)from to:(NSString *)to extraData:(NSDictionary *)extraData { + [[RollbarTelemetry sharedInstance] recordNavigationEventForLevel:level from:from to:to @@ -501,6 +588,7 @@ + (void)recordNavigationEventForLevel:(RollbarLevel)level + (void)recordManualEventForLevel:(RollbarLevel)level withData:(NSDictionary *)extraData { + [[RollbarTelemetry sharedInstance] recordManualEventForLevel:level withData:extraData]; } @@ -509,6 +597,7 @@ + (void)recordManualEventForLevel:(RollbarLevel)level + (void)recordLogEventForLevel:(RollbarLevel)level message:(NSString *)message { + [self recordLogEventForLevel:level message:message extraData:nil]; @@ -517,6 +606,7 @@ + (void)recordLogEventForLevel:(RollbarLevel)level + (void)recordLogEventForLevel:(RollbarLevel)level message:(NSString *)message extraData:(NSDictionary *)extraData { + [[RollbarTelemetry sharedInstance] recordLogEventForLevel:level message:message extraData:extraData]; diff --git a/RollbarNotifier/Sources/RollbarNotifier/RollbarLogger.m b/RollbarNotifier/Sources/RollbarNotifier/RollbarLogger.m index 66372066..d6fb0ffa 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/RollbarLogger.m +++ b/RollbarNotifier/Sources/RollbarNotifier/RollbarLogger.m @@ -708,6 +708,7 @@ -(NSSet *)getScrubFields { #pragma mark - LEGACY payload data builders - (void)queuePayload:(NSDictionary *)payload { + [self performSelector:@selector(queuePayload_OnlyCallOnThread:) onThread:rollbarThread withObject:payload @@ -716,17 +717,24 @@ - (void)queuePayload:(NSDictionary *)payload { } - (void)queuePayload_OnlyCallOnThread:(NSDictionary *)payload { - NSFileHandle *fileHandle = - [NSFileHandle fileHandleForWritingAtPath:queuedItemsFilePath]; - [fileHandle seekToEndOfFile]; + NSError *error = nil; - [fileHandle writeData:[NSJSONSerialization rollbar_dataWithJSONObject:payload - options:0 - error:&error - safe:true]]; - if (error) { - RollbarSdkLog(@"Error: %@", [error localizedDescription]); + NSData *data = [NSJSONSerialization rollbar_dataWithJSONObject:payload + options:0 + error:&error + safe:true]; + if (nil == data) { + + RollbarSdkLog(@"Couldn't generate and save JSON data from: %@", payload); + if (error) { + RollbarSdkLog(@" Error: %@", [error localizedDescription]); + } + return; } + + NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:queuedItemsFilePath]; + [fileHandle seekToEndOfFile]; + [fileHandle writeData:data]; [fileHandle writeData:[@"\n" dataUsingEncoding:NSUTF8StringEncoding]]; [fileHandle closeFile]; [[RollbarTelemetry sharedInstance] clearAllData]; @@ -737,15 +745,54 @@ - (BOOL)sendItem:(NSDictionary *)payload RollbarPayload *rollbarPayload = [[RollbarPayload alloc] initWithDictionary:[payload copy]]; + if (nil == rollbarPayload) { + + RollbarSdkLog( + @"Couldn't init and send RollbarPayload with data: %@", + payload + ); +// queueState[@"offset"] = [NSNumber numberWithUnsignedInteger:nextOffset]; +// queueState[@"retry_count"] = [NSNumber numberWithUnsignedInteger:0]; +// [RollbarLogger saveQueueState]; + return YES; // no retry needed + } NSMutableDictionary *newPayload = [NSMutableDictionary dictionaryWithDictionary:payload]; [RollbarPayloadTruncator truncatePayload:newPayload]; + if (nil == newPayload) { + + RollbarSdkLog( + @"Couldn't send truncated payload that is nil" + ); +// queueState[@"offset"] = [NSNumber numberWithUnsignedInteger:nextOffset]; +// queueState[@"retry_count"] = [NSNumber numberWithUnsignedInteger:0]; +// [RollbarLogger saveQueueState]; + return YES; // no retry needed + } + NSError *error; NSData *jsonPayload = [NSJSONSerialization rollbar_dataWithJSONObject:newPayload options:0 - error:nil + error:&error safe:true]; + if (nil == jsonPayload) { + + RollbarSdkLog( + @"Couldn't send jsonPayload that is nil" + ); + if (nil != error) { + + RollbarSdkLog( + @" DETAILS: an error while generating JSON data: %@", + error + ); + } +// queueState[@"offset"] = [NSNumber numberWithUnsignedInteger:nextOffset]; +// queueState[@"retry_count"] = [NSNumber numberWithUnsignedInteger:0]; +// [RollbarLogger saveQueueState]; + return YES; // no retry needed + } if (NSOrderedDescending != [nextSendTime compare: [[NSDate alloc] init] ]) { @@ -790,6 +837,7 @@ - (BOOL)sendItem:(NSDictionary *)payload } } else { + RollbarSdkLog( @"Omitting payload until nextSendTime is reached: %@", [[NSString alloc] initWithData:jsonPayload encoding:NSUTF8StringEncoding] @@ -806,6 +854,18 @@ - (BOOL)sendItem:(NSDictionary *)payload - (BOOL)sendPayload:(nonnull NSData *)payload usingConfig:(nonnull RollbarConfig *)config { + if ((nil == payload) + || (nil == self.configuration) + || (nil == self.configuration.destination) + || (nil == self.configuration.destination.endpoint) + || (nil == self.configuration.destination.accessToken) + || (0 == self.configuration.destination.endpoint.length) + || (0 == self.configuration.destination.accessToken.length) + ) { + + return NO; + } + NSURL *url = [NSURL URLWithString:config.destination.endpoint]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; @@ -874,6 +934,18 @@ - (BOOL)sendPayload:(nonnull NSData *)payload /// Use/maintain sendPayload:usingConfig: instead! - (BOOL)sendPayload:(NSData *)payload { + if ((nil == payload) + || (nil == self.configuration) + || (nil == self.configuration.destination) + || (nil == self.configuration.destination.endpoint) + || (nil == self.configuration.destination.accessToken) + || (0 == self.configuration.destination.endpoint.length) + || (0 == self.configuration.destination.accessToken.length) + ) { + + return NO; + } + NSURL *url = [NSURL URLWithString:self.configuration.destination.endpoint]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; diff --git a/RollbarNotifier/Sources/RollbarNotifier/RollbarPayloadTruncator.m b/RollbarNotifier/Sources/RollbarNotifier/RollbarPayloadTruncator.m index efd89d4b..b1d08fd7 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/RollbarPayloadTruncator.m +++ b/RollbarNotifier/Sources/RollbarNotifier/RollbarPayloadTruncator.m @@ -34,6 +34,7 @@ +(void)truncatePayloads:(NSArray*)payloads { +(void)truncatePayloads:(NSArray*)payloads toMaxByteSize:(unsigned long)maxByteSize { + [payloads enumerateObjectsUsingBlock: ^(id item, NSUInteger idx, BOOL *stop) { [RollbarPayloadTruncator truncatePayload:item toTotalBytes:maxByteSize]; @@ -41,11 +42,13 @@ +(void)truncatePayloads:(NSArray*)payloads } +(void)truncatePayload:(NSMutableDictionary*)payload { + [RollbarPayloadTruncator truncatePayload:payload toTotalBytes:payloadTotalBytesLimit]; } +(void)truncatePayload:(NSMutableDictionary*)payload toTotalBytes:(unsigned long) limit { + BOOL continueTruncation = [RollbarPayloadTruncator truncatePayload:payload toTotalBytes:limit @@ -54,6 +57,7 @@ +(void)truncatePayload:(NSMutableDictionary*)payload keepingTailsCount:payloadTailFramesToKeep ]; if (continueTruncation) { + continueTruncation = [RollbarPayloadTruncator truncatePayload:payload toTotalBytes:limit @@ -65,6 +69,7 @@ +(void)truncatePayload:(NSMutableDictionary*)payload unsigned long stringLimit = maxStringBytesLimit; while (continueTruncation && (stringLimit >= minStringBytesLimit)) { + continueTruncation = [RollbarPayloadTruncator truncatePayload:payload toTotalBytes:limit byLimitingStringBytes:stringLimit @@ -73,6 +78,7 @@ +(void)truncatePayload:(NSMutableDictionary*)payload } if (continueTruncation) { + continueTruncation = [RollbarPayloadTruncator truncatePayload:payload toTotalBytes:limit withExceptionMessageLimit:maxExceptionMessageChars @@ -81,21 +87,28 @@ +(void)truncatePayload:(NSMutableDictionary*)payload } if (continueTruncation) { + [RollbarPayloadTruncator limitRawCrashReportInPayload:payload]; } } +(void)limitRawCrashReportInPayload:(NSMutableDictionary *)payload { + id raw = [payload valueForKeyPath:pathToRaw]; if (!raw || raw == [NSNull null]) { + return; } + if ([raw isKindOfClass:[NSMutableString class]] && ![RollbarPayloadTruncator isMutable:raw]) { + NSMutableString *mutableRaw = [raw mutableCopy]; payload[@"body"][@"crash_report"][@"raw"] = mutableRaw; [mutableRaw setString:[RollbarPayloadTruncator truncateString:mutableRaw toTotalBytes:minRawStringByteLimit]]; - } else { + } + else { + [raw setString:[RollbarPayloadTruncator truncateString:raw toTotalBytes:minRawStringByteLimit]]; } @@ -107,35 +120,46 @@ +(BOOL) truncatePayload:(NSMutableDictionary*)payload andTraceFramesLimit:(unsigned long)traceFramesLimit { if (nil == payload) { + return FALSE; } if (![RollbarPayloadTruncator isTruncationNeeded:payload forLimit:payloadLimit]) { + return FALSE; //payload is small enough, no need to truncate further... } id value = [payload valueForKeyPath:pathToTraceChain]; - if (value == [NSNull null] || value == nil) - { - value = [NSMutableArray arrayWithObject:[payload valueForKeyPath:pathToTrace]]; + if (value == [NSNull null] || value == nil) { + + id traceElement = [payload valueForKeyPath:pathToTrace]; + if (nil != traceElement) { + + value = [NSMutableArray arrayWithObject:traceElement]; + } } if (value == nil || value == [NSNull null]) { + return TRUE; } NSMutableArray *traces = (NSMutableArray *) value; [traces enumerateObjectsUsingBlock:^(id item, NSUInteger idx, BOOL *stop) { + NSMutableDictionary *exception = [item objectForKey:@"exception"]; if (nil != exception) { + [exception removeObjectForKey:@"description"]; NSMutableString *message = [exception objectForKey:@"message"]; if (nil != message && message.length > exeptionMessageLimit) { + [exception setObject:[message substringWithRange:NSMakeRange(0, exeptionMessageLimit)] forKey:@"message"]; } } NSMutableArray *frames = [item objectForKey:@"frames"]; if (frames) { + [frames removeObjectsInRange:NSMakeRange(traceFramesLimit, frames.count - traceFramesLimit)]; } }]; @@ -148,6 +172,7 @@ +(BOOL)truncatePayload:(NSMutableDictionary*)payload byLimitingStringBytes:(unsigned long)stringBytesLimit { if (![RollbarPayloadTruncator isTruncationNeeded:payload forLimit:payloadLimit]) { + return FALSE; //payload is small enough, no need to truncate further... } @@ -160,18 +185,23 @@ +(BOOL)truncatePayload:(NSMutableDictionary*)payload +(void)itereateObjectStructure:(id)obj whileTuncatingStrings:(unsigned long)stringBytesLimit { if ([obj isKindOfClass:[NSMutableString class]] && [RollbarPayloadTruncator isMutable:obj]) { + //truncate the string obj: [obj setString:[RollbarPayloadTruncator truncateString:obj toTotalBytes:stringBytesLimit] ]; - } else if ([obj isKindOfClass:[NSArray class]]) { + } + else if ([obj isKindOfClass:[NSArray class]]) { + //recurse the collection obj's items: [obj enumerateObjectsUsingBlock: ^(id item, NSUInteger idx, BOOL *stop) { [RollbarPayloadTruncator itereateObjectStructure:item whileTuncatingStrings:stringBytesLimit ]; }]; - } else if ([obj isKindOfClass:[NSDictionary class]]) { + } + else if ([obj isKindOfClass:[NSDictionary class]]) { + //recurse the collection obj's items: [obj enumerateKeysAndObjectsUsingBlock: ^(id key, id item, BOOL *stop) { if (![key isEqualToString:@"raw"]) { @@ -186,19 +216,23 @@ +(void)itereateObjectStructure:(id)obj whileTuncatingStrings:(unsigned long)stri } } }]; - } else if ([obj isKindOfClass:[NSSet class]]) { + } + else if ([obj isKindOfClass:[NSSet class]]) { + //recurse the collection obj's items: [obj enumerateObjectsUsingBlock: ^(id item, BOOL *stop) { [RollbarPayloadTruncator itereateObjectStructure:item whileTuncatingStrings:stringBytesLimit ]; }]; - } else { + } + else { //nothing really... } } +(BOOL)isMutable:(id)str { + NSString *copy = [str copy]; return copy != str; } @@ -210,6 +244,7 @@ +(BOOL)truncatePayload:(NSMutableDictionary*)payload keepingTailsCount:(unsigned long)tailsCount { if (![RollbarPayloadTruncator isTruncationNeeded:payload forLimit:payloadLimit]) { + return FALSE; //payload is small enough, no need to truncate further... } @@ -225,10 +260,12 @@ +(BOOL)truncatePayload:(NSMutableDictionary*)payload id value = [payload valueForKeyPath:pathToItems]; if (value == [NSNull null] || [value isKindOfClass:[NSNull class]]) { + return TRUE; } if ([value isKindOfClass:[NSArray class]]) { + NSMutableArray *items = ((NSArray *)value).mutableCopy; if (items.count <= (headsCount + tailsCount)) { return TRUE; @@ -276,6 +313,7 @@ +(NSString*)truncateString:(NSString*)inputString // let's take care if the trivial cases first: if (currentStringEncoodingBytes <= totalBytesLimit) { + // no need to truncate: return inputString; } @@ -284,6 +322,7 @@ +(NSString*)truncateString:(NSString*)inputString const unsigned long totalEllipsisEncodingBytes = [RollbarPayloadTruncator measureTotalEncodingBytes:ellipsis]; if (totalEllipsisEncodingBytes >= totalBytesLimit) { + // we have to have at least the ellipsis as a reasult of a string truncation: return ellipsis; } @@ -292,6 +331,7 @@ +(NSString*)truncateString:(NSString*)inputString NSUInteger cutOffCodeUnitIndex = (totalBytesLimit - totalEllipsisEncodingBytes); if (cutOffCodeUnitIndex >= inputString.length) { + cutOffCodeUnitIndex = inputString.length - 1; // valid index == no trouble down the road... } NSRange cutOffCharRange = [inputString rangeOfComposedCharacterSequenceAtIndex:cutOffCodeUnitIndex]; @@ -303,6 +343,7 @@ +(NSString*)truncateString:(NSString*)inputString currentStringEncoodingBytes = [RollbarPayloadTruncator measureTotalEncodingBytes:result]; while (currentStringEncoodingBytes > (totalBytesLimit - totalEllipsisEncodingBytes)) { + cutOffCharRange = [result rangeOfComposedCharacterSequenceAtIndex:(result.length - 1)]; [result deleteCharactersInRange:cutOffCharRange]; currentStringEncoodingBytes = [RollbarPayloadTruncator measureTotalEncodingBytes:result]; diff --git a/RollbarNotifier/Sources/RollbarNotifier/RollbarReachability.m b/RollbarNotifier/Sources/RollbarNotifier/RollbarReachability.m index 000fb612..b010678d 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/RollbarReachability.m +++ b/RollbarNotifier/Sources/RollbarNotifier/RollbarReachability.m @@ -115,6 +115,11 @@ +(RollbarReachability*)reachabilityWithHostName:(NSString*)hostname +(RollbarReachability*)reachabilityWithHostname:(NSString*)hostname { + if ((nil == hostname) || (nil == [hostname UTF8String])) { + + return nil; + } + SCNetworkReachabilityRef ref = SCNetworkReachabilityCreateWithName(NULL, [hostname UTF8String]); if (ref) { diff --git a/RollbarNotifier/Sources/RollbarNotifier/include/RollbarLevel.h b/RollbarNotifier/Sources/RollbarNotifier/include/RollbarLevel.h index f63b2c1b..388d4512 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/include/RollbarLevel.h +++ b/RollbarNotifier/Sources/RollbarNotifier/include/RollbarLevel.h @@ -25,7 +25,7 @@ NS_ASSUME_NONNULL_BEGIN /// Converts string value into its RollbarLevel enum value equivalent or default enum value. /// @param value input string -+ (RollbarLevel) RollbarLevelFromString:(NSString *)value; ++ (RollbarLevel) RollbarLevelFromString:(nullable NSString *)value; @end diff --git a/RollbarNotifier/Sources/RollbarNotifier/include/RollbarSource.h b/RollbarNotifier/Sources/RollbarNotifier/include/RollbarSource.h index 704822f2..8a510d20 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/include/RollbarSource.h +++ b/RollbarNotifier/Sources/RollbarNotifier/include/RollbarSource.h @@ -27,7 +27,7 @@ NS_ASSUME_NONNULL_BEGIN /// Convert RollbarSource value from a string /// @param value string representation of a RollbarSource value -+ (RollbarSource) RollbarSourceFromString:(NSString *)value; ++ (RollbarSource) RollbarSourceFromString:(nullable NSString *)value; @end diff --git a/RollbarNotifier/Sources/RollbarNotifier/include/RollbarTelemetryEvent.h b/RollbarNotifier/Sources/RollbarNotifier/include/RollbarTelemetryEvent.h index 06366358..930baf4b 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/include/RollbarTelemetryEvent.h +++ b/RollbarNotifier/Sources/RollbarNotifier/include/RollbarTelemetryEvent.h @@ -70,7 +70,7 @@ NS_UNAVAILABLE; #pragma mark - Class utility -+ (nullable RollbarTelemetryBody *)createTelemetryBodyWithType:(RollbarTelemetryType)type ++ (RollbarTelemetryBody *)createTelemetryBodyWithType:(RollbarTelemetryType)type data:(nullable NSDictionary *)data; @end diff --git a/RollbarNotifier/Sources/RollbarNotifier/include/RollbarTelemetryType.h b/RollbarNotifier/Sources/RollbarNotifier/include/RollbarTelemetryType.h index 39bb1180..40e649d7 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/include/RollbarTelemetryType.h +++ b/RollbarNotifier/Sources/RollbarNotifier/include/RollbarTelemetryType.h @@ -28,7 +28,7 @@ NS_ASSUME_NONNULL_BEGIN /// Converts string value into its RollbarTelemetryType enum value equivalent or default enum value. /// @param value input string -+ (RollbarTelemetryType) RollbarTelemetryTypeFromString:(NSString *)value; ++ (RollbarTelemetryType) RollbarTelemetryTypeFromString:(nullable NSString *)value; @end diff --git a/RollbarPLCrashReporter.podspec b/RollbarPLCrashReporter.podspec index df6e3188..9f6cd771 100644 --- a/RollbarPLCrashReporter.podspec +++ b/RollbarPLCrashReporter.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| - s.version = "2.0.0-beta.21" + s.version = "2.0.0-beta.22" s.name = "RollbarPLCrashReporter" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." s.description = <<-DESC diff --git a/RollbarSDK.experimental_podspec b/RollbarSDK.experimental_podspec index 94ff7479..3de4b330 100644 --- a/RollbarSDK.experimental_podspec +++ b/RollbarSDK.experimental_podspec @@ -9,7 +9,7 @@ Pod::Spec.new do |sdk| # Rollbar SDK: # ============ - sdk.version = "2.0.0-beta.21" + sdk.version = "2.0.0-beta.22" sdk.name = "RollbarSDK" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." sdk.description = <<-DESC diff --git a/RollbarSwift.podspec b/RollbarSwift.podspec index 54358f15..b18e3da9 100644 --- a/RollbarSwift.podspec +++ b/RollbarSwift.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| - s.version = "2.0.0-beta.21" + s.version = "2.0.0-beta.22" s.name = "RollbarSwift" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." s.description = <<-DESC