diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 235c74fd..6fe54f34 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,6 +5,8 @@ class ApplicationController < ActionController::Base # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception + include SentryUserContext + after_action :store_location def store_location diff --git a/app/controllers/concerns/sentry_user_context.rb b/app/controllers/concerns/sentry_user_context.rb new file mode 100644 index 00000000..949570c6 --- /dev/null +++ b/app/controllers/concerns/sentry_user_context.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +module SentryUserContext + extend ActiveSupport::Concern + + included do + before_action :set_sentry_context + end + + private + + def sentry_user_context + {}.tap do |user| + next unless current_user + + user[:id] = current_user.id + user[:email] = current_user.cas_mail + user[:name] = current_user.username + end + end + + def set_sentry_context + Sentry.set_user(sentry_user_context) + end +end