From 3212ba98add3d1f58d78120d32974c2d34c87d65 Mon Sep 17 00:00:00 2001 From: Jan Hovancik Date: Fri, 10 Jan 2025 12:33:07 +0000 Subject: [PATCH] Adds rollbar --- .env.example | 2 + Gemfile | 3 ++ Gemfile.lock | 2 + config/initializers/rollbar.rb | 85 ++++++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 config/initializers/rollbar.rb diff --git a/.env.example b/.env.example index 855ee8c..6c121e4 100644 --- a/.env.example +++ b/.env.example @@ -2,9 +2,11 @@ DATABASE_URL=postgres://postgres:@db:5432/bsdsec_development TEST_DATABASE_URL=postgres://postgres:@db:5432/bsdsec_test TEST_EMAIL=test@example.com MAILGUN_INGRESS_API_KEY=asdf +MAILGUN_INGRESS_SIGNING_KEY=notSureWhichOne # Consumer Keys TWITTER_CONSUMER_KEY=aa TWITTER_CONSUMER_SECRET=ddd # Access Token and Secret TWITTER_ACCESS_TOKEN=sdss TWITTER_ACCESS_SECRET=asda +ROLLBAR_ACCESS_TOKEN=yourtokenhere diff --git a/Gemfile b/Gemfile index 17a2a50..5d7522c 100644 --- a/Gemfile +++ b/Gemfile @@ -54,3 +54,6 @@ gem 'bootsnap' # Monitoring gem 'scout_apm' + +# Error tracking +gem 'rollbar' diff --git a/Gemfile.lock b/Gemfile.lock index 8b63ebb..f818ded 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -186,6 +186,7 @@ GEM rb-fsevent (0.11.2) rb-inotify (0.11.1) ffi (~> 1.0) + rollbar (3.6.0) sass-rails (6.0.0) sassc-rails (~> 2.1, >= 2.1.1) sassc (2.4.0) @@ -249,6 +250,7 @@ DEPENDENCIES pg puma rails (~> 6.0) + rollbar sass-rails (~> 6.0) scout_apm simplecov diff --git a/config/initializers/rollbar.rb b/config/initializers/rollbar.rb new file mode 100644 index 0000000..0048152 --- /dev/null +++ b/config/initializers/rollbar.rb @@ -0,0 +1,85 @@ +Rollbar.configure do |config| + # Without configuration, Rollbar is enabled in all environments. + # To disable in specific environments, set config.enabled=false. + + config.access_token = ENV['ROLLBAR_ACCESS_TOKEN'] + + # Here we'll disable in 'test': + if Rails.env.test? + config.enabled = false + end + + # By default, Rollbar will try to call the `current_user` controller method + # to fetch the logged-in user object, and then call that object's `id` + # method to fetch this property. To customize: + # config.person_method = "my_current_user" + # config.person_id_method = "my_id" + + # Additionally, you may specify the following: + # config.person_username_method = "username" + # config.person_email_method = "email" + + # If you want to attach custom data to all exception and message reports, + # provide a lambda like the following. It should return a hash. + # config.custom_data_method = lambda { {:some_key => "some_value" } } + + # Add exception class names to the exception_level_filters hash to + # change the level that exception is reported at. Note that if an exception + # has already been reported and logged the level will need to be changed + # via the rollbar interface. + # Valid levels: 'critical', 'error', 'warning', 'info', 'debug', 'ignore' + # 'ignore' will cause the exception to not be reported at all. + # config.exception_level_filters.merge!('MyCriticalException' => 'critical') + # + # You can also specify a callable, which will be called with the exception instance. + # config.exception_level_filters.merge!('MyCriticalException' => lambda { |e| 'critical' }) + + # Enable asynchronous reporting (uses girl_friday or Threading if girl_friday + # is not installed) + # config.use_async = true + # Supply your own async handler: + # config.async_handler = Proc.new { |payload| + # Thread.new { Rollbar.process_from_async_handler(payload) } + # } + + # Enable asynchronous reporting (using sucker_punch) + # config.use_sucker_punch + + # Enable delayed reporting (using Sidekiq) + # config.use_sidekiq + # You can supply custom Sidekiq options: + # config.use_sidekiq 'queue' => 'default' + + # If your application runs behind a proxy server, you can set proxy parameters here. + # If https_proxy is set in your environment, that will be used. Settings here have precedence. + # The :host key is mandatory and must include the URL scheme (e.g. 'http://'), all other fields + # are optional. + # + # config.proxy = { + # host: 'http://some.proxy.server', + # port: 80, + # user: 'username_if_auth_required', + # password: 'password_if_auth_required' + # } + + # If you run your staging application instance in production environment then + # you'll want to override the environment reported by `Rails.env` with an + # environment variable like this: `ROLLBAR_ENV=staging`. This is a recommended + # setup for Heroku. See: + # https://devcenter.heroku.com/articles/deploying-to-a-custom-rails-environment + config.environment = ENV['ROLLBAR_ENV'].presence || Rails.env + + BLACKLISTED_REGEX = %r{ + ^/wp-login/| + ^/\.well-known/| + }x.freeze + + handler = proc do |options| + url = options[:exception].message[/.*"([^"]*)"/,1] + if options[:exception].is_a?(ActionController::RoutingError) + raise Rollbar::Ignore if url =~ BLACKLISTED_REGEX + end + end + + config.before_process << handler +end