Skip to content

Commit

Permalink
fix fetch instrumentation bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ndesai-newrelic committed Feb 20, 2024
1 parent 120a648 commit bf934db
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 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
21 changes: 18 additions & 3 deletions www/js/newrelic.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cordova.define("newrelic-cordova-plugin.NewRelic", function(require, exports, module) {
/*
* Copyright (c) 2022-present New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
Expand Down Expand Up @@ -402,7 +401,9 @@ cordova.define("newrelic-cordova-plugin.NewRelic", function(require, exports, mo
networkRequest.body = "";
}

if(isValidURL(networkRequest.url)) {
NewRelic.noticeHttpTransaction(networkRequest.url, networkRequest.method, networkRequest.status, networkRequest.startTime, networkRequest.endTime, networkRequest.bytesSent, networkRequest.bytesreceived, networkRequest.body,networkRequest.params);
}
}
},
false
Expand Down Expand Up @@ -479,7 +480,10 @@ cordova.define("newrelic-cordova-plugin.NewRelic", function(require, exports, mo
}
});
} else {
options = {headers:{}};
if(options === undefined) {
options = {};
}
options['headers'] = {};
options.headers['newrelic'] = headers['newrelic'];
options.headers['traceparent'] = headers['traceparent'];
options.headers['tracestate'] = headers['tracestate'];
Expand Down Expand Up @@ -514,6 +518,8 @@ cordova.define("newrelic-cordova-plugin.NewRelic", function(require, exports, mo

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

if(isValidURL(url)) {
NewRelic.noticeHttpTransaction(
url,
method,
Expand All @@ -526,9 +532,19 @@ cordova.define("newrelic-cordova-plugin.NewRelic", function(require, exports, mo
params,
headers
);
}

});
}

function isValidURL(url) {
try {
const newUrl = new URL(url);
return newUrl.protocol === 'http:' || newUrl.protocol === 'https:';
} catch (err) {
return false;
}
}

const defaultLog = window.console.log;
const defaultWarn = window.console.warn;
Expand Down Expand Up @@ -666,5 +682,4 @@ cordova.define("newrelic-cordova-plugin.NewRelic", function(require, exports, mo

module.exports = NewRelic;

});

0 comments on commit bf934db

Please sign in to comment.