From 5fe5f915eacf6675d2bd18e972ea4f8b2cc2d047 Mon Sep 17 00:00:00 2001 From: Neel Shah Date: Mon, 3 Feb 2025 14:10:01 +0100 Subject: [PATCH] Deprecate enable_tracing in favor of traces_sample_rate --- CHANGELOG.md | 6 ++++++ sentry-rails/lib/generators/sentry_generator.rb | 2 +- sentry-rails/spec/sentry/generator_spec.rb | 4 ++-- sentry-ruby/lib/sentry/configuration.rb | 7 +++++++ sentry-ruby/spec/sentry/configuration_spec.rb | 11 +++++++++++ sentry-ruby/spec/sentry/metrics/aggregator_spec.rb | 4 ++-- sentry-ruby/spec/sentry/metrics_spec.rb | 2 +- 7 files changed, 30 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0248c94c..fb7de78f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## Unreleased + +### Miscellaneous + +- Deprecate `enable_tracing` in favor of `traces_sample_rate = 1.0` [#2535](https://github.com/getsentry/sentry-ruby/pull/2535) + ## 5.22.4 ### Bug Fixes diff --git a/sentry-rails/lib/generators/sentry_generator.rb b/sentry-rails/lib/generators/sentry_generator.rb index e293dae95..ae6be1d7c 100644 --- a/sentry-rails/lib/generators/sentry_generator.rb +++ b/sentry-rails/lib/generators/sentry_generator.rb @@ -16,7 +16,7 @@ def copy_initializer_file Sentry.init do |config| config.breadcrumbs_logger = [:active_support_logger] config.dsn = #{dsn} - config.enable_tracing = true + config.traces_sample_rate = 1.0 end RUBY end diff --git a/sentry-rails/spec/sentry/generator_spec.rb b/sentry-rails/spec/sentry/generator_spec.rb index 0e1f6856f..5f5c77b52 100644 --- a/sentry-rails/spec/sentry/generator_spec.rb +++ b/sentry-rails/spec/sentry/generator_spec.rb @@ -55,7 +55,7 @@ Sentry.init do |config| config.breadcrumbs_logger = [:active_support_logger] config.dsn = ENV['SENTRY_DSN'] - config.enable_tracing = true + config.traces_sample_rate = 1.0 end RUBY end @@ -87,7 +87,7 @@ Sentry.init do |config| config.breadcrumbs_logger = [:active_support_logger] config.dsn = 'foobarbaz' - config.enable_tracing = true + config.traces_sample_rate = 1.0 end RUBY end diff --git a/sentry-ruby/lib/sentry/configuration.rb b/sentry-ruby/lib/sentry/configuration.rb index f654db156..9ff9bde6d 100644 --- a/sentry-ruby/lib/sentry/configuration.rb +++ b/sentry-ruby/lib/sentry/configuration.rb @@ -264,6 +264,7 @@ def capture_exception_frame_locals=(value) # Easier way to use performance tracing # If set to true, will set traces_sample_rate to 1.0 + # @deprecated It will be removed in the next major release. # @return [Boolean, nil] attr_reader :enable_tracing @@ -542,6 +543,12 @@ def instrumenter=(instrumenter) end def enable_tracing=(enable_tracing) + unless enable_tracing.nil? + log_warn <<~MSG + `enable_tracing` is now deprecated in favor of `traces_sample_rate = 1.0`. + MSG + end + @enable_tracing = enable_tracing @traces_sample_rate ||= 1.0 if enable_tracing end diff --git a/sentry-ruby/spec/sentry/configuration_spec.rb b/sentry-ruby/spec/sentry/configuration_spec.rb index ab6ee86e5..03227210d 100644 --- a/sentry-ruby/spec/sentry/configuration_spec.rb +++ b/sentry-ruby/spec/sentry/configuration_spec.rb @@ -123,6 +123,17 @@ expect(subject.tracing_enabled?).to eq(false) end + + it "prints deprecation message when being assigned" do + string_io = StringIO.new + subject.logger = Logger.new(string_io) + + subject.enable_tracing = true + + expect(string_io.string).to include( + "WARN -- sentry: `enable_tracing` is now deprecated in favor of `traces_sample_rate = 1.0`." + ) + end end end diff --git a/sentry-ruby/spec/sentry/metrics/aggregator_spec.rb b/sentry-ruby/spec/sentry/metrics/aggregator_spec.rb index b54c6a0d9..7686e3fd0 100644 --- a/sentry-ruby/spec/sentry/metrics/aggregator_spec.rb +++ b/sentry-ruby/spec/sentry/metrics/aggregator_spec.rb @@ -11,7 +11,7 @@ before do perform_basic_setup do |config| config.metrics.enabled = true - config.enable_tracing = true + config.traces_sample_rate = 1.0 config.release = 'test-release' config.environment = 'test' config.logger = Logger.new(string_io) @@ -194,7 +194,7 @@ before do perform_basic_setup do |config| config.metrics.enabled = true - config.enable_tracing = true + config.traces_sample_rate = 1.0 config.release = 'test-release' config.environment = 'test' config.logger = Logger.new(string_io) diff --git a/sentry-ruby/spec/sentry/metrics_spec.rb b/sentry-ruby/spec/sentry/metrics_spec.rb index e50c55074..9ca15081f 100644 --- a/sentry-ruby/spec/sentry/metrics_spec.rb +++ b/sentry-ruby/spec/sentry/metrics_spec.rb @@ -116,7 +116,7 @@ before do perform_basic_setup do |config| - config.enable_tracing = true + config.traces_sample_rate = 1.0 config.metrics.enabled = true end