Confused by latest JavaScript documentation regarding customData
Joshua
Posted on
May 15 2014
When attaching custom data on init the documentation shows:
Raygun.init('yourApiKey', null).attach().withCustomData([ {custom: "data" }]);
It also says that custom data is an array that may contain objects. I might be missing something, but that seems to be contradicted by the active state example which just returns it as an object:
var desiredNum: 1; function getMyData() { return { num: desiredNum }; } Raygun.init('apikey').attach().withCustomData(getMyData); desiredNum++;
So my question is should I submit custom data as an object with the attributes holding my organized custom data or should I submit it as an array with objects?
Callum
Posted on
May 16 2014
Fair questions, the documention needs some clarification here which I am updating now.
withCustomData is liberal about what it accepts, the only difference will be the manner in which it is presented in the Custom Data tab on the dashboard. Passing in an array of objects is acceptable, and will result in them presented with their 0, 1, 2... index.
An alternative is to pass in one object with keys and sub objects as values, for instance:
{number : {one: 1}, otherNumber : {two: 2}}
Both of these will set the custom data once as they are passed in by value, thus if they refer to variables, their state will be the value they had when withCustomData was called.
To get around this, we offer the second option where a function can be passed in which returns an object with variables from an outer scope (closure). In this way it allows you to transmit the current state of the variables.
To sum up: if you want to send data that is set once on script init & doesn't change, pass in an object or array of objects. If your data will change, and you want to see the latest variable state at the time of an error, pass in a function which returns an object containing those variables.
Joshua
Posted on
May 17 2014
Much better now and I've got everything working with my attached custom data, thanks!