Skip to content

Commit e300cfa

Browse files
committed
Changed offline to enabled by default and fix a few place to check for offline in handled exceptions and crashes
1 parent 1efd215 commit e300cfa

File tree

8 files changed

+34
-11
lines changed

8 files changed

+34
-11
lines changed

Agent/CrashHandler/NRMAExceptionHandlerManager.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,13 @@ - (instancetype) initWithLastSessionsAttributes:(NSDictionary*)attributes
107107
[_reportManager processReportsWithSessionAttributes:attributes
108108
analyticsEvents:events];
109109

110-
[self.uploader uploadCrashReports];
110+
NRMAReachability* r = [NewRelicInternalUtils reachability];
111+
@synchronized(r) {
112+
NRMANetworkStatus status = [r currentReachabilityStatus];
113+
if (status != NotReachable) { // Because we support offline mode check if we're online before sending the crash reports
114+
[self.uploader uploadCrashReports];
115+
}
116+
}
111117
}
112118

113119
self.handler = [[NRMAUncaughtExceptionHandler alloc] initWithCrashReporter:_crashReporter];

Agent/FeatureFlags/NRMAFlags.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ + (NRMAFeatureFlags) featureFlags
4747
NRFeatureFlag_NetworkRequestEvents |
4848
NRFeatureFlag_RequestErrorEvents |
4949
NRFeatureFlag_DistributedTracing |
50-
NRFeatureFlag_AppStartMetrics;
50+
NRFeatureFlag_AppStartMetrics |
51+
NRFeatureFlag_OfflineStorage;
5152
});
5253
return __flags;
5354
}

Agent/General/NewRelicAgentInternal.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ - (void) onSessionStart {
488488
sessionId:[self currentSessionId]];
489489

490490

491-
if (status != NotReachable) {
491+
if (status != NotReachable) { // Because we support offline mode check if we're online before sending the handled exceptions
492492
[self.handledExceptionsController processAndPublishPersistedReports];
493493
}
494494

@@ -500,7 +500,7 @@ - (void) onSessionStart {
500500

501501
// Attempt to upload crash report files (if any exist)
502502
if ([NRMAFlags shouldEnableCrashReporting]) {
503-
if (status != NotReachable) {
503+
if (status != NotReachable) { // Because we support offline mode check if we're online before sending the crash reports
504504
[[NRMAExceptionHandlerManager manager].uploader uploadCrashReports];
505505
}
506506
}

Agent/HandledException/NRMAHandledExceptions.mm

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,18 @@ - (instancetype) initWithAnalyticsController:(NRMAAnalytics*)analytics
131131
}
132132

133133
- (void) onHarvest {
134-
_controller->publish();
135-
_store->clear();
136-
_publisher->retry();
134+
NRMAReachability* r = [NewRelicInternalUtils reachability];
135+
@synchronized(r) {
136+
NRMANetworkStatus status = [r currentReachabilityStatus];
137+
if (status != NotReachable) { // Because we support offline mode check if we're online before sending the handled exceptions reports
138+
if(!_controller->publish()) { // If there are no reports in the controller to publish we still want to try and send persisted reports before we clear.
139+
[self processAndPublishPersistedReports];
140+
} else {
141+
_store->clear();
142+
_publisher->retry();
143+
}
144+
}
145+
}
137146
}
138147

139148
- (fbs::Platform) fbsPlatformFromString:(NSString*)platform {

Agent/Public/NewRelicFeatureFlags.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@
7272
Disabled by default. Enable or disable (default) flag for automatic instrumentation of async URLSession functions in Swift.
7373
7474
- NRFeatureFlag_LogReporting
75-
Disabled by default. Enable or disable (default) flag to enable log forwarding of logs passed to NewRelic.log* functions..
75+
Disabled by default. Enable or disable (default) flag to enable log forwarding of logs passed to NewRelic.log* functions.
76+
77+
- NRFeatureFlag_OfflineStorage
78+
Enabled by default. Enable (default) or disable flag to enable the storage of offline payloads.
7679
*/
7780

7881

@@ -99,5 +102,5 @@ typedef NS_OPTIONS(unsigned long long, NRMAFeatureFlags){
99102

100103
// NOTE: Temporarily removed NRFeatureFlag_LogReporting
101104
NRFeatureFlag_NewEventSystem = 1 << 20, // Disabled by default
102-
NRFeatureFlag_OfflineStorage = 1 << 21, // Disabled by default
105+
NRFeatureFlag_OfflineStorage = 1 << 21,
103106
};

Agent/Utilities/NewRelicInternalUtils.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ + (NSString*) carrierName {
230230
} else {
231231
cachedCarrierName = carrier.carrierName;
232232
}
233+
} else if (internetStatus == NotReachable) {
234+
cachedCarrierName = @"";
233235
} else {
234236
cachedCarrierName = NRMA_CARRIER_WIFI;
235237
}

libMobileAgent/src/Hex/include/Hex/HexController.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace NewRelic {
4040

4141
void submit(std::shared_ptr<Report::HexReport> report);
4242

43-
void publish();
43+
bool publish();
4444

4545
void setSessionId(const char* sessionId);
4646

libMobileAgent/src/Hex/src/HexController.cxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,14 @@ std::shared_ptr<HexReportContext> HexController::detachKeyContext() {
8484
}
8585

8686

87-
void HexController::publish() {
87+
bool HexController::publish() {
8888
auto context = detachKeyContext();
8989
if (context->reports() > 0) {
9090
context->finalize();
9191
_publisher->publish(context);
92+
return true;
9293
}
94+
return false;
9395
}
9496

9597
void HexController::submit(std::shared_ptr<Report::HexReport> report) {

0 commit comments

Comments
 (0)