Module: Datadog::DeprecatedPin

Overview

Modification to Pin which logs deprecation warnings if accessed. Will be used by integrations which are phasing out the direct use of #datadog_pin.

Constant Summary collapse

DEPRECATION_WARNING =
%(
Use of Datadog::Pin is DEPRECATED.
Upgrade to the configuration API using the migration guide here:
https://github.com/DataDog/dd-trace-rb/releases/tag/v0.11.0).freeze

Instance Method Summary collapse

Methods included from Patcher

included

Methods included from Patcher::CommonMethods

#do_once, #done?, #without_warnings

Instance Method Details

#log_deprecation_warning(method_name) ⇒ Object



107
108
109
110
111
112
# File 'lib/ddtrace/pin.rb', line 107

def log_deprecation_warning(method_name)
  # Only log each deprecation warning once (safeguard against log spam)
  do_once(method_name) do
    Datadog::Tracer.log.warn("#{method_name}:#{DEPRECATION_WARNING}")
  end
end

#onto(obj) ⇒ Object

Raise a deprecation warning when #datadog_pin or #datadog_pin= is accessed.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/ddtrace/pin.rb', line 82

def onto(obj)
  obj.instance_exec(self) do |pin|
    @datadog_deprecated_pin = pin

    unless respond_to? :datadog_pin=
      def datadog_pin=(pin)
        @datadog_deprecated_pin.log_deprecation_warning('#datadog_pin=')
        @datadog_pin = pin
      end
    end

    unless respond_to? :datadog_pin
      def datadog_pin
        @datadog_deprecated_pin.log_deprecation_warning('#datadog_pin')
        @datadog_pin
      end
    end

    # Set instance variable to avoid deprecation warnings
    @datadog_pin = @datadog_deprecated_pin
  end

  self
end