20 September 2014

Bugsnag integration for Unity

Recently we started using bugsnag in kweetet. Bugsnag is a website that exposes an api that you can use to send your error reporting to, and then you have a nice interface to follow up on these errors, assign them to users, resolve them, etc. All well described here. What a lifesaver it has been to us!

They also have a unity notifier. Too bad it only works on Android and iOS. Since we are developing for the unity webplayer I had no choice but to build my own notifier. This turns out to be really easy, starting with the notifier documentation. There's one subtlety that is not mentioned in the docs: you must provide a stack trace of at least one line, or the error report won't show. I received tremendous good help from the people on their support chat.

The one problem with the unity webplayer is that it runs in a security sandbox. With the WWW class you can only access websites that are on the same domain as the webplayer. So sending reports from kweetet.be to bugsnag.com is a no-go.

With a bit of research I managed to set up a proxy on that forwards the error reports to bugsnag, and with that solution I was able to receive the errors, hurray! Kweetet runs on nginx, I added this to our server configuration (something similar is possible with apache):

location ~ /bugsnag {
 rewrite /bugsnag / break;
 proxy_set_header X-Forwarded-Host $host;
 proxy_set_header X-Forwarded-Server $host;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_pass https://notify.bugsnag.com;
}

This enabled me to send the reports to our own domain which then gets forwarded. Now we receive all errors that occur in the game from anyone! The setup is similar to the official unity notifier. For web players you can specify another reporting url, depending on the proxy that you've set up. For all other platforms it should work with the default url.

I started a bitbucket project, I'll be improving this notifier since I keep on improving it for kweetet. This is the link: https://bitbucket.org/grrava/unitybugsnag.

It should also work on android and ios. I confirmed that it worked on android but not on ios. On android however I wasn't able to get a stacktrace, so probably the official unity notifier from bugsnag will be more suited for those two platforms.

As always, use the code at will - let me know if it helped you in any way or if you have questions, post them here or on the bitbucket project page.

No comments: