Permalink
Browse files

Merge pull request #30619 from jagthedrummer/jeremy/instrumentation-p…

…ayload-names

Update payload names for `sql.active_record` instrumentation to be more descriptive.
  • Loading branch information...
eileencodes committed Sep 20, 2017
2 parents aa0c877 + fda9df7 commit 55e50f7c7819ee5d3234c47e34b5e20196ac24b7
@@ -1,3 +1,10 @@
* Update payload names for `sql.active_record` instrumentation to be
more descriptive.
Fixes #30586.
*Jeremy Green*
* Add new error class `TransactionTimeout` for MySQL adapter which will be raised
when lock wait time expires.
@@ -63,7 +63,7 @@ def insert(values) # :nodoc:
@klass.connection.insert(
im,
"SQL",
"#{@klass} Create",
primary_key || false,
primary_key_value,
nil,
@@ -86,7 +86,7 @@ def _update_record(values, id, id_was) # :nodoc:
@klass.connection.update(
um,
"SQL",
"#{@klass} Update",
)
end
@@ -373,7 +373,7 @@ def update_all(updates)
stmt.wheres = arel.constraints
end
@klass.connection.update stmt, "SQL"
@klass.connection.update stmt, "#{@klass} Update All"
end
# Destroys the records by instantiating each
@@ -432,7 +432,7 @@ def delete_all
stmt.wheres = arel.constraints
end
affected = @klass.connection.delete(stmt, "SQL")
affected = @klass.connection.delete(stmt, "#{@klass} Destroy")
reset
affected
@@ -0,0 +1,72 @@
# frozen_string_literal: true
require "cases/helper"
require "models/book"
module ActiveRecord
class InstrumentationTest < ActiveRecord::TestCase
def test_payload_name_on_load
Book.create(name: "test book")
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
event = ActiveSupport::Notifications::Event.new *args
if event.payload[:sql].match "SELECT"
assert_equal "Book Load", event.payload[:name]
end
end
Book.first
ensure
ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber
end
def test_payload_name_on_create
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
event = ActiveSupport::Notifications::Event.new *args
if event.payload[:sql].match "INSERT"
assert_equal "Book Create", event.payload[:name]
end
end
Book.create(name: "test book")
ensure
ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber
end
def test_payload_name_on_update
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
event = ActiveSupport::Notifications::Event.new *args
if event.payload[:sql].match "UPDATE"
assert_equal "Book Update", event.payload[:name]
end
end
book = Book.create(name: "test book")
book.update_attribute(:name, "new name")
ensure
ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber
end
def test_payload_name_on_update_all
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
event = ActiveSupport::Notifications::Event.new *args
if event.payload[:sql].match "UPDATE"
assert_equal "Book Update All", event.payload[:name]
end
end
Book.create(name: "test book")
Book.update_all(name: "new name")
ensure
ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber
end
def test_payload_name_on_destroy
subscriber = ActiveSupport::Notifications.subscribe("sql.active_record") do |*args|
event = ActiveSupport::Notifications::Event.new *args
if event.payload[:sql].match "DELETE"
assert_equal "Book Destroy", event.payload[:name]
end
end
book = Book.create(name: "test book")
book.destroy
ensure
ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber
end
end
end

0 comments on commit 55e50f7

Please sign in to comment.