From 623b14fac4d3b918350c660cc9e66cd83b4c2709 Mon Sep 17 00:00:00 2001 From: Emanuele Palazzetti Date: Thu, 19 Jan 2017 09:46:06 +0100 Subject: [PATCH] [rails] avoid conditional require for active_record contrib module --- lib/ddtrace/contrib/rails/active_record.rb | 3 +++ lib/ddtrace/contrib/rails/framework.rb | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/ddtrace/contrib/rails/active_record.rb b/lib/ddtrace/contrib/rails/active_record.rb index d2edba777c9..4281d4ce580 100644 --- a/lib/ddtrace/contrib/rails/active_record.rb +++ b/lib/ddtrace/contrib/rails/active_record.rb @@ -8,6 +8,9 @@ module Rails # TODO[manu]: write docs module ActiveRecord def self.instrument + # ActiveRecord is instrumented only if it's available + return unless defined?(::ActiveRecord) + # subscribe when the active record query has been processed ::ActiveSupport::Notifications.subscribe('sql.active_record') do |*args| sql(*args) diff --git a/lib/ddtrace/contrib/rails/framework.rb b/lib/ddtrace/contrib/rails/framework.rb index 2afe9178fc2..fdd866b4cea 100644 --- a/lib/ddtrace/contrib/rails/framework.rb +++ b/lib/ddtrace/contrib/rails/framework.rb @@ -4,7 +4,7 @@ require 'ddtrace/contrib/rails/core_extensions' require 'ddtrace/contrib/rails/action_controller' require 'ddtrace/contrib/rails/action_view' -require 'ddtrace/contrib/rails/active_record' if defined?(::ActiveRecord) +require 'ddtrace/contrib/rails/active_record' require 'ddtrace/contrib/rails/active_support' require 'ddtrace/contrib/rails/utils' @@ -102,7 +102,7 @@ def self.auto_instrument # instrumenting Rails framework Datadog::Contrib::Rails::ActionController.instrument() Datadog::Contrib::Rails::ActionView.instrument() - Datadog::Contrib::Rails::ActiveRecord.instrument() if defined?(::ActiveRecord) + Datadog::Contrib::Rails::ActiveRecord.instrument() Datadog::Contrib::Rails::ActiveSupport.instrument() # by default, Rails 3 doesn't instrument the cache system