Skip to content

Commit

Permalink
DEBUG-3182 move Rails utils to core
Browse files Browse the repository at this point in the history
  • Loading branch information
p committed Jan 6, 2025
1 parent 9605f99 commit 5e08393
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/datadog/tracing/contrib/action_cable/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/datadog/tracing/contrib/action_mailer/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/datadog/tracing/contrib/action_pack/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/datadog/tracing/contrib/action_view/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/datadog/tracing/contrib/active_job/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/datadog/tracing/contrib/active_record/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/datadog/tracing/contrib/active_support/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/tracing/contrib/auto_instrument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def self.auto_instrument!
require_relative '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!
Expand Down
4 changes: 2 additions & 2 deletions lib/datadog/tracing/contrib/rack/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/datadog/tracing/contrib/rails/framework.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/tracing/contrib/rails/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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? }

Expand Down
4 changes: 2 additions & 2 deletions spec/datadog/tracing/contrib/auto_instrument_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

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) }
end

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) }
Expand Down

0 comments on commit 5e08393

Please sign in to comment.