The first time i searched about sentry in the internet was quite a confusing time. Because google was showing some comic character from marvel where i was told that sentry is a great tool for detecting errors and exceptions in an application. Setting aside my interest for this newly found superhero(who can defeat batman ), I concentrated on the sentry i wanted to know and below is the glimpse of some of my findings.
Even an well-coded and well-tested application can have exceptional error scenario that can be hard to debug and ressolve. Sentry comes like a messiah in this situation. So the question may arise, What this actually is? Sentry is an open-source real time error tracking system in all the environments of an application lifecycle. It is an easily configurable system which support many programming languages and their framworks in frontend, backend, mobile and desktop like Java, Python, Ruby, React, c#, PHP and more. Many reknowed companies as well as start-ups have given their faith in their product development and producing smooth and error-free systems for the users.
Installation in Rails
Creating an account in sentry is free for developers(although the error tacking number is limited) with the option of enterprse options with unlimited track. To connect the project with sentry we need to create an account in sentry and collect the DSN string for communicate project with sentry. This DSN value is a secret key assigned for the project. So we should handle it with care. For this we will save the DSN value in environmental variable file as
SENTRY_DSN and call it in the project as
Now to ease the integration of sentry has an official gemfile named sentry-ruby . To use this we need to follow 2 steps:
in the gemfile and run
- In the
application.rbsimply add the DSN value we created and restart the server.
Sentry.init do |config| config.dsn = ENV["SENTRY_DSN"] end
After integrating the sentry in the project, next we can create an exception from our console(dont forget to restart the console too). Run this code from the console you will see an entry of exception in your own dashboard.
Sentry.capture_message("hello") begin 1 / 0 rescue ZeroDivisionError => exception Sentry.capture_exception(exception) end
and in the list: when you enter the error description:
User feedback is one of the enriching features of sentry system. It allows an end-user to volunteerily contribute to the source of an error. It is an excellent feature for the developers to recreate the bug scenario and fix them in the path of making a good software. This is particularly advantageous when the application has a error page known as
500 page. Enabling this feature in ruby projects is not so hazzardous but need to follow some steps. I am discussing the steps below:
- First we will create a 500 page for our application. It will be shown when an unexceptional error or exception occurs. So our 500.slim page will be:
= image_tag "error_500.png", class: "error-page-image"
which will generate
Now it will show the feedback form first like this
- Next step is to just fill this form up and submit the report. The person responsible to fix this issue can see the feedback in error page of that particular error
Thank you for reading
All Rights Reserved