Sentry is an open source error-tracking system that helps Rails developers to monitor and track the error which is getting triggered in our code.
How Does Sentry Work?
Sentry provides an SDK for many platforms, frameworks, and languages, and easy to integrate with our application and program stacks like python, node.js, and ruby. It will monitor the application continuously and notify through the email or a phone call while we get an error in our code.
When to use Sentry?
While our code was running in production mode if it throws an error to end-users, who will notify the developers?
How did the developer come to know about the urgency and impact of the bug?
How to set a root cause of the bug quickly?
After resolving the bug, how developers know the fixes are correct or not?
All these above questions can get an answer to our question.
The workflow of Sentry
when the end-user hits the application’s server and unfortunately if it throws error to the users then sentry will immediately send a notification to the developer through either mail or slack or pager duty.
That specific notification will take us to the sentry application dashboard. In the dashboard we can clearly show the bug report and where it is affected, the end-users impact, and the details of end users. Also, from dashboard itself we can assign the bug to a particular developer in the team.
After identifying and resolving the issue, We can deploy the code to production, afterward no need to worry about the issue. Automatically sentry resolves the issue report aroused on dashboard once the code is deployed . If the issue occurs again, the Sentry will mark it as regression and again it will be intimated to the developers.
Configuring Sentry with Rails Framework
The process required to configure Sentry,
- Sign Up the account with sentry
- Configure an SDK With Ruby
- DSN Configuration
Sign Up the account with Sentry
Sign up and log in to the sentry with required credentials,
Configure An SDK With Ruby
Installation
If you’re using the builder, just add the gem in gemfile and lock with the latest gem version. Raven Ruby SDK available as gem plugin.
Note: Raven for Ruby is a client and integration layer for the Sentry error reporting API. It supports Ruby 1.9.3 and above version.
gem “sentry-raven”
Alternatively, if you want to install the development version from GitHub, you can install with below command,
gem “sentry-raven”, :github => “getsentry/raven-ruby”
Another case, If we want to integrate sentry manually, we require “ravan/base” insteadof “ravan” or “sentry-raven”.
In gemfile give the below command,
gem “sentry-raven”, require: false
Commands to initialize the code in our file,
require “raven/base”
require “raven/integrations/rails”
require “raven/integrations/delayed_job”
We’re almost done, Now, we need to configure the DSN with an application. We can find This SENTRY_DSN environment variable in project setting page under the API keys.
After adding and defining items to the log filter then sentry will not sent those items.
Some Inbuilt Features Of Sentry
Async With Raven
If the errors are continuously triggering in code, then Raven will immediately send the notifications to the sentry whereas Sentry already has explicitly configured with Raven to send the notifications asynchronously.
Moreover, Raven will create a background job, using a background job processor that will send notifications in the background.
Encoding
Raven compresses outgoing messages with gzip by default. If you want to disable the zip, need to config the below settings in the file named “application.rb”.
Environments
Sentry will process with all the environment live development, production and testing, Meanwhile if you want to process the particular environment then you can achieve it with the below mentioned way.
Excluded_exceptions
If you want to skip some exception, specify ‘excluded_exceptions’ in the configuration file.
Logger
Sentry uses the logger to address the bug reports. The default instance of Raven Raven::Logger because Raven respects the logger status.
Notification
Typically, Sentry sends an error report notification to the specified email which is default configured with the Sentry.
The End! Almost I have covered all the topics that could help to integrate Rails with Sentry. Luckily, This open source tool will seamlessly help us to track and fix the errors then & thereby providing clear insights into the error report.
For more Technical blogs, check out our largest blog repository and for any inquiries on hiring Rails developer reach us via info@agiratech.com