Sha256: 2eae4699f582e513ae1da379732646b13d449ad189cb25928faf510f248ad28c

Contents?: true

Size: 570 Bytes

Versions: 3

Compression:

Stored size: 570 Bytes

Contents

if defined?(ActiveRecord)
  ActiveSupport::Notifications.subscribe 'sql.active_record' do |name, start, finish, id, payload|
    if payload[:sql].downcase.match(/(select|update|insert|delete)(.+)/i)
      table, action = ServiceTemplate::ActiveRecordStats.extract_sql_content(payload[:sql])
    end

    if table
      ServiceTemplate::Stats.emitter.timing(
        "sql.query_time",
      (finish - start) * 1000)

      ServiceTemplate::Stats.emitter.timing(
        "sql.table.#{table}.#{action.downcase}.query_time",
      (finish - start) * 1000)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
service_template-0.5.2 lib/service_template/active_record_extensions/notifications_subscriber.rb
service_template-0.5.1 lib/service_template/active_record_extensions/notifications_subscriber.rb
service_template-0.5.0 lib/service_template/active_record_extensions/notifications_subscriber.rb