From 9db8997e021fc653554f91c8a1a5247914d7f347 Mon Sep 17 00:00:00 2001 From: Weiwei Shi Date: Fri, 8 Sep 2017 15:18:43 -0600 Subject: [PATCH] on behalf of @astrilet, resubmit the rollbar PR #143 --- Gemfile | 3 ++ Gemfile.lock | 3 ++ app/models/user.rb | 12 +++++--- config/initializers/rollbar.rb | 54 ++++++++++++++++++++++++++++++++++ config/secrets.yml.sample | 1 + 5 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 config/initializers/rollbar.rb diff --git a/Gemfile b/Gemfile index 4dbcf9ea..d3c81959 100644 --- a/Gemfile +++ b/Gemfile @@ -13,6 +13,9 @@ gem 'i18n' gem 'globalize', '~>3.1.0' gem 'dragonfly' +# added rollbar for log monitoring +gem 'rollbar' + # Gems used only for assets and not required # in production environments by default. group :assets do diff --git a/Gemfile.lock b/Gemfile.lock index 77121eff..2dc0a05b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -208,6 +208,8 @@ GEM responders (1.1.2) railties (>= 3.2, < 4.2) rolify (5.1.0) + rollbar (2.15.1) + multi_json rspec (3.5.0) rspec-core (~> 3.5.0) rspec-expectations (~> 3.5.0) @@ -313,6 +315,7 @@ DEPENDENCIES rails (~> 3.2.22) recaptcha rolify + rollbar rspec rspec-rails rubyzip (~> 1.2.1) diff --git a/app/models/user.rb b/app/models/user.rb index 557474fc..0137dc38 100755 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -140,10 +140,14 @@ def is_org_admin? return !org_admin.nil? end - def org_type - org_type = organisation.organisation_type.name - return org_type - end + def org_type + org_type = organisation.organisation_type.name + return org_type + end + # For masking the ID that we send to rollbar + def id_as_hash + Digest::SHA2.hexdigest("#{DMPonline4::Application.config.secret_token}_#{id}") + end end diff --git a/config/initializers/rollbar.rb b/config/initializers/rollbar.rb new file mode 100644 index 00000000..e7c458a2 --- /dev/null +++ b/config/initializers/rollbar.rb @@ -0,0 +1,54 @@ +Rollbar.configure do |config| + config.access_token = ENV['ROLLBAR_ACCESS_TOKEN'] + + # Without configuration, Rollbar is enabled in all environments. + # To disable in specific environments, set config.enabled=false. + # Enable rollbar for production only + config.enabled = Rails.env.production? && config.access_token.present? + + # 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`, + # `username`, and `email` methods to fetch those properties. To customize: + # config.person_method = "my_current_user" + config.person_id_method = 'id_as_hash' + config.person_username_method = 'id_as_hash' + config.person_email_method = 'id_as_hash' + + # 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 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'] || Rails.env +end diff --git a/config/secrets.yml.sample b/config/secrets.yml.sample index 228f4488..812d33a9 100644 --- a/config/secrets.yml.sample +++ b/config/secrets.yml.sample @@ -8,3 +8,4 @@ MAILER_DEFAULT_HOST: "houston.library.ualberta.ca" MAILER_FROM: "dittest@ualberta.ca" EXCEPT_SENDER: "" EXCEPT_RECIPIENTS: "dittest@ualberta.ca" +ROLLBAR_ACCESS_TOKEN: ""