Skip to content

Commit

Permalink
Fixed: Analytics for Rails not propagating to ActionPack.
Browse files Browse the repository at this point in the history
  • Loading branch information
delner committed Sep 3, 2019
1 parent b0b0ab9 commit 173f540
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/ddtrace/contrib/action_pack/configuration/settings.rb
Expand Up @@ -8,7 +8,7 @@ module Configuration
# Custom settings for the ActionPack integration
class Settings < Contrib::Configuration::Settings
option :analytics_enabled,
default: -> { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) },
default: -> { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, nil) },
lazy: true

option :analytics_sample_rate,
Expand Down
14 changes: 12 additions & 2 deletions lib/ddtrace/contrib/rails/configuration/settings.rb
Expand Up @@ -8,11 +8,21 @@ module Configuration
class Settings < Contrib::Configuration::Settings
option :analytics_enabled,
default: -> { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, nil) },
lazy: true
lazy: true do |value|
value.tap do
# Update ActionPack analytics too
Datadog.configuration[:action_pack][:analytics_enabled] = value
end
end

option :analytics_sample_rate,
default: -> { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) },
lazy: true
lazy: true do |value|
value.tap do
# Update ActionPack analytics too
Datadog.configuration[:action_pack][:analytics_sample_rate] = value
end
end

option :cache_service do |value|
value.tap do
Expand Down
11 changes: 5 additions & 6 deletions spec/ddtrace/contrib/rails/action_controller_spec.rb
Expand Up @@ -5,9 +5,13 @@
let(:rails_options) { { tracer: tracer } }

before(:each) do
Datadog::RailsActionPatcher.patch_action_controller
Datadog.configure do |c|
c.use :rails, rails_options
# Manually activate ActionPack to trigger patching.
# This is because Rails instrumentation normally defers patching until #after_initialize
# when it activates and configures each of the Rails components with application details.
# We aren't initializing a full Rails application here, so the patch doesn't auto-apply.
c.use :action_pack
end
end

Expand Down Expand Up @@ -44,11 +48,6 @@ def index
context 'that inherits from ActionController::Metal' do
let(:base_class) { ActionController::Metal }

before(:each) do
# ActionController::Metal is only patched in 2.0+
skip 'Not supported for Ruby < 2.0' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.0.0')
end

it_behaves_like 'a successful dispatch'

context 'when response is overridden' do
Expand Down
11 changes: 5 additions & 6 deletions spec/ddtrace/contrib/rails/analytics_spec.rb
Expand Up @@ -6,9 +6,13 @@
let(:configuration_options) { { tracer: tracer } }

before(:each) do
Datadog::RailsActionPatcher.patch_action_controller
Datadog.configure do |c|
c.use :rails, configuration_options
# Manually activate ActionPack to trigger patching.
# This is because Rails instrumentation normally defers patching until #after_initialize
# when it activates and configures each of the Rails components with application details.
# We aren't initializing a full Rails application here, so the patch doesn't auto-apply.
c.use :action_pack
end
end

Expand Down Expand Up @@ -36,11 +40,6 @@ def index
let(:action) { controller.action(name) }
let(:env) { {} }

before(:each) do
# ActionController::Metal is only patched in 2.0+
skip 'Not supported for Ruby < 2.0' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.0.0')
end

shared_examples_for 'a successful dispatch' do
it do
expect { result }.to_not raise_error
Expand Down

0 comments on commit 173f540

Please sign in to comment.