How to add custom data to Environment summary for every message
Nimble
Posted on
Aug 13 2014
We have a few environment details that we need to be sent with errors, for every occurrence. For example, our application supports both offline and online modes (note: offline mode is elective). As such, whenever an error occurs, we need to know:
- Network connection type (if any), Wifi, 3G, GRPS, None
- Whether the application was in 'local database only mode' (aka 'offline mode').
What would cover all bases, would be somewhere in the singleton client instance, a method to register a callback for populating a custom region that would appear in the "Environment" section of the error report.
Something like this:
RaygunClient.AddCustomEnvironmentData("NetworkType",
(appDelegate) => (appDelegate as MyApplicationDelegate).NetworkConnectionType);
RaygunClient.AddCustomEnvironmentData("Offline",
(appDelegate) => (appDelegate as MyApplicationDelegate).IsOffline);
(of course, the RaygunClient would wrap invocation of each of these lambdas to ensure they don't cause the error report to fail).
Which would result in this in the outbound message:
"Environment": {
"ProcessorCount": 8,
"OSVersion": "iPhone OS 6.1",
"WindowBoundsWidth": 768,
"WindowBoundsHeight": 1024,
"CurrentOrientation": "Unknown",
"PackageVersion": "25",
"Architecture": "x86_64",
"Model": "iPad Simulator",
"TotalPhysicalMemory": 4294967295,
"AvailablePhysicalMemory": 10645504,
"DeviceName": "iPad Simulator",
"UtcOffset": 12,
"Locale": "English (United States)"
},
"CustomEnvironment": {
"NetworkType": "Wifi",
"Offline": false
}
Jason Fauchelle
Raygun
Posted on
Aug 14 2014
Hello Nimble
An existing feature that you may find useful for this is the ability to attach custom data to each exception message sent. This can be done by calling the Send method overload that takes in a list of tags and a dictionary. Your custom data would be best in a dictionary, so you can send null as the list of tags.
To use this feature, you'd currently need to stop using the Attach method, and set up your own event handlers as seen below where you could call the Send method yourself, passing in your custom data:
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
Some of our other Raygun providers have a SendingMessage event which would allow you to continue using the Attach method, and then add a handler to the RaygunClient.SendingMessage event where you can add additional values to the RaygunMessage object before it is serialized and sent. This is a feature that we can add to the Xamarin.iOS provider which will make this even easier for you.
This custom data will be displayed in a Custom tab on the Raygun dashboard though, not inside the Environment tab.
Try this out and let me know if that works for you.
-Jason fauchelle
Nimble
Posted on
Aug 14 2014
HiJason,
Thanks for that - I have implemented the change you suggested and it will indeed suit our needs. When this is implemented in the Xamarin binding, I will move to that implementation.
Thanks and regards
Jason Fauchelle
Raygun
Posted on
Aug 15 2014
Excellent, I've implemented the SendingMessage event for Xamarin.iOS and plan to push the NuGet package with this feature next week.
-Jason Fauchelle
Jason Fauchelle
Raygun
Posted on
Aug 22 2014
The SendingMessage event is now available in the Xamarin.iOS provider in the latest NuGet package now: https://www.nuget.org/packages/Mindscape.Raygun4Net/