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

Use public prepend, include, and extend methods #1509

Merged
merged 1 commit into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions lib/ddtrace/configuration/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ module Configuration
# Basic configuration behavior
module Base
def self.included(base)
base.send(:extend, Datadog::Environment::Helpers)
base.send(:include, Datadog::Environment::Helpers)
base.send(:include, Options)
base.extend(Datadog::Environment::Helpers)
base.include(Datadog::Environment::Helpers)
base.include(Options)

base.send(:extend, ClassMethods)
base.send(:include, InstanceMethods)
base.extend(ClassMethods)
base.include(InstanceMethods)
end

# Class methods for configuration
Expand Down
4 changes: 2 additions & 2 deletions lib/ddtrace/configuration/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module Configuration
# Behavior for a configuration object that has options
module Options
def self.included(base)
base.send(:extend, ClassMethods)
base.send(:include, InstanceMethods)
base.extend(ClassMethods)
base.include(InstanceMethods)
end

# Class behavior for a configuration object with options
Expand Down
8 changes: 4 additions & 4 deletions lib/ddtrace/contrib/action_cable/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module ActionCable
# Defines basic behaviors for an event.
module Event
def self.included(base)
base.send(:include, ActiveSupport::Notifications::Event)
base.send(:extend, ClassMethods)
base.include(ActiveSupport::Notifications::Event)
base.extend(ClassMethods)
end

# Class methods for events.
Expand All @@ -34,8 +34,8 @@ def configuration
# but to start a fresh tracing context.
module RootContextEvent
def self.included(base)
base.send(:include, ActiveSupport::Notifications::Event)
base.send(:extend, ClassMethods)
base.include(ActiveSupport::Notifications::Event)
base.extend(ClassMethods)
end

# Class methods for events.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def target_version
end

def patch
::ActionController::Metal.send(:prepend, ActionController::Instrumentation::Metal)
::ActionController::Metal.prepend(ActionController::Instrumentation::Metal)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/ddtrace/contrib/action_view/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ module ActionView
# Defines basic behavior for an ActionView event.
module Event
def self.included(base)
base.send(:include, ActiveSupport::Notifications::Event)
base.send(:extend, ClassMethods)
base.include(ActiveSupport::Notifications::Event)
base.extend(ClassMethods)
end

# Class methods for ActionView events.
Expand Down
8 changes: 4 additions & 4 deletions lib/ddtrace/contrib/action_view/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ def patch_renderer
# Rendering events are not nested in this version, creating
# render_partial spans outside of the parent render_template span.
# We fall back to manual patching instead.
::ActionView::TemplateRenderer.send(:prepend, Instrumentation::TemplateRenderer::RailsLessThan4)
::ActionView::PartialRenderer.send(:prepend, Instrumentation::PartialRenderer::RailsLessThan4)
::ActionView::TemplateRenderer.prepend(Instrumentation::TemplateRenderer::RailsLessThan4)
::ActionView::PartialRenderer.prepend(Instrumentation::PartialRenderer::RailsLessThan4)
elsif defined?(::ActionView::Rendering) && defined?(::ActionView::Partials::PartialRenderer)
# NOTE: Rails < 3.1 compatibility: different classes are used
::ActionView::Rendering.send(:prepend, Instrumentation::TemplateRenderer::Rails30)
::ActionView::Partials::PartialRenderer.send(:prepend, Instrumentation::PartialRenderer::RailsLessThan4)
::ActionView::Rendering.prepend(Instrumentation::TemplateRenderer::Rails30)
::ActionView::Partials::PartialRenderer.prepend(Instrumentation::PartialRenderer::RailsLessThan4)
else
Datadog.logger.debug('Expected Template/Partial classes not found; template rendering disabled')
end
Expand Down
4 changes: 2 additions & 2 deletions lib/ddtrace/contrib/active_model_serializers/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ module ActiveModelSerializers
# Defines basic behaviors for an ActiveModelSerializers event.
module Event
def self.included(base)
base.send(:include, ActiveSupport::Notifications::Event)
base.send(:extend, ClassMethods)
base.include(ActiveSupport::Notifications::Event)
base.extend(ClassMethods)
end

# Class methods for ActiveModelSerializers events.
Expand Down
4 changes: 2 additions & 2 deletions lib/ddtrace/contrib/active_record/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ module ActiveRecord
# Defines basic behaviors for an ActiveRecord event.
module Event
def self.included(base)
base.send(:include, ActiveSupport::Notifications::Event)
base.send(:extend, ClassMethods)
base.include(ActiveSupport::Notifications::Event)
base.extend(ClassMethods)
end

# Class methods for ActiveRecord events.
Expand Down
14 changes: 7 additions & 7 deletions lib/ddtrace/contrib/active_support/cache/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,37 @@ def cache_store_class(meth)
end

