Skip to content

Commit 252780c

Browse files
committed
Added the offline attribute to sessions
1 parent 97cb3bf commit 252780c

File tree

9 files changed

+32
-25
lines changed

9 files changed

+32
-25
lines changed

Agent/Analytics/Events/NRMAMobileEvent.m

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,6 @@ - (id)JSONObject {
5858
dict[kNRMA_RA_sessionElapsedTime] = @(self.sessionElapsedTimeSeconds);
5959
dict[kNRMA_RA_eventType] = self.eventType;
6060

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-
}
6861
return [NSDictionary dictionaryWithDictionary:dict];
6962
}
7063

Agent/General/NewRelicAgentInternal.m

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ - (void) onSessionStart {
475475

476476
// Initializing analytics take a while. Take care executing time sensitive code after this point the since initializeAnalytics method will delay its execution.
477477
[self initializeAnalytics];
478+
NRMAReachability* r = [NewRelicInternalUtils reachability];
478479

479480
if ([NRMAFlags shouldEnableHandledExceptionEvents]) {
480481
self.handledExceptionsController = [[NRMAHandledExceptions alloc] initWithAnalyticsController:self.analyticsController
@@ -483,7 +484,12 @@ - (void) onSessionStart {
483484
platform:[NewRelicInternalUtils osName]
484485
sessionId:[self currentSessionId]];
485486

486-
[self.handledExceptionsController processAndPublishPersistedReports];
487+
@synchronized(r) {
488+
NRMANetworkStatus status = [r currentReachabilityStatus];
489+
if (status != NotReachable) {
490+
[self.handledExceptionsController processAndPublishPersistedReports];
491+
}
492+
}
487493

488494
[NRMAHarvestController addHarvestListener:self.handledExceptionsController];
489495

@@ -493,8 +499,12 @@ - (void) onSessionStart {
493499

494500
// Attempt to upload crash report files (if any exist)
495501
if ([NRMAFlags shouldEnableCrashReporting]) {
496-
497-
[[NRMAExceptionHandlerManager manager].uploader uploadCrashReports];
502+
@synchronized(r) {
503+
NRMANetworkStatus status = [r currentReachabilityStatus];
504+
if (status != NotReachable) {
505+
[[NRMAExceptionHandlerManager manager].uploader uploadCrashReports];
506+
}
507+
}
498508
}
499509

500510
if([NRMAFlags shouldEnableGestureInstrumentation])

Agent/HandledException/NRMAHexUploader.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
#import "NRLogger.h"
1212
#include <libkern/OSAtomic.h>
1313
#import "NRMASupportMetricHelper.h"
14+
#import "NRConstants.h"
1415

1516
#define kNRMARetryLimit 2 // this will result in 2 additional upload attempts.
16-
#define kNRMAMaxPayloadSizeLimit 1000000
1717

1818
@interface NRMAHexUploader()
1919
@property(strong) NSString* host;

Agent/Harvester/NRMAHarvester.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,10 @@ - (void) connected
366366

367367
- (BOOL) checkOfflineAndPersist:(NRMAHarvestResponse*) response {
368368
if([NRMAOfflineStorage checkErrorToPersist:response.error]) {
369+
NSMutableDictionary *tempAnalyticsAttributes = [[NSMutableDictionary alloc] initWithDictionary:self.harvestData.analyticsAttributes];
370+
[tempAnalyticsAttributes setValue:[NSNumber numberWithBool:YES] forKey:@"offline"];
371+
[self.harvestData setAnalyticsAttributes:[[NSDictionary alloc] initWithDictionary:tempAnalyticsAttributes]];
372+
369373
NSError* error = nil;
370374
NSData* jsonData = [NRMAJSON dataWithJSONABLEObject:self.harvestData options:0 error:&error];
371375
if (error) {

Agent/Harvester/NRMAHarvesterConnection.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ -(void) sendOfflineStorage {
4646
NRLOG_ERROR(@"Failed to create data POST");
4747
return;
4848
}
49-
[NRMASupportMetricHelper enqueueOfflinePayloadMetric:@"data" size:[post.HTTPBody length]];
49+
[NRMASupportMetricHelper enqueueOfflinePayloadMetric:[post.HTTPBody length]];
5050

5151
NRMAHarvestResponse* response = [self send:post];
5252

Agent/Measurements/NRMASupportMetricHelper.h

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

Agent/Public/NRConstants.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ typedef NSString NRMetricUnit;
124124
#define kNRMAMaxPayloadSizeLimitSupportabilityFormatString @"Supportability/Mobile/%@/%@/%@/MaxPayloadSizeLimit/%@"
125125
#define kNRMAMaxPayloadSizeLimit 1000000 // bytes
126126

127-
#define kNRMAOfflineSupportabilityFormatString @"Supportability/Mobile/%@/%@/%@/Offline/bytes"
127+
#define kNRMAOfflineSupportabilityFormatString @"Supportability/Mobile/%@/%@/%@/OfflinePayload/bytes"
128128

129129
#define kNRMABytesOutConnectAPIString @"/connect/Output/Bytes"
130130
#define kNRMABytesOutDataAPIString @"/data/Output/Bytes"

Agent/Utilities/NRMAOfflineStorage.m

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ - (id)initWithEndpoint:(NSString*) name {
2828
}
2929

3030
- (void) createDirectory {
31-
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:[NRMAOfflineStorage offlineDirectoryPath] isDirectory:nil];
31+
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:[self offlineDirectoryPath] isDirectory:nil];
3232
if(!fileExists){
3333
NSError *error = nil;
34-
if(![[NSFileManager defaultManager] createDirectoryAtPath:[NRMAOfflineStorage offlineDirectoryPath] withIntermediateDirectories:YES attributes:nil error:&error]) {
35-
NSLog(@"Failed to create directory \"%@\". Error: %@", [NRMAOfflineStorage offlineDirectoryPath], error);
34+
if(![[NSFileManager defaultManager] createDirectoryAtPath:[self offlineDirectoryPath] withIntermediateDirectories:YES attributes:nil error:&error]) {
35+
NSLog(@"Failed to create directory \"%@\". Error: %@", [self offlineDirectoryPath], error);
3636
}
3737
}
3838
}
@@ -43,7 +43,7 @@ - (BOOL) persistDataToDisk:(NSData*) data {
4343

4444
NSError *error = nil;
4545
if (data) {
46-
if ([data writeToFile:[NRMAOfflineStorage newOfflineFilePath] options:NSDataWritingAtomic error:&error]) {
46+
if ([data writeToFile:[self newOfflineFilePath] options:NSDataWritingAtomic error:&error]) {
4747
NRLOG_VERBOSE(@"Successfully persisted failed upload data to disk for offline storage.");
4848
return YES;
4949
}
@@ -58,11 +58,11 @@ - (BOOL) persistDataToDisk:(NSData*) data {
5858
@synchronized (self) {
5959
NSMutableArray<NSData *> *combinedPosts = [NSMutableArray array];
6060

61-
NSArray* dirs = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[NRMAOfflineStorage offlineDirectoryPath]
61+
NSArray* dirs = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[self offlineDirectoryPath]
6262
error:NULL];
6363
[dirs enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
6464
NSString *filename = (NSString *)obj;
65-
NSData * data = [NSData dataWithContentsOfFile:[NSString stringWithFormat:@"%@/%@",[NRMAOfflineStorage offlineDirectoryPath],filename]];
65+
NSData * data = [NSData dataWithContentsOfFile:[NSString stringWithFormat:@"%@/%@",[self offlineDirectoryPath],filename]];
6666
NRLOG_VERBOSE(@"Offline storage to be uploaded from %@", filename);
6767

6868
[combinedPosts addObject:data];
@@ -77,19 +77,19 @@ - (BOOL) persistDataToDisk:(NSData*) data {
7777
}
7878

7979
- (BOOL) clearAllOfflineFiles {
80-
return [[NSFileManager defaultManager] removeItemAtPath:[NRMAOfflineStorage offlineDirectoryPath] error:NULL];
80+
return [[NSFileManager defaultManager] removeItemAtPath:[self offlineDirectoryPath] error:NULL];
8181
}
8282

83-
+ (NSString*)offlineDirectoryPath {
83+
- (NSString*)offlineDirectoryPath {
8484
return [NSString stringWithFormat:@"%@/%@/%@",[NewRelicInternalUtils getStorePath],kNRMA_Offline_file,_name];
8585
}
8686

87-
+ (NSString*)newOfflineFilePath {
87+
- (NSString*)newOfflineFilePath {
8888
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
8989
[dateFormatter setDateFormat:@"yyyy-MM-dd-HH-mm-ss"];
9090
NSString *date = [dateFormatter stringFromDate:[NSDate date]];
9191

92-
return [NSString stringWithFormat:@"%@/%@%@",[NRMAOfflineStorage offlineDirectoryPath],date,@".txt"];
92+
return [NSString stringWithFormat:@"%@/%@%@",[self offlineDirectoryPath],date,@".txt"];
9393
}
9494

9595
+ (BOOL)checkErrorToPersist:(NSError*) error {

Agent/Utilities/NewRelicInternalUtils.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ + (NRMANetworkMonitor*) networkMonitor {
443443
static NRMANetworkMonitor* nm = nil;
444444
static dispatch_once_t onceToken;
445445
dispatch_once(&onceToken, ^{
446-
if (@available(tvOS 12.0, *)) {
446+
if (@available(iOS 12.0, tvOS 12.0, *)) {
447447
nm = [[NRMANetworkMonitor alloc] init];
448448
}
449449
});

0 commit comments

Comments
 (0)