Skip to content

Sentry

Introduction

Sentry is a tool for error monitoring and application performance tracking. In our API, Sentry is used to collect information about exceptions and analyze issues occurring in the production environment.

Integrating Sentry with a Rails Application

To add Sentry to a Ruby on Rails application, we use the official sentry-ruby gem and its Rails extension sentry-rails.

gem 'sentry-ruby'
gem 'sentry-rails'

Configuration

The configuration file is located in config/initializers/sentry.rb

Sentry.init do |config|
  config.dsn = ENV['SENTRY_DSN']
  config.breadcrumbs_logger = [:active_support_logger, :http_logger]
  config.excluded_exceptions += [
    'ActionController::RoutingError',
    'ActiveRecord::RecordNotFound',
  ]
  config.send_default_pii = true
end

The value of SENTRY_DSN is retrieved from environment variables and points to the unique project address in Sentry. The value of SENTRY_ENVIRONMENT is retrieved from environment variables and indicates the environment from which errors are reported.

Automatic Error Capturing

Thanks to integration with Rails, Sentry automatically captures exceptions reported in the application. If an unhandled error occurs in the code, it will be sent to Sentry.

Manual Error Reporting

We can also manually report errors in the application, for example, in operations or services, using the LoggerTool object.

LoggerTool.log_exception(message) LoggerTool.log_message(message)

Summary

Sentry is a key tool in our API for:

Automatically monitoring errors in the production environment.

Manually reporting exceptions in the application code.

Tracking application performance and optimizing its operation.

Thanks to Sentry, we can identify and fix errors faster, increasing the stability and reliability of our API.