Tracking current network state for Android

Liam

Posted on
Dec 11 2014

Hi,

I would like to send the current network state of the device (connected to Wifi, connected to cellular) along with any uncaught exceptions. Each time the network state changes I'd like to update that information sent along with the future exception so I always have the correct network state. The implementation of the network state change is fine but I'm unsure how to append this information to any subsequent exception sent via Raygun.

Can you advise on the best way to achieve this?

Thanks Liam


Callum

Posted on
Dec 11 2014

Hi Liam,

You could implement this scenario now by creating your own implementation of Thread.UncaughtExceptionHandler which sets the current network state data on a Map object, then passes this object to RaygunClient.Send as the third parameter (the userCustomData param) inside the uncaughtException overload. This will replace the default behaviour of RaygunClient.AttachExceptionHandler. The implementation of your handler would be very similar to the default implementation at line 421 in RaygunClient.cs, but would simple add/update the latest network state prior to line 449 for instance.

As this can be handled by the provider I am working on a new version which will allow updating the customData map after the default handler has been attached, which means you won't have to provide your own implementation. This is dependent on QA and Maven's release delay so if you want it working immediately you could implement the above. Otherwise I will post here when a new version is available with this feature.


Callum

Posted on
Dec 11 2014

I'm pleased to report that the above feature request has now been implemented in two ways and released to GitHub and Maven where it will be available within the next 24 hours as v1.3.0. This adds the ability to set both tags and custom data with

RaygunClient.SetUserCustomData(map)

When exceptions are caught after this by the default handler (after calling AttachExceptionHandler() as standard), the provided map (or list for SetTags) will be attached to the outgoing exception payload.

For your specific need of seeing the network connectivity state, we're now providing this on the Request object as a string. This will appear as 'disconnected', 'connected', 'connected - mobile/wifi/etc'. This data will be available under the Request tab in the web app.

If you require additional data you can call Raygun.SetUserCustomData and pass in the appropriate updated network connection info, most likely in a handler in response to the connection change event. This will appear under the Custom tab as standard.


Dan Too

Posted on
Jan 29 2015

I'm trying to do exactly this kind of thing for iOS, but can't seem to figure out how I can do it. Do you guys know if it's possible to override the exception parameters for a crash to send this kind of information?

Seems pretty easy to do for a manual send: but I'd love to be able to have network state sent with a crash


Jason Fauchelle

Raygun

Posted on
Jan 30 2015

Hi Dan,

Just to confirm, are you working with the native Raygun4iOS provider, or the Xamarin Raygun4Net provider?

-Jason Fauchelle


Dan Too

Posted on
Jan 30 2015

Native iOS, usually via the cocoapod


Jason Fauchelle

Raygun

Posted on
Jan 30 2015

Thanks Dan,

So you are sending the network connection state as custom data during a manual send, but also want to specify this for automatic sends? This currently is not possible, but I can look at adding this feature in the next version which I'll be working on soon. This would either be done by providing some kind of sending-error callback that allows you to attach the custom data before sending, or by setting "global" custom data on the shared Raygun client that will be sent with automatic error reports.

If you could send the code snippet you are using to determine the network connection state, that would help us too.

-Jason Fauchelle


Dan Too

Posted on
Jan 30 2015

At the moment, I'm using a bunch of things, like the Reachability framework, and getting IP addresses in a way similar to:

http://stackoverflow.com/questions/7072989/iphone-ipad-osx-how-to-get-my-ip-address-programmatically

Needless to say though, it'd be absolutely amazing if you could add this! =)


Jason Fauchelle

Raygun

Posted on
Feb 11 2015

Hi Dan,

The latest version of Raygun4iOS (v1.6.0) is now available. This can be updated via CocoaPods, or from the downloads page: https://raygun.io/raygun-providers/ios

you can now call the setUserCustomData method to set a custom dictionary on the Raygun shared reporter instance:

[[Raygun sharedReporter] setUserCustomData:dictionary];

This dictionary will then be sent with all automatic crash reports. So you could now detect changes to the network state, then call setUserCustomData with an updated dictionary of custom values.

Please let us know if you have any questions about this.

-Jason Fauchelle


Dan Too

Posted on
Feb 11 2015

Amazing thanks! I'll give it a go over the next couple of weeks and let you know how it goes. Thanks so much for the update


Reply