Skip to content

Commit

Permalink
[iOS] NR-178366: Log reporting (#169)
Browse files Browse the repository at this point in the history
* [7.4.7-rc.589] Staging Release

* do cocoapods, then swift pm

* push SPM change for 7.4.7

* Branching from the main for beta tests (#133)

* Branching from the main for beta tests

* This should fix the tvOS beta not being found

* Added tvOS app tests

* Added a step to the app unit tests to add a secret api key

* Fixed some typos

* [7.4.7] Production Release (#159)

* [create-pull-request] automated change

* Fix auto-prod PR to include Cocoapod spec update

---------

Co-authored-by: cdillard-NewRelic <[email protected]>
Co-authored-by: Chris Dillard <[email protected]>

* push log reporting back to working state

* Add entity.guid back into NRLogger payload.

* [7.4.8-rc.710] Staging Release

* Include Prod Podspec Job by default in productionDeploy

* Verbose logging to Loggin endpoint

* log sessionId on logs endpoint success

* ws fix

* push WIP for /connect config parse

* Code dynamic enable/disable of LogReporting based on connect response

* Remote logging config

* [create-pull-request] automated change

* Initial pass at handling 409 to reconnect and fetch new config

* Send Support Metric kNRMAConfigurationUpdated when Logging Config is updated

* Impl setLogEntityGuid

* feat: Remote Logging with manual set entityGuid and ingestKey feature complete.

* NR-220019: App Token auth

* NR-220019: Adds GHA for Bespoke Branch Based Build (#198)

* Add 100 logs test, fix levelToString for "level" attribute on log messages.

* NR-228761: Implement uploadQueue for log data, NRLoggerTests

* Logs fix

* Use correct endpoints for logging

* NR-223195: Support metric for success and failure remote logging

* NR-227297: logErrorObject impl, NR-227300: logAttributes impl

* Log attributes

* Temporarily remove LogReporting

* fix tvOS job Xcode version in GHA

---------

Co-authored-by: cdillard-NewRelic <[email protected]>
Co-authored-by: mbruin-NR <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Apr 25, 2024
1 parent 28bdf58 commit e8ab3e8
Show file tree
Hide file tree
Showing 32 changed files with 817 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:

- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '14.2'
xcode-version: '14.3'

- name: Install lcov
run: brew install lcov
Expand Down
8 changes: 8 additions & 0 deletions Agent.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,8 @@
2BA9CA45280DF87A00FDCD00 /* NRMAHarvesterConnection+GZip.m in Sources */ = {isa = PBXBuildFile; fileRef = 2BA9CA42280DF87A00FDCD00 /* NRMAHarvesterConnection+GZip.m */; };
2BA9CA46280DF87A00FDCD00 /* NRMAHarvesterConnection+GZip.m in Sources */ = {isa = PBXBuildFile; fileRef = 2BA9CA42280DF87A00FDCD00 /* NRMAHarvesterConnection+GZip.m */; };
2BBBE70E28BD528F003CADF3 /* NRMAStartTimerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2BBBE70D28BD528F003CADF3 /* NRMAStartTimerTests.m */; };
2BCA57B42B7E85AD00991C5E /* NRLoggerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2BCA57B32B7E85AD00991C5E /* NRLoggerTests.m */; };
2BCA57B52B7E85AD00991C5E /* NRLoggerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2BCA57B32B7E85AD00991C5E /* NRLoggerTests.m */; };
2BDCA8A42A8C40D50005740D /* NRMASAM.h in Headers */ = {isa = PBXBuildFile; fileRef = 2BDCA8A32A8C40D50005740D /* NRMASAM.h */; };
2BDCA8A52A8C40D50005740D /* NRMASAM.h in Headers */ = {isa = PBXBuildFile; fileRef = 2BDCA8A32A8C40D50005740D /* NRMASAM.h */; };
2BDCA8AA2A8C41160005740D /* NRMASAM.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2BDCA8A92A8C41160005740D /* NRMASAM.mm */; };
Expand Down Expand Up @@ -1886,6 +1888,8 @@
2BA9CA42280DF87A00FDCD00 /* NRMAHarvesterConnection+GZip.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NRMAHarvesterConnection+GZip.m"; sourceTree = "<group>"; };
2BBBE6FA28BD528F003CADF3 /* NRMAStartTimerTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NRMAStartTimerTests.h; sourceTree = "<group>"; };
2BBBE70D28BD528F003CADF3 /* NRMAStartTimerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NRMAStartTimerTests.m; sourceTree = "<group>"; };
2BCA579F2B7E85AD00991C5E /* NRLoggerTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NRLoggerTests.h; sourceTree = "<group>"; };
2BCA57B32B7E85AD00991C5E /* NRLoggerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NRLoggerTests.m; sourceTree = "<group>"; };
2BDCA8A32A8C40D50005740D /* NRMASAM.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NRMASAM.h; sourceTree = "<group>"; };
2BDCA8A92A8C41160005740D /* NRMASAM.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NRMASAM.mm; sourceTree = "<group>"; };
2BDCA8B02A8C43040005740D /* NRMASAMTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NRMASAMTest.mm; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2326,6 +2330,8 @@
0209AC7524E7392E00E45C90 /* NewRelicNonJenkinsTests-Bridging-Header.h */,
0209AC7124E7392E00E45C90 /* NRCPUVitalsTest.h */,
0209AC8224E7393100E45C90 /* NRCPUVitalsTest.m */,
2BCA579F2B7E85AD00991C5E /* NRLoggerTests.h */,
2BCA57B32B7E85AD00991C5E /* NRLoggerTests.m */,
0209AC7924E7392F00E45C90 /* NRCustomMetricsTests.h */,
0209AC8624E7393200E45C90 /* NRCustomMetricsTests.m */,
0209AC8B24E7393300E45C90 /* NRMA_Swift_Trouble_Class.h */,
Expand Down Expand Up @@ -4340,6 +4346,7 @@
0209AC3F24E7075200E45C90 /* NRHarvesterStateTest.m in Sources */,
0209AC2F24E7073800E45C90 /* NRMAHarvestableHTTPReqeustTests.m in Sources */,
0209ABD724E706AE00E45C90 /* TestHexUploader.m in Sources */,
2BCA57B42B7E85AD00991C5E /* NRLoggerTests.m in Sources */,
0209AC2924E7071F00E45C90 /* NRMeasurementPoolTest.m in Sources */,
0209AC0324E7070900E45C90 /* NRMASessionExclusivityWithDelegateTests.m in Sources */,
0209AC8E24E7393300E45C90 /* NRThreadTest.m in Sources */,
Expand Down Expand Up @@ -4575,6 +4582,7 @@
2B40F4FF28BEB95E00EAD248 /* NRMAStartTimerTests.m in Sources */,
025657FC24EB19BF00FE3125 /* TestUITableViewInstrumentation.m in Sources */,
025657FD24EB19BF00FE3125 /* TestHexUploadPublisher.mm in Sources */,
2BCA57B52B7E85AD00991C5E /* NRLoggerTests.m in Sources */,
025657FE24EB19BF00FE3125 /* NRMetricTests.m in Sources */,
343883572834405700B31C2E /* NRMAURLTransformerTests.m in Sources */,
0256580124EB19BF00FE3125 /* NRMAActingClassUtilsTest.m in Sources */,
Expand Down
10 changes: 5 additions & 5 deletions Agent/Analytics/PersistentEventStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ - (void)setObject:(nonnull id)object forKey:(nonnull id)key {
@synchronized (store) {
store[key] = object;
_dirty = YES;
NRLOG_VERBOSE(@"Marked dirty for adding");
NRLOG_AUDIT(@"Marked dirty for adding");
}

NRLOG_VERBOSE(@"Scheduling block");
NRLOG_AUDIT(@"Scheduling block");
[self performWrite: ^ {
NRLOG_VERBOSE(@"Entered block");
NRLOG_AUDIT(@"Entered block");
@synchronized (self) {
if(!self->_dirty) {
NRLOG_VERBOSE(@"Not writing file because it's not dirty");
NRLOG_AUDIT(@"Not writing file because it's not dirty");
return;
}
}
Expand Down Expand Up @@ -157,7 +157,7 @@ - (void)saveToFile {
if(!success) {
NRLOG_ERROR(@"Error saving data: %@", error.description);
} else {
NRLOG_VERBOSE(@"Wrote file");
NRLOG_AUDIT(@"Wrote file");
_lastSave = [NSDate new];
}
}
Expand Down
12 changes: 7 additions & 5 deletions Agent/CrashHandler/NRMACrashDataUploader.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ - (void) uploadFileAtPath:(NSURL*)path
// Get the size in bytes of the crash report to be uploaded via below uploadTaskWithRequest:fromFile call.
__block NSData* reqData = [NSData dataWithContentsOfURL:path options:0 error:nil];
NSURLRequest* request = [self buildPost];

if ([reqData length] > kNRMAMaxPayloadSizeLimit) {
NRLOG_ERROR(@"Unable to upload crash log because payload is larger than 1 MB, discarding crash report");
[NRMASupportMetricHelper enqueueMaxPayloadSizeLimitMetric:@"mobile_crash"];
Expand All @@ -133,16 +133,18 @@ - (void) uploadFileAtPath:(NSURL*)path
__NRMACrashDataUploaderInProgressRequestCount = __NRMACrashDataUploaderInProgressRequestCount - 1;

return;
}

}

NRLOG_VERBOSE(@"NEWRELIC CRASH UPLOADER - Perform crash upload");

[[self.uploadSession uploadTaskWithRequest:request fromFile:path completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable responseError) {
__NRMACrashDataUploaderInProgressRequestCount = __NRMACrashDataUploaderInProgressRequestCount - 1;

NRLOG_VERBOSE(@"NEWRELIC CRASH UPLOADER - Crash Upload Response: %@", response);
if(responseError) {
NRLOG_ERROR(@"NEWRELIC CRASH UPLOADER - Crash Upload Response Error: %@", responseError);
}

if ([response isKindOfClass:[NSHTTPURLResponse class]]) {

unsigned long long requestLength = [reqData length];
Expand Down Expand Up @@ -200,7 +202,7 @@ - (BOOL) shouldUploadFileWithUniqueIdentifier:(NSString*)key {
if (value.integerValue > kNRMAMaxCrashUploadRetry) {
[self stopTrackingFileUploadWithUniqueIdentifier:key];


return NO;
}

Expand Down
6 changes: 3 additions & 3 deletions Agent/FeatureFlags/NRMAFlags.m
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ + (BOOL) shouldEnableOfflineStorage {
}

+ (BOOL) shouldEnableLogReporting {
// TODO: LogReporting
return NO;
//return ([NRMAFlags featureFlags] & NRFeatureFlag_LogReporting) != 0;
// return ([NRMAFlags featureFlags] & NRFeatureFlag_LogReporting) != 0;
}
+ (BOOL) shouldEnableNewEventSystem {
return ([NRMAFlags featureFlags] & NRFeatureFlag_NewEventSystem) != 0;
Expand Down Expand Up @@ -231,8 +232,7 @@ + (BOOL) shouldEnableBackgroundReporting {
if ((flags & NRFeatureFlag_OfflineStorage) == NRFeatureFlag_OfflineStorage) {
[retArray addObject:@"OfflineStorage"];
}

// NOTE: Temporarily removed NRFeatureFlag_LogReporting
// TODO: LogReporting
// if ((flags & NRFeatureFlag_LogReporting) == NRFeatureFlag_LogReporting) {
// [retArray addObject:@"LogReporting"];
// }
Expand Down
2 changes: 1 addition & 1 deletion Agent/HandledException/NRMAHexUploader.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ - (void) URLSession:(NSURLSession*)session
}
[self handledErroredRequest:task.originalRequest];
} else {
NRLOG_ERROR(@"NEWRELIC HEX UPLOADER - Handled exception upload completed successfully");
NRLOG_VERBOSE(@"NEWRELIC HEX UPLOADER - Handled exception upload completed successfully");
}
}

Expand Down
11 changes: 7 additions & 4 deletions Agent/Harvester/DataStore/NRMAAgentConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@

@class NRMAAppToken;

// Collector Hosts.
#define kNRMA_DEFAULT_COLLECTOR_HOST @"mobile-collector.newrelic.com"
#define kNRMA_DEFAULT_CRASH_COLLECTOR_HOST @"mobile-crash.newrelic.com"
#define kNRMA_FEDRAMP_COLLECTOR_HOST @"gov-mobile-collector.newrelic.com"
#define KNRMA_FEDRAMP_CRASH_COLLECTOR_HOST @"gov-mobile-crash.newrelic.com"
#define kNRMA_REGION_SPECIFIC_COLLECTOR_HOST @"mobile-collector.%@.nr-data.net"
#define kNRMA_REGION_SPECIFIC_CRASH_HOST @"mobile-crash.%@.nr-data.net"

#define kNRMA_DEFAULT_LOGGING_HOST @"log-api.newrelic.com"
#define kNRMA_REGION_SPECIFIC_LOGGING_HOST @"log-api.%@.newrelic.com"
#define kNRMA_STAGING_LOGGING_HOST @"staging-log-api.newrelic.com"
#define kNRMA_FEDRAMP_LOGGING_HOST @"gov-log-api.newrelic.com"
// Logging Hosts.
#define kNRMA_DEFAULT_LOGGING_HOST @"mobile-collector.newrelic.com"
#define kNRMA_REGION_SPECIFIC_LOGGING_HOST @"mobile-collector.%@.nr-data.net"
#define kNRMA_STAGING_LOGGING_HOST @"staging-mobile-collector.newrelic.com"
#define kNRMA_FEDRAMP_LOGGING_HOST @"gov-mobile-collector.newrelic.com"
#define kNRMA_STAGING_FEDRAMP_LOGGING_HOST @"gov-staging-mobile-collector.newrelic"

@interface NRMAAgentConfiguration : NSObject

Expand Down
19 changes: 12 additions & 7 deletions Agent/Harvester/DataStore/NRMAAgentConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,25 +127,30 @@ - (void) setCrashCollectorHost:(NSString*)host {
}

- (void) setLoggingURL {
if (![NRMAFlags shouldEnableLogReporting]) { return; }

if (self.applicationToken.regionCode.length) {
_loggingURL = [NSString stringWithFormat:kNRMA_REGION_SPECIFIC_LOGGING_HOST,self.applicationToken.regionCode];
}
else if ([NRMAFlags shouldEnableFedRampSupport]) {
if ([self.collectorHost isEqualToString:@"staging-mobile-collector.newrelic.com"]) {
_loggingURL = kNRMA_STAGING_FEDRAMP_LOGGING_HOST;
}
else {
_loggingURL = kNRMA_FEDRAMP_LOGGING_HOST;
}
}
else if ([self.collectorHost isEqualToString:@"staging-mobile-collector.newrelic.com"]) {
_loggingURL = kNRMA_STAGING_LOGGING_HOST;
}
else if ([NRMAFlags shouldEnableFedRampSupport]) {
_loggingURL = kNRMA_FEDRAMP_LOGGING_HOST;
}
else {
_loggingURL = kNRMA_DEFAULT_LOGGING_HOST;
}
_loggingURL = [_loggingURL stringByAppendingFormat:@"/log/v1"];
_loggingURL = [_loggingURL stringByAppendingFormat:@"/mobile/logs"];

NSString* logURL = [NSString stringWithFormat:@"%@%@", @"https://", _loggingURL];

[NRLogger setLogURL:logURL];

[NRLogger setLogIngestKey:self.applicationToken.value];
}

+ (NRMAConnectInformation*) connectionInformation
Expand Down
1 change: 1 addition & 0 deletions Agent/Harvester/DataStore/NRMAHarvestResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define UNAUTHORIZED 401
#define FORBIDDEN 403
#define NOT_FOUND 404
#define CONFIGURATION_UPDATE 409
#define ENTITY_TOO_LARGE 413
#define INVALID_AGENT_ID 450
#define UNSUPPORTED_MEDIA_TYPE 415
Expand Down
1 change: 1 addition & 0 deletions Agent/Harvester/DataStore/NRMAHarvestResponse.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ - (int) getResponseCode
case FORBIDDEN:
case INVALID_AGENT_ID:
case UNSUPPORTED_MEDIA_TYPE:
case CONFIGURATION_UPDATE:
return self.statusCode;
break;
default:
Expand Down
8 changes: 8 additions & 0 deletions Agent/Harvester/DataStore/NRMAHarvesterConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#define kNRMA_ACCOUNT_ID @"account_id"
#define kNMRA_APPLICATION_ID @"application_id"
#define kNRMA_TRUSTED_ACCOUNT_KEY @"trusted_account_key"
#define kNRMA_ENTITY_GUID_KEY @"entity_guid"
#define kNRMA_LOG_REPORTING_KEY @"log_reporting"

#define NRMA_DEFAULT_COLLECT_NETWORK_ERRORS YES // boolean
#define NRMA_DEFAULT_REPORT_PERIOD 60 // seconds
Expand Down Expand Up @@ -60,6 +62,12 @@
@property(nonatomic,assign) long long account_id;
@property(nonatomic,assign) long long application_id;
@property(nonatomic,strong) NSString* trusted_account_key;
@property(nonatomic,strong) NSString* entity_guid;
@property(nonatomic,assign) BOOL log_reporting_enabled;

// CAN BE
// NONE < ERROR < WARN < INFO < DEBUG < AUDIT < VERBOSE
@property(nonatomic,assign) NSString* log_reporting_level;

+ (id) defaultHarvesterConfiguration;
- (BOOL) isValid;
Expand Down
28 changes: 27 additions & 1 deletion Agent/Harvester/DataStore/NRMAHarvesterConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ - (id) initWithDictionary:(NSDictionary*)dict
self.application_id = [[dict valueForKey:kNMRA_APPLICATION_ID] longLongValue];
self.trusted_account_key = [dict valueForKey:kNRMA_TRUSTED_ACCOUNT_KEY];

if ([dict objectForKey:kNRMA_ENTITY_GUID_KEY]) {
self.entity_guid = [dict valueForKey:kNRMA_ENTITY_GUID_KEY];
} else {
self.entity_guid = @"";
}

// begin parsing log reporting section.
if ([dict objectForKey:kNRMA_LOG_REPORTING_KEY]) {
id innerDict = [dict objectForKey:kNRMA_LOG_REPORTING_KEY];
self.log_reporting_enabled = innerDict[@"enabled"];
self.log_reporting_level = innerDict[@"level"];
}
// end parsing log reporting section.

// The collector does not currently send down this key, but we still want a sane default
if ([dict objectForKey:kNRMA_AT_MAX_SEND_ATTEMPTS]) {
self.activity_trace_max_send_attempts = [[dict valueForKey:kNRMA_AT_MAX_SEND_ATTEMPTS] intValue];
Expand All @@ -110,6 +124,8 @@ + (id) defaultHarvesterConfiguration
configuration.activity_trace_max_send_attempts = NRMA_DEFAULT_ACTIVITY_TRACE_MAX_SEND_ATTEMPTS;
configuration.activity_trace_min_utilization = NRMA_DEFAULT_ACTIVITY_TRACE_MIN_UTILIZATION;
configuration.trusted_account_key = @"";
configuration.entity_guid = @"";
configuration.log_reporting_level = @"WARNING";

configuration.at_capture = [NRMATraceConfigurations defaultTraceConfigurations];
return configuration;
Expand Down Expand Up @@ -148,7 +164,17 @@ - (NSDictionary*) asDictionary
dictionary[kNMRA_APPLICATION_ID] = @(self.application_id);
dictionary[kNRMA_ACCOUNT_ID] = @(self.account_id);
dictionary[kNRMA_ENCODING_KEY] = self.encoding_key;
dictionary[kNRMA_TRUSTED_ACCOUNT_KEY] = self.trusted_account_key;

if ([self.trusted_account_key length]) {
dictionary[kNRMA_TRUSTED_ACCOUNT_KEY] = self.trusted_account_key;
}

if ([self.entity_guid length]) {
dictionary[kNRMA_ENTITY_GUID_KEY] = self.entity_guid;
}

// TODO: Check the right way to handle this inner Dict.
//dictionary[kNRMA_LOG_REPORTING_KEY] = @{@"enabled": @(self.log_reporting_enabled), @"level": self.log_reporting_level};

return dictionary;
}
Expand Down
Loading

0 comments on commit e8ab3e8

Please sign in to comment.