Sha256: a3f4f93804918bab525131a3e8cc90f1976f0b064127850e3aeffbd59179f645

Contents?: true

Size: 1.05 KB

Versions: 17

Compression:

Stored size: 1.05 KB

Contents

require 'airbrake/rails/event'
require 'airbrake/rails/backtrace_cleaner'

module Airbrake
  module Rails
    # ActiveRecordSubscriber sends SQL information, including performance data.
    #
    # @since v8.1.0
    class ActiveRecordSubscriber
      def call(*args)
        routes = Airbrake::Rack::RequestStore[:routes]
        return if !routes || routes.none?

        event = Airbrake::Rails::Event.new(*args)
        frame = last_caller

        routes.each do |route, params|
          Airbrake.notify_query(
            route: route,
            method: params[:method],
            query: event.sql,
            func: frame[:function],
            file: frame[:file],
            line: frame[:line],
            start_time: event.time,
            end_time: event.end
          )
        end
      end

      private

      def last_caller
        exception = StandardError.new
        exception.set_backtrace(
          Airbrake::Rails::BacktraceCleaner.clean(Kernel.caller)
        )
        Airbrake::Backtrace.parse(exception).first || {}
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
airbrake-9.5.5 lib/airbrake/rails/active_record_subscriber.rb
airbrake-9.5.4 lib/airbrake/rails/active_record_subscriber.rb
airbrake-9.5.3 lib/airbrake/rails/active_record_subscriber.rb
airbrake-9.5.2 lib/airbrake/rails/active_record_subscriber.rb
airbrake-9.5.1 lib/airbrake/rails/active_record_subscriber.rb
airbrake-9.5.0 lib/airbrake/rails/active_record_subscriber.rb
airbrake-9.4.5 lib/airbrake/rails/active_record_subscriber.rb
airbrake-9.4.4 lib/airbrake/rails/active_record_subscriber.rb
airbrake-9.4.3 lib/airbrake/rails/active_record_subscriber.rb
airbrake-9.4.2 lib/airbrake/rails/active_record_subscriber.rb
airbrake-9.4.1 lib/airbrake/rails/active_record_subscriber.rb
airbrake-9.4.0 lib/airbrake/rails/active_record_subscriber.rb
airbrake-9.3.0 lib/airbrake/rails/active_record_subscriber.rb
airbrake-9.2.2 lib/airbrake/rails/active_record_subscriber.rb
airbrake-9.2.1 lib/airbrake/rails/active_record_subscriber.rb
airbrake-9.2.0 lib/airbrake/rails/active_record_subscriber.rb
airbrake-9.1.0 lib/airbrake/rails/active_record_subscriber.rb