How does withCustomData work exactly?
Joshua
Posted on
May 03 2014
Following the example listed in the docs:
Raygun.init('yourApiKey', null).attach().withCustomData([{custom: myApp.someObject}]);
Does myApp.someObject get cloned and stored immediately after it has been declared? Or does a fresh copy of it get sent along when an error is reported? I'm hoping for the second so that a updated version of my object will get sent at the time of the error rather than the initialized values. Thanks in advance!
Callum
Posted on
May 05 2014
Hi Joshua,
Your second option is the intended behaviour, unfortunately the current 1.8.2 version only stores the current state of the object passed in to withCustomData at the time when it was called.
We've created a candidate implementation that will allow your desired behaviour- it's available from this branch here: https://raw.githubusercontent.com/MindscapeHQ/raygun4js/customdata-function/dist/raygun.min.js.
It can be used like this, which should hopefully be your expected use:
var desiredNum: 1;
function getMyData() {
return { num: desiredNum };
}
Raygun.init('apikey').attach().withCustomData(getMyData);
In this example, whenever an error is sent via Raygun4JS the current state of desiredNum will be in the custom data. The supplied function should return an object with a key and value for each variable as standard- unexpected behaviour may result if the function just returns a variable.
If you could grab the branch of the library from the above link, give it a test and confirm that it suits your needs I can get it merge & deployed as a new version - let me know how it goes and if there's any issues.
Joshua
Posted on
May 09 2014
Yes, that does solve my issue. Thanks for the prompt reply!