lib/ddtrace.rb in ddtrace-0.9.2 vs lib/ddtrace.rb in ddtrace-0.10.0
- old
+ new
@@ -1,14 +1,16 @@
-require 'ddtrace/monkey'
+require 'ddtrace/registry'
require 'ddtrace/pin'
require 'ddtrace/tracer'
require 'ddtrace/error'
require 'ddtrace/pipeline'
+require 'ddtrace/configuration'
# \Datadog global namespace that includes all tracing functionality for Tracer and Span classes.
module Datadog
- @tracer = Datadog::Tracer.new()
+ @tracer = Tracer.new
+ @registry = Registry.new
# Default tracer that can be used as soon as +ddtrace+ is required:
#
# require 'ddtrace'
#
@@ -23,44 +25,28 @@
# pin.tracer = tracer
def self.tracer
@tracer
end
-end
-# Datadog auto instrumentation for frameworks
-if defined?(Rails::VERSION)
- if !ENV['DISABLE_DATADOG_RAILS']
- if Rails::VERSION::MAJOR.to_i >= 3
- require 'ddtrace/contrib/rails/framework'
- require 'ddtrace/contrib/rails/middlewares'
+ def self.registry
+ @registry
+ end
- module Datadog
- # Railtie class initializes
- class Railtie < Rails::Railtie
- # add instrumentation middlewares
- options = {}
- config.app_middleware.insert_before(0, Datadog::Contrib::Rack::TraceMiddleware, options)
- config.app_middleware.use(Datadog::Contrib::Rails::ExceptionMiddleware)
+ class << self
+ attr_writer :configuration
- # auto instrument Rails and third party components after
- # the framework initialization
- config.after_initialize do |app|
- Datadog::Contrib::Rails::Framework.configure(config: app.config)
- Datadog::Contrib::Rails::Framework.auto_instrument()
- Datadog::Contrib::Rails::Framework.auto_instrument_redis()
- Datadog::Contrib::Rails::Framework.auto_instrument_grape()
+ def configuration
+ @configuration ||= Configuration.new
+ end
- # override Rack Middleware configurations with Rails
- options.update(::Rails.configuration.datadog_trace)
- end
- end
- end
- else
- Datadog::Tracer.log.warn 'Detected a Rails version < 3.x.'\
- 'This version is not supported yet and the'\
- 'auto-instrumentation for core components will be disabled.'
+ def configure
+ yield(configuration)
end
- else
- Datadog::Tracer.log.info 'Skipping Rails auto-instrumentation, DISABLE_DATADOG_RAILS is set.'
end
end
+
+# Monkey currently is responsible for loading all contributions, which in turn
+# rely on the registry defined above. We should make our code less dependent on
+# the load order, by letting things be lazily loaded while keeping
+# thread-safety.
+require 'ddtrace/monkey'