Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[iOS] NR-178366: Log reporting #169

Merged
merged 54 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
e4c1bdd
Merge pull request #153 from newrelic/develop
cdillard-NewRelic Sep 26, 2023
169e81b
[7.4.7-rc.589] Staging Release
cdillard-NewRelic Sep 26, 2023
fdaec87
do cocoapods, then swift pm
cdillard-NewRelic Sep 28, 2023
021bb1d
Merge pull request #156 from newrelic/747prod
cdillard-NewRelic Oct 2, 2023
52251d1
push SPM change for 7.4.7
cdillard-NewRelic Oct 2, 2023
9e1d783
Branching from the main for beta tests (#133)
mbruin-NR Oct 2, 2023
71c95be
[7.4.7] Production Release (#159)
github-actions[bot] Oct 3, 2023
d015703
push log reporting back to working state
cdillard-NewRelic Nov 2, 2023
06a8e6d
Add entity.guid back into NRLogger payload.
cdillard-NewRelic Nov 3, 2023
13f2448
Merge branch 'develop' of github.com:newrelic/newrelic-ios-agent into…
cdillard-NewRelic Nov 20, 2023
622ec3b
Merge branch 'staging' of github.com:newrelic/newrelic-ios-agent into…
cdillard-NewRelic Nov 20, 2023
b6565e3
Merge pull request #185 from newrelic/stage748
cdillard-NewRelic Nov 21, 2023
9c84aa1
[7.4.8-rc.710] Staging Release
cdillard-NewRelic Nov 21, 2023
7356d29
Merge branch 'main' of github.com:newrelic/newrelic-ios-agent into pr…
cdillard-NewRelic Nov 27, 2023
d3a8f81
Merge pull request #187 from newrelic/prod748
cdillard-NewRelic Nov 27, 2023
9a7637d
Include Prod Podspec Job by default in productionDeploy
cdillard-NewRelic Nov 27, 2023
03f581b
Merge pull request #188 from newrelic/includeCpInProductionDeploy
cdillard-NewRelic Nov 27, 2023
7f54869
Merge branch 'develop' of github.com:newrelic/newrelic-ios-agent into…
cdillard-NewRelic Nov 28, 2023
195936c
Verbose logging to Loggin endpoint
cdillard-NewRelic Nov 28, 2023
a0f7706
log sessionId on logs endpoint success
cdillard-NewRelic Nov 28, 2023
31aa27d
ws fix
cdillard-NewRelic Nov 29, 2023
403847e
push WIP for /connect config parse
cdillard-NewRelic Nov 30, 2023
20f11f9
Code dynamic enable/disable of LogReporting based on connect response
cdillard-NewRelic Dec 1, 2023
f23b658
Remote logging config
cdillard-NewRelic Dec 4, 2023
daa3f04
[create-pull-request] automated change
cdillard-NewRelic Dec 11, 2023
05ce315
Initial pass at handling 409 to reconnect and fetch new config
cdillard-NewRelic Dec 12, 2023
a44828a
Merge pull request #191 from newrelic/auto-production-release-7.4.8
cdillard-NewRelic Dec 13, 2023
c6ba333
Send Support Metric kNRMAConfigurationUpdated when Logging Config is …
cdillard-NewRelic Dec 20, 2023
3181b55
Impl setLogEntityGuid
cdillard-NewRelic Dec 20, 2023
1be17d1
Merge branch 'develop' of github.com:newrelic/newrelic-ios-agent into…
cdillard-NewRelic Jan 8, 2024
0aff012
feat: Remote Logging with manual set entityGuid and ingestKey feature…
cdillard-NewRelic Jan 9, 2024
8d1cb61
Merge branch 'develop' of github.com:newrelic/newrelic-ios-agent into…
cdillard-NewRelic Jan 29, 2024
016aad2
Merge branch 'develop' into log-reporting
cdillard-NewRelic Jan 30, 2024
882f48a
NR-220019: App Token auth
cdillard-NewRelic Feb 6, 2024
9f7ea1a
NR-220019: Adds GHA for Bespoke Branch Based Build (#198)
cdillard-NewRelic Feb 7, 2024
ca08240
Merge branch 'main' of github.com:newrelic/newrelic-ios-agent into lo…
cdillard-NewRelic Feb 8, 2024
1d60f7e
Merge branch 'develop' of github.com:newrelic/newrelic-ios-agent into…
cdillard-NewRelic Feb 14, 2024
4cbf7fe
Add 100 logs test, fix levelToString for "level" attribute on log mes…
cdillard-NewRelic Feb 14, 2024
4d0fc7a
NR-228761: Implement uploadQueue for log data, NRLoggerTests
cdillard-NewRelic Feb 16, 2024
ce328fd
Logs fix
cdillard-NewRelic Feb 21, 2024
7210bcc
Use correct endpoints for logging
cdillard-NewRelic Feb 22, 2024
5dd30d3
Merge branch 'develop' of github.com:newrelic/newrelic-ios-agent into…
cdillard-NewRelic Feb 23, 2024
06c6b3a
Merge branch 'develop' of github.com:newrelic/newrelic-ios-agent into…
cdillard-NewRelic Feb 27, 2024
0ca8dd2
NR-223195: Support metric for success and failure remote logging
cdillard-NewRelic Mar 4, 2024
369bf7b
Merge branch 'develop' of github.com:newrelic/newrelic-ios-agent into…
cdillard-NewRelic Mar 4, 2024
0f0f415
Merge branch 'develop' of github.com:newrelic/newrelic-ios-agent into…
cdillard-NewRelic Mar 6, 2024
04dd99e
NR-227297: logErrorObject impl, NR-227300: logAttributes impl
cdillard-NewRelic Mar 8, 2024
3ed0a5e
Merge branch 'develop' of github.com:newrelic/newrelic-ios-agent into…
cdillard-NewRelic Apr 11, 2024
9e2fa56
Merge branch 'develop' of github.com:newrelic/newrelic-ios-agent into…
cdillard-NewRelic Apr 17, 2024
b4814ee
Log attributes
cdillard-NewRelic Apr 19, 2024
4d67b0c
Merge branch 'develop' of github.com:newrelic/newrelic-ios-agent into…
cdillard-NewRelic Apr 23, 2024
f20c0a3
Merge branch 'develop' of github.com:newrelic/newrelic-ios-agent into…
cdillard-NewRelic Apr 25, 2024
ce2e6c8
Temporarily remove LogReporting
cdillard-NewRelic Apr 25, 2024
2d86f5d
fix tvOS job Xcode version in GHA
cdillard-NewRelic Apr 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Agent.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,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 @@ -1900,6 +1902,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 @@ -2341,6 +2345,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 @@ -4363,6 +4369,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 @@ -4600,6 +4607,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 */,
025657FF24EB19BF00FE3125 /* TestSessionIdentifierManger.m in Sources */,
343883572834405700B31C2E /* NRMAURLTransformerTests.m in Sources */,
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
11 changes: 4 additions & 7 deletions Agent/FeatureFlags/NRMAFlags.m
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ + (BOOL) shouldEnableOfflineStorage {
}

+ (BOOL) shouldEnableLogReporting {
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 @@ -226,11 +225,9 @@ + (BOOL) shouldEnableNewEventSystem {
if ((flags & NRFeatureFlag_OfflineStorage) == NRFeatureFlag_OfflineStorage) {
[retArray addObject:@"OfflineStorage"];
}

// NOTE: Temporarily removed NRFeatureFlag_LogReporting
// if ((flags & NRFeatureFlag_LogReporting) == NRFeatureFlag_LogReporting) {
// [retArray addObject:@"LogReporting"];
// }
if ((flags & NRFeatureFlag_LogReporting) == NRFeatureFlag_LogReporting) {
[retArray addObject:@"LogReporting"];
}
if ((flags & NRFeatureFlag_NewEventSystem) == NRFeatureFlag_NewEventSystem) {
[retArray addObject:@"NewEventSystem"];
}
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
76 changes: 75 additions & 1 deletion Agent/Harvester/NRMAHarvester.mm
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,17 @@ - (void) connected
case UNSUPPORTED_MEDIA_TYPE:
case ENTITY_TOO_LARGE:
[self.harvestData clear];
break;
case CONFIGURATION_UPDATE:
// WHEN RECEIVING A 409 status code from the /data endpoint we will PERFORM A CONNECT CALL TO REFRESH THE CONFIG.
[self clearStoredHarvesterConfiguration];
[self transition:NRMA_HARVEST_DISCONNECTED];
// Reconnect performed here.
[self execute];

// Send Supportability metric when received 409 to indicate that a config update should happen or send it when actual /connect call finishes which refreshes the data.
[NRMASupportMetricHelper enqueueConfigurationUpdateMetric];

break;
default:
break;
Expand Down Expand Up @@ -392,6 +403,8 @@ - (void) disconnected
configuration = [NRMAHarvesterConfiguration defaultHarvesterConfiguration];
}

[self handleLoggingConfigurationUpdate];

// If we have a data token (config is valid), then skip the connect call.
if (configuration.isValid && [configuration.application_token isEqualToString:_agentConfiguration.applicationToken.value]) {
[NRMAMeasurements recordSessionStartMetric];
Expand Down Expand Up @@ -434,6 +447,9 @@ - (void) disconnected
}
// Configuration saved here.
configuration.application_token = connection.applicationToken;

[self handleLoggingConfigurationUpdate];

[self saveHarvesterConfiguration:configuration];

[NRMASupportMetricHelper processDeferredMetrics];
Expand Down Expand Up @@ -513,6 +529,41 @@ - (NRMAHarvesterConfiguration*) configureFromCollector:(NRMAHarvestResponse*)res
NRMAHarvesterConfiguration* config = nil;
@try {
NSError* error = nil;

// // TODO: Remove CannedConnect response
////
// // Obfuscated secrets values.
// NSString *cannedConnect = @"{\n"
// @" \"server_timestamp\":1701302638,"
// @" \"collect_network_errors\":true,"
// @" \"activity_trace_max_size\":65535,"
// @" \"data_report_period\":60,"
// @" \"response_body_limit\":2048,"
// @" \"activity_trace_min_utilization\":0.3,"
// @" \"stack_trace_limit\":100,"
// @" \"report_max_transaction_age\":600,"
// @" \"report_max_transaction_count\":1000,"
// @" \"error_limit\":50,"
// @" \"at_capture\":[1,[]],"
// @" \"data_token\":[31111113,52222220],"
// @" \"cross_process_id\":\"VQYPSFAaAQcRV1hSBQYDLVc=\","
// @" \"encoding_key\":\"d67afd830dab717fd263bfcb1b8b88423e9a1a3c\",\n"
// @" \"account_id\":\"13313993\","
// @" \"application_id\":\"19225431\","
// @" \"trusted_account_key\":\"1\","
// @" \"entity_guid\": \"MTA4MTY5OTR8TU9ASUxFfEFQUExDQ0FUSU9OfDM5MDI3NDMz\","
// @" \"log_reporting\": {"
// @" \"enabled\": true,"
// @" \"level\": \"NONE \""
// @"}"
// @"}";
// // CANNED CONFIG
// NRLOG_VERBOSE(@"Harvest config canned: %@", cannedConnect);
// id jsonObject = [NRMAJSON JSONObjectWithData: [cannedConnect dataUsingEncoding:NSUTF8StringEncoding]
// options:0
// error:&error];

// REAL CONFIG
NRLOG_VERBOSE(@"Harvest config: %@", response.responseBody);
id jsonObject = [NRMAJSON JSONObjectWithData:[response.responseBody dataUsingEncoding:NSUTF8StringEncoding]
options:0
Expand Down Expand Up @@ -631,7 +682,7 @@ - (void) fireOnHarvest
}
if ([NRMAFlags shouldEnableLogReporting]) {
// Do log upload
[NRLogger upload];
[NRLogger enqueueLogUpload];
}
}
}
Expand Down Expand Up @@ -725,4 +776,27 @@ - (void) setMaxOfflineStorageSize:(NSUInteger) size {
[connection setMaxOfflineStorageSize:size];
}

- (void) handleLoggingConfigurationUpdate {
// TODO: Evaluating if this is the best spot?

// Should it check if remote logs are already on?

// Code for dynamically enabling or disabling remote logging at runtime based on the state of configuration.log_reporting_enabled and the existing state of NRFlags.NRFeatureFlag_LogReporting
if (configuration.log_reporting_enabled) {
// it is required to enable NRLogTargetFile when using LogReporting.
// Should this be done programmatically?
[NRLogger setLogTargets:NRLogTargetConsole | NRLogTargetFile];
// Parse NSString into NRLogLevel
NRLogLevels level = [NRLogger stringToLevel: configuration.log_reporting_level];
[NRLogger setLogLevels:level];

[NRMAFlags enableFeatures:NRFeatureFlag_LogReporting];
}
//TODO:
// // OVERWRITE user selected value for LogReporting -- Should must be included once API returns log_reporting { enabled: false} reliably.
// else {
// [NRMAFlags disableFeatures:NRFeatureFlag_LogReporting];
// }
}

@end
5 changes: 5 additions & 0 deletions Agent/Measurements/NRMASupportMetricHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ static NSMutableArray *deferredMetrics = NULL;
+ (void) enqueueMaxPayloadSizeLimitMetric:(NSString*)endpoint;
+ (void) enqueueUpgradeMetric;
+ (void) enqueueStopAgentMetric;
+ (void) enqueueConfigurationUpdateMetric;
+ (void) processDeferredMetrics;
+ (void) enqueueOfflinePayloadMetric:(long)size;

+ (void) enqueueLogSuccessMetric:(long)size;
+ (void) enqueueLogFailedMetric;

@end
Loading
Loading