Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature:offline storage functionality #83

Merged
merged 19 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
29e593d
Add optional attributes for recordError (#69)
mchavez-newrelic Jul 14, 2023
6978ec9
Add optional attributes for recordError (#69)
mchavez-newrelic Jul 14, 2023
57cb7d3
Merge remote-tracking branch 'origin/develop' into develop
ndesai-newrelic Jul 20, 2023
af6ede3
Merge remote-tracking branch 'origin/develop' into develop
ndesai-newrelic Jul 26, 2023
efe8bcc
Update iOS agent to 7.4.6 (#73)
github-actions[bot] Jul 26, 2023
783eb69
Add optional attributes for recordError (#69)
mchavez-newrelic Jul 14, 2023
4f3e1e8
Add optional attributes for recordError (#69)
mchavez-newrelic Jul 14, 2023
881857e
merge from master
ndesai-newrelic Feb 13, 2024
53bbf1c
merge from master
ndesai-newrelic Feb 13, 2024
685eeca
Merge remote-tracking branch 'origin/develop' into develop
ndesai-newrelic Feb 13, 2024
120a648
resolve merge conflicts with master
ndesai-newrelic Feb 13, 2024
cf845f2
Add optional attributes for recordError (#69)
mchavez-newrelic Jul 14, 2023
79c9ee0
Add optional attributes for recordError (#69)
mchavez-newrelic Jul 14, 2023
21687fb
Add optional attributes for recordError (#69)
mchavez-newrelic Jul 14, 2023
bf2df2c
resolve merge conflicts with master
ndesai-newrelic Feb 13, 2024
79cf9af
Merge branch 'develop' of https://github.com/newrelic/newrelic-cordov…
ndesai-newrelic Mar 5, 2024
d98ee2d
merge with master
ndesai-newrelic Mar 5, 2024
bceac70
feature: added offline storage functionality for cordova
ndesai-newrelic Mar 5, 2024
d3d1c49
Merge branch 'master' into release_6_2_6
ndesai-newrelic Mar 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
# 6.2.6

### New in this release
* Fixed a bug in the fetch instrumentation where customer options were inadvertently removed when no headers were specified. Now, options will be preserved even when headers are absent.
* Addressed an issue that resulted in app crashes when an invalid URL was encountered in the capacitor plugin. To mitigate this, a valid URL checker has been implemented to ensure that mobilerequest events are created only with valid URLs.
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

Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
```
Expand Down Expand Up @@ -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.

Expand Down
9 changes: 6 additions & 3 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<engine name="cordova-android" version=">=5.0.0" />
</engines>

<preference name="PLUGIN_VERSION" default="6.2.5" />
<preference name="PLUGIN_VERSION" default="6.2.6" />
<preference name="CRASH_REPORTING_ENABLED" default="true" />
<preference name="DISTRIBUTED_TRACING_ENABLED" default="true" />
<preference name="INTERACTION_TRACING_ENABLED" default="true" />
Expand All @@ -29,6 +29,7 @@
<preference name="COLLECTOR_ADDRESS" default="x" />
<preference name="CRASH_COLLECTOR_ADDRESS" default="x" />
<preference name="FEDRAMP_ENABLED" default="false" />
<preference name="OFFLINE_STORAGE_ENABLED" default="true" />
<preference name="CONSOLE_LOGS_ENABLED" default="true" />


Expand All @@ -53,6 +54,7 @@
<preference name="COLLECTOR_ADDRESS" value="$COLLECTOR_ADDRESS" />
<preference name="CRASH_COLLECTOR_ADDRESS" value="$CRASH_COLLECTOR_ADDRESS" />
<preference name="FEDRAMP_ENABLED" value="$FEDRAMP_ENABLED" />
<preference name="OFFLINE_STORAGE_ENABLED" value="$OFFLINE_STORAGE_ENABLED" />
<preference name="CONSOLE_LOGS_ENABLED" value="$CONSOLE_LOGS_ENABLED" />
<param name="ios-package" value="NewRelicCordovaPlugin" onload="true" />
</feature>
Expand All @@ -71,7 +73,7 @@
<source url="https://cdn.cocoapods.org/" />
</config>
<pods use-frameworks="true">
<pod name="NewRelicAgent" spec="7.4.8" />
<pod name="NewRelicAgent" spec="7.4.9" />
</pods>
</podspec>

Expand All @@ -81,7 +83,7 @@

<platform name="android">
<preference name="ANDROID_APP_TOKEN" default="x" />
<preference name="ANDROID_AGENT_VER" default="7.2.0" />
<preference name="ANDROID_AGENT_VER" default="7.3.0" />

<config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.INTERNET" />
Expand Down Expand Up @@ -109,6 +111,7 @@
<preference name="COLLECTOR_ADDRESS" value="$COLLECTOR_ADDRESS" />
<preference name="CRASH_COLLECTOR_ADDRESS" value="$CRASH_COLLECTOR_ADDRESS" />
<preference name="FEDRAMP_ENABLED" value="$FEDRAMP_ENABLED" />
<preference name="OFFLINE_STORAGE_ENABLED" value="$OFFLINE_STORAGE_ENABLED" />
<preference name="CONSOLE_LOGS_ENABLED" value="$CONSOLE_LOGS_ENABLED" />
</config-file>

Expand Down
8 changes: 8 additions & 0 deletions src/android/NewRelicCordovaPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/ios/NewRelicCordovaPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@

- (void)setMaxEventPoolSize:(CDVInvokedUrlCommand *)command;

- (void)setMaxOfflineStorageSize:(CDVInvokedUrlCommand *)command;

- (void)analyticsEventEnabled:(CDVInvokedUrlCommand *) command;

- (void)networkRequestEnabled:(CDVInvokedUrlCommand *) command;
Expand Down
9 changes: 9 additions & 0 deletions src/ios/NewRelicCordovaPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
21 changes: 14 additions & 7 deletions www/js/newrelic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -682,4 +690,3 @@

module.exports = NewRelic;


Loading