Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEBUG-3182 move Rails utils to core #4261

Merged
merged 3 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Steepfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# frozen_string_literal: true
p-datadog marked this conversation as resolved.
Show resolved Hide resolved

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
4 changes: 2 additions & 2 deletions lib/datadog/tracing/contrib/auto_instrument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!
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
Loading