From 6bcc8986337ab201bfc460a35bfa749ca45825a5 Mon Sep 17 00:00:00 2001 From: Marco Costa Date: Wed, 31 Mar 2021 12:04:13 -0700 Subject: [PATCH] Add deprecation warning for Ruby 2.0 support --- docs/GettingStarted.md | 2 +- lib/ddtrace/configuration.rb | 24 +++++++++++++++++++++++- lib/ddtrace/version.rb | 2 ++ spec/ddtrace/configuration_spec.rb | 27 +++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 802df1609d0..630b870ecfa 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -98,7 +98,7 @@ To contribute, check out the [contribution guidelines][contribution docs] and [d | | | 2.3 | Full | Latest | | | | 2.2 | Full | Latest | | | | 2.1 | Full | Latest | -| | | 2.0 | Full | Latest | +| | | 2.0 | Deprecated | < 0.50.0 | | | | 1.9.3 | EOL since August 6th, 2020 | < 0.27.0 | | | | 1.9.1 | EOL since August 6th, 2020 | < 0.27.0 | | JRuby | https://www.jruby.org | 9.2 | Full | Latest | diff --git a/lib/ddtrace/configuration.rb b/lib/ddtrace/configuration.rb index 81387a150ce..09e90c82c4e 100644 --- a/lib/ddtrace/configuration.rb +++ b/lib/ddtrace/configuration.rb @@ -2,10 +2,11 @@ require 'ddtrace/configuration/pin_setup' require 'ddtrace/configuration/settings' require 'ddtrace/configuration/components' +require 'ddtrace/utils/only_once' module Datadog # Configuration provides a unique access point for configurations - module Configuration + module Configuration # rubocop:disable Metrics/ModuleLength extend Forwardable # Used to ensure that @components initialization/reconfiguration is performed one-at-a-time, by a single thread. @@ -42,6 +43,8 @@ def configuration end def configure(target = configuration, opts = {}) + ruby_version_deprecation_warning + if target.is_a?(Settings) yield(target) if block_given? @@ -168,5 +171,24 @@ def logger_without_components logger end end + + # Perform version check only once + DEPRECATED_RUBY_VERSION = Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.1') + private_constant :DEPRECATED_RUBY_VERSION + + RUBY_VERSION_DEPRECATION_ONLY_ONCE = Datadog::Utils::OnlyOnce.new + private_constant :RUBY_VERSION_DEPRECATION_ONLY_ONCE + + def ruby_version_deprecation_warning + return unless DEPRECATED_RUBY_VERSION + + RUBY_VERSION_DEPRECATION_ONLY_ONCE.run do + Datadog.logger.warn( + "Support for Ruby versions < 2.1 in dd-trace-rb is DEPRECATED.\n" \ + "Last version to support Ruby < 2.1 will be 0.49.x, which will only receive critical bugfixes.\n" \ + 'Support for Ruby versions < 2.1 will be REMOVED in version 0.50.0.' + ) + end + end end end diff --git a/lib/ddtrace/version.rb b/lib/ddtrace/version.rb index e21b34126d2..ff8e2f3dc65 100644 --- a/lib/ddtrace/version.rb +++ b/lib/ddtrace/version.rb @@ -7,6 +7,8 @@ module VERSION STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.') + # Support for Ruby < 2.1 is currently deprecated in the tracer. + # Support will be dropped in the near future. MINIMUM_RUBY_VERSION = '2.0.0'.freeze end end diff --git a/spec/ddtrace/configuration_spec.rb b/spec/ddtrace/configuration_spec.rb index a8b32bdf698..6706cbfac9e 100644 --- a/spec/ddtrace/configuration_spec.rb +++ b/spec/ddtrace/configuration_spec.rb @@ -348,6 +348,33 @@ end end end + + context 'deprecation warning' do + before { described_class.const_get('RUBY_VERSION_DEPRECATION_ONLY_ONCE').send(:reset_ran_once_state_for_tests) } + after { described_class.const_get('RUBY_VERSION_DEPRECATION_ONLY_ONCE').send(:reset_ran_once_state_for_tests) } + + context 'with a deprecated Ruby version' do + before { skip unless Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.1') } + + it 'emits deprecation warning once' do + expect(Datadog.logger).to receive(:warn) + .with(/Support for Ruby versions < 2\.1 in dd-trace-rb is DEPRECATED/).once + + test_class.configure + test_class.configure + end + end + + context 'with a supported Ruby version' do + before { skip if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.1') } + + it 'emits no warnings' do + expect(Datadog.logger).to_not receive(:warn) + + configure + end + end + end end describe '#health_metrics' do