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

[rails] Add feature flags to Rails integration #448

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
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
1 change: 1 addition & 0 deletions docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ Where `options` is an optional `Hash` that accepts the following parameters:
| ``distributed_tracing`` | Enables [distributed tracing](#distributed-tracing) so that this service trace is connected with a trace of another service if tracing headers are received | `false` |
| ``middleware_names`` | Enables any short-circuited middleware requests to display the middleware name as resource for the trace. | `false` |
| ``template_base_path`` | Used when the template name is parsed. If you don't store your templates in the ``views/`` folder, you may need to change this value | ``views/`` |
| ``flags`` | Flags used in `rails` instrumentation. | ```{ instrument_action_view_rendering: true, instrument_action_controller_processing: true, instrument_active_support_caching: true, use_rack_integration: true, use_active_record_integration: true}``` |
| ``tracer`` | A ``Datadog::Tracer`` instance used to instrument the application. Usually you don't need to set that. | ``Datadog.tracer`` |

### Redis
Expand Down
9 changes: 7 additions & 2 deletions lib/ddtrace/contrib/rails/framework.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ module Framework
def self.setup
config = config_with_defaults

activate_rack!(config)
activate_active_record!(config)
activate_rack!(config) if datadog_configuration[:flags][:use_rack_integration]
activate_active_record!(config) if datadog_configuration[:flags][:use_active_record_integration]

set_service_info!(config)

# By default, default service would be guessed from the script
Expand Down Expand Up @@ -69,6 +70,10 @@ def self.set_service_info!(config)
tracer.set_service_info(config[:controller_service], 'rails', Ext::AppTypes::WEB)
tracer.set_service_info(config[:cache_service], 'rails', Ext::AppTypes::CACHE)
end

def self.datadog_configuration
Datadog.configuration[:rails]
end
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions lib/ddtrace/contrib/rails/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ module Rails
# Patcher
module Patcher
include Base

DEFAULT_FLAGS = {
instrument_action_view_rendering: true,
instrument_action_controller_processing: true,
instrument_active_support_caching: true,
use_rack_integration: true,
use_active_record_integration: true
}.freeze

register_as :rails, auto_patch: true

option :service_name
Expand All @@ -21,6 +30,7 @@ module Patcher
option :distributed_tracing, default: false
option :template_base_path, default: 'views/'
option :exception_controller, default: nil
option :flags, setter: ->(value) { DEFAULT_FLAGS.merge(value) }, default: DEFAULT_FLAGS
option :tracer, default: Datadog.tracer

@patched = false
Expand Down
17 changes: 14 additions & 3 deletions lib/ddtrace/contrib/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,20 @@ class Railtie < Rails::Railtie

config.after_initialize do
Datadog::Contrib::Rails::Framework.setup
Datadog::Contrib::Rails::ActionController.instrument
Datadog::Contrib::Rails::ActionView.instrument
Datadog::Contrib::Rails::ActiveSupport.instrument

if datadog_configuration[:flags][:instrument_action_controller_processing]
Datadog::Contrib::Rails::ActionController.instrument
end
if datadog_configuration[:flags][:instrument_action_view_rendering]
Datadog::Contrib::Rails::ActionView.instrument
end
if datadog_configuration[:flags][:instrument_active_support_caching]
Datadog::Contrib::Rails::ActiveSupport.instrument
end
end

def self.datadog_configuration
Datadog.configuration[:rails]
end
end
end