Skip to content

Commit

Permalink
Merge pull request #1690 from ruby-agent/RUBY-1916_activerecord_travi…
Browse files Browse the repository at this point in the history
…s_failure

Record Datastore update metrics on touch in ActiveRecord >= 5.1.6
  • Loading branch information
mwear authored and GitHub Enterprise committed Apr 5, 2018
2 parents ddbe054 + 8d4b5b0 commit fdee4eb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/new_relic/agent/instrumentation/active_record_5.rb
Expand Up @@ -31,6 +31,11 @@
::NewRelic::Agent::PrependSupportability.record_metrics_for(::ActiveRecord::Base, ::ActiveRecord::Relation)
::ActiveRecord::Base.prepend ::NewRelic::Agent::Instrumentation::ActiveRecordPrepend::BaseExtensions
::ActiveRecord::Relation.prepend ::NewRelic::Agent::Instrumentation::ActiveRecordPrepend::RelationExtensions

if ::ActiveRecord::VERSION::MINOR.to_i == 1 &&
::ActiveRecord::VERSION::TINY.to_i >= 6
::ActiveRecord::Base.prepend ::NewRelic::Agent::Instrumentation::ActiveRecordPrepend::BaseExtensions516
end
end
end
end
15 changes: 14 additions & 1 deletion lib/new_relic/agent/instrumentation/active_record_prepend.rb
Expand Up @@ -24,6 +24,19 @@ def save!(*args, &blk)
end
end

module BaseExtensions516
# In ActiveRecord v5.0.0 through v5.1.5, touch() will call
# update_all() and cause us to record a transaction.
# Starting in v5.1.6, this call no longer happens. We'll
# have to set the database metrics explicitly now.
#
def touch(*args, &blk)
::NewRelic::Agent.with_database_metric_name(self.class.name, nil, ACTIVE_RECORD) do
super
end
end
end

module RelationExtensions
def update_all(*args, &blk)
::NewRelic::Agent.with_database_metric_name(self.name, nil, ACTIVE_RECORD) do
Expand Down Expand Up @@ -58,4 +71,4 @@ def pluck(*args, &blk)
end
end
end
end
end
4 changes: 2 additions & 2 deletions test/multiverse/suites/active_record/Envfile
Expand Up @@ -13,14 +13,14 @@ if RUBY_VERSION >= '2.2.2' && RUBY_PLATFORM != 'java'
mysql_vsn = '~>0.4.4'

gemfile <<-RB
gem 'activerecord', '~> 5.2.0.beta2'
gem 'activerecord', '~> 5.2.0.rc2'
gem 'minitest', '~> 5.2.3'
gem '#{mysql_gem}', '#{mysql_vsn}'
#{boilerplate_gems}
RB

gemfile <<-RB
gem 'activerecord', '~> 5.1.0'
gem 'activerecord', '~> 5.1.6'
gem 'minitest', '~> 5.2.3'
gem '#{mysql_gem}', '#{mysql_vsn}'
#{boilerplate_gems}
Expand Down

0 comments on commit fdee4eb

Please sign in to comment.