From d632d59d560c0b81e2e60cd44cf7d487cec8aecb Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 30 Dec 2024 11:34:51 -0500 Subject: [PATCH] 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) }