lib/ddtrace/patcher.rb in ddtrace-0.46.0 vs lib/ddtrace/patcher.rb in ddtrace-0.47.0

- old
+ new

@@ -1,9 +1,23 @@ +require 'ddtrace/utils/only_once' + module Datadog - # Defines some useful patching methods for integrations + # Deprecated: This module should no longer be included. It's only being kept around for backwards compatibility + # concerns regarding customer usage. module Patcher + INCLUDED_WARN_ONLY_ONCE = Datadog::Utils::OnlyOnce.new + DO_ONCE_USAGE_WARN_ONLY_ONCE = Datadog::Utils::OnlyOnce.new + def self.included(base) + INCLUDED_WARN_ONLY_ONCE.run do + Datadog.logger.warn( + 'Including Datadog::Patcher is deprecated. ' \ + 'For the #do_once behavior, use Datadog::Utils::OnlyOnce instead. ' \ + 'For the #without_warnings behavior, use Datadog::Patcher.without_warnings { ... } as a module function.' + ) + end + base.send(:extend, CommonMethods) base.send(:include, CommonMethods) end # Defines some common methods for patching, that can be used @@ -20,10 +34,14 @@ $VERBOSE = v end end def do_once(key = nil, options = {}) + DO_ONCE_USAGE_WARN_ONLY_ONCE.run do + Datadog.logger.warn('Datadog::Patcher#do_once is deprecated. Use Datadog::Utils::OnlyOnce instead.') + end + # If already done, don't do again @done_once ||= Hash.new { |h, k| h[k] = {} } return @done_once[key][options[:for]] if @done_once.key?(key) && @done_once[key].key?(options[:for]) # Otherwise 'do' @@ -32,9 +50,13 @@ @done_once[key][options[:for]] = true end end def done?(key, options = {}) + DO_ONCE_USAGE_WARN_ONLY_ONCE.run do + Datadog.logger.warn('Datadog::Patcher#done? is deprecated. Use Datadog::Utils::OnlyOnce instead.') + end + return false unless instance_variable_defined?(:@done_once) !@done_once.nil? && @done_once.key?(key) && @done_once[key].key?(options[:for]) end end