Skip to content

Commit 97cb3bf

Browse files
committed
added an offline attribute to events created offline and added an offline data sent support metric
1 parent 8b876f3 commit 97cb3bf

File tree

8 files changed

+32
-8
lines changed

8 files changed

+32
-8
lines changed

Agent/Analytics/Events/NRMAMobileEvent.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#import "NRMAMobileEvent.h"
1010
#import "Constants.h"
11+
#import "NewRelicInternalUtils.h"
1112

1213
static NSString* const kTimestampKey = @"Timestamp";
1314
static NSString* const kSessionElapsedTimeKey = @"SessionElapsedTime";
@@ -56,7 +57,14 @@ - (id)JSONObject {
5657
dict[kNRMA_RA_timestamp] = @(self.timestamp);
5758
dict[kNRMA_RA_sessionElapsedTime] = @(self.sessionElapsedTimeSeconds);
5859
dict[kNRMA_RA_eventType] = self.eventType;
59-
60+
61+
NRMAReachability* r = [NewRelicInternalUtils reachability];
62+
@synchronized(r) {
63+
NRMANetworkStatus status = [r currentReachabilityStatus];
64+
if (status == NotReachable) {
65+
dict[@"Offline"] = [[NSNumber alloc] initWithBool:TRUE];
66+
}
67+
}
6068
return [NSDictionary dictionaryWithDictionary:dict];
6169
}
6270

Agent/Harvester/NRMAHarvester.mm

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,18 +333,20 @@ - (void) connected
333333
//TODO: add addition collector response processing.
334334
if (response.isError) {
335335
// failure
336-
if([self checkResponseAndPersist:response]) {
336+
if([self checkOfflineAndPersist:response]) {
337+
// If the harvest was persisted for offline storage clear the harvest.
337338
[self.harvestData clear];
338339
} else {
339340
[self fireOnHarvestFailure];
340341
}
341342
} else {
342343
// success
343344
[self.harvestData clear];
345+
// If there was a successful harvest upload send the persisted offline payloads.
344346
[connection sendOfflineStorage];
345347
}
346348
//Supportability/MobileAgent/Collector/Harvest
347-
continues:
349+
348350
[harvestTimer stopTimer];
349351
#ifndef DISABLE_NRMA_EXCEPTION_WRAPPER
350352
@try {
@@ -362,7 +364,7 @@ - (void) connected
362364
[self fireOnHarvestComplete];
363365
}
364366

365-
- (BOOL) checkResponseAndPersist:(NRMAHarvestResponse*) response {
367+
- (BOOL) checkOfflineAndPersist:(NRMAHarvestResponse*) response {
366368
if([NRMAOfflineStorage checkErrorToPersist:response.error]) {
367369
NSError* error = nil;
368370
NSData* jsonData = [NRMAJSON dataWithJSONABLEObject:self.harvestData options:0 error:&error];

Agent/Harvester/NRMAHarvesterConnection.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ -(void) sendOfflineStorage {
4646
NRLOG_ERROR(@"Failed to create data POST");
4747
return;
4848
}
49-
49+
[NRMASupportMetricHelper enqueueOfflinePayloadMetric:@"data" size:[post.HTTPBody length]];
50+
5051
NRMAHarvestResponse* response = [self send:post];
5152

5253
if([NRMAOfflineStorage checkErrorToPersist:response.error]) {
53-
[_offlineStorage persistDataToDisk:jsonData];
54+
// [_offlineStorage persistDataToDisk:jsonData]; Re-save if failed to send again?
5455
}
5556
}];
5657
}

Agent/Measurements/NRMASupportMetricHelper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ static NSMutableArray *deferredMetrics = NULL;
1919
+ (void) enqueueUpgradeMetric;
2020
+ (void) enqueueStopAgentMetric;
2121
+ (void) processDeferredMetrics;
22+
+ (void) enqueueOfflinePayloadMetric:(NSString*)endpoint size:(long)size;
2223
@end

Agent/Measurements/NRMASupportMetricHelper.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ + (void) enqueueMaxPayloadSizeLimitMetric:(NSString*)endpoint {
5959
scope:nil]];
6060
}
6161

62+
+ (void) enqueueOfflinePayloadMetric:(long)size {
63+
NSString* nativePlatform = [NewRelicInternalUtils osName];
64+
NSString* platform = [NewRelicInternalUtils stringFromNRMAApplicationPlatform:[NRMAAgentConfiguration connectionInformation].deviceInformation.platform];
65+
[NRMATaskQueue queue:[[NRMAMetric alloc] initWithName:[NSString stringWithFormat: kNRMAOfflineSupportabilityFormatString, nativePlatform, platform, kNRMACollectorDest]
66+
value:[NSNumber numberWithLongLong:size]
67+
scope:nil]];
68+
}
69+
6270
+ (void) enqueueUpgradeMetric {
6371
if (deferredMetrics == nil) {
6472
deferredMetrics = [NSMutableArray array];

Agent/Public/NRConstants.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ typedef NSString NRMetricUnit;
124124
#define kNRMAMaxPayloadSizeLimitSupportabilityFormatString @"Supportability/Mobile/%@/%@/%@/MaxPayloadSizeLimit/%@"
125125
#define kNRMAMaxPayloadSizeLimit 1000000 // bytes
126126

127+
#define kNRMAOfflineSupportabilityFormatString @"Supportability/Mobile/%@/%@/%@/Offline/bytes"
128+
127129
#define kNRMABytesOutConnectAPIString @"/connect/Output/Bytes"
128130
#define kNRMABytesOutDataAPIString @"/data/Output/Bytes"
129131
#define kNRMABytesOutFAPIString @"/f/Output/Bytes"

Agent/Utilities/NRMAOfflineStorage.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#import "NRMAOfflineStorage.h"
1313
#import "Constants.h"
1414
#import "NRMAJSON.h"
15+
#import "NRMASupportMetricHelper.h"
1516

1617
@implementation NRMAOfflineStorage {
1718
}
@@ -92,8 +93,7 @@ + (NSString*)newOfflineFilePath {
9293
}
9394

9495
+ (BOOL)checkErrorToPersist:(NSError*) error {
95-
return (error.code == NSURLErrorNotConnectedToInternet || error.code == NSURLErrorTimedOut);
96-
96+
return (error.code == NSURLErrorNotConnectedToInternet || error.code == NSURLErrorTimedOut || error.code == NSURLErrorCannotFindHost || error.code == NSURLErrorNetworkConnectionLost || error.code == NSURLErrorCannotConnectToHost);
9797
}
9898

9999
@end

Agent/Utilities/NewRelicInternalUtils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,7 @@ NSTimeInterval NRMAMillisecondTimestamp(void);
9393

9494
+ (NRMANetworkMonitor*) networkMonitor;
9595

96+
+ (NRMAReachability*) reachability;
97+
9698
@end
9799

0 commit comments

Comments
 (0)