From 601fd80c2d180d7a51771b8db694b91f504b622d Mon Sep 17 00:00:00 2001 From: David Elner Date: Thu, 20 Dec 2018 16:32:18 -0500 Subject: [PATCH] Removed: ActiveRecord AbstractAdapter patch. --- lib/ddtrace/contrib/active_record/patcher.rb | 2 - .../active_record/patches/abstract_adapter.rb | 72 ------------------- 2 files changed, 74 deletions(-) delete mode 100644 lib/ddtrace/contrib/active_record/patches/abstract_adapter.rb diff --git a/lib/ddtrace/contrib/active_record/patcher.rb b/lib/ddtrace/contrib/active_record/patcher.rb index 74d5f132e59..ff172372fbc 100644 --- a/lib/ddtrace/contrib/active_record/patcher.rb +++ b/lib/ddtrace/contrib/active_record/patcher.rb @@ -1,5 +1,4 @@ require 'ddtrace/contrib/patcher' -require 'ddtrace/contrib/active_record/patches/abstract_adapter' require 'ddtrace/contrib/active_record/events' module Datadog @@ -18,7 +17,6 @@ def patched? def patch do_once(:active_record) do begin - ::ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:include, Patches::AbstractAdapter) Events.subscribe! rescue StandardError => e Datadog::Tracer.log.error("Unable to apply Active Record integration: #{e}") diff --git a/lib/ddtrace/contrib/active_record/patches/abstract_adapter.rb b/lib/ddtrace/contrib/active_record/patches/abstract_adapter.rb deleted file mode 100644 index 3ddefd1cac3..00000000000 --- a/lib/ddtrace/contrib/active_record/patches/abstract_adapter.rb +++ /dev/null @@ -1,72 +0,0 @@ -require 'set' -require 'ddtrace/augmentation/shim' - -module Datadog - module Contrib - module ActiveRecord - # Defines basic behaviors for an ActiveRecord event. - module Patches - # Adds patch to AbstractAdapter to make it pass more information through - # ActiveSupport notifications, for better instrumentation. - module AbstractAdapter - def self.included(base) - if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.0.0') - base.class_eval do - alias_method :log_without_datadog, :log - remove_method :log - include InstanceMethods - end - else - base.send(:prepend, InstanceMethods) - end - end - - # Compatibility shim for Rubies not supporting `.prepend` - module InstanceMethodsCompatibility - def log(*args, &block) - log_without_datadog(*args, &block) - end - end - - # InstanceMethods - implementing instrumentation - module InstanceMethods - include InstanceMethodsCompatibility unless Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.0.0') - - EVENT_ACTIVERECORD_SQL = 'sql.active_record'.freeze - - # Override #log since sometimes connections are initialized prior - # to when the patch is applied; this will allow existing connections - # to receive the Shim as well. - def log(*args, &block) - insert_shim! unless shim_inserted? - super - end - - private - - def shim_inserted? - instance_variable_defined?(:@instrumenter) \ - && Datadog::Shim.shim?(@instrumenter) - end - - def insert_shim! - @instrumenter = Datadog::Shim.new(@instrumenter) do |shim| - connection = self - - shim.override_method!(:instrument) do |*args, &block| - # Inject connection into arguments - if args[0] == EVENT_ACTIVERECORD_SQL && args[1].is_a?(Hash) - args[1][:connection] ||= connection - end - - # Call original - shim_target.instrument(*args, &block) - end - end - end - end - end - end - end - end -end