Skip to content

Commit

Permalink
Bug fix fetch instrumentation (#82)
Browse files Browse the repository at this point in the history
* Add optional attributes for recordError (#69)

* feat: add optional attributes parameter for javascript code

* feat: handle optional attributes for record error in native code

* test: add unit tests for optional attributes parameter in record error

* feat: add boolean type for value in optional attributes for record error

* test: modify test for record error to test boolean and number values in optional attributes

* feat: update README documentation for record error to include optional attributes

* Add optional attributes for recordError (#69)

* feat: add optional attributes parameter for javascript code

* feat: handle optional attributes for record error in native code

* test: add unit tests for optional attributes parameter in record error

* feat: add boolean type for value in optional attributes for record error

* test: modify test for record error to test boolean and number values in optional attributes

* feat: update README documentation for record error to include optional attributes

* Update iOS agent to 7.4.6 (#73)

* Update iOS Version to 7.4.6

* Release 6.2.3

---------

Co-authored-by: ndesai-newrelic <[email protected]>
Co-authored-by: ndesai-newrelic <[email protected]>

* Add optional attributes for recordError (#69)

* feat: add optional attributes parameter for javascript code

* feat: handle optional attributes for record error in native code

* test: add unit tests for optional attributes parameter in record error

* feat: add boolean type for value in optional attributes for record error

* test: modify test for record error to test boolean and number values in optional attributes

* feat: update README documentation for record error to include optional attributes

* Add optional attributes for recordError (#69)

* feat: add optional attributes parameter for javascript code

* feat: handle optional attributes for record error in native code

* test: add unit tests for optional attributes parameter in record error

* feat: add boolean type for value in optional attributes for record error

* test: modify test for record error to test boolean and number values in optional attributes

* feat: update README documentation for record error to include optional attributes

* resolve merge conflicts with master

* fix fetch instrumentation bugs

---------

Co-authored-by: mchavez-newrelic <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: ndesai-newrelic <[email protected]>
  • Loading branch information
4 people committed Mar 5, 2024
1 parent d98ee2d commit 832f486
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

# 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.


# 6.2.5

### New in this release
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="newrelic-cordova-plugin" version="6.2.5">
id="newrelic-cordova-plugin" version="6.2.6">
<name>NewRelic</name>
<description>New Relic Cordova Plugin for iOS and Android</description>
<author>New Relic</author>
Expand Down
48 changes: 22 additions & 26 deletions www/js/newrelic.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,75 +288,75 @@
analyticsEventEnabled: function (enabled, cb, fail) {
cordova.exec(cb, fail, "NewRelicCordovaPlugin", "analyticsEventEnabled", [enabled]);
},

/**
* Enable or disable reporting sucessful HTTP request to the MobileRequest event type.
* @param {boolean} enabled Boolean value for enable successful HTTP requests.
*/
networkRequestEnabled: function (enabled, cb, fail) {
cordova.exec(cb, fail, "NewRelicCordovaPlugin", "networkRequestEnabled", [enabled]);
},

/**
* Enable or disable reporting network and HTTP request errors to the MobileRequestError event type.
* @param {boolean} enabled Boolean value for enabling network request errors.
*/
networkErrorRequestEnabled: function (enabled, cb, fail) {
cordova.exec(cb, fail, "NewRelicCordovaPlugin", "networkErrorRequestEnabled", [enabled]);
},

/**
* Enable or disable capture of HTTP response bodies for HTTP error traces, and MobileRequestError events.
* @param {boolean} enabled Boolean value for enabling HTTP response bodies.
* @param {boolean} enabled Boolean value for enabling HTTP response bodies.
*/
httpRequestBodyCaptureEnabled: function (enabled, cb, fail) {
cordova.exec(cb, fail, "NewRelicCordovaPlugin", "httpRequestBodyCaptureEnabled", [enabled]);
},

/**
* Shut down the agent within the current application lifecycle during runtime.
* Once the agent has shut down, it cannot be restarted within the current application lifecycle.
*/
shutdown: function (cb, fail) {
cordova.exec(cb, fail, "NewRelicCordovaPlugin", "shutdown");
},

addHTTPHeadersTrackingFor: function (headers,cb, fail) {
cordova.exec(cb, fail, "NewRelicCordovaPlugin", "addHTTPHeadersTrackingFor",[headers]);
},

getHTTPHeadersTrackingFor: function (cb, fail) {

return new Promise(function (cb, fail) {
cordova.exec(cb, fail, "NewRelicCordovaPlugin", "getHTTPHeadersTrackingFor");
});
},

generateDistributedTracingHeaders: function (cb, fail) {

return new Promise(function (cb, fail) {
cordova.exec(cb, fail, "NewRelicCordovaPlugin", "generateDistributedTracingHeaders");
});
},

}

networkRequest = {};
var originalXhrOpen = XMLHttpRequest.prototype.open;
var originalXHRSend = XMLHttpRequest.prototype.send;

window.XMLHttpRequest.prototype.open = function (method, url) {
// Keep track of the method and url
// start time is tracked by the `send` method

// eslint-disable-next-line prefer-rest-params

networkRequest.url = url;
networkRequest.method = method;
networkRequest.bytesSent = 0;
networkRequest.startTime = Date.now();
return originalXhrOpen.apply(this, arguments)

}


Expand Down Expand Up @@ -401,7 +401,7 @@
networkRequest.body = "";
}

if(isValidURL(networkRequest.url)) {
if(isValidURL(networkRequest.url)) {
NewRelic.noticeHttpTransaction(networkRequest.url, networkRequest.method, networkRequest.status, networkRequest.startTime, networkRequest.endTime, networkRequest.bytesSent, networkRequest.bytesreceived, networkRequest.body,networkRequest.params);
}
}
Expand Down Expand Up @@ -480,10 +480,7 @@
}
});
} else {
if(options === undefined) {
options = {};
}
options['headers'] = {};
options = {headers:{}};
options.headers['newrelic'] = headers['newrelic'];
options.headers['traceparent'] = headers['traceparent'];
options.headers['tracestate'] = headers['tracestate'];
Expand Down Expand Up @@ -518,8 +515,8 @@

function handleFetchSuccess(response, method, url, startTime,headers,params) {
response.text().then((v)=>{
if(isValidURL(url)) {

if(isValidURL(url)) {
NewRelic.noticeHttpTransaction(
url,
method,
Expand All @@ -533,7 +530,7 @@
headers
);
}

});
}

Expand All @@ -545,7 +542,7 @@
return false;
}
}

const defaultLog = window.console.log;
const defaultWarn = window.console.warn;
const defaultError = window.console.error;
Expand Down Expand Up @@ -681,5 +678,4 @@
};

module.exports = NewRelic;



0 comments on commit 832f486

Please sign in to comment.