Iskandar Setiadi

Flag #6 - Leveraging Error Logging and Monitoring with Sentry


First of all, thank you for 4000 views in 6 posts!

A quick blog post in the middle of the week: There are a number of interesting tools for monitoring out there, such as CloudWatch, Fluentd, Nagios, etc. One of the most important monitoring tools is a real-time error monitoring system, so that we don't need to rely to users' report and we can implement the hotfix quicker. Sentry, which can be accessed at https://getsentry.com/ is not a logging system, but an error logging system. What is the difference? Error logging system should give a more detailed trace logs compared to a normal logging system and we don't actually care about the trace logs size as long as we can fix those bugs quickly. For example, a system may have million of requests per day and we may want to log all of those requests to our favorite analytic tools. However, the number of errors may be less than hundred per day. So, an error logging system is not created to replace your usual monitoring tools, but we can utilize it in order to make the entire product development and bug fixes faster than ever.

Of course, there are several competitors of Sentry out there: Airbrake, Bugsnag, etc. I haven't tested all of them one by one, but from several reviews, Sentry seems to have a better advantage compared to the others. If you're interested in it, I suggest you to read the following posts:
http://stackshare.io/stackups/sentry-vs-bugsnag-vs-airbrake https://www.quora.com/Why-would-you-use-Airbrake-over-Sentry

In short, I believe that each of them have their own advantages and disadvantages. Several famous companies which are using those services:
* Sentry: Instagram, Uber, Path, Musixmatch, etc
* Airbrake: Foursquare, Kickstarter, etc
* Bugsnag: LinkedIn, Zendesk, etc

As you can see, each of them are quite battle-tested in handling million of requests per day without any significant problem. In any case, if you haven't used any error logging system before reading this post, I recommend you to give a short try with these tools.

Sentry is commercializing itself as a modern error logging and aggregation platform. Historically, Sentry started as an open source project 4 years ago and their codebase can be at https://github.com/getsentry/sentry. Sentry itself is implemented in Python and it used to be integrated with Django. Nowadays, Sentry has supported a broad range of programming languages, which can be seen in the picture below.

Sentry also offers a lot of integration with other apps and services, which are commonly used in our development process. We can automatically make an issue in Github/Bitbucket/Jira, we can send a notification to our Slack team chat, and we can integrate it with a lot of other tools.

For example, let's say we have a following code:


import logging
from raven.handlers.logging import SentryHandler
from raven.conf import setup_logging

# . . . Some other codes here

def stupid(): t = 5 * 5 return t / 0

def main(): # Manually specify a client client = Client('https://[secret]@app.getsentry.com/[project_id]') handler = SentryHandler(client, level=logging.ERROR) logging.info("Handler is ready to go!") # . . . Some other codes here try: z = stupid() except Exception, e: logging.exception("Division by zero!", extra={'hora': 'haro'})

if __name__ == '__main__': main()

What will happen then? Our server will send a number of information to the provided endpoint. Sentry will receive those messages, send you an error notification, and give you the following report:

The traceback is amazingly good, where it will show you the contents of each variable when the following error occurred. In the case above, it is shown that t is equal to 25. It will also show you the server information and several other information. If you're creating a website, it will also give you browser, device, and OS information.


* The second screenshot is taken from other code

If you're not satisfied with the provided information, you can also pass additional information to Sentry. In the example above, I try to pass {'hora': 'haro'} as an extra.


* The second screenshot is taken from other code

There are still a lot of features out there that you can leverage from Sentry. I may elaborate it more in the future, but I think this quick skit is enough for now.

Let's dive in to the uninteresting part. Sentry is not free, but you can utilize the 14-day free trial with all of those features. In addition, you still can receive 250 events per day after the trial period ends. This is still quite useful for, let's say, personal websites. In case you're wondering, an event is defined as a single occurrence of error. The cheapest (paid) one is $29 per month for 10 team members and 20 events reporting per minute. In any case, if your system receives more than 20 events per minute, you should be prepared with another cup of coffee in order to fix those bugs :p

Final words, I have no affiliation with Sentry :p And if you have better alternatives for error logging tools, feel free to share it here!

--
Iskandar Setiadi
Software Engineer at HDE, Inc.
Freedomofkeima's Github

Author: Iskandar Setiadi - Type: Work - Date: 16th Dec, 2015


# Back

  • Williammig

    I value the article. Awesome. Lapusnak
    1