From d632d59d560c0b81e2e60cd44cf7d487cec8aecb Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 30 Dec 2024 11:34:51 -0500 Subject: [PATCH 1/3] DEBUG-3182 move Rails utils to core --- Steepfile | 2 +- lib/datadog/{tracing => core}/contrib/rails/utils.rb | 4 +--- lib/datadog/tracing/contrib/action_cable/integration.rb | 4 ++-- lib/datadog/tracing/contrib/action_mailer/integration.rb | 4 ++-- lib/datadog/tracing/contrib/action_pack/integration.rb | 4 ++-- lib/datadog/tracing/contrib/action_view/integration.rb | 4 ++-- lib/datadog/tracing/contrib/active_job/integration.rb | 4 ++-- lib/datadog/tracing/contrib/active_record/integration.rb | 4 ++-- lib/datadog/tracing/contrib/active_support/integration.rb | 4 ++-- lib/datadog/tracing/contrib/auto_instrument.rb | 4 ++-- lib/datadog/tracing/contrib/rack/integration.rb | 4 ++-- lib/datadog/tracing/contrib/rails/framework.rb | 4 ++-- lib/datadog/tracing/contrib/rails/patcher.rb | 2 +- sig/datadog/{tracing => core}/contrib/rails/utils.rbs | 6 +++--- spec/datadog/{tracing => core}/contrib/rails/utils_spec.rb | 4 ++-- spec/datadog/tracing/contrib/auto_instrument_examples.rb | 4 ++-- 16 files changed, 30 insertions(+), 32 deletions(-) rename lib/datadog/{tracing => core}/contrib/rails/utils.rb (91%) rename sig/datadog/{tracing => core}/contrib/rails/utils.rbs (50%) rename spec/datadog/{tracing => core}/contrib/rails/utils_spec.rb (81%) diff --git a/Steepfile b/Steepfile index d2cce9c3ef6..ffb73d3e43a 100644 --- a/Steepfile +++ b/Steepfile @@ -89,6 +89,7 @@ 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' @@ -426,7 +427,6 @@ target :datadog do ignore 'lib/datadog/tracing/contrib/rails/middlewares.rb' ignore 'lib/datadog/tracing/contrib/rails/patcher.rb' ignore 'lib/datadog/tracing/contrib/rails/railtie.rb' - ignore 'lib/datadog/tracing/contrib/rails/utils.rb' ignore 'lib/datadog/tracing/contrib/rake/configuration/settings.rb' ignore 'lib/datadog/tracing/contrib/rake/ext.rb' ignore 'lib/datadog/tracing/contrib/rake/instrumentation.rb' diff --git a/lib/datadog/tracing/contrib/rails/utils.rb b/lib/datadog/core/contrib/rails/utils.rb similarity index 91% rename from lib/datadog/tracing/contrib/rails/utils.rb rename to lib/datadog/core/contrib/rails/utils.rb index 1e77a5dbaee..864f8ab3c9f 100644 --- a/lib/datadog/tracing/contrib/rails/utils.rb +++ b/lib/datadog/core/contrib/rails/utils.rb @@ -1,9 +1,7 @@ # frozen_string_literal: true -require_relative '../analytics' - module Datadog - module Tracing + module Core module Contrib module Rails # common utilities for Rails diff --git a/lib/datadog/tracing/contrib/action_cable/integration.rb b/lib/datadog/tracing/contrib/action_cable/integration.rb index fa1086e74ac..db2d656174c 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 '../rails/utils' +require_relative '../../../core/contrib/rails/utils' 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? - !Contrib::Rails::Utils.railtie_supported? + !Core::Contrib::Rails::Utils.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 fc9b4e5a980..f4296086863 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 '../rails/utils' +require_relative '../../../core/contrib/rails/utils' 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? - !Contrib::Rails::Utils.railtie_supported? + !Core::Contrib::Rails::Utils.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 881d9ce273c..89819c59411 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 '../rails/utils' +require_relative '../../../core/contrib/rails/utils' 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? - !Contrib::Rails::Utils.railtie_supported? + !Core::Contrib::Rails::Utils.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 c56240be1f4..01cb17c46f4 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 '../rails/utils' +require_relative '../../../core/contrib/rails/utils' 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? - !Contrib::Rails::Utils.railtie_supported? + !Core::Contrib::Rails::Utils.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 89718a647f2..54d0c9f55b8 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 '../rails/utils' +require_relative '../../../core/contrib/rails/utils' 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? - !Contrib::Rails::Utils.railtie_supported? + !Core::Contrib::Rails::Utils.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 d5fd2294aae..5da4e133266 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 '../rails/utils' +require_relative '../../../core/contrib/rails/utils' 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? - !Contrib::Rails::Utils.railtie_supported? + !Core::Contrib::Rails::Utils.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 9cf29c4b1c5..56f357adf5b 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 '../rails/utils' +require_relative '../../../core/contrib/rails/utils' 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? - !Contrib::Rails::Utils.railtie_supported? + !Core::Contrib::Rails::Utils.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 98556045be1..23988c2e2f6 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 'rails/utils' + require_relative '../../core/contrib/rails/utils' # Defer to Rails if this is a Rails application - if Datadog::Tracing::Contrib::Rails::Utils.railtie_supported? + if Datadog::Core::Contrib::Rails::Utils.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 febd5526690..72166753885 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 '../rails/utils' +require_relative '../../../core/contrib/rails/utils' 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? - !Contrib::Rails::Utils.railtie_supported? + !Core::Contrib::Rails::Utils.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 6a36cb0168b..66f03dd3da9 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 'utils' +require_relative '../../../core/contrib/rails/utils' 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] || Utils.app_name + datadog_config.service = rails_config[:service_name] || Core::Contrib::Rails::Utils.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 a3e34d3ff85..0fadc07735c 100644 --- a/lib/datadog/tracing/contrib/rails/patcher.rb +++ b/lib/datadog/tracing/contrib/rails/patcher.rb @@ -6,7 +6,7 @@ require_relative 'log_injection' require_relative 'middlewares' require_relative 'runner' -require_relative 'utils' +require_relative '../../../core/contrib/rails/utils' require_relative '../semantic_logger/patcher' module Datadog diff --git a/sig/datadog/tracing/contrib/rails/utils.rbs b/sig/datadog/core/contrib/rails/utils.rbs similarity index 50% rename from sig/datadog/tracing/contrib/rails/utils.rbs rename to sig/datadog/core/contrib/rails/utils.rbs index a683874122f..49db36402bc 100644 --- a/sig/datadog/tracing/contrib/rails/utils.rbs +++ b/sig/datadog/core/contrib/rails/utils.rbs @@ -1,11 +1,11 @@ module Datadog - module Tracing + module Core module Contrib module Rails module Utils - def self.app_name: () -> untyped + def self.app_name: () -> String - def self.railtie_supported?: () -> untyped + def self.railtie_supported?: () -> bool end end end diff --git a/spec/datadog/tracing/contrib/rails/utils_spec.rb b/spec/datadog/core/contrib/rails/utils_spec.rb similarity index 81% rename from spec/datadog/tracing/contrib/rails/utils_spec.rb rename to spec/datadog/core/contrib/rails/utils_spec.rb index 66a08af7d76..b3f04ed32bc 100644 --- a/spec/datadog/tracing/contrib/rails/utils_spec.rb +++ b/spec/datadog/core/contrib/rails/utils_spec.rb @@ -1,7 +1,7 @@ -require 'lib/datadog/tracing/contrib/rails/utils' +require 'lib/datadog/core/contrib/rails/utils' require 'rails/version' -RSpec.describe Datadog::Tracing::Contrib::Rails::Utils do +RSpec.describe Datadog::Core::Contrib::Rails::Utils 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 5dc2950a1cd..499cd95fb16 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::Tracing::Contrib::Rails::Utils).to receive(:railtie_supported?).and_return(false) + allow(Datadog::Core::Contrib::Rails::Utils).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::Tracing::Contrib::Rails::Utils).to receive(:railtie_supported?).and_return(true) + allow(Datadog::Core::Contrib::Rails::Utils).to receive(:railtie_supported?).and_return(true) end it { is_expected.to be(false) } From 7bf4169cfc4b5e9827dba66535b2e4de8ff3db47 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 7 Jan 2025 10:29:33 -0500 Subject: [PATCH 2/3] move to Core::Utils::Rails --- Steepfile | 2 +- lib/datadog/core/contrib/rails/utils.rb | 24 ------------------- lib/datadog/core/utils/rails.rb | 22 +++++++++++++++++ .../contrib/action_cable/integration.rb | 4 ++-- .../contrib/action_mailer/integration.rb | 4 ++-- .../contrib/action_pack/integration.rb | 4 ++-- .../contrib/action_view/integration.rb | 4 ++-- .../tracing/contrib/active_job/integration.rb | 4 ++-- .../contrib/active_record/integration.rb | 4 ++-- .../contrib/active_support/integration.rb | 4 ++-- .../tracing/contrib/auto_instrument.rb | 4 ++-- .../tracing/contrib/rack/integration.rb | 4 ++-- .../tracing/contrib/rails/framework.rb | 4 ++-- lib/datadog/tracing/contrib/rails/patcher.rb | 1 - sig/datadog/core/contrib/rails/utils.rbs | 13 ---------- sig/datadog/core/utils/rails.rbs | 11 +++++++++ .../utils_spec.rb => utils/rails_spec.rb} | 4 ++-- .../contrib/auto_instrument_examples.rb | 4 ++-- 18 files changed, 58 insertions(+), 63 deletions(-) delete mode 100644 lib/datadog/core/contrib/rails/utils.rb create mode 100644 lib/datadog/core/utils/rails.rb delete mode 100644 sig/datadog/core/contrib/rails/utils.rbs create mode 100644 sig/datadog/core/utils/rails.rbs rename spec/datadog/core/{contrib/rails/utils_spec.rb => utils/rails_spec.rb} (82%) 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/sig/datadog/core/contrib/rails/utils.rbs b/sig/datadog/core/contrib/rails/utils.rbs deleted file mode 100644 index 49db36402bc..00000000000 --- a/sig/datadog/core/contrib/rails/utils.rbs +++ /dev/null @@ -1,13 +0,0 @@ -module Datadog - module Core - module Contrib - module Rails - module Utils - def self.app_name: () -> String - - def self.railtie_supported?: () -> bool - end - end - end - end -end diff --git a/sig/datadog/core/utils/rails.rbs b/sig/datadog/core/utils/rails.rbs new file mode 100644 index 00000000000..49dec926755 --- /dev/null +++ b/sig/datadog/core/utils/rails.rbs @@ -0,0 +1,11 @@ +module Datadog + module Core + module Utils + module Rails + def self.app_name: () -> String + + def self.railtie_supported?: () -> bool + end + end + end +end 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) } From 5179713c818ca0351c01d5a3b2c5fd552e1e76fe Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 7 Jan 2025 16:57:28 -0500 Subject: [PATCH 3/3] Revert "move to Core::Utils::Rails" This reverts commit 7bf4169cfc4b5e9827dba66535b2e4de8ff3db47. --- Steepfile | 2 +- lib/datadog/core/contrib/rails/utils.rb | 24 +++++++++++++++++++ lib/datadog/core/utils/rails.rb | 22 ----------------- .../contrib/action_cable/integration.rb | 4 ++-- .../contrib/action_mailer/integration.rb | 4 ++-- .../contrib/action_pack/integration.rb | 4 ++-- .../contrib/action_view/integration.rb | 4 ++-- .../tracing/contrib/active_job/integration.rb | 4 ++-- .../contrib/active_record/integration.rb | 4 ++-- .../contrib/active_support/integration.rb | 4 ++-- .../tracing/contrib/auto_instrument.rb | 4 ++-- .../tracing/contrib/rack/integration.rb | 4 ++-- .../tracing/contrib/rails/framework.rb | 4 ++-- lib/datadog/tracing/contrib/rails/patcher.rb | 1 + sig/datadog/core/contrib/rails/utils.rbs | 13 ++++++++++ sig/datadog/core/utils/rails.rbs | 11 --------- .../rails/utils_spec.rb} | 4 ++-- .../contrib/auto_instrument_examples.rb | 4 ++-- 18 files changed, 63 insertions(+), 58 deletions(-) create mode 100644 lib/datadog/core/contrib/rails/utils.rb delete mode 100644 lib/datadog/core/utils/rails.rb create mode 100644 sig/datadog/core/contrib/rails/utils.rbs delete mode 100644 sig/datadog/core/utils/rails.rbs rename spec/datadog/core/{utils/rails_spec.rb => contrib/rails/utils_spec.rb} (82%) diff --git a/Steepfile b/Steepfile index c797845fcde..ffb73d3e43a 100644 --- a/Steepfile +++ b/Steepfile @@ -89,6 +89,7 @@ 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' @@ -127,7 +128,6 @@ 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 new file mode 100644 index 00000000000..864f8ab3c9f --- /dev/null +++ b/lib/datadog/core/contrib/rails/utils.rb @@ -0,0 +1,24 @@ +# 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 deleted file mode 100644 index f36568bdac9..00000000000 --- a/lib/datadog/core/utils/rails.rb +++ /dev/null @@ -1,22 +0,0 @@ -# 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 b6693bc91fe..db2d656174c 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/utils/rails' +require_relative '../../../core/contrib/rails/utils' 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::Utils::Rails.railtie_supported? + !Core::Contrib::Rails::Utils.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 c204846fb54..f4296086863 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/utils/rails' +require_relative '../../../core/contrib/rails/utils' 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::Utils::Rails.railtie_supported? + !Core::Contrib::Rails::Utils.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 4966a1b0f97..89819c59411 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/utils/rails' +require_relative '../../../core/contrib/rails/utils' 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::Utils::Rails.railtie_supported? + !Core::Contrib::Rails::Utils.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 134aefc604b..01cb17c46f4 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/utils/rails' +require_relative '../../../core/contrib/rails/utils' 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::Utils::Rails.railtie_supported? + !Core::Contrib::Rails::Utils.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 d84fa2af842..54d0c9f55b8 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/utils/rails' +require_relative '../../../core/contrib/rails/utils' 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::Utils::Rails.railtie_supported? + !Core::Contrib::Rails::Utils.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 c69cb1733f9..5da4e133266 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/utils/rails' +require_relative '../../../core/contrib/rails/utils' 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::Utils::Rails.railtie_supported? + !Core::Contrib::Rails::Utils.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 fe83fe3266a..56f357adf5b 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/utils/rails' +require_relative '../../../core/contrib/rails/utils' 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::Utils::Rails.railtie_supported? + !Core::Contrib::Rails::Utils.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 29c31846579..23988c2e2f6 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/utils/rails' + require_relative '../../core/contrib/rails/utils' # Defer to Rails if this is a Rails application - if Datadog::Core::Utils::Rails.railtie_supported? + if Datadog::Core::Contrib::Rails::Utils.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 684cf6be669..72166753885 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/utils/rails' +require_relative '../../../core/contrib/rails/utils' 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::Utils::Rails.railtie_supported? + !Core::Contrib::Rails::Utils.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 b224b50dda8..66f03dd3da9 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/utils/rails' +require_relative '../../../core/contrib/rails/utils' 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::Utils::Rails.app_name + datadog_config.service = rails_config[:service_name] || Core::Contrib::Rails::Utils.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 bf8208c4fbb..0fadc07735c 100644 --- a/lib/datadog/tracing/contrib/rails/patcher.rb +++ b/lib/datadog/tracing/contrib/rails/patcher.rb @@ -6,6 +6,7 @@ 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/sig/datadog/core/contrib/rails/utils.rbs b/sig/datadog/core/contrib/rails/utils.rbs new file mode 100644 index 00000000000..49db36402bc --- /dev/null +++ b/sig/datadog/core/contrib/rails/utils.rbs @@ -0,0 +1,13 @@ +module Datadog + module Core + module Contrib + module Rails + module Utils + def self.app_name: () -> String + + def self.railtie_supported?: () -> bool + end + end + end + end +end diff --git a/sig/datadog/core/utils/rails.rbs b/sig/datadog/core/utils/rails.rbs deleted file mode 100644 index 49dec926755..00000000000 --- a/sig/datadog/core/utils/rails.rbs +++ /dev/null @@ -1,11 +0,0 @@ -module Datadog - module Core - module Utils - module Rails - def self.app_name: () -> String - - def self.railtie_supported?: () -> bool - end - end - end -end diff --git a/spec/datadog/core/utils/rails_spec.rb b/spec/datadog/core/contrib/rails/utils_spec.rb similarity index 82% rename from spec/datadog/core/utils/rails_spec.rb rename to spec/datadog/core/contrib/rails/utils_spec.rb index 4c0356e5752..b3f04ed32bc 100644 --- a/spec/datadog/core/utils/rails_spec.rb +++ b/spec/datadog/core/contrib/rails/utils_spec.rb @@ -1,7 +1,7 @@ -require 'lib/datadog/core/utils/rails' +require 'lib/datadog/core/contrib/rails/utils' require 'rails/version' -RSpec.describe Datadog::Core::Utils::Rails do +RSpec.describe Datadog::Core::Contrib::Rails::Utils 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 7fd9376add7..499cd95fb16 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::Utils::Rails).to receive(:railtie_supported?).and_return(false) + allow(Datadog::Core::Contrib::Rails::Utils).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::Utils::Rails).to receive(:railtie_supported?).and_return(true) + allow(Datadog::Core::Contrib::Rails::Utils).to receive(:railtie_supported?).and_return(true) end it { is_expected.to be(false) }