def patch_cache_store_read
cache_store_class(:read).send(:prepend, Cache::Instrumentation::Read)
cache_store_class(:read).prepend(Cache::Instrumentation::Read)
end

def patch_cache_store_read_multi
cache_store_class(:read_multi).send(:prepend, Cache::Instrumentation::ReadMulti)
cache_store_class(:read_multi).prepend(Cache::Instrumentation::ReadMulti)
end

def patch_cache_store_fetch
cache_store_class(:fetch).send(:prepend, Cache::Instrumentation::Fetch)
cache_store_class(:fetch).prepend(Cache::Instrumentation::Fetch)
end

def patch_cache_store_fetch_multi
klass = cache_store_class(:fetch_multi)
return unless klass.public_method_defined?(:fetch_multi)

klass.send(:prepend, Cache::Instrumentation::FetchMulti)
klass.prepend(Cache::Instrumentation::FetchMulti)
end

def patch_cache_store_write
cache_store_class(:write).send(:prepend, Cache::Instrumentation::Write)
cache_store_class(:write).prepend(Cache::Instrumentation::Write)
end

def patch_cache_store_write_multi
klass = cache_store_class(:write_multi)
return unless klass.public_method_defined?(:write_multi)

klass.send(:prepend, Cache::Instrumentation::WriteMulti)
klass.prepend(Cache::Instrumentation::WriteMulti)
end

def patch_cache_store_delete
cache_store_class(:delete).send(:prepend, Cache::Instrumentation::Delete)
cache_store_class(:delete).prepend(Cache::Instrumentation::Delete)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/ddtrace/contrib/active_support/notifications/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ module Notifications
# invoke Event.subscribe! to more easily subscribe to an event.
module Event
def self.included(base)
base.send(:include, Subscriber)
base.send(:extend, ClassMethods)
base.include(Subscriber)
base.extend(ClassMethods)
base.send(:on_subscribe) { base.subscribe }
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Notifications
# Creates subscriptions that are wrapped with tracing.
module Subscriber
def self.included(base)
base.send(:extend, ClassMethods)
base.extend(ClassMethods)
end

# Class methods that are implemented in the inheriting class.
Expand Down
2 changes: 1 addition & 1 deletion lib/ddtrace/contrib/auto_instrument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Contrib
# AutoInstrumentation enables all integration
module AutoInstrument
def self.extended(base)
base.send(:extend, Patch)
base.extend(Patch)
end

# Patch adds method for invoking auto_instrumentation
Expand Down
2 changes: 1 addition & 1 deletion lib/ddtrace/contrib/concurrent_ruby/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def patch

# Propagate tracing context in Concurrent::Future
def patch_future
::Concurrent::Future.send(:include, FuturePatch)
::Concurrent::Future.include(FuturePatch)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ddtrace/contrib/configurable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Contrib
# fallback.
module Configurable
def self.included(base)
base.send(:include, InstanceMethods)
base.include(InstanceMethods)
end

# Configurable instance behavior for integrations
Expand Down
2 changes: 1 addition & 1 deletion lib/ddtrace/contrib/cucumber/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Cucumber
# Instrumentation for Cucumber
module Instrumentation
def self.included(base)
base.send(:prepend, InstanceMethods)
base.prepend(InstanceMethods)
end

# Instance methods for configuration
Expand Down
2 changes: 1 addition & 1 deletion lib/ddtrace/contrib/cucumber/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def target_version
end

def patch
::Cucumber::Runtime.send(:include, Instrumentation)
::Cucumber::Runtime.include(Instrumentation)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ddtrace/contrib/dalli/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Dalli
# Instruments every interaction with the memcached server
module Instrumentation
def self.included(base)
base.send(:prepend, InstanceMethods)
base.prepend(InstanceMethods)
end

# InstanceMethods - implementing instrumentation
Expand Down
2 changes: 1 addition & 1 deletion lib/ddtrace/contrib/dalli/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def target_version
end

def patch
::Dalli::Server.send(:include, Instrumentation)
::Dalli::Server.include(Instrumentation)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ddtrace/contrib/ethon/easy_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Ethon
# Ethon EasyPatch
module EasyPatch
def self.included(base)
base.send(:prepend, InstanceMethods)
base.prepend(InstanceMethods)
end

# InstanceMethods - implementing instrumentation
Expand Down
2 changes: 1 addition & 1 deletion lib/ddtrace/contrib/ethon/multi_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Ethon
module MultiPatch
def self.included(base)
# No need to prepend here since add method is included into Multi class
base.send(:include, InstanceMethods)
base.include(InstanceMethods)
end

# InstanceMethods - implementing instrumentation
Expand Down
4 changes: 2 additions & 2 deletions lib/ddtrace/contrib/ethon/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def patch
require 'ddtrace/contrib/ethon/easy_patch'
require 'ddtrace/contrib/ethon/multi_patch'

::Ethon::Easy.send(:include, EasyPatch)
::Ethon::Multi.send(:include, MultiPatch)
::Ethon::Easy.include(EasyPatch)
::Ethon::Multi.include(MultiPatch)
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/ddtrace/contrib/extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ module Contrib
# Adds registry, configuration access for integrations.
module Extensions
def self.extended(base)
Datadog.send(:extend, Helpers)
Datadog.send(:extend, Configuration)
Datadog::Configuration::Settings.send(:include, Configuration::Settings)
Datadog.extend(Helpers)
Datadog.extend(Configuration)
Datadog::Configuration::Settings.include(Configuration::Settings)
end

# Helper methods for Datadog module.
Expand Down
4 changes: 2 additions & 2 deletions lib/ddtrace/contrib/faraday/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def add_default_middleware!
::Faraday.default_connection.use(:ddtrace)

# Patch new connection instances (e.g. +Faraday.new+)
::Faraday::Connection.send(:prepend, Connection)
::Faraday::Connection.prepend(Connection)
else
# Patch the default connection (e.g. +Faraday.get+)
#
Expand All @@ -44,7 +44,7 @@ def add_default_middleware!
::Faraday.default_connection.builder.insert(idx, Middleware)

# Patch new connection instances (e.g. +Faraday.new+)
::Faraday::RackBuilder.send(:prepend, RackBuilder)
::Faraday::RackBuilder.prepend(RackBuilder)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/ddtrace/contrib/grape/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ module Grape
# Instrumentation for Grape::Endpoint
module Instrumentation
def self.included(base)
base.singleton_class.send(:prepend, ClassMethods)
base.send(:prepend, InstanceMethods)
base.singleton_class.prepend(ClassMethods)
base.prepend(InstanceMethods)
end

# ClassMethods - implementing instrumentation
Expand Down
2 changes: 1 addition & 1 deletion lib/ddtrace/contrib/grape/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def target_version

def patch
# Patch endpoints
::Grape::Endpoint.send(:include, Instrumentation)
::Grape::Endpoint.include(Instrumentation)

# Subscribe to ActiveSupport events
Datadog::Contrib::Grape::Endpoint.subscribe
Expand Down
2 changes: 1 addition & 1 deletion lib/ddtrace/contrib/grpc/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def patch

def prepend_interceptor
::GRPC::InterceptionContext
.send(:prepend, Datadog::Contrib::GRPC::InterceptWithDatadog)
.prepend(Datadog::Contrib::GRPC::InterceptWithDatadog)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ddtrace/contrib/http/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module HTTP
# Instrumentation for Net::HTTP
module Instrumentation
def self.included(base)
base.send(:prepend, InstanceMethods)
base.prepend(InstanceMethods)
end

# Span hook invoked after request is completed.
Expand Down
2 changes: 1 addition & 1 deletion lib/ddtrace/contrib/http/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def target_version

# patch applies our patch if needed
def patch
::Net::HTTP.send(:include, Instrumentation)
::Net::HTTP.include(Instrumentation)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ddtrace/contrib/httpclient/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Httpclient
# Instrumentation for Httpclient
module Instrumentation
def self.included(base)
base.send(:prepend, InstanceMethods)
base.prepend(InstanceMethods)
end

# Instance methods for configuration
Expand Down
2 changes: 1 addition & 1 deletion lib/ddtrace/contrib/httpclient/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def target_version
def patch
PATCH_ONLY_ONCE.run do
begin
::HTTPClient.send(:include, Instrumentation)
::HTTPClient.include(Instrumentation)
rescue StandardError => e
Datadog::Logger.error("Unable to apply httpclient integration: #{e}")
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ddtrace/contrib/httprb/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Httprb
# Instrumentation for Httprb
module Instrumentation
def self.included(base)
base.send(:prepend, InstanceMethods)
base.prepend(InstanceMethods)
end

# Instance methods for configuration
Expand Down
2 changes: 1 addition & 1 deletion lib/ddtrace/contrib/httprb/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def target_version
def patch
PATCH_ONLY_ONCE.run do
begin
::HTTP::Client.send(:include, Instrumentation)
::HTTP::Client.include(Instrumentation)
rescue StandardError => e
Datadog::Logger.error("Unable to apply httprb integration: #{e}")
end
Expand Down
6 changes: 3 additions & 3 deletions lib/ddtrace/contrib/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ module Contrib
# Base provides features that are shared across all integrations
module Integration
def self.included(base)
base.send(:include, Configurable)
base.send(:include, Patchable)
base.send(:include, Registerable)
base.include(Configurable)
base.include(Patchable)
base.include(Registerable)
end
end
end
Expand Down
Loading