From bceac706f125fc7c8123be2edec3f98655a2297b Mon Sep 17 00:00:00 2001 From: ndesai Date: Tue, 5 Mar 2024 10:13:13 -0600 Subject: [PATCH] feature: added offline storage functionality for cordova --- CHANGELOG.md | 12 ++++++++++++ README.md | 8 ++++++++ package.json | 2 +- plugin.xml | 11 +++++++---- src/android/NewRelicCordovaPlugin.java | 8 ++++++++ src/ios/NewRelicCordovaPlugin.h | 2 ++ src/ios/NewRelicCordovaPlugin.m | 9 +++++++++ www/js/newrelic.js | 20 ++++++++++++++------ 8 files changed, 61 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c6ed57..a23afc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +# 6.2.6 + +### New in this release +In this release, we are introducing several new features and updates: + +* Added Offline Harvesting Feature: This new feature enables the preservation of harvest data that would otherwise be lost when the application lacks an internet connection. The stored harvests will be sent once the internet connection is re-established and the next harvest upload is successful. +* Introduced setMaxOfflineStorageSize API: This new API allows the user to determine the maximum volume of data that can be stored locally. This aids in better management and control of local data storage. +* Updated native iOS Agent: We've upgraded the native iOS agent to version 7.4.9, which includes performance improvements and bug fixes. +* Updated native Android Agent: We've also upgraded the native Android agent to version 7.3.0 bringing benefits like improved stability and enhanced features. + +These enhancements help to improve overall user experience and application performance. + # 6.2.5 ### New in this release diff --git a/README.md b/README.md index 29e76e0..f0b1188 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,8 @@ Currently, the plugin supports the following agent configuration options: * Possible values are `true` and `false`. Defaults to `false`. * `CONSOLE_LOGS_ENABLED`: Enable or disable reporting javascript console logs as custom events. * Possible values are `true` and `false`. Defaults to `false`. +* `OFFLINE_STORAGE_ENABLED`: Enable or disable offline data storage when no internet connection is available. . + * Possible values are `true` and `false`. Defaults to `true`. # Updating the plugin Update the New Relic Cordova plugin to the latest released version easily via the following command: ``` @@ -211,6 +213,12 @@ Our plugin uses the same APIs as our native agents. See the examples below for u NewRelic.setMaxEventPoolSize(2000); ``` +### [setMaxOfflineStorageSize](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/set-max-offline-storage)(megaBytes: number): void; +> Sets the maximum size of total data that can be stored for offline storage.By default, mobile monitoring can collect a maximum of 100 megaBytes of offline storage. When a data payload fails to send because the device doesn't have an internet connection, it can be stored in the file system until an internet connection has been made. After a typical harvest payload has been successfully sent, all offline data is sent to New Relic and cleared from storage. +```js + NewRelic.setMaxOfflineStorageSize(200); +``` + ### The following methods allow you to set some agent configurations *after* the agent has started: By default, these configurations are already set to true on agent start. diff --git a/package.json b/package.json index ee7910c..2e2783c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "newrelic-cordova-plugin", - "version": "6.2.5", + "version": "6.2.6", "description": "New Relic Cordova Plugin for iOS and Android", "repo": "https://github.com/newrelic/newrelic-cordova-plugin/", "scripts": { diff --git a/plugin.xml b/plugin.xml index 2af25cc..1543c74 100644 --- a/plugin.xml +++ b/plugin.xml @@ -6,7 +6,7 @@ + id="newrelic-cordova-plugin" version="6.2.6"> NewRelic New Relic Cordova Plugin for iOS and Android New Relic @@ -18,7 +18,7 @@ - + @@ -29,6 +29,7 @@ + @@ -53,6 +54,7 @@ + @@ -71,7 +73,7 @@ - + @@ -81,7 +83,7 @@ - + @@ -109,6 +111,7 @@ + diff --git a/src/android/NewRelicCordovaPlugin.java b/src/android/NewRelicCordovaPlugin.java index e7ae6ec..b8c17ef 100644 --- a/src/android/NewRelicCordovaPlugin.java +++ b/src/android/NewRelicCordovaPlugin.java @@ -76,6 +76,9 @@ public void initialize(CordovaInterface cordova, CordovaWebView webView) { } if (preferences.getString("default_interactions_enabled", "true").equalsIgnoreCase("false")) { NewRelic.disableFeature(FeatureFlag.DefaultInteractions); + } + if (preferences.getString("offline_storage_enabled", "true").equalsIgnoreCase("true")) { + NewRelic.enableFeature(FeatureFlag.OfflineStorage); } if (preferences.getString("fedramp_enabled", "false").equalsIgnoreCase("true")) { NewRelic.enableFeature(FeatureFlag.FedRampEnabled); @@ -403,6 +406,11 @@ public void run() { NewRelic.setMaxEventBufferTime(maxEventBufferTimeInSeconds); break; } + case "setMaxOfflineStorageSize": { + final int megabytes = args.getInt(0); + NewRelic.setMaxOfflineStorageSize(megabytes); + break; + } case "setMaxEventPoolSize": { final int maxPoolSize = args.getInt(0); NewRelic.setMaxEventPoolSize(maxPoolSize); diff --git a/src/ios/NewRelicCordovaPlugin.h b/src/ios/NewRelicCordovaPlugin.h index 506c509..aaaf8f8 100644 --- a/src/ios/NewRelicCordovaPlugin.h +++ b/src/ios/NewRelicCordovaPlugin.h @@ -49,6 +49,8 @@ - (void)setMaxEventPoolSize:(CDVInvokedUrlCommand *)command; +- (void)setMaxOfflineStorageSize:(CDVInvokedUrlCommand *)command; + - (void)analyticsEventEnabled:(CDVInvokedUrlCommand *) command; - (void)networkRequestEnabled:(CDVInvokedUrlCommand *) command; diff --git a/src/ios/NewRelicCordovaPlugin.m b/src/ios/NewRelicCordovaPlugin.m index 61614c1..95561df 100644 --- a/src/ios/NewRelicCordovaPlugin.m +++ b/src/ios/NewRelicCordovaPlugin.m @@ -55,6 +55,9 @@ - (void)pluginInitialize if (![self shouldDisableFeature:config[@"fedramp_enabled"]]) { [NewRelic enableFeatures:NRFeatureFlag_FedRampEnabled]; } + if (![self shouldDisableFeature:config[@"offline_storage_enabled"]]) { + [NewRelic enableFeatures:NRFeatureFlag_OfflineStorage]; + } // Set log level depending on loggingEnabled and logLevel NRLogLevels logLevel = NRLogLevelWarning; @@ -356,6 +359,12 @@ - (void)setMaxEventPoolSize:(CDVInvokedUrlCommand *)command { [NewRelic setMaxEventPoolSize:uint_maxPoolSize]; } +- (void)setMaxOfflineStorageSize:(CDVInvokedUrlCommand *)command { + NSNumber* megaBytes = [command.arguments objectAtIndex:0]; + unsigned int uint_megaBytes = megaBytes.unsignedIntValue; + [NewRelic setMaxOfflineStorageSize:uint_megaBytes]; +} + - (void)analyticsEventEnabled:(CDVInvokedUrlCommand *)command { // This should only be an android method call, so we do nothing here. return; diff --git a/www/js/newrelic.js b/www/js/newrelic.js index a4a716c..d6e457b 100644 --- a/www/js/newrelic.js +++ b/www/js/newrelic.js @@ -280,6 +280,14 @@ cordova.exec(cb, fail, "NewRelicCordovaPlugin", "setMaxEventPoolSize", [maxPoolSize]); }, + /** + * Sets the maximum size of total data that can be stored for offline storage.. + * @param {number} maxPoolSize The Maximum size in megaBytes that can be stored in the file system. + */ + setMaxOfflineStorageSize: function (megaBytes, cb, fail) { + cordova.exec(cb, fail, "NewRelicCordovaPlugin", "setMaxOfflineStorageSize", [megaBytes]); + }, + /** * FOR ANDROID ONLY. * Enable or disable collection of event data. @@ -490,14 +498,14 @@ _arguments[1] = options; } - if(options && 'body' in options) { - networkRequest.bytesSent = options.body.length; + if (options && 'body' in options && options.body !== undefined) { + networkRequest.bytesSent = options.body.length; } else { - networkRequest.bytesSent = 0; + networkRequest.bytesSent = 0; } - - if (networkRequest.method === undefined || networkRequest.method === "" ) { - networkRequest.method = 'GET'; + + if (networkRequest.method === undefined || networkRequest.method === "") { + networkRequest.method = 'GET'; } return new Promise(function (resolve, reject) { // pass through to native fetch