Sha256: 879fd0d555242c4fba7977a4fbd9fd0e3b7c906dd1a88139554c29958b444c9c

Contents?: true

Size: 1.43 KB

Versions: 2

Compression:

Stored size: 1.43 KB

Contents

module Bugsnag
  class Rack
    def initialize(app)
      @app = app
    end

    def call(env)
      begin
        response = @app.call(env)
      rescue Exception => raised
        error_id = Bugsnag.notify(raised, bugsnag_request_data(env))
        raise
      end

      if env['rack.exception']
        error_id = Bugsnag.notify(env['rack.exception'], bugsnag_request_data(env))
      end

      response
    end
    
    private
    def bugsnag_request_data(env)
      request = ::Rack::Request.new(env)

      session = env['rack.session'] || {}
      params = env['action_dispatch.request.parameters'] || request.params || {}

      {
        :userId => session[:session_id] || session["session_id"],
        :context => Bugsnag::Helpers.param_context(params),
        :metaData => {
          :request => {
            :url => request.url,
            :controller => params[:controller],
            :action => params[:action],
            :params => bugsnag_filter_if_filtering(env, Bugsnag::Helpers.cleanup_hash(params.to_hash)),
          },
          :session => bugsnag_filter_if_filtering(env, Bugsnag::Helpers.cleanup_hash(session)),
          :environment => bugsnag_filter_if_filtering(env, Bugsnag::Helpers.cleanup_hash(env))
        }
      }
    end

    def bugsnag_filter_if_filtering(env, hash)
      @params_filters ||= env["action_dispatch.parameter_filter"]
      Bugsnag::Helpers.apply_filters(hash, @params_filters)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bugsnag-1.0.2 lib/bugsnag/rack.rb
bugsnag-1.0.1 lib/bugsnag/rack.rb