class Airbrake::Rack::ContextFilter
Adds context (URL, User-Agent, framework version, controller and more).
@since v5.7.0
Attributes
weight[R]
@return [Integer]
Public Class Methods
new()
click to toggle source
# File lib/airbrake/rack/context_filter.rb, line 12 def initialize @weight = 99 end
Public Instance Methods
call(notice)
click to toggle source
@see Airbrake::FilterChain#refine
# File lib/airbrake/rack/context_filter.rb, line 17 def call(notice) return unless (request = notice.stash[:rack_request]) context = notice[:context] context[:url] = request.url context[:userAgent] = request.user_agent add_ip(context, request) add_framework_version(context) controller = request.env['action_controller.instance'] return unless controller context[:component] = controller.controller_name context[:action] = controller.action_name end
Private Instance Methods
add_framework_version(context)
click to toggle source
# File lib/airbrake/rack/context_filter.rb, line 37 def add_framework_version(context) if context.key?(:versions) context[:versions].merge!(framework_version) else context[:versions] = framework_version end end
add_ip(context, request)
click to toggle source
# File lib/airbrake/rack/context_filter.rb, line 59 def add_ip(context, request) context[:userAddr] = if request.respond_to?(:remote_ip) request.remote_ip else request.ip end end
framework_version()
click to toggle source
# File lib/airbrake/rack/context_filter.rb, line 45 def framework_version @framework_version ||= if defined?(::Rails) && ::Rails.respond_to?(:version) { 'rails' => ::Rails.version } elsif defined?(::Sinatra) { 'sinatra' => Sinatra::VERSION } else { 'rack_version' => ::Rack.version, 'rack_release' => ::Rack.release, } end end