diff --git a/Steepfile b/Steepfile index ffb73d3e43a..c797845fcde 100644 --- a/Steepfile +++ b/Steepfile @@ -89,7 +89,6 @@ target :datadog do ignore 'lib/datadog/core/configuration/option_definition_set.rb' ignore 'lib/datadog/core/configuration/options.rb' ignore 'lib/datadog/core/configuration/settings.rb' - ignore 'lib/datadog/core/contrib/rails/utils.rb' ignore 'lib/datadog/core/diagnostics/health.rb' ignore 'lib/datadog/core/encoding.rb' ignore 'lib/datadog/core/environment/container.rb' @@ -128,6 +127,7 @@ target :datadog do ignore 'lib/datadog/core/utils/hash.rb' # Refinement module ignore 'lib/datadog/core/utils/network.rb' ignore 'lib/datadog/core/utils/only_once.rb' + ignore 'lib/datadog/core/utils/rails.rb' ignore 'lib/datadog/core/utils/safe_dup.rb' ignore 'lib/datadog/core/utils/sequence.rb' ignore 'lib/datadog/core/utils/time.rb' diff --git a/lib/datadog/core/contrib/rails/utils.rb b/lib/datadog/core/contrib/rails/utils.rb deleted file mode 100644 index 864f8ab3c9f..00000000000 --- a/lib/datadog/core/contrib/rails/utils.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -module Datadog - module Core - module Contrib - module Rails - # common utilities for Rails - module Utils - def self.app_name - if ::Rails::VERSION::MAJOR >= 6 - ::Rails.application.class.module_parent_name.underscore - else - ::Rails.application.class.parent_name.underscore - end - end - - def self.railtie_supported? - !!defined?(::Rails::Railtie) - end - end - end - end - end -end diff --git a/lib/datadog/core/utils/rails.rb b/lib/datadog/core/utils/rails.rb new file mode 100644 index 00000000000..f36568bdac9 --- /dev/null +++ b/lib/datadog/core/utils/rails.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module Datadog + module Core + module Utils + # common utilities for Rails + module Rails + def self.app_name + if ::Rails::VERSION::MAJOR >= 6 + ::Rails.application.class.module_parent_name.underscore + else + ::Rails.application.class.parent_name.underscore + end + end + + def self.railtie_supported? + !!defined?(::Rails::Railtie) + end + end + end + end +end diff --git a/lib/datadog/tracing/contrib/action_cable/integration.rb b/lib/datadog/tracing/contrib/action_cable/integration.rb index db2d656174c..b6693bc91fe 100644 --- a/lib/datadog/tracing/contrib/action_cable/integration.rb +++ b/lib/datadog/tracing/contrib/action_cable/integration.rb @@ -3,7 +3,7 @@ require_relative '../integration' require_relative 'configuration/settings' require_relative 'patcher' -require_relative '../../../core/contrib/rails/utils' +require_relative '../../../core/utils/rails' module Datadog module Tracing @@ -33,7 +33,7 @@ def self.compatible? # enabled by rails integration so should only auto instrument # if detected that it is being used without rails def auto_instrument? - !Core::Contrib::Rails::Utils.railtie_supported? + !Core::Utils::Rails.railtie_supported? end def new_configuration diff --git a/lib/datadog/tracing/contrib/action_mailer/integration.rb b/lib/datadog/tracing/contrib/action_mailer/integration.rb index f4296086863..c204846fb54 100644 --- a/lib/datadog/tracing/contrib/action_mailer/integration.rb +++ b/lib/datadog/tracing/contrib/action_mailer/integration.rb @@ -3,7 +3,7 @@ require_relative 'configuration/settings' require_relative 'patcher' require_relative '../integration' -require_relative '../../../core/contrib/rails/utils' +require_relative '../../../core/utils/rails' module Datadog module Tracing @@ -33,7 +33,7 @@ def self.compatible? # enabled by rails integration so should only auto instrument # if detected that it is being used without rails def auto_instrument? - !Core::Contrib::Rails::Utils.railtie_supported? + !Core::Utils::Rails.railtie_supported? end def new_configuration diff --git a/lib/datadog/tracing/contrib/action_pack/integration.rb b/lib/datadog/tracing/contrib/action_pack/integration.rb index 89819c59411..4966a1b0f97 100644 --- a/lib/datadog/tracing/contrib/action_pack/integration.rb +++ b/lib/datadog/tracing/contrib/action_pack/integration.rb @@ -4,7 +4,7 @@ require_relative 'patcher' require_relative '../integration' require_relative '../rails/ext' -require_relative '../../../core/contrib/rails/utils' +require_relative '../../../core/utils/rails' module Datadog module Tracing @@ -34,7 +34,7 @@ def self.compatible? # enabled by rails integration so should only auto instrument # if detected that it is being used without rails def auto_instrument? - !Core::Contrib::Rails::Utils.railtie_supported? + !Core::Utils::Rails.railtie_supported? end def new_configuration diff --git a/lib/datadog/tracing/contrib/action_view/integration.rb b/lib/datadog/tracing/contrib/action_view/integration.rb index 01cb17c46f4..134aefc604b 100644 --- a/lib/datadog/tracing/contrib/action_view/integration.rb +++ b/lib/datadog/tracing/contrib/action_view/integration.rb @@ -4,7 +4,7 @@ require_relative 'patcher' require_relative '../integration' require_relative '../rails/ext' -require_relative '../../../core/contrib/rails/utils' +require_relative '../../../core/utils/rails' module Datadog module Tracing @@ -41,7 +41,7 @@ def self.compatible? # enabled by rails integration so should only auto instrument # if detected that it is being used without rails def auto_instrument? - !Core::Contrib::Rails::Utils.railtie_supported? + !Core::Utils::Rails.railtie_supported? end def new_configuration diff --git a/lib/datadog/tracing/contrib/active_job/integration.rb b/lib/datadog/tracing/contrib/active_job/integration.rb index 54d0c9f55b8..d84fa2af842 100644 --- a/lib/datadog/tracing/contrib/active_job/integration.rb +++ b/lib/datadog/tracing/contrib/active_job/integration.rb @@ -3,7 +3,7 @@ require_relative 'configuration/settings' require_relative 'patcher' require_relative '../integration' -require_relative '../../../core/contrib/rails/utils' +require_relative '../../../core/utils/rails' module Datadog module Tracing @@ -33,7 +33,7 @@ def self.compatible? # enabled by rails integration so should only auto instrument # if detected that it is being used without rails def auto_instrument? - !Core::Contrib::Rails::Utils.railtie_supported? + !Core::Utils::Rails.railtie_supported? end def new_configuration diff --git a/lib/datadog/tracing/contrib/active_record/integration.rb b/lib/datadog/tracing/contrib/active_record/integration.rb index 5da4e133266..c69cb1733f9 100644 --- a/lib/datadog/tracing/contrib/active_record/integration.rb +++ b/lib/datadog/tracing/contrib/active_record/integration.rb @@ -7,7 +7,7 @@ require_relative '../component' require_relative '../integration' require_relative '../rails/ext' -require_relative '../../../core/contrib/rails/utils' +require_relative '../../../core/utils/rails' module Datadog module Tracing @@ -37,7 +37,7 @@ def self.compatible? # enabled by rails integration so should only auto instrument # if detected that it is being used without rails def auto_instrument? - !Core::Contrib::Rails::Utils.railtie_supported? + !Core::Utils::Rails.railtie_supported? end def new_configuration diff --git a/lib/datadog/tracing/contrib/active_support/integration.rb b/lib/datadog/tracing/contrib/active_support/integration.rb index 56f357adf5b..fe83fe3266a 100644 --- a/lib/datadog/tracing/contrib/active_support/integration.rb +++ b/lib/datadog/tracing/contrib/active_support/integration.rb @@ -5,7 +5,7 @@ require_relative 'patcher' require_relative 'cache/redis' require_relative '../rails/ext' -require_relative '../../../core/contrib/rails/utils' +require_relative '../../../core/utils/rails' module Datadog module Tracing @@ -35,7 +35,7 @@ def self.compatible? # enabled by rails integration so should only auto instrument # if detected that it is being used without rails def auto_instrument? - !Core::Contrib::Rails::Utils.railtie_supported? + !Core::Utils::Rails.railtie_supported? end def new_configuration diff --git a/lib/datadog/tracing/contrib/auto_instrument.rb b/lib/datadog/tracing/contrib/auto_instrument.rb index 23988c2e2f6..29c31846579 100644 --- a/lib/datadog/tracing/contrib/auto_instrument.rb +++ b/lib/datadog/tracing/contrib/auto_instrument.rb @@ -9,10 +9,10 @@ module Tracing module Contrib # Auto-activate instrumentation def self.auto_instrument! - require_relative '../../core/contrib/rails/utils' + require_relative '../../core/utils/rails' # Defer to Rails if this is a Rails application - if Datadog::Core::Contrib::Rails::Utils.railtie_supported? + if Datadog::Core::Utils::Rails.railtie_supported? require_relative 'rails/auto_instrument_railtie' else AutoInstrument.patch_all! diff --git a/lib/datadog/tracing/contrib/rack/integration.rb b/lib/datadog/tracing/contrib/rack/integration.rb index 72166753885..684cf6be669 100644 --- a/lib/datadog/tracing/contrib/rack/integration.rb +++ b/lib/datadog/tracing/contrib/rack/integration.rb @@ -3,7 +3,7 @@ require_relative '../integration' require_relative 'configuration/settings' require_relative 'patcher' -require_relative '../../../core/contrib/rails/utils' +require_relative '../../../core/utils/rails' module Datadog module Tracing @@ -33,7 +33,7 @@ def self.compatible? # enabled by rails integration so should only auto instrument # if detected that it is being used without rails def auto_instrument? - !Core::Contrib::Rails::Utils.railtie_supported? + !Core::Utils::Rails.railtie_supported? end def new_configuration diff --git a/lib/datadog/tracing/contrib/rails/framework.rb b/lib/datadog/tracing/contrib/rails/framework.rb index 66f03dd3da9..b224b50dda8 100644 --- a/lib/datadog/tracing/contrib/rails/framework.rb +++ b/lib/datadog/tracing/contrib/rails/framework.rb @@ -9,7 +9,7 @@ require_relative '../grape/endpoint' require_relative '../lograge/integration' require_relative 'ext' -require_relative '../../../core/contrib/rails/utils' +require_relative '../../../core/utils/rails' require_relative '../semantic_logger/integration' module Datadog @@ -41,7 +41,7 @@ def self.setup # being executed, but here we know better, get it from Rails config. # Don't set this if service has been explicitly provided by the user. if datadog_config.service_without_fallback.nil? - datadog_config.service = rails_config[:service_name] || Core::Contrib::Rails::Utils.app_name + datadog_config.service = rails_config[:service_name] || Core::Utils::Rails.app_name end activate_rack!(datadog_config, rails_config) diff --git a/lib/datadog/tracing/contrib/rails/patcher.rb b/lib/datadog/tracing/contrib/rails/patcher.rb index 0fadc07735c..bf8208c4fbb 100644 --- a/lib/datadog/tracing/contrib/rails/patcher.rb +++ b/lib/datadog/tracing/contrib/rails/patcher.rb @@ -6,7 +6,6 @@ require_relative 'log_injection' require_relative 'middlewares' require_relative 'runner' -require_relative '../../../core/contrib/rails/utils' require_relative '../semantic_logger/patcher' module Datadog diff --git a/spec/datadog/core/contrib/rails/utils_spec.rb b/spec/datadog/core/utils/rails_spec.rb similarity index 82% rename from spec/datadog/core/contrib/rails/utils_spec.rb rename to spec/datadog/core/utils/rails_spec.rb index b3f04ed32bc..4c0356e5752 100644 --- a/spec/datadog/core/contrib/rails/utils_spec.rb +++ b/spec/datadog/core/utils/rails_spec.rb @@ -1,7 +1,7 @@ -require 'lib/datadog/core/contrib/rails/utils' +require 'lib/datadog/core/utils/rails' require 'rails/version' -RSpec.describe Datadog::Core::Contrib::Rails::Utils do +RSpec.describe Datadog::Core::Utils::Rails do describe 'railtie_supported?' do subject(:railtie_supported?) { described_class.railtie_supported? } diff --git a/spec/datadog/tracing/contrib/auto_instrument_examples.rb b/spec/datadog/tracing/contrib/auto_instrument_examples.rb index 499cd95fb16..7fd9376add7 100644 --- a/spec/datadog/tracing/contrib/auto_instrument_examples.rb +++ b/spec/datadog/tracing/contrib/auto_instrument_examples.rb @@ -4,7 +4,7 @@ context 'outside of a rails application' do before do - allow(Datadog::Core::Contrib::Rails::Utils).to receive(:railtie_supported?).and_return(false) + allow(Datadog::Core::Utils::Rails).to receive(:railtie_supported?).and_return(false) end it { is_expected.to be(true) } @@ -12,7 +12,7 @@ context 'when within a rails application' do before do - allow(Datadog::Core::Contrib::Rails::Utils).to receive(:railtie_supported?).and_return(true) + allow(Datadog::Core::Utils::Rails).to receive(:railtie_supported?).and_return(true) end it { is_expected.to be(false) }