Skip to content

Commit

Permalink
Merge pull request #65 from palazzem/better-logging
Browse files Browse the repository at this point in the history
[rails] reduce logs verbosity
  • Loading branch information
Emanuele Palazzetti authored Jan 21, 2017
2 parents 89d6737 + 4a1f50d commit 94ce33a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/ddtrace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class Railtie < Rails::Railtie
# (typically in initialize callback) does not work, it does not
# get loaded in the right context.
require 'redis-rails'
Datadog::Tracer.log.info("'redis-rails' module found, datadog redis integration is available")
Datadog::Tracer.log.debug("'redis-rails' module found, Datadog 'redis-rails' integration is available")
rescue LoadError
Datadog::Tracer.log.info("no 'redis-rails' module found, datadog redis integration is not available")
Datadog::Tracer.log.debug("'redis-rails' module not found, Datadog 'redis-rails' integration is disabled")
end

Datadog::Monkey.patch_module(:redis)
Expand Down
14 changes: 8 additions & 6 deletions lib/ddtrace/contrib/rails/framework.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ def self.configure(config)
Datadog::Ext::AppTypes::CACHE
)

# set default database service details and store it in the configuration
if defined?(::ActiveRecord)
begin
# set default database service details and store it in the configuration
conn_cfg = ::ActiveRecord::Base.connection_config()
adapter_name = Datadog::Contrib::Rails::Utils.normalize_vendor(conn_cfg[:adapter])
database_service = datadog_config.fetch(:default_database_service, adapter_name)
Expand All @@ -72,7 +72,7 @@ def self.configure(config)
Datadog::Ext::AppTypes::DB
)
rescue StandardError => e
Datadog::Tracer.log.info("cannot configuring database service (#{e}), skipping activerecord instrumentation")
Datadog::Tracer.log.warn("Unable to get database config (#{e}), skipping ActiveRecord instrumentation")
end
end

Expand All @@ -81,19 +81,21 @@ def self.configure(config)
end

def self.auto_instrument_redis
Datadog::Tracer.log.debug('instrumenting redis')
# configure Redis PIN
return unless (defined? ::Rails.cache) && ::Rails.cache.respond_to?(:data)
Datadog::Tracer.log.debug('redis cache exists')
pin = Datadog::Pin.get_from(::Rails.cache.data)
return unless pin
Datadog::Tracer.log.debug('redis cache pin is set')

# enable Redis instrumentation if activated
pin.tracer = nil unless ::Rails.configuration.datadog_trace[:auto_instrument_redis]
return unless pin.tracer
Datadog::Tracer.log.debug("'redis' module found, Datadog 'redis' integration is available")
end

# automatically instrument all Rails component
def self.auto_instrument
return unless ::Rails.configuration.datadog_trace[:auto_instrument]
Datadog::Tracer.log.info('Detected Rails >= 3.x. Enabling auto-instrumentation for core components.')
Datadog::Tracer.log.info('Detected Rails >= 3.x. Enabling auto-instrumentation for core components')

# instrumenting Rails framework
Datadog::Contrib::Rails::ActionController.instrument()
Expand Down

0 comments on commit 94ce33a

Please sign in to comment.