lib/ddtrace/contrib/rails/framework.rb in ddtrace-0.6.2 vs lib/ddtrace/contrib/rails/framework.rb in ddtrace-0.7.0

- old
+ new

@@ -1,7 +1,11 @@ +require 'ddtrace/pin' require 'ddtrace/ext/app_types' +require 'ddtrace/contrib/grape/endpoint' +require 'ddtrace/contrib/rack/middlewares' + require 'ddtrace/contrib/rails/core_extensions' require 'ddtrace/contrib/rails/action_controller' require 'ddtrace/contrib/rails/action_view' require 'ddtrace/contrib/rails/active_record' require 'ddtrace/contrib/rails/active_support' @@ -18,12 +22,15 @@ # is kept disabled. DEFAULT_CONFIG = { enabled: true, auto_instrument: false, auto_instrument_redis: false, + auto_instrument_grape: false, default_service: 'rails-app', + default_controller_service: 'rails-controller', default_cache_service: 'rails-cache', + default_grape_service: 'grape', template_base_path: 'views/', tracer: Datadog.tracer, debug: false, trace_agent_hostname: Datadog::Writer::HOSTNAME, trace_agent_port: Datadog::Writer::PORT, @@ -55,10 +62,16 @@ datadog_config[:tracer].set_tags('env' => datadog_config[:env]) if datadog_config[:env] # set default service details datadog_config[:tracer].set_service_info( datadog_config[:default_service], + 'rack', + Datadog::Ext::AppTypes::WEB + ) + + datadog_config[:tracer].set_service_info( + datadog_config[:default_controller_service], 'rails', Datadog::Ext::AppTypes::WEB ) datadog_config[:tracer].set_service_info( @@ -111,9 +124,22 @@ if ::Rails::VERSION::MAJOR.to_i == 3 silence_warnings { Object.const_set 'RAILS_CACHE', cache_instance } elsif ::Rails::VERSION::MAJOR.to_i > 3 ::Rails.cache = cache_instance end + end + + def self.auto_instrument_grape + return unless ::Rails.configuration.datadog_trace[:auto_instrument_grape] + + # patch the Grape library so that endpoints are traced + Datadog::Monkey.patch_module(:grape) + + # update the Grape pin object + pin = Datadog::Pin.get_from(::Grape) + return unless pin && pin.enabled? + pin.tracer = ::Rails.configuration.datadog_trace[:tracer] + pin.service = ::Rails.configuration.datadog_trace[:default_grape_service] end # automatically instrument all Rails component def self.auto_instrument return unless ::Rails.configuration.datadog_trace[:auto_instrument]