Sha256: ef43b6322771b9f6b292071c4abdd0dc82864a9672854da78bdf461299b33a25

Contents?: true

Size: 948 Bytes

Versions: 6

Compression:

Stored size: 948 Bytes

Contents

# frozen_string_literal: true

module PagesCore
  module ErrorReporting
    extend ActiveSupport::Concern

    included do
      before_action :configure_sentry_context
    end

    protected

    def configure_sentry_context
      if Object.const_defined?("Sentry")
        Sentry.set_user(current_user_context)
        Sentry.set_tags(locale: params[:locale] || I18n.default_locale.to_s)
        Sentry.set_extras(params: params.to_unsafe_h)
      elsif Object.const_defined?("Raven")
        configure_legacy_sentry_context
      end
    end

    def configure_legacy_sentry_context
      Raven.user_context(current_user_context)
      Raven.tags_context(locale: params[:locale] || I18n.default_locale.to_s)
      Raven.extra_context(params: params.to_unsafe_h)
    end

    def current_user_context
      return { user_id: :guest } unless logged_in?

      { user_id: current_user.id,
        user_email: current_user.email }
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pages_core-3.9.0 app/controllers/concerns/pages_core/error_reporting.rb
pages_core-3.8.3 app/controllers/concerns/pages_core/error_reporting.rb
pages_core-3.8.2 app/controllers/concerns/pages_core/error_reporting.rb
pages_core-3.8.1 app/controllers/concerns/pages_core/error_reporting.rb
pages_core-3.8.0 app/controllers/concerns/pages_core/error_reporting.rb
pages_core-3.7.0 app/controllers/concerns/pages_core/error_reporting.rb