Module: Datadog::Contrib::Rails::Framework
- Defined in:
- lib/ddtrace/contrib/rails/framework.rb
Overview
Rails framework code, used to essentially:
-
handle configuration entries which are specific to Datadog tracing
-
instrument parts of the framework when needed
Class Method Summary collapse
- .activate_action_cable!(config) ⇒ Object
- .activate_action_pack!(config) ⇒ Object
- .activate_action_view!(config) ⇒ Object
- .activate_active_record!(config) ⇒ Object
- .activate_active_support!(config) ⇒ Object
- .activate_rack!(config) ⇒ Object
- .config_with_defaults ⇒ Object
-
.setup ⇒ Object
configure Datadog settings.
Class Method Details
.activate_action_cable!(config) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/ddtrace/contrib/rails/framework.rb', line 83 def self.activate_action_cable!(config) return unless defined?(::ActionCable) Datadog.configuration.use( :action_cable, service_name: "#{config[:service_name]}-#{Contrib::ActionCable::Ext::SERVICE_NAME}", tracer: config[:tracer] ) end |
.activate_action_pack!(config) ⇒ Object
93 94 95 96 97 98 99 100 101 |
# File 'lib/ddtrace/contrib/rails/framework.rb', line 93 def self.activate_action_pack!(config) return unless defined?(::ActionPack) Datadog.configuration.use( :action_pack, service_name: config[:service_name], tracer: config[:tracer] ) end |
.activate_action_view!(config) ⇒ Object
103 104 105 106 107 108 109 110 111 |
# File 'lib/ddtrace/contrib/rails/framework.rb', line 103 def self.activate_action_view!(config) return unless defined?(::ActionView) Datadog.configuration.use( :action_view, service_name: config[:service_name], tracer: config[:tracer] ) end |
.activate_active_record!(config) ⇒ Object
113 114 115 116 117 118 119 120 121 |
# File 'lib/ddtrace/contrib/rails/framework.rb', line 113 def self.activate_active_record!(config) return unless defined?(::ActiveRecord) Datadog.configuration.use( :active_record, service_name: config[:database_service], tracer: config[:tracer] ) end |
.activate_active_support!(config) ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/ddtrace/contrib/rails/framework.rb', line 73 def self.activate_active_support!(config) return unless defined?(::ActiveSupport) Datadog.configuration.use( :active_support, cache_service: config[:cache_service], tracer: config[:tracer] ) end |
.activate_rack!(config) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ddtrace/contrib/rails/framework.rb', line 62 def self.activate_rack!(config) Datadog.configuration.use( :rack, tracer: config[:tracer], application: ::Rails.application, service_name: config[:service_name], middleware_names: config[:middleware_names], distributed_tracing: config[:distributed_tracing] ) end |
.config_with_defaults ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ddtrace/contrib/rails/framework.rb', line 51 def self.config_with_defaults # We set defaults here instead of in the patcher because we need to wait # for the Rails application to be fully initialized. Datadog.configuration[:rails].tap do |config| config[:service_name] ||= (Datadog.configuration.service || Utils.app_name) config[:database_service] ||= "#{config[:service_name]}-#{Contrib::ActiveRecord::Utils.adapter_name}" config[:controller_service] ||= config[:service_name] config[:cache_service] ||= "#{config[:service_name]}-cache" end end |
.setup ⇒ Object
configure Datadog settings
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ddtrace/contrib/rails/framework.rb', line 23 def self.setup config = config_with_defaults activate_rack!(config) activate_action_cable!(config) activate_active_support!(config) activate_action_pack!(config) activate_action_view!(config) activate_active_record!(config) # By default, default service would be guessed from the script # 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. Datadog.configuration.service ||= config[:service_name] # Set the environment to the Rails environment. # Don't set this if env has been explicitly provided by the user. Datadog.configuration.env ||= ::Rails.env if ::Rails.respond_to?(:env) # Update the tracer if its not the default tracer. if config[:tracer] != Datadog.configuration.tracer config[:tracer].default_service = config[:service_name] env = Datadog.configuration.env || (::Rails.respond_to?(:env) && ::Rails.env) config[:tracer].('env' => env) if env end end |