Skip to content

Commit a87bd97

Browse files
committed
Changing offline to only care about the persisted reports to eliminate missed or duplicated reports
1 parent e300cfa commit a87bd97

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

Agent/HandledException/NRMAHandledExceptions.mm

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,20 @@ - (instancetype) initWithAnalyticsController:(NRMAAnalytics*)analytics
131131
}
132132

133133
- (void) onHarvest {
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();
134+
if([NRMAFlags shouldEnableOfflineStorage]) {
135+
NRMAReachability* r = [NewRelicInternalUtils reachability];
136+
@synchronized(r) {
137+
NRMANetworkStatus status = [r currentReachabilityStatus];
138+
if (status != NotReachable) {
139+
[self processAndPublishPersistedReports]; // When using offline we always want to send from persisted because the keyContext doesn't persist.
140+
_controller->resetKeyContext();
142141
_publisher->retry();
143142
}
144143
}
144+
} else {
145+
_controller->publish();
146+
_store->clear();
147+
_publisher->retry();
145148
}
146149
}
147150

Test Harness/NRTestApp/NRTestApp/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
6767
}
6868

6969
NewRelic.setMaxEventPoolSize(5000)
70-
NewRelic.setMaxEventBufferTime(600)
70+
NewRelic.setMaxEventBufferTime(60)
7171

7272
NewRelic.logVerbose("NewRelic.start was called.")
7373
return true

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

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

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

43-
bool publish();
43+
void publish();
44+
45+
void resetKeyContext();
4446

4547
void setSessionId(const char* sessionId);
4648

libMobileAgent/src/Hex/src/HexController.cxx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "Hex/HexPublisher.hpp"
99
#include "Hex/HexController.hpp"
1010

11-
1211
using namespace NewRelic::Hex;
1312

1413
HexController::HexController(std::shared_ptr<const AnalyticsController>& analytics,
@@ -83,15 +82,17 @@ std::shared_ptr<HexReportContext> HexController::detachKeyContext() {
8382
return context;
8483
}
8584

85+
void HexController::resetKeyContext() {
86+
std::unique_lock<std::mutex> resetLock(_keyContextMutex);
87+
_keyContext = std::make_shared<HexReportContext>(_applicationInfo, _analytics->getAttributeValidator());
88+
}
8689

87-
bool HexController::publish() {
90+
void HexController::publish() {
8891
auto context = detachKeyContext();
8992
if (context->reports() > 0) {
9093
context->finalize();
9194
_publisher->publish(context);
92-
return true;
9395
}
94-
return false;
9596
}
9697

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

0 commit comments

Comments
 (0)