Skip to content

Commit

Permalink
Add deprecation warning for Ruby 2.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
marcotc committed Mar 31, 2021
1 parent dfddf9b commit eb37c67
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
24 changes: 23 additions & 1 deletion lib/ddtrace/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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?

Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions lib/ddtrace/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 24 additions & 0 deletions spec/ddtrace/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,30 @@
end
end
end

context 'deprecation warning' do
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
Expand Down

0 comments on commit eb37c67

Please sign in to comment.