Skip to content
This repository was archived by the owner on Aug 29, 2023. It is now read-only.

Commit 97fdcfe

Browse files
authored
Merge pull request #147 from ualbertalib/rollbar-implementation
on behalf of @astrilet, resubmit the rollbar PR #143
2 parents adba1c4 + 9db8997 commit 97fdcfe

File tree

5 files changed

+69
-4
lines changed

5 files changed

+69
-4
lines changed

Gemfile

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ gem 'i18n'
1313
gem 'globalize', '~>3.1.0'
1414
gem 'dragonfly'
1515

16+
# added rollbar for log monitoring
17+
gem 'rollbar'
18+
1619
# Gems used only for assets and not required
1720
# in production environments by default.
1821
group :assets do

Gemfile.lock

+3
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ GEM
208208
responders (1.1.2)
209209
railties (>= 3.2, < 4.2)
210210
rolify (5.1.0)
211+
rollbar (2.15.1)
212+
multi_json
211213
rspec (3.5.0)
212214
rspec-core (~> 3.5.0)
213215
rspec-expectations (~> 3.5.0)
@@ -313,6 +315,7 @@ DEPENDENCIES
313315
rails (~> 3.2.22)
314316
recaptcha
315317
rolify
318+
rollbar
316319
rspec
317320
rspec-rails
318321
rubyzip (~> 1.2.1)

app/models/user.rb

+8-4
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,14 @@ def is_org_admin?
140140
return !org_admin.nil?
141141
end
142142

143-
def org_type
144-
org_type = organisation.organisation_type.name
145-
return org_type
146-
end
143+
def org_type
144+
org_type = organisation.organisation_type.name
145+
return org_type
146+
end
147+
# For masking the ID that we send to rollbar
148+
def id_as_hash
149+
Digest::SHA2.hexdigest("#{DMPonline4::Application.config.secret_token}_#{id}")
150+
end
147151

148152

149153
end

config/initializers/rollbar.rb

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
Rollbar.configure do |config|
2+
config.access_token = ENV['ROLLBAR_ACCESS_TOKEN']
3+
4+
# Without configuration, Rollbar is enabled in all environments.
5+
# To disable in specific environments, set config.enabled=false.
6+
# Enable rollbar for production only
7+
config.enabled = Rails.env.production? && config.access_token.present?
8+
9+
# By default, Rollbar will try to call the `current_user` controller method
10+
# to fetch the logged-in user object, and then call that object's `id`,
11+
# `username`, and `email` methods to fetch those properties. To customize:
12+
# config.person_method = "my_current_user"
13+
config.person_id_method = 'id_as_hash'
14+
config.person_username_method = 'id_as_hash'
15+
config.person_email_method = 'id_as_hash'
16+
17+
# If you want to attach custom data to all exception and message reports,
18+
# provide a lambda like the following. It should return a hash.
19+
# config.custom_data_method = lambda { {:some_key => "some_value" } }
20+
21+
# Add exception class names to the exception_level_filters hash to
22+
# change the level that exception is reported at. Note that if an exception
23+
# has already been reported and logged the level will need to be changed
24+
# via the rollbar interface.
25+
# Valid levels: 'critical', 'error', 'warning', 'info', 'debug', 'ignore'
26+
# 'ignore' will cause the exception to not be reported at all.
27+
# config.exception_level_filters.merge!('MyCriticalException' => 'critical')
28+
#
29+
# You can also specify a callable, which will be called with the exception instance.
30+
# config.exception_level_filters.merge!('MyCriticalException' => lambda { |e| 'critical' })
31+
32+
# Enable asynchronous reporting (uses girl_friday or Threading if girl_friday
33+
# is not installed)
34+
# config.use_async = true
35+
# Supply your own async handler:
36+
# config.async_handler = Proc.new { |payload|
37+
# Thread.new { Rollbar.process_from_async_handler(payload) }
38+
# }
39+
40+
# Enable asynchronous reporting (using sucker_punch)
41+
# config.use_sucker_punch
42+
43+
# Enable delayed reporting (using Sidekiq)
44+
# config.use_sidekiq
45+
# You can supply custom Sidekiq options:
46+
# config.use_sidekiq 'queue' => 'default'
47+
48+
# If you run your staging application instance in production environment then
49+
# you'll want to override the environment reported by `Rails.env` with an
50+
# environment variable like this: `ROLLBAR_ENV=staging`. This is a recommended
51+
# setup for Heroku. See:
52+
# https://devcenter.heroku.com/articles/deploying-to-a-custom-rails-environment
53+
config.environment = ENV['ROLLBAR_ENV'] || Rails.env
54+
end

config/secrets.yml.sample

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ MAILER_DEFAULT_HOST: "houston.library.ualberta.ca"
88
MAILER_FROM: "[email protected]"
99
EXCEPT_SENDER: "<[email protected]>"
1010
EXCEPT_RECIPIENTS: "[email protected]"
11+
ROLLBAR_ACCESS_TOKEN: ""

0 commit comments

Comments
 (0)