Skip to content

Commit

Permalink
Changed: Rails to patch Base, API instead of Metal.
Browse files Browse the repository at this point in the history
  • Loading branch information
delner committed Jan 10, 2019
1 parent 047e43a commit 59204f3
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 72 deletions.
9 changes: 0 additions & 9 deletions lib/ddtrace/contrib/rails/action_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@ module Contrib
module Rails
# Code used to create and handle 'rails.action_controller' spans.
module ActionController
include Datadog::Patcher

def self.instrument
# patch Rails core components
do_once(:instrument) do
Datadog::RailsActionPatcher.patch_action_controller
end
end

def self.start_processing(payload)
# trace the execution
tracer = Datadog.configuration[:rails][:tracer]
Expand Down
2 changes: 2 additions & 0 deletions lib/ddtrace/contrib/rails/action_controller_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module Rails
# Instrument ActiveController processing
module ActionControllerPatch
def self.included(base)
return if base.ancestors.include?(ProcessActionPatch)

if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.0.0')
base.send(:prepend, ProcessActionPatch)
else
Expand Down
19 changes: 0 additions & 19 deletions lib/ddtrace/contrib/rails/action_view.rb

This file was deleted.

9 changes: 0 additions & 9 deletions lib/ddtrace/contrib/rails/active_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@ module Contrib
module Rails
# Code used to create and handle 'rails.cache' spans.
module ActiveSupport
include Datadog::Patcher

def self.instrument
do_once(:instrument) do
# patch Rails core components
Datadog::RailsCachePatcher.patch_cache_store
end
end

def self.start_trace_cache(payload)
tracer = Datadog.configuration[:rails][:tracer]

Expand Down
24 changes: 7 additions & 17 deletions lib/ddtrace/contrib/rails/core_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,22 +169,6 @@ def with_datadog_span(span)
module RailsActionPatcher
include Datadog::Patcher

# Patch for ActionController::Metal
module MetalPatch
# For any Controller class that inherits from ActionController::Metal,
# make sure to include the tracing patch. We do this instead of Metal.include(Patch)
# because Base and API compose modules that would take precedence over the tracing patch.
# By adding it onto the inheriting class, we can make sure it has a higher precedence.
def inherited(base)
super

# Make sure not to include the patch twice, to avoid double measurements on controllers.
unless base.ancestors.include?(Datadog::Contrib::Rails::ActionControllerPatch)
base.send(:include, Datadog::Contrib::Rails::ActionControllerPatch)
end
end
end

module_function

def patch_action_controller
Expand All @@ -197,7 +181,13 @@ def patch_process_action
do_once(:patch_process_action) do
require 'ddtrace/contrib/rails/action_controller_patch'

::ActionController::Metal.extend(MetalPatch)
if defined?(::ActionController::Base)
::ActionController::Base.send(:include, Datadog::Contrib::Rails::ActionControllerPatch)
end

if defined?(::ActionController::API)
::ActionController::API.send(:include, Datadog::Contrib::Rails::ActionControllerPatch)
end
end
end
end
Expand Down
1 change: 0 additions & 1 deletion lib/ddtrace/contrib/rails/framework.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
require 'ddtrace/contrib/rails/ext'
require 'ddtrace/contrib/rails/core_extensions'
require 'ddtrace/contrib/rails/action_controller'
require 'ddtrace/contrib/rails/action_view'
require 'ddtrace/contrib/rails/active_support'
require 'ddtrace/contrib/rails/utils'

Expand Down
6 changes: 3 additions & 3 deletions lib/ddtrace/contrib/rails/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ def setup_tracer

# Add instrumentation to Rails components
def instrument_rails
Datadog::Contrib::Rails::ActionController.instrument
Datadog::Contrib::Rails::ActionView.instrument
Datadog::Contrib::Rails::ActiveSupport.instrument
Datadog::RailsActionPatcher.patch_action_controller
Datadog::RailsRendererPatcher.patch_renderer
Datadog::RailsCachePatcher.patch_cache_store
end
end
end
Expand Down
3 changes: 1 addition & 2 deletions spec/ddtrace/contrib/rails/action_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
require 'ddtrace/contrib/rails/rails_helper'

RSpec.describe 'ActionController tracing' do
let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) }
let(:tracer) { get_test_tracer }
let(:rails_options) { { tracer: tracer } }

before(:each) do
Datadog::RailsActionPatcher.patch_action_controller
Datadog.configure do |c|
c.use :rails, rails_options
end
Expand Down
1 change: 0 additions & 1 deletion spec/ddtrace/contrib/rails/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def all_spans
end

before(:each) do
Datadog::RailsActionPatcher.patch_action_controller
Datadog.configure do |c|
c.use :rack, rack_options if use_rack
c.use :rails, rails_options if use_rails
Expand Down
11 changes: 0 additions & 11 deletions spec/ddtrace/contrib/rails/railtie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,6 @@

let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) }

let(:routes) { { '/' => 'test#index' } }
let(:controllers) { [controller] }

let(:controller) do
stub_const('TestController', Class.new(ActionController::Base) do
def index
head :ok
end
end)
end

RSpec::Matchers.define :have_kind_of_middleware do |expected|
match do |actual|
found = 0
Expand Down

0 comments on commit 59204f3

Please sign in to comment.