diff --git a/CHANGELOG.md b/CHANGELOG.md index d67af6f9c..0921af507 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ - Active serving static files from the `/public` folder by default from rails - Display custom error message if the PDF invoice is not found - Report subsription mismatch with user's group +- Added sentry for error reporting - Fix a bug: unable to run test in negative timezones (#425) - Fix a bug: providing an array of attributes to filter OpenApi data, results in error - Fix a bug: unable to manage stocks on new products diff --git a/Gemfile b/Gemfile index a90ff1d16..0ebaab188 100644 --- a/Gemfile +++ b/Gemfile @@ -143,3 +143,7 @@ gem 'sassc', '= 2.1.0' gem 'redis-session-store' gem 'acts_as_list' + +# Error reporting +gem 'sentry-rails' +gem 'sentry-ruby' diff --git a/Gemfile.lock b/Gemfile.lock index 5bf61ccf1..8ec03ab3c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -397,6 +397,11 @@ GEM activerecord (>= 4) activesupport (>= 4) semantic_range (3.0.0) + sentry-rails (5.7.0) + railties (>= 5.0) + sentry-ruby (~> 5.7.0) + sentry-ruby (5.7.0) + concurrent-ruby (~> 1.0, >= 1.0.2) sha3 (1.0.1) shakapacker (6.2.0) activesupport (>= 5.2) @@ -559,6 +564,8 @@ DEPENDENCIES rubyzip (>= 1.3.0) sassc (= 2.1.0) seed_dump + sentry-rails + sentry-ruby sha3 shakapacker (= 6.2.0) sidekiq (>= 6.0.7) @@ -574,4 +581,4 @@ DEPENDENCIES webmock BUNDLED WITH - 2.3.25 + 2.3.26 diff --git a/config/initializers/sentry.rb b/config/initializers/sentry.rb new file mode 100644 index 000000000..f7808789d --- /dev/null +++ b/config/initializers/sentry.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +Sentry.init do |config| + config.excluded_exceptions += ['Pundit::NotAuthorizedError'] + + config.before_send = lambda do |event, hint| + if hint[:exception].is_a?(Redis::CommandError) && hint[:exception].message == 'LOADING Redis is loading the dataset in memory' + nil + else + event + end + end + + if ENV.fetch('ENABLE_SENTRY', 'false') == 'true' + config.dsn = 'https://b7dd8812fd0d4d4eac907001e2efec86@o486357.ingest.sentry.io/4504446773886976' + end + + config.breadcrumbs_logger = [:active_support_logger] + + # Set traces_sample_rate to 1.0 to capture 100% + # of transactions for performance monitoring. + # We recommend adjusting this value in production. + config.traces_sample_rate = 0.01 + config.environment = Rails.env +end diff --git a/doc/environment.md b/doc/environment.md index 3e71ea414..8f290b0de 100644 --- a/doc/environment.md +++ b/doc/environment.md @@ -300,6 +300,11 @@ Accordingly, `RAILS_LOCALE` and `APP_LOCALE` must be configured to `zu`. NO_COLOR If set to any value, this will set `config.colorize_logging` to `false`, disabling ANSI color codes when logging information. + + + ENABLE_SENTRY + +Sentry is an automated error reporting tool. It is disabled by default, but you can enable it by setting `ENABLE_SENTRY=true`. ## OpenLab settings diff --git a/env.example b/env.example index 38b00ec3e..1b52f176e 100644 --- a/env.example +++ b/env.example @@ -61,6 +61,7 @@ LOG_LEVEL=debug RAILS_LOG_TO_STDOUT=true DISK_SPACE_MB_ALERT=100 ADMINSYS_EMAIL=admin@sleede.com +ENABLE_SENTRY=false # 5242880 = 5 megabytes MAX_IMPORT_SIZE=5242880 diff --git a/setup/env.example b/setup/env.example index 5907dd4ad..09ce72842 100644 --- a/setup/env.example +++ b/setup/env.example @@ -45,6 +45,7 @@ LOG_LEVEL=debug DISK_SPACE_MB_ALERT=1024 ADMINSYS_EMAIL= ALLOW_INSECURE_HTTP=false +ENABLE_SENTRY=false # 5242880 = 5 megabytes MAX_IMPORT_SIZE='5242880'