diff --git a/Gemfile b/Gemfile index a1918c1..52045dd 100644 --- a/Gemfile +++ b/Gemfile @@ -48,6 +48,10 @@ gem 'faraday' gem 'sidekiq', '< 7' gem 'sidekiq-scheduler' +# Monitoring +gem "sentry-ruby" +gem "sentry-rails" + group :development, :test do # Use sqlite3 as the database for Active Record gem 'sqlite3', '~> 1.4' diff --git a/Gemfile.lock b/Gemfile.lock index e788bef..7c655ba 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -254,6 +254,11 @@ GEM ruby2_keywords (0.0.5) rufus-scheduler (3.8.2) fugit (~> 1.1, >= 1.1.6) + sentry-rails (5.8.0) + railties (>= 5.0) + sentry-ruby (~> 5.8.0) + sentry-ruby (5.8.0) + concurrent-ruby (~> 1.0, >= 1.0.2) sidekiq (6.5.5) connection_pool (>= 2.2.2) rack (~> 2.0) @@ -335,6 +340,8 @@ DEPENDENCIES rails-settings-cached (~> 2.8.3) rqrcode (~> 2.0) rspec-rails + sentry-rails + sentry-ruby sidekiq (< 7) sidekiq-scheduler sprockets-rails diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c672886..ee049bc 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,6 +3,18 @@ class ApplicationController < ActionController::Base render :text => exception, :status => 500 end + before_action :sentry_set_user + + def sentry_set_user + return unless Setting.sentry_enabled + + if user_signed_in? + Sentry.set_user(id: current_user.id, username: current_user.cn) + else + Sentry.set_user({}) + end + end + def require_user_signed_in unless user_signed_in? redirect_to welcome_path and return diff --git a/app/models/setting.rb b/app/models/setting.rb index 56aa785..e86a79c 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -10,6 +10,13 @@ class Setting < RailsSettings::Base account accounts donations mail webmaster support ] + # + # Sentry + # + + field :sentry_enabled, type: :boolean, readonly: true, + default: (ENV["SENTRY_DSN"].present?.to_s || false) + # # Discourse # diff --git a/config/initializers/sentry.rb b/config/initializers/sentry.rb new file mode 100644 index 0000000..202fe75 --- /dev/null +++ b/config/initializers/sentry.rb @@ -0,0 +1,9 @@ +if ENV["SENTRY_DSN"].present? + Sentry.init do |config| + config.dsn = ENV["SENTRY_DSN"] + config.breadcrumbs_logger = [:active_support_logger, :http_logger] + config.traces_sampler = lambda do |context| + true + end + end +end diff --git a/config/routes.rb b/config/routes.rb index 8b4866b..e729019 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,7 @@ require 'sidekiq/web' Rails.application.routes.draw do - devise_for :users, :controllers => { :confirmations => "users/confirmations" } + devise_for :users, controllers: { confirmations: "users/confirmations" } get 'welcome', to: 'welcome#index' get 'check_your_email', to: 'welcome#check_your_email'