Skip to content

Commit

Permalink
Changed offline to enabled by default and fix a few place to check fo…
Browse files Browse the repository at this point in the history
…r offline in handled exceptions and crashes
  • Loading branch information
mbruin-NR committed Jan 25, 2024
1 parent 1efd215 commit e300cfa
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 11 deletions.
8 changes: 7 additions & 1 deletion Agent/CrashHandler/NRMAExceptionHandlerManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,13 @@ - (instancetype) initWithLastSessionsAttributes:(NSDictionary*)attributes
[_reportManager processReportsWithSessionAttributes:attributes
analyticsEvents:events];

[self.uploader uploadCrashReports];
NRMAReachability* r = [NewRelicInternalUtils reachability];
@synchronized(r) {
NRMANetworkStatus status = [r currentReachabilityStatus];
if (status != NotReachable) { // Because we support offline mode check if we're online before sending the crash reports
[self.uploader uploadCrashReports];
}
}
}

self.handler = [[NRMAUncaughtExceptionHandler alloc] initWithCrashReporter:_crashReporter];
Expand Down
3 changes: 2 additions & 1 deletion Agent/FeatureFlags/NRMAFlags.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ + (NRMAFeatureFlags) featureFlags
NRFeatureFlag_NetworkRequestEvents |
NRFeatureFlag_RequestErrorEvents |
NRFeatureFlag_DistributedTracing |
NRFeatureFlag_AppStartMetrics;
NRFeatureFlag_AppStartMetrics |
NRFeatureFlag_OfflineStorage;
});
return __flags;
}
Expand Down
4 changes: 2 additions & 2 deletions Agent/General/NewRelicAgentInternal.m
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ - (void) onSessionStart {
sessionId:[self currentSessionId]];


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

Expand All @@ -500,7 +500,7 @@ - (void) onSessionStart {

// Attempt to upload crash report files (if any exist)
if ([NRMAFlags shouldEnableCrashReporting]) {
if (status != NotReachable) {
if (status != NotReachable) { // Because we support offline mode check if we're online before sending the crash reports
[[NRMAExceptionHandlerManager manager].uploader uploadCrashReports];
}
}
Expand Down
15 changes: 12 additions & 3 deletions Agent/HandledException/NRMAHandledExceptions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,18 @@ - (instancetype) initWithAnalyticsController:(NRMAAnalytics*)analytics
}

- (void) onHarvest {
_controller->publish();
_store->clear();
_publisher->retry();
NRMAReachability* r = [NewRelicInternalUtils reachability];
@synchronized(r) {
NRMANetworkStatus status = [r currentReachabilityStatus];
if (status != NotReachable) { // Because we support offline mode check if we're online before sending the handled exceptions reports
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.
[self processAndPublishPersistedReports];
} else {
_store->clear();
_publisher->retry();
}
}
}
}

- (fbs::Platform) fbsPlatformFromString:(NSString*)platform {
Expand Down
7 changes: 5 additions & 2 deletions Agent/Public/NewRelicFeatureFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@
Disabled by default. Enable or disable (default) flag for automatic instrumentation of async URLSession functions in Swift.
- NRFeatureFlag_LogReporting
Disabled by default. Enable or disable (default) flag to enable log forwarding of logs passed to NewRelic.log* functions..
Disabled by default. Enable or disable (default) flag to enable log forwarding of logs passed to NewRelic.log* functions.
- NRFeatureFlag_OfflineStorage
Enabled by default. Enable (default) or disable flag to enable the storage of offline payloads.
*/


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

// NOTE: Temporarily removed NRFeatureFlag_LogReporting
NRFeatureFlag_NewEventSystem = 1 << 20, // Disabled by default
NRFeatureFlag_OfflineStorage = 1 << 21, // Disabled by default
NRFeatureFlag_OfflineStorage = 1 << 21,
};
2 changes: 2 additions & 0 deletions Agent/Utilities/NewRelicInternalUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ + (NSString*) carrierName {
} else {
cachedCarrierName = carrier.carrierName;
}
} else if (internetStatus == NotReachable) {
cachedCarrierName = @"";
} else {
cachedCarrierName = NRMA_CARRIER_WIFI;
}
Expand Down
2 changes: 1 addition & 1 deletion libMobileAgent/src/Hex/include/Hex/HexController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace NewRelic {

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

void publish();
bool publish();

void setSessionId(const char* sessionId);

Expand Down
4 changes: 3 additions & 1 deletion libMobileAgent/src/Hex/src/HexController.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ std::shared_ptr<HexReportContext> HexController::detachKeyContext() {
}


void HexController::publish() {
bool HexController::publish() {
auto context = detachKeyContext();
if (context->reports() > 0) {
context->finalize();
_publisher->publish(context);
return true;
}
return false;
}

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

0 comments on commit e300cfa

Please sign in to comment.