Using BugSense to Track Errors and Events in a Windows Phone App
Join the DZone community and get the full member experience.
Join For Free
Why BugSense?
Errors/exceptions are annoying and helpful at the same time. They can annoy you while creating your app. At the same time, they help you to improve the quality of your app (most of the time, that is). They annoy your users, if they lead to crash your app. At the same time, they are a good chance to get in contact with your users – for example you could catch unhandled exceptions and ask the user to send it over to you.
But what if your users choose to ignore the error? How should you improve your app’s quality? What if the only thing you get are bad reviews? Pretty hard task, especially if you have a completely new app. I had that situation over and over again – and of course, I was annoyed of that fact.
So I researched the internet for solutions. Google Analytics is one service that works and is mostly used in enterprise apps. I use it in the app I am developing for my 9to5 job on Windows Phone and Android, but I only am able to use it on Windows Phone due to a third party library. If the developer chooses to not continue his efforts, at one point it will stop working or at least needs manual maintenance from my part (looking at you, TweetSharp).
BugSense was the second alternative I had a look on. They are a big player in the mobile monitoring market, and have a very good basic model, that fits perfectly for the average developer (500 errors per month, 350000 data points per month for free) to get started, and their first pricing stage if you have more apps comes close to what indie developers like I am need to maintain more than one app.
On top, there is often the possibility to gain promo codes that unlock some of the functionalities for free for a limited time (like DVLUP promo codes etc.).
I can only recommend to give it at least a try. On major point on the plus side was the fact that BugSense also has a Windows Phone app that helps you to keep up to date with the errors and insights while you are on the go.
Setting up an app is also pretty easy, be it tracking errors or tracking events. Let’s have a look at the code.
Error handling
The first thing you’ll need to to install is the BugSense SDK either via Nuget (‘BugSense.WP8′ for WP 8.0 / 8.1 Silverlight, ‘BugSense.WP81′ for WP 8.1 Runtime) or you can download the package manually here and import the dll for SL projects.
Next step is to authorize your app in your app’s constructor:
public App() { //connect your app to the BugSense API’s BugSenseHandler.Instance.InitAndStartSession(new ExceptionManager(Current), RootFrame, "<your key="" api="">"); }</your>
For WINPRT projects, you’ll leave the Rootframe parameter out.
The official documentation says you don’t need the UnhandledException handler any longer and can remove it. In a real Windows Phone app, this could lead to crashes from exceptions by the BugSense handler that are not caught without any error logging – thanks to Sara Silva for pointing me to that (follow her!). I’ll leave it up to you if you leave it there to handle those errors or if you are fine with your app being crashing in this case.
I am also telling you what I did: I left the UnhandledException handler in there because my users are already used to another thing I used before: Telerik’s RadDiagnostics, which enables users to send those error messages via mail. I left it there for two reasons:
- to keep the interaction with my user that I already had when an error showed up
- to prevent my app from crashing – no matter if the error comes from BugSense or my code
For error logging, there is only one point left to do. After my experience, error logging only works after registering a new instance of the BugSense handler (I am doing this in my first page’s Loaded event):
BugSenseHandler.Instance.RegisterAsyncHandlerContext();
That’s all, now all your errors are collected into your BugSense account.
Event tracking
If you want to track events in your app, BugSense is helpful on that task, too. The easiest way to achieve is this one:
await BugSenseHandler.Instance.LogEventAsync(“<your here="" text="" event="" custom="">");</your>
Conclusion
With BugSense you don’t need a complex setup to collect errors and track events remotely from your users devices. Pricing is moderate, and you even have a mobile app that allows you to keep track of errors when your are not on your dev machine. BugSense has a lot more options, for getting started, I hope this post is helpful for some of you.
Until the next post, happy coding!
Published at DZone with permission of Marco Siccardi, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
Batch Request Processing With API Gateway
-
Execution Type Models in Node.js
-
Building and Deploying Microservices With Spring Boot and Docker
-
JavaFX Goes Mobile
Comments