Skip to content

Commit

Permalink
Add deprecation warning for Ruby 2.1 support
Browse files Browse the repository at this point in the history
This PR, modelled on #1441, adds a deprecation warning for Ruby 2.1
users of ddtrace.

Ruby 2.1 has not received security updates since the
[1st of April, 2017](https://www.ruby-lang.org/en/news/2017/04/01/support-of-ruby-2-1-has-ended/)
and we, like the core team, highly recommend upgrading to a later
version.

Support for Ruby 2.1 will be dropped in a future release, probably
`0.54.0`.

Users are welcome to continue to use `< 1.0.0` for their Ruby 2.1
deployments going forward.
  • Loading branch information
ivoanjo committed Oct 25, 2021
1 parent 72892df commit 87bf2fd
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ To contribute, check out the [contribution guidelines][contribution docs] and [d
| | | 2.4 | Full | Latest |
| | | 2.3 | Full | Latest |
| | | 2.2 | Full | Latest |
| | | 2.1 | Full | Latest |
| | | 2.1 | Deprecated | < 1.0.0 |
| | | 2.0 | EOL since June 7th, 2021 | < 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 |
Expand Down
18 changes: 18 additions & 0 deletions lib/ddtrace/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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
Expand Down Expand Up @@ -44,6 +45,8 @@ def configuration
end

def configure(target = configuration, opts = {})
ruby_version_deprecation_warning

if target.is_a?(Settings)
yield(target) if block_given?

Expand Down Expand Up @@ -191,5 +194,20 @@ def handle_interrupt_shutdown!

nil
end

RUBY_VERSION_DEPRECATION_ONLY_ONCE = Datadog::Utils::OnlyOnce.new
private_constant :RUBY_VERSION_DEPRECATION_ONLY_ONCE

def ruby_version_deprecation_warning
return unless Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2')

RUBY_VERSION_DEPRECATION_ONLY_ONCE.run do
Datadog.logger.warn(
"Support for Ruby versions < 2.2 in dd-trace-rb is DEPRECATED.\n" \
"Last version to support Ruby < 2.2 will be 0.54.x, which will only receive critical bugfixes.\n" \
'Support for Ruby versions < 2.2 will be REMOVED in version 1.0.0.'
)
end
end
end
end
1 change: 1 addition & 0 deletions lib/ddtrace/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module VERSION

STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')

# Support for Ruby < 2.2 is being phased out and will be dropped in the near future.
MINIMUM_RUBY_VERSION = '2.1.0'.freeze

# Ruby 3.2 is not supported: Ruby 3.x support as implemented using *args
Expand Down
28 changes: 28 additions & 0 deletions spec/ddtrace/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,34 @@
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 'Spec only runs on Ruby < 2.2' unless Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2') }

it 'emits deprecation warning once' do
expect(Datadog.logger).to receive(:warn)
.with(/Support for Ruby versions < 2\.2 in dd-trace-rb is DEPRECATED/).once

test_class.configure
test_class.configure
end
end

context 'with a supported Ruby version' do
before { skip 'Spec only runs on Ruby >= 2.2' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2') }

it 'emits no warnings' do
expect(Datadog.logger).to_not receive(:warn)

configure
end
end
end
end

describe '#health_metrics' do
Expand Down

0 comments on commit 87bf2fd

Please sign in to comment.