Skip to content

Commit

Permalink
update to sentry-ruby (#10364)
Browse files Browse the repository at this point in the history
* update to sentry-ruby

* enabled_environments
  • Loading branch information
jywarren committed Oct 19, 2021
1 parent 72ece9c commit cfcd6ef
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 16 deletions.
6 changes: 5 additions & 1 deletion Gemfile
Expand Up @@ -56,7 +56,11 @@ gem 'responders', '~> 3.0'
gem 'rubocop', '~> 1.20.0', require: false
gem "ruby-openid", :require => "openid"
gem 'sanitize'
gem 'sentry-raven'
gem 'sentry-ruby'
gem 'sentry-rails'
gem 'sentry-resque'
gem 'sentry-sidekiq'
gem 'sentry-delayed_job'
gem 'sidekiq'
gem 'skylight' # performance tracking via skylight.io
gem 'turbolinks', '~> 5'
Expand Down
45 changes: 42 additions & 3 deletions Gemfile.lock
Expand Up @@ -105,6 +105,8 @@ GEM
crass (1.0.6)
critical-path-css-rails (4.1.1)
declarative (0.0.20)
delayed_job (4.1.9)
activesupport (>= 3.0, < 6.2)
diff-lcs (1.4.4)
digest-crc (0.6.3)
rake (>= 12.0.0, < 14.0.0)
Expand Down Expand Up @@ -334,6 +336,7 @@ GEM
minitest (>= 5.0)
ruby-progressbar
mocha (1.13.0)
mono_logger (1.1.1)
multi_json (1.15.0)
multi_xml (0.6.0)
multipart-post (2.1.1)
Expand Down Expand Up @@ -471,6 +474,8 @@ GEM
recaptcha (4.14.0)
json
redis (4.1.4)
redis-namespace (1.8.1)
redis (>= 3.0.4)
regexp_parser (2.1.1)
representable (3.1.1)
declarative (< 0.1.0)
Expand All @@ -481,6 +486,12 @@ GEM
responders (3.0.1)
actionpack (>= 5.0)
railties (>= 5.0)
resque (2.1.0)
mono_logger (~> 1.0)
multi_json (~> 1.0)
redis-namespace (~> 1.6)
sinatra (>= 0.9.2)
vegas (~> 0.1.2)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
Expand Down Expand Up @@ -536,8 +547,25 @@ GEM
childprocess (>= 0.5, < 4.0)
rubyzip (>= 1.2.2)
semantic_range (3.0.0)
sentry-raven (3.1.2)
sentry-delayed_job (4.7.3)
delayed_job (>= 4.0)
sentry-ruby-core (~> 4.7.0)
sentry-rails (4.7.3)
railties (>= 5.0)
sentry-ruby-core (~> 4.7.0)
sentry-resque (4.7.3)
resque (>= 1.24)
sentry-ruby-core (~> 4.7.0)
sentry-ruby (4.7.3)
concurrent-ruby (~> 1.0, >= 1.0.2)
faraday (>= 1.0)
sentry-ruby-core (= 4.7.3)
sentry-ruby-core (4.7.3)
concurrent-ruby
faraday
sentry-sidekiq (4.7.3)
sentry-ruby-core (~> 4.7.0)
sidekiq (>= 3.0)
sidekiq (5.2.9)
connection_pool (~> 2.2, >= 2.2.2)
rack (~> 2.0)
Expand All @@ -555,6 +583,11 @@ GEM
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.3)
sinatra (2.0.8.1)
mustermann (~> 1.0)
rack (~> 2.0)
rack-protection (= 2.0.8.1)
tilt (~> 2.0)
skylight (5.1.1)
activesupport (>= 5.2.0)
sprockets (3.7.2)
Expand Down Expand Up @@ -604,6 +637,8 @@ GEM
unicode-emoji (2.8.0)
unicode-version (~> 1.0)
unicode-version (1.1.0)
vegas (0.1.11)
rack (>= 1.0.0)
web-console (3.7.0)
actionview (>= 5.0)
activemodel (>= 5.0)
Expand Down Expand Up @@ -722,7 +757,11 @@ DEPENDENCIES
sassc-rails
scrypt (~> 3)
selenium-webdriver (~> 3.142.7)
sentry-raven
sentry-delayed_job
sentry-rails
sentry-resque
sentry-ruby
sentry-sidekiq
sidekiq
simplecov
skylight
Expand All @@ -746,4 +785,4 @@ RUBY VERSION
ruby 2.6.6p146

BUNDLED WITH
2.2.21
2.2.29
11 changes: 7 additions & 4 deletions app/controllers/application_controller.rb
Expand Up @@ -8,7 +8,7 @@ class ApplicationController < ActionController::Base

before_action :set_locale

before_action :set_raven_context
before_action :set_sentry_context

private

Expand All @@ -17,9 +17,12 @@ def is_dataurl_post
params[:controller] == "editor" && params[:action] == "post" && !params[:datauri_main_image].nil?
end

def set_raven_context
Raven.user_context(id: session[:current_user_id]) # or anything else in session
Raven.extra_context(params: params.to_unsafe_h, url: request.url)
def set_sentry_context
Sentry.with_scope do |scope|
scope.set_user(id: session[:current_user_id])
scope.set_extras(params: params.to_unsafe_h)
scope.set_extras(url: request.url)
end
end

# non-Authlogic... homebrew
Expand Down
33 changes: 28 additions & 5 deletions config/application.rb
Expand Up @@ -96,11 +96,34 @@ class Application < Rails::Application
config.paths.add File.join('app','api'), glob: File.join('**', '*.rb')
config.autoload_paths += Dir[Rails.root.join('app', 'api', '*')]

Raven.configure do |config|
# DSN should be an ENV variable!
config.dsn = ENV["SENTRY_DSN"] || 'https://0490297edae647b3bd935bdb4658da54@o239675.ingest.sentry.io/1410626'
config.current_environment = ENV["COMPOSE_PROJECT_NAME"] || ENV["RAILS_ENV"] || %w(production)
end
Sentry.init do |config|
# DSN should be an ENV variable!
config.dsn = ENV["SENTRY_DSN"] || 'https://0490297edae647b3bd935bdb4658da54@o239675.ingest.sentry.io/1410626'
config.breadcrumbs_logger = [:sentry_logger, :http_logger]

# To activate performance monitoring, set one of these options.
# We recommend adjusting the value in production:
config.traces_sample_rate = 0.5

config.environment = case ENV["COMPOSE_PROJECT_NAME"]
when 'plots_stable'
'stable'
when 'plots_unstable'
'unstable'
else
ENV["RAILS_ENV"]
end
config.enabled_environments = %w[production, stable, unstable]

# use Rails' parameter filter to sanitize the event payload:
# for Rails 6+:
# filter = ActiveSupport::ParameterFilter.new(Rails.application.config.filter_parameters)
# for Rails 5:
filter = ActionDispatch::Http::ParameterFilter.new(Rails.application.config.filter_parameters)
config.before_send = lambda do |event, hint|
filter.filter(event.to_hash)
end
end

end
end
3 changes: 0 additions & 3 deletions config/initializers/sentry.rb

This file was deleted.

0 comments on commit cfcd6ef

Please sign in to comment.