Skip to content

Commit

Permalink
Release 6.2.2 (#70)
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

* 1)Fixes the issue where the response body appears empty for HTTP requests.
2) Upgraded native Android agent to v7.0.0

* 1)Fixes the issue where the response body appears empty for HTTP requests.
2) Upgraded native Android agent to v7.0.0

---------

Co-authored-by: mchavez-newrelic <[email protected]>
  • Loading branch information
ndesai-newrelic and mchavez-newrelic authored Jul 21, 2023
1 parent 3cb2cfe commit b9c0b6b
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

# 6.2.2

### New in this release
* Fixes the issue where the response body appears empty for HTTP requests.
* Upgraded native Android agent to v7.0.0

# 6.2.1

### New in this release
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ By default, these configurations are already set to true on agent start.
```
## Error Reporting
### recordError(err: [Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)) : void;
### recordError(err: [Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error), attributes?: {[key: string]: boolean | number | string}) : void;
Records JavaScript errors for Cordova. It is useful to add this method by adding it to the error handler of the framework that you are using. Here are some examples below:
### Angular
Expand Down
10 changes: 5 additions & 5 deletions 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.1">
id="newrelic-cordova-plugin" version="6.2.2">
<name>NewRelic</name>
<description>New Relic Cordova Plugin for iOS and Android</description>
<author>New Relic</author>
Expand All @@ -18,16 +18,16 @@
<engine name="cordova-android" version=">=5.0.0" />
</engines>

<preference name="PLUGIN_VERSION" default="6.2.1" />
<preference name="PLUGIN_VERSION" default="6.2.2" />
<preference name="CRASH_REPORTING_ENABLED" default="true" />
<preference name="DISTRIBUTED_TRACING_ENABLED" default="true" />
<preference name="INTERACTION_TRACING_ENABLED" default="true" />
<preference name="DEFAULT_INTERACTIONS_ENABLED" default="true" />
<preference name="LOGGING_ENABLED" default="true" />
<preference name="LOG_LEVEL" default="default" />
<preference name="WEB_VIEW_INSTRUMENTATION" default="true" />
<preference name="COLLECTOR_ADDRESS" default="x" />
<preference name="CRASH_COLLECTOR_ADDRESS" default="x" />
<preference name="COLLECTOR_ADDRESS" default="mobile-collector.newrelic.com" />
<preference name="CRASH_COLLECTOR_ADDRESS" default="mobile-crash.newrelic.com" />
<preference name="FEDRAMP_ENABLED" default="false" />

<platform name="ios">
Expand Down Expand Up @@ -78,7 +78,7 @@

<platform name="android">
<preference name="ANDROID_APP_TOKEN" default="x" />
<preference name="ANDROID_AGENT_VER" default="6.11.1" />
<preference name="ANDROID_AGENT_VER" default="7.0.0" />

<config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.INTERNET" />
Expand Down
8 changes: 8 additions & 0 deletions src/android/NewRelicCordovaPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,20 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
final String errorMessage = args.getString(1);
final String errorStack = args.getString(2);
final Boolean isFatal = args.getBoolean(3);
final JSONObject attributesAsJson = args.getJSONObject(4);

HashMap<String, Object> exceptionMap = new HashMap<>();
try {
exceptionMap.put("name", errorName);
exceptionMap.put("message", errorMessage);
exceptionMap.put("isFatal", isFatal);
if (attributesAsJson != null) {
final Map<String, Object> attributes = new Gson().fromJson(String.valueOf(attributesAsJson),
Map.class);
for (String key : attributes.keySet()) {
exceptionMap.put(key, attributes.get(key));
}
}
} catch (IllegalArgumentException e) {
Log.w("NRMA", e.getMessage());
}
Expand Down
6 changes: 6 additions & 0 deletions src/ios/NewRelicCordovaPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ - (void)recordError:(CDVInvokedUrlCommand *)command {
NSString* errorMessage = [command.arguments objectAtIndex:1];
NSString* errorStack = [command.arguments objectAtIndex:2];
NSString* isFatal = @"false";
NSDictionary* errorAttributes = [command.arguments objectAtIndex:4];

if ([[command.arguments objectAtIndex:3] boolValue] == YES) {
isFatal = @"true";
Expand All @@ -207,6 +208,11 @@ - (void)recordError:(CDVInvokedUrlCommand *)command {
attributes[@"cause"] = errorMessage;
attributes[@"reason"] = errorMessage;
attributes[@"fatal"] = isFatal;
if (errorAttributes != nil && ![errorAttributes isKindOfClass:[NSNull class]]) {
for(id key in errorAttributes) {
attributes[key] = errorAttributes[key];
}
}

NSMutableArray* stackTraceArr = [self parseStackTrace:errorStack];
attributes[@"stackTraceElements"] = stackTraceArr;
Expand Down
18 changes: 16 additions & 2 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,29 @@ exports.defineAutoTests = () => {
window.NewRelic.recordError(new ReferenceError);
window.NewRelic.recordError(new Error);

// should parse errors with non-empty custom attributes
let errorAttributes = new Map([
["errorKey1", "errorValue1"],
["errorKey2", 2],
["errorKey3", true]
]);
window.NewRelic.recordError(exampleError, errorAttributes);

// should parse errors with null custom attributes
window.NewRelic.recordError(exampleError, null);

// should parse errors with empty custom attributes
window.NewRelic.recordError(exampleError, {});

// Bad arguments
window.NewRelic.recordError(undefined);
window.NewRelic.recordError(null);
window.NewRelic.recordError(123);
window.NewRelic.recordError(true);

let numOfNativeCalls = cordova.exec.calls.count() - window.console.warn.calls.count();
expect(numOfNativeCalls).toBe(6);
expect(window.NewRelic.recordError).toHaveBeenCalledTimes(10);
expect(numOfNativeCalls).toBe(9);
expect(window.NewRelic.recordError).toHaveBeenCalledTimes(13);
});

it('should parse JS error with missing fields', () => {
Expand Down
14 changes: 12 additions & 2 deletions www/js/newrelic.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,13 @@ var NewRelic = {
/**
* Records JavaScript errors for Cordova.
* @param {Error} err The error to record.
* @param {Map<string, boolean|number|string>} attributes Optional attributes that will be appended to the handled exception event created in insights.
*/
recordError: function(err, cb, fail) {
recordError: function(err, attributes={}, cb, fail) {
let errorAttributes = attributes instanceof Map ? Object.fromEntries(attributes) : attributes;
if (attributes === null) {
errorAttributes = {};
}
if (err) {
var error;

Expand All @@ -139,7 +144,7 @@ var NewRelic = {
}

if(error !== undefined) {
cordova.exec(cb, fail, "NewRelicCordovaPlugin", "recordError", [error.name, error.message, error.stack, false]);
cordova.exec(cb, fail, "NewRelicCordovaPlugin", "recordError", [error.name, error.message, error.stack, false, errorAttributes]);
} else {
window.console.warn('Undefined error in NewRelic.recordError');
}
Expand Down Expand Up @@ -346,8 +351,13 @@ window.XMLHttpRequest.prototype.send = function (data) {
if (this.readyState === this.DONE) {
networkRequest.endTime = Date.now();
networkRequest.status = this.status;
if(this.responseText !== undefined) {
networkRequest.bytesreceived = this.responseText.length;
networkRequest.body = this.responseText;
} else {
networkRequest.bytesreceived = 0;
networkRequest.body = "";
}


NewRelic.noticeHttpTransaction(networkRequest.url, networkRequest.method, networkRequest.status, networkRequest.startTime, networkRequest.endTime, networkRequest.bytesSent, networkRequest.bytesreceived, networkRequest.body);
Expand Down

0 comments on commit b9c0b6b

Please sign in to comment.