From 4d79fd051e6f4878f127f7896035cd3af3ec93a7 Mon Sep 17 00:00:00 2001 From: Angel Ruiz-Bates Date: Mon, 7 Dec 2020 17:27:37 -0400 Subject: [PATCH 1/2] integrated rollbar --- Gemfile | 1 + Gemfile.lock | 2 + config/application.rb | 9 +++++ config/initializers/rollbar.rb | 71 ++++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 config/initializers/rollbar.rb diff --git a/Gemfile b/Gemfile index b3992de..e230d73 100644 --- a/Gemfile +++ b/Gemfile @@ -20,6 +20,7 @@ gem 'bcrypt', '~> 3.1.7' gem 'jwt' gem 'rack-cors' gem 'sidekiq' +gem 'rollbar' # Use Active Storage variant # gem 'image_processing', '~> 1.2' diff --git a/Gemfile.lock b/Gemfile.lock index c9105a8..69ac12d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -154,6 +154,7 @@ GEM redis (4.2.2) regexp_parser (1.8.2) rexml (3.2.4) + rollbar (3.1.1) rspec-core (3.10.0) rspec-support (~> 3.10.0) rspec-expectations (3.10.0) @@ -233,6 +234,7 @@ DEPENDENCIES rack-cors rails (~> 6.0.3, >= 6.0.3.4) redis (~> 4.0) + rollbar rspec-rails (~> 4.0.1) rubocop sidekiq diff --git a/config/application.rb b/config/application.rb index 4c47ad3..c1ea6e7 100644 --- a/config/application.rb +++ b/config/application.rb @@ -35,5 +35,14 @@ class Application < Rails::Application # Middleware like session, flash, cookies can be added back manually. # Skip views, helpers and assets when generating a new resource. config.api_only = true + + config.before_configuration do + env_file = File.join(Rails.root, '.env') + if File.exist?(env_file) + YAML.safe_load(File.open(env_file)).each do |key, value| + ENV[key.to_s] = value + end + end + end end end diff --git a/config/initializers/rollbar.rb b/config/initializers/rollbar.rb new file mode 100644 index 0000000..0b6baec --- /dev/null +++ b/config/initializers/rollbar.rb @@ -0,0 +1,71 @@ +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_SECRET'] + + # Here we'll disable in 'test': + if Rails.env.test? || Rails.env.development? + 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 +end From 28b97567be65317674f06d7b557dd9913ba8e0f3 Mon Sep 17 00:00:00 2001 From: Angel Ruiz-Bates Date: Mon, 7 Dec 2020 17:30:55 -0400 Subject: [PATCH 2/2] rubo --- Gemfile | 2 +- config/initializers/rollbar.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index e230d73..234db07 100644 --- a/Gemfile +++ b/Gemfile @@ -19,8 +19,8 @@ gem 'redis', '~> 4.0' gem 'bcrypt', '~> 3.1.7' gem 'jwt' gem 'rack-cors' -gem 'sidekiq' gem 'rollbar' +gem 'sidekiq' # Use Active Storage variant # gem 'image_processing', '~> 1.2' diff --git a/config/initializers/rollbar.rb b/config/initializers/rollbar.rb index 0b6baec..95e363b 100644 --- a/config/initializers/rollbar.rb +++ b/config/initializers/rollbar.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rollbar.configure do |config| # Without configuration, Rollbar is enabled in all environments. # To disable in specific environments, set config.enabled=false. @@ -5,9 +7,7 @@ config.access_token = ENV['ROLLBAR_SECRET'] # Here we'll disable in 'test': - if Rails.env.test? || Rails.env.development? - config.enabled = false - end + config.enabled = false if Rails.env.test? || Rails.env.development? # 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`