diff --git a/CHANGELOG.md b/CHANGELOG.md index d7befc7d7..933a8cc71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,9 @@ ### Internal - Remove `user_segment` from DSC ([#2586](https://github.com/getsentry/sentry-ruby/pull/2586)) +- New configuration option called `report_after_job_retries` for ActiveJob which makes reporting exceptions only happen when the last retry attempt failed ([#2500](https://github.com/getsentry/sentry-ruby/pull/2500)) +- Replace `logger` with `sdk_logger` ([#2621](https://github.com/getsentry/sentry-ruby/pull/2621)) +- `Sentry.logger` is now deprecated when `enable_logs` is turned off. It's original behavior was ported to `Sentry.configuration.sdk_logger`. Please notice that this logger *is internal* and should only be used for SDK-specific logging needs. ([#2621](https://github.com/getsentry/sentry-ruby/pull/2621)) ## 5.23.0 diff --git a/sentry-delayed_job/spec/spec_helper.rb b/sentry-delayed_job/spec/spec_helper.rb index 56281d89f..af62fa7e6 100644 --- a/sentry-delayed_job/spec/spec_helper.rb +++ b/sentry-delayed_job/spec/spec_helper.rb @@ -87,7 +87,7 @@ def build_exception def perform_basic_setup Sentry.init do |config| config.dsn = DUMMY_DSN - config.logger = ::Logger.new(nil) + config.sdk_logger = ::Logger.new(nil) config.background_worker_threads = 0 config.transport.transport_class = Sentry::DummyTransport yield(config) if block_given? diff --git a/sentry-opentelemetry/spec/spec_helper.rb b/sentry-opentelemetry/spec/spec_helper.rb index 9f0ca0917..21241a270 100644 --- a/sentry-opentelemetry/spec/spec_helper.rb +++ b/sentry-opentelemetry/spec/spec_helper.rb @@ -44,7 +44,7 @@ def perform_basic_setup Sentry.init do |config| - config.logger = Logger.new(nil) + config.sdk_logger = Logger.new(nil) config.dsn = Sentry::TestHelper::DUMMY_DSN config.transport.transport_class = Sentry::DummyTransport # so the events will be sent synchronously for testing diff --git a/sentry-rails/lib/sentry/rails/configuration.rb b/sentry-rails/lib/sentry/rails/configuration.rb index a82a11359..2669a84a6 100644 --- a/sentry-rails/lib/sentry/rails/configuration.rb +++ b/sentry-rails/lib/sentry/rails/configuration.rb @@ -17,12 +17,12 @@ class Configuration if ::Rails.logger if defined?(::ActiveSupport::BroadcastLogger) && ::Rails.logger.is_a?(::ActiveSupport::BroadcastLogger) dupped_broadcasts = ::Rails.logger.broadcasts.map(&:dup) - @logger = ::ActiveSupport::BroadcastLogger.new(*dupped_broadcasts) + self.sdk_logger = ::ActiveSupport::BroadcastLogger.new(*dupped_broadcasts) else - @logger = ::Rails.logger.dup + self.sdk_logger = ::Rails.logger.dup end else - @logger.warn(Sentry::LOGGER_PROGNAME) do + sdk_logger.warn(Sentry::LOGGER_PROGNAME) do <<~MSG sentry-rails can't detect Rails.logger. it may be caused by misplacement of the SDK initialization code please make sure you place the Sentry.init block under the `config/initializers` folder, e.g. `config/initializers/sentry.rb` diff --git a/sentry-rails/lib/sentry/rails/tracing/action_controller_subscriber.rb b/sentry-rails/lib/sentry/rails/tracing/action_controller_subscriber.rb index 42b89ce32..996332bb5 100644 --- a/sentry-rails/lib/sentry/rails/tracing/action_controller_subscriber.rb +++ b/sentry-rails/lib/sentry/rails/tracing/action_controller_subscriber.rb @@ -14,7 +14,7 @@ class ActionControllerSubscriber < AbstractSubscriber SPAN_ORIGIN = "auto.view.rails" def self.subscribe! - Sentry.logger.warn <<~MSG + Sentry.sdk_logger.warn <<~MSG DEPRECATION WARNING: sentry-rails has changed its approach on controller span recording and #{self.name} is now depreacted. Please stop using or referencing #{self.name} as it will be removed in the next major release. MSG diff --git a/sentry-rails/spec/dummy/test_rails_app/app.rb b/sentry-rails/spec/dummy/test_rails_app/app.rb index 5b1bd82a9..2a16ff695 100644 --- a/sentry-rails/spec/dummy/test_rails_app/app.rb +++ b/sentry-rails/spec/dummy/test_rails_app/app.rb @@ -55,7 +55,7 @@ def self.name app.config.action_controller.view_paths = "spec/dummy/test_rails_app" app.config.hosts = nil app.config.secret_key_base = "test" - app.config.logger = ActiveSupport::Logger.new(nil) + app.config.sdk_logger = ActiveSupport::Logger.new(nil) app.config.eager_load = false app.config.active_job.queue_adapter = :test app.config.cache_store = :memory_store diff --git a/sentry-rails/spec/isolated/active_job_activation.rb b/sentry-rails/spec/isolated/active_job_activation.rb index 82483e008..04a8f0a99 100644 --- a/sentry-rails/spec/isolated/active_job_activation.rb +++ b/sentry-rails/spec/isolated/active_job_activation.rb @@ -53,7 +53,7 @@ def perform app.config.eager_load = true app.initializer :sentry do Sentry.init do |config| - config.logger = Logger.new(nil) + config.sdk_logger = Logger.new(nil) config.dsn = 'https://2fb45f003d054a7ea47feb45898f7649@o447951.ingest.sentry.io/5434472' config.background_worker_threads = 0 end diff --git a/sentry-rails/spec/sentry/rails/tracing/action_controller_subscriber_spec.rb b/sentry-rails/spec/sentry/rails/tracing/action_controller_subscriber_spec.rb index 9d0a4df4e..59c69f849 100644 --- a/sentry-rails/spec/sentry/rails/tracing/action_controller_subscriber_spec.rb +++ b/sentry-rails/spec/sentry/rails/tracing/action_controller_subscriber_spec.rb @@ -17,7 +17,7 @@ make_basic_app do |config| config.traces_sample_rate = 1.0 config.rails.tracing_subscribers = [described_class] - config.logger = logger + config.sdk_logger = logger end end diff --git a/sentry-rails/spec/sentry/rails/tracing_spec.rb b/sentry-rails/spec/sentry/rails/tracing_spec.rb index 36063f39d..158a7f79e 100644 --- a/sentry-rails/spec/sentry/rails/tracing_spec.rb +++ b/sentry-rails/spec/sentry/rails/tracing_spec.rb @@ -182,7 +182,7 @@ make_basic_app do |config, app| app.config.public_file_server.enabled = true config.traces_sample_rate = 1.0 - config.logger = logger + config.sdk_logger = logger end end @@ -202,7 +202,7 @@ make_basic_app do |config, app| app.config.public_file_server.enabled = true config.traces_sample_rate = 1.0 - config.logger = logger + config.sdk_logger = logger config.rails.assets_regexp = %r{/foo/} end end @@ -232,7 +232,7 @@ make_basic_app do |config, app| app.config.public_file_server.enabled = true config.traces_sample_rate = 1.0 - config.logger = logger + config.sdk_logger = logger end end diff --git a/sentry-rails/spec/sentry/rails_spec.rb b/sentry-rails/spec/sentry/rails_spec.rb index 75df766f5..ffbc4ca2e 100644 --- a/sentry-rails/spec/sentry/rails_spec.rb +++ b/sentry-rails/spec/sentry/rails_spec.rb @@ -44,22 +44,22 @@ describe "logger detection" do it "sets a duplicated Rails logger as the SDK's logger" do if Gem::Version.new(Rails.version) > Gem::Version.new("7.1.0.beta") - expect(Sentry.configuration.logger).to be_a(ActiveSupport::BroadcastLogger) + expect(Sentry.configuration.sdk_logger).to be_a(ActiveSupport::BroadcastLogger) - Sentry.configuration.logger.level = ::Logger::WARN + Sentry.configuration.sdk_logger.level = ::Logger::WARN # Configuring the SDK's logger should not affect the Rails logger expect(Rails.logger.broadcasts.first).to be_a(ActiveSupport::Logger) expect(Rails.logger.broadcasts.first.level).to eq(::Logger::DEBUG) - expect(Sentry.configuration.logger.level).to eq(::Logger::WARN) + expect(Sentry.configuration.sdk_logger.level).to eq(::Logger::WARN) else - expect(Sentry.configuration.logger).to be_a(ActiveSupport::Logger) + expect(Sentry.configuration.sdk_logger).to be_a(ActiveSupport::Logger) - Sentry.configuration.logger.level = ::Logger::WARN + Sentry.configuration.sdk_logger.level = ::Logger::WARN # Configuring the SDK's logger should not affect the Rails logger expect(Rails.logger.level).to eq(::Logger::DEBUG) - expect(Sentry.configuration.logger.level).to eq(::Logger::WARN) + expect(Sentry.configuration.sdk_logger.level).to eq(::Logger::WARN) end end @@ -67,10 +67,10 @@ logger = ::Logger.new(nil) make_basic_app do |config| - config.logger = logger + config.sdk_logger = logger end - expect(Sentry.configuration.logger).to eq(logger) + expect(Sentry.configuration.sdk_logger).to eq(logger) end it "doesn't cause error if Rails::Logger is not present during SDK initialization" do @@ -78,7 +78,7 @@ Sentry.init - expect(Sentry.configuration.logger).to be_a(Sentry::Logger) + expect(Sentry.configuration.sdk_logger).to be_a(Sentry::Logger) end end diff --git a/sentry-resque/spec/spec_helper.rb b/sentry-resque/spec/spec_helper.rb index 183d829be..4d516832c 100644 --- a/sentry-resque/spec/spec_helper.rb +++ b/sentry-resque/spec/spec_helper.rb @@ -73,7 +73,7 @@ def perform_basic_setup Sentry.init do |config| config.dsn = DUMMY_DSN - config.logger = ::Logger.new(nil) + config.sdk_logger = ::Logger.new(nil) config.background_worker_threads = 0 config.transport.transport_class = Sentry::DummyTransport yield(config) if block_given? diff --git a/sentry-ruby/lib/sentry-ruby.rb b/sentry-ruby/lib/sentry-ruby.rb index f2c81ae3a..e3fff2a62 100644 --- a/sentry-ruby/lib/sentry-ruby.rb +++ b/sentry-ruby/lib/sentry-ruby.rb @@ -94,6 +94,11 @@ def exception_locals_tp # @return [Metrics::Aggregator, nil] attr_reader :metrics_aggregator + # @!attribute [r] logger + # @return [Logger] + # @!visibility private + attr_reader :sdk_logger + ##### Patch Registration ##### # @!visibility private @@ -138,7 +143,7 @@ def integrations # @param version [String] version of the integration def register_integration(name, version) if initialized? - logger.warn(LOGGER_PROGNAME) do + sdk_logger.warn(LOGGER_PROGNAME) do <<~MSG Integration '#{name}' is loaded after the SDK is initialized, which can cause unexpected behavior. Please make sure all integrations are loaded before SDK initialization. MSG @@ -238,6 +243,10 @@ def add_attachment(**opts) def init(&block) config = Configuration.new yield(config) if block_given? + + # Internal SDK logger + @sdk_logger = config.sdk_logger + config.detect_release apply_patches(config) config.validate @@ -607,6 +616,16 @@ def continue_trace(env, **options) ##### Helpers ##### + # @!visibility private + def logger + warn <<~STR + [sentry] `Sentry.logger` will no longer be used as internal SDK logger when `enable_logs` feature is turned on. + Use Sentry.configuration.sdk_logger for SDK-specific logging needs." + STR + + configuration.sdk_logger + end + # @!visibility private def sys_command(command) result = `#{command} 2>&1` rescue nil @@ -615,11 +634,6 @@ def sys_command(command) result.strip end - # @!visibility private - def logger - configuration.logger - end - # @!visibility private def sdk_meta META diff --git a/sentry-ruby/lib/sentry/background_worker.rb b/sentry-ruby/lib/sentry/background_worker.rb index ee5b94305..9841230f4 100644 --- a/sentry-ruby/lib/sentry/background_worker.rb +++ b/sentry-ruby/lib/sentry/background_worker.rb @@ -9,8 +9,7 @@ class BackgroundWorker include LoggingHelper attr_reader :max_queue, :number_of_threads - # @deprecated Use Sentry.logger to retrieve the current logger instead. - attr_reader :logger + attr_accessor :shutdown_timeout DEFAULT_MAX_QUEUE = 30 @@ -19,7 +18,7 @@ def initialize(configuration) @shutdown_timeout = 1 @number_of_threads = configuration.background_worker_threads @max_queue = configuration.background_worker_max_queue - @logger = configuration.logger + @sdk_logger = configuration.sdk_logger @debug = configuration.debug @shutdown_callback = nil diff --git a/sentry-ruby/lib/sentry/backpressure_monitor.rb b/sentry-ruby/lib/sentry/backpressure_monitor.rb index b3f5652c7..ed2581b1d 100644 --- a/sentry-ruby/lib/sentry/backpressure_monitor.rb +++ b/sentry-ruby/lib/sentry/backpressure_monitor.rb @@ -6,7 +6,7 @@ class BackpressureMonitor < ThreadedPeriodicWorker MAX_DOWNSAMPLE_FACTOR = 10 def initialize(configuration, client, interval: DEFAULT_INTERVAL) - super(configuration.logger, interval) + super(configuration.sdk_logger, interval) @client = client @healthy = true diff --git a/sentry-ruby/lib/sentry/breadcrumb.rb b/sentry-ruby/lib/sentry/breadcrumb.rb index e453345ac..69490f78a 100644 --- a/sentry-ruby/lib/sentry/breadcrumb.rb +++ b/sentry-ruby/lib/sentry/breadcrumb.rb @@ -63,7 +63,7 @@ def serialized_data begin ::JSON.parse(::JSON.generate(@data, max_nesting: MAX_NESTING)) rescue Exception => e - Sentry.logger.debug(LOGGER_PROGNAME) do + Sentry.sdk_logger.debug(LOGGER_PROGNAME) do <<~MSG can't serialize breadcrumb data because of error: #{e} data: #{@data} diff --git a/sentry-ruby/lib/sentry/client.rb b/sentry-ruby/lib/sentry/client.rb index 995727373..23d8c0e32 100644 --- a/sentry-ruby/lib/sentry/client.rb +++ b/sentry-ruby/lib/sentry/client.rb @@ -19,13 +19,10 @@ class Client # @!macro configuration attr_reader :configuration - # @deprecated Use Sentry.logger to retrieve the current logger instead. - attr_reader :logger - # @param configuration [Configuration] def initialize(configuration) @configuration = configuration - @logger = configuration.logger + @sdk_logger = configuration.sdk_logger if transport_class = configuration.transport.transport_class @transport = transport_class.new(configuration) diff --git a/sentry-ruby/lib/sentry/configuration.rb b/sentry-ruby/lib/sentry/configuration.rb index 29dd985cb..02df33604 100644 --- a/sentry-ruby/lib/sentry/configuration.rb +++ b/sentry-ruby/lib/sentry/configuration.rb @@ -184,7 +184,19 @@ def capture_exception_frame_locals=(value) # Logger used by Sentry. In Rails, this is the Rails logger, otherwise # Sentry provides its own Sentry::Logger. # @return [Logger] - attr_accessor :logger + attr_accessor :sdk_logger + + # @deprecated Use {#sdk_logger=} instead. + def logger=(logger) + warn "[sentry] `config.logger=` is deprecated. Please use `config.sdk_logger=` instead." + self.sdk_logger = logger + end + + # @deprecated Use {#sdk_logger} instead. + def logger + warn "[sentry] `config.logger` is deprecated. Please use `config.sdk_logger` instead." + self.sdk_logger + end # Project directory root for in_app detection. Could be Rails root, etc. # Set automatically for Rails. @@ -424,7 +436,7 @@ def initialize self.excluded_exceptions = IGNORE_DEFAULT + PUMA_IGNORE_DEFAULT self.inspect_exception_causes_for_exclusion = true self.linecache = ::Sentry::LineCache.new - self.logger = ::Sentry::Logger.new(STDOUT) + self.sdk_logger = ::Sentry::Logger.new(STDOUT) self.project_root = Dir.pwd self.propagate_traces = true diff --git a/sentry-ruby/lib/sentry/interfaces/request.rb b/sentry-ruby/lib/sentry/interfaces/request.rb index 4647e6562..88feded23 100644 --- a/sentry-ruby/lib/sentry/interfaces/request.rb +++ b/sentry-ruby/lib/sentry/interfaces/request.rb @@ -99,7 +99,7 @@ def filter_and_format_headers(env, send_default_pii) # Rails adds objects to the Rack env that can sometimes raise exceptions # when `to_s` is called. # See: https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/remote_ip.rb#L134 - Sentry.logger.warn(LOGGER_PROGNAME) { "Error raised while formatting headers: #{e.message}" } + Sentry.sdk_logger.warn(LOGGER_PROGNAME) { "Error raised while formatting headers: #{e.message}" } next end end diff --git a/sentry-ruby/lib/sentry/log_event_buffer.rb b/sentry-ruby/lib/sentry/log_event_buffer.rb index 652f0753a..6864a6662 100644 --- a/sentry-ruby/lib/sentry/log_event_buffer.rb +++ b/sentry-ruby/lib/sentry/log_event_buffer.rb @@ -8,7 +8,8 @@ class LogEventBuffer < ThreadedPeriodicWorker DEFAULT_MAX_EVENTS = 100 def initialize(configuration, client) - super(configuration.logger, FLUSH_INTERVAL) + super(configuration.sdk_logger, FLUSH_INTERVAL) + @client = client @pending_events = [] @max_events = configuration.max_log_events || DEFAULT_MAX_EVENTS @@ -16,7 +17,7 @@ def initialize(configuration, client) @sdk = Sentry.sdk_meta @mutex = Mutex.new - log_debug("[LogEvents] Initialized buffer with max_events=#{@max_events}, flush_interval=#{FLUSH_INTERVAL}s") + log_debug("[Logging] Initialized buffer with max_events=#{@max_events}, flush_interval=#{FLUSH_INTERVAL}s") end def start diff --git a/sentry-ruby/lib/sentry/metrics/aggregator.rb b/sentry-ruby/lib/sentry/metrics/aggregator.rb index 12ad54f69..ca7e95563 100644 --- a/sentry-ruby/lib/sentry/metrics/aggregator.rb +++ b/sentry-ruby/lib/sentry/metrics/aggregator.rb @@ -34,7 +34,7 @@ class Aggregator < ThreadedPeriodicWorker attr_reader :client, :thread, :buckets, :flush_shift, :code_locations def initialize(configuration, client) - super(configuration.logger, FLUSH_INTERVAL) + super(configuration.sdk_logger, FLUSH_INTERVAL) @client = client @before_emit = configuration.metrics.before_emit @enable_code_locations = configuration.metrics.enable_code_locations diff --git a/sentry-ruby/lib/sentry/profiler.rb b/sentry-ruby/lib/sentry/profiler.rb index b1fbaf39b..d1fd733f7 100644 --- a/sentry-ruby/lib/sentry/profiler.rb +++ b/sentry-ruby/lib/sentry/profiler.rb @@ -193,7 +193,7 @@ def to_hash private def log(message) - Sentry.logger.debug(LOGGER_PROGNAME) { "[Profiler] #{message}" } + Sentry.sdk_logger.debug(LOGGER_PROGNAME) { "[Profiler] #{message}" } end def record_lost_event(reason) diff --git a/sentry-ruby/lib/sentry/session_flusher.rb b/sentry-ruby/lib/sentry/session_flusher.rb index 8f0510832..11bd5bfdf 100644 --- a/sentry-ruby/lib/sentry/session_flusher.rb +++ b/sentry-ruby/lib/sentry/session_flusher.rb @@ -5,7 +5,7 @@ class SessionFlusher < ThreadedPeriodicWorker FLUSH_INTERVAL = 60 def initialize(configuration, client) - super(configuration.logger, FLUSH_INTERVAL) + super(configuration.sdk_logger, FLUSH_INTERVAL) @client = client @pending_aggregates = {} @release = configuration.release diff --git a/sentry-ruby/lib/sentry/threaded_periodic_worker.rb b/sentry-ruby/lib/sentry/threaded_periodic_worker.rb index 581d2b5df..aff5682d5 100644 --- a/sentry-ruby/lib/sentry/threaded_periodic_worker.rb +++ b/sentry-ruby/lib/sentry/threaded_periodic_worker.rb @@ -4,11 +4,11 @@ module Sentry class ThreadedPeriodicWorker include LoggingHelper - def initialize(logger, interval) + def initialize(sdk_logger, interval) @thread = nil @exited = false @interval = interval - @logger = logger + @sdk_logger = sdk_logger end def ensure_thread diff --git a/sentry-ruby/lib/sentry/transaction.rb b/sentry-ruby/lib/sentry/transaction.rb index 4e6411a8f..60e262cf0 100644 --- a/sentry-ruby/lib/sentry/transaction.rb +++ b/sentry-ruby/lib/sentry/transaction.rb @@ -45,9 +45,6 @@ class Transaction < Span # @deprecated Use Sentry.configuration instead. attr_reader :configuration - # @deprecated Use Sentry.logger instead. - attr_reader :logger - # The effective sample rate at which this transaction was sampled. # @return [Float, nil] attr_reader :effective_sample_rate @@ -78,7 +75,7 @@ def initialize( @tracing_enabled = hub.configuration.tracing_enabled? @traces_sampler = hub.configuration.traces_sampler @traces_sample_rate = hub.configuration.traces_sample_rate - @logger = hub.configuration.logger + @sdk_logger = hub.configuration.sdk_logger @release = hub.configuration.release @environment = hub.configuration.environment @dsn = hub.configuration.dsn diff --git a/sentry-ruby/lib/sentry/transport.rb b/sentry-ruby/lib/sentry/transport.rb index 40c313a12..2877982c2 100644 --- a/sentry-ruby/lib/sentry/transport.rb +++ b/sentry-ruby/lib/sentry/transport.rb @@ -26,11 +26,8 @@ class Transport attr_reader :rate_limits, :discarded_events, :last_client_report_sent - # @deprecated Use Sentry.logger to retrieve the current logger instead. - attr_reader :logger - def initialize(configuration) - @logger = configuration.logger + @sdk_logger = configuration.sdk_logger @transport_configuration = configuration.transport @dsn = configuration.dsn @rate_limits = {} diff --git a/sentry-ruby/lib/sentry/utils/logging_helper.rb b/sentry-ruby/lib/sentry/utils/logging_helper.rb index 34a589e8f..e7bf25c13 100644 --- a/sentry-ruby/lib/sentry/utils/logging_helper.rb +++ b/sentry-ruby/lib/sentry/utils/logging_helper.rb @@ -1,22 +1,29 @@ # frozen_string_literal: true module Sentry + # @private module LoggingHelper + # @!visibility private + attr_reader :sdk_logger + + # @!visibility private def log_error(message, exception, debug: false) message = "#{message}: #{exception.message}" message += "\n#{exception.backtrace.join("\n")}" if debug - @logger.error(LOGGER_PROGNAME) do + sdk_logger.error(LOGGER_PROGNAME) do message end end + # @!visibility private def log_debug(message) - @logger.debug(LOGGER_PROGNAME) { message } + sdk_logger.debug(LOGGER_PROGNAME) { message } end + # @!visibility private def log_warn(message) - @logger.warn(LOGGER_PROGNAME) { message } + sdk_logger.warn(LOGGER_PROGNAME) { message } end end end diff --git a/sentry-ruby/lib/sentry/vernier/profiler.rb b/sentry-ruby/lib/sentry/vernier/profiler.rb index 77f42a36a..450ed496a 100644 --- a/sentry-ruby/lib/sentry/vernier/profiler.rb +++ b/sentry-ruby/lib/sentry/vernier/profiler.rb @@ -104,7 +104,7 @@ def to_hash private def log(message) - Sentry.logger.debug(LOGGER_PROGNAME) { "[Profiler::Vernier] #{message}" } + Sentry.sdk_logger.debug(LOGGER_PROGNAME) { "[Profiler::Vernier] #{message}" } end def record_lost_event(reason) diff --git a/sentry-ruby/spec/sentry/background_worker_spec.rb b/sentry-ruby/spec/sentry/background_worker_spec.rb index 9e15b43ec..fae1b6e50 100644 --- a/sentry-ruby/spec/sentry/background_worker_spec.rb +++ b/sentry-ruby/spec/sentry/background_worker_spec.rb @@ -7,7 +7,7 @@ let(:configuration) do Sentry::Configuration.new.tap do |config| - config.logger = Logger.new(string_io) + config.sdk_logger = Logger.new(string_io) end end diff --git a/sentry-ruby/spec/sentry/backpressure_monitor_spec.rb b/sentry-ruby/spec/sentry/backpressure_monitor_spec.rb index e0147d87c..04f4ae18f 100644 --- a/sentry-ruby/spec/sentry/backpressure_monitor_spec.rb +++ b/sentry-ruby/spec/sentry/backpressure_monitor_spec.rb @@ -8,7 +8,7 @@ before do perform_basic_setup do |config| config.enable_backpressure_handling = true - config.logger = Logger.new(string_io) + config.sdk_logger = Logger.new(string_io) end end diff --git a/sentry-ruby/spec/sentry/breadcrumb/http_logger_spec.rb b/sentry-ruby/spec/sentry/breadcrumb/http_logger_spec.rb index a92c4c81a..a6a7ecbca 100644 --- a/sentry-ruby/spec/sentry/breadcrumb/http_logger_spec.rb +++ b/sentry-ruby/spec/sentry/breadcrumb/http_logger_spec.rb @@ -15,7 +15,7 @@ perform_basic_setup do |config| config.breadcrumbs_logger = [:http_logger] config.transport.transport_class = Sentry::HTTPTransport - config.logger = logger + config.sdk_logger = logger # the dsn needs to have a real host so we can make a real connection before sending a failed request config.dsn = 'http://foobarbaz@o447951.ingest.sentry.io/5434472' end diff --git a/sentry-ruby/spec/sentry/breadcrumb_spec.rb b/sentry-ruby/spec/sentry/breadcrumb_spec.rb index d5d11017c..e6df98063 100644 --- a/sentry-ruby/spec/sentry/breadcrumb_spec.rb +++ b/sentry-ruby/spec/sentry/breadcrumb_spec.rb @@ -7,7 +7,7 @@ before do perform_basic_setup do |config| - config.logger = ::Logger.new(stringio) + config.sdk_logger = ::Logger.new(stringio) end end diff --git a/sentry-ruby/spec/sentry/client/event_sending_spec.rb b/sentry-ruby/spec/sentry/client/event_sending_spec.rb index f87821ae9..b4e21edff 100644 --- a/sentry-ruby/spec/sentry/client/event_sending_spec.rb +++ b/sentry-ruby/spec/sentry/client/event_sending_spec.rb @@ -5,7 +5,7 @@ RSpec.describe Sentry::Client do let(:configuration) do Sentry::Configuration.new.tap do |config| - config.logger = Logger.new(nil) + config.sdk_logger = Logger.new(nil) config.dsn = Sentry::TestHelper::DUMMY_DSN config.transport.transport_class = Sentry::DummyTransport end @@ -102,7 +102,7 @@ let(:event) { client.event_from_message("Bad data '\x80\xF8'") } it "does not mask the exception" do - configuration.logger = logger + configuration.sdk_logger = logger client.capture_event(event, scope) @@ -269,7 +269,7 @@ it "warns if before_send returns nil" do string_io = StringIO.new logger = Logger.new(string_io, level: :debug) - configuration.logger = logger + configuration.sdk_logger = logger configuration.before_send = lambda do |_event, _hint| nil end @@ -281,7 +281,7 @@ it "warns if before_send returns non-Event objects" do string_io = StringIO.new logger = Logger.new(string_io, level: :debug) - configuration.logger = logger + configuration.sdk_logger = logger configuration.before_send = lambda do |_event, _hint| 123 end @@ -294,7 +294,7 @@ it "warns about Hash value's deprecation" do string_io = StringIO.new logger = Logger.new(string_io, level: :debug) - configuration.logger = logger + configuration.sdk_logger = logger configuration.before_send = lambda do |_event, _hint| { foo: "bar" } end @@ -349,7 +349,7 @@ it "warns if before_send_transaction returns nil" do string_io = StringIO.new logger = Logger.new(string_io, level: :debug) - configuration.logger = logger + configuration.sdk_logger = logger configuration.before_send_transaction = lambda do |_event, _hint| nil end @@ -362,7 +362,7 @@ it "warns about Hash value's deprecation" do string_io = StringIO.new logger = Logger.new(string_io, level: :debug) - configuration.logger = logger + configuration.sdk_logger = logger configuration.before_send_transaction = lambda do |_event, _hint| { foo: "bar" } end @@ -390,7 +390,7 @@ let(:configuration) do Sentry::Configuration.new.tap do |config| config.dsn = Sentry::TestHelper::DUMMY_DSN - config.logger = logger + config.sdk_logger = logger end end diff --git a/sentry-ruby/spec/sentry/client_spec.rb b/sentry-ruby/spec/sentry/client_spec.rb index 51e493023..e165f72b9 100644 --- a/sentry-ruby/spec/sentry/client_spec.rb +++ b/sentry-ruby/spec/sentry/client_spec.rb @@ -141,7 +141,7 @@ def sentry_context before do configuration.debug = true - configuration.logger = ::Logger.new(string_io) + configuration.sdk_logger = ::Logger.new(string_io) allow(subject.transport).to receive(:send_envelope).and_raise(Sentry::ExternalError.new("networking error")) end @@ -739,7 +739,7 @@ module ExcTag; end end before do - configuration.logger = logger + configuration.sdk_logger = logger end let(:span) { Sentry::Span.new(transaction: transaction) } @@ -763,7 +763,7 @@ module ExcTag; end end describe "#generate_baggage" do - before { configuration.logger = logger } + before { configuration.sdk_logger = logger } let(:string_io) { StringIO.new } let(:logger) { ::Logger.new(string_io) } diff --git a/sentry-ruby/spec/sentry/configuration_spec.rb b/sentry-ruby/spec/sentry/configuration_spec.rb index 03227210d..4a126daee 100644 --- a/sentry-ruby/spec/sentry/configuration_spec.rb +++ b/sentry-ruby/spec/sentry/configuration_spec.rb @@ -726,7 +726,7 @@ class SentryConfigurationSample < Sentry::Configuration expect { Sentry.init do |config| - config.logger = Logger.new($stdout) + config.sdk_logger = Logger.new($stdout) config.profiles_sample_rate = 1.0 end }.to output(/Please add the 'stackprof' gem to your Gemfile/).to_stdout @@ -737,7 +737,7 @@ class SentryConfigurationSample < Sentry::Configuration expect { Sentry.init do |config| - config.logger = Logger.new($stdout) + config.sdk_logger = Logger.new($stdout) config.profiles_sample_rate = nil end }.to_not output(/Please add the 'stackprof' gem to your Gemfile/).to_stdout @@ -748,7 +748,7 @@ class SentryConfigurationSample < Sentry::Configuration expect { Sentry.init do |config| - config.logger = Logger.new($stdout) + config.sdk_logger = Logger.new($stdout) config.profiler_class = Sentry::Vernier::Profiler config.profiles_sample_rate = 1.0 end @@ -760,10 +760,26 @@ class SentryConfigurationSample < Sentry::Configuration expect { Sentry.init do |config| - config.logger = Logger.new($stdout) + config.sdk_logger = Logger.new($stdout) config.profiles_sample_rate = nil end }.to_not output(/Please add the 'vernier' gem to your Gemfile/).to_stdout end end + + describe "#logger" do + it "returns configured sdk_logger and prints deprecation warning" do + expect { + expect(subject.logger).to be(subject.sdk_logger) + }.to output(/`config.logger` is deprecated/).to_stderr + end + end + + describe "#logger=" do + it "sets sdk_logger and prints deprecation warning" do + expect { + subject.logger = Logger.new($stdout) + }.to output(/`config.logger=` is deprecated/).to_stderr + end + end end diff --git a/sentry-ruby/spec/sentry/excon_spec.rb b/sentry-ruby/spec/sentry/excon_spec.rb index 44abbe03d..96b4e0a12 100644 --- a/sentry-ruby/spec/sentry/excon_spec.rb +++ b/sentry-ruby/spec/sentry/excon_spec.rb @@ -50,7 +50,7 @@ before do perform_basic_setup do |config| config.traces_sample_rate = 1.0 - config.logger = logger + config.sdk_logger = logger # the dsn needs to have a real host so we can make a real connection before sending a failed request config.dsn = "http://foobarbaz@o447951.ingest.sentry.io/5434472" config.enabled_patches += [:excon] unless config.enabled_patches.include?(:excon) diff --git a/sentry-ruby/spec/sentry/faraday_spec.rb b/sentry-ruby/spec/sentry/faraday_spec.rb index 45a0c5db6..48f129486 100644 --- a/sentry-ruby/spec/sentry/faraday_spec.rb +++ b/sentry-ruby/spec/sentry/faraday_spec.rb @@ -9,7 +9,7 @@ perform_basic_setup do |config| config.enabled_patches << :faraday config.traces_sample_rate = 1.0 - config.logger = ::Logger.new(StringIO.new) + config.sdk_logger = ::Logger.new(StringIO.new) end end diff --git a/sentry-ruby/spec/sentry/graphql_spec.rb b/sentry-ruby/spec/sentry/graphql_spec.rb index a90dfe6b0..4ea948f88 100644 --- a/sentry-ruby/spec/sentry/graphql_spec.rb +++ b/sentry-ruby/spec/sentry/graphql_spec.rb @@ -69,7 +69,7 @@ class MySchema < GraphQL::Schema perform_basic_setup do |config| config.enabled_patches << :graphql - config.logger = Logger.new(string_io) + config.sdk_logger = Logger.new(string_io) end expect(string_io.string).to include('WARN -- sentry: You tried to enable the GraphQL integration but no GraphQL gem was detected. Make sure you have the `graphql` gem (>= 2.2.6) in your Gemfile.') diff --git a/sentry-ruby/spec/sentry/hub_spec.rb b/sentry-ruby/spec/sentry/hub_spec.rb index 735bc6acd..6bf8f6111 100644 --- a/sentry-ruby/spec/sentry/hub_spec.rb +++ b/sentry-ruby/spec/sentry/hub_spec.rb @@ -12,7 +12,7 @@ config.dsn = Sentry::TestHelper::DUMMY_DSN config.transport.transport_class = Sentry::DummyTransport config.background_worker_threads = 0 - config.logger = logger + config.sdk_logger = logger config end let(:client) { Sentry::Client.new(configuration) } diff --git a/sentry-ruby/spec/sentry/integrable_spec.rb b/sentry-ruby/spec/sentry/integrable_spec.rb index 6e7a03a07..891a07403 100644 --- a/sentry-ruby/spec/sentry/integrable_spec.rb +++ b/sentry-ruby/spec/sentry/integrable_spec.rb @@ -28,7 +28,7 @@ module AnotherIntegration; end before do perform_basic_setup do |config| - config.logger = logger + config.sdk_logger = logger end end diff --git a/sentry-ruby/spec/sentry/log_event_buffer_spec.rb b/sentry-ruby/spec/sentry/log_event_buffer_spec.rb index dcfeba2e6..dacf02899 100644 --- a/sentry-ruby/spec/sentry/log_event_buffer_spec.rb +++ b/sentry-ruby/spec/sentry/log_event_buffer_spec.rb @@ -10,7 +10,7 @@ before do perform_basic_setup do |config| - config.logger = logger + config.sdk_logger = logger config.background_worker_threads = 0 config.max_log_events = 3 end diff --git a/sentry-ruby/spec/sentry/metrics/aggregator_spec.rb b/sentry-ruby/spec/sentry/metrics/aggregator_spec.rb index 7686e3fd0..63d2829df 100644 --- a/sentry-ruby/spec/sentry/metrics/aggregator_spec.rb +++ b/sentry-ruby/spec/sentry/metrics/aggregator_spec.rb @@ -14,7 +14,7 @@ config.traces_sample_rate = 1.0 config.release = 'test-release' config.environment = 'test' - config.logger = Logger.new(string_io) + config.sdk_logger = Logger.new(string_io) end end @@ -197,7 +197,7 @@ config.traces_sample_rate = 1.0 config.release = 'test-release' config.environment = 'test' - config.logger = Logger.new(string_io) + config.sdk_logger = Logger.new(string_io) config.metrics.before_emit = lambda do |key, tags| return nil if key == 'foo' diff --git a/sentry-ruby/spec/sentry/net/http_spec.rb b/sentry-ruby/spec/sentry/net/http_spec.rb index 3e50f9cbe..ebbcc21c4 100644 --- a/sentry-ruby/spec/sentry/net/http_spec.rb +++ b/sentry-ruby/spec/sentry/net/http_spec.rb @@ -16,7 +16,7 @@ perform_basic_setup do |config| config.traces_sample_rate = 1.0 config.transport.transport_class = Sentry::HTTPTransport - config.logger = logger + config.sdk_logger = logger # the dsn needs to have a real host so we can make a real connection before sending a failed request config.dsn = 'http://foobarbaz@o447951.ingest.sentry.io/5434472' end diff --git a/sentry-ruby/spec/sentry/session_flusher_spec.rb b/sentry-ruby/spec/sentry/session_flusher_spec.rb index 14f927ec0..d90dfdebf 100644 --- a/sentry-ruby/spec/sentry/session_flusher_spec.rb +++ b/sentry-ruby/spec/sentry/session_flusher_spec.rb @@ -12,7 +12,7 @@ config.environment = 'test' config.transport.transport_class = Sentry::DummyTransport config.background_worker_threads = 0 - config.logger = Logger.new(string_io) + config.sdk_logger = Logger.new(string_io) end end diff --git a/sentry-ruby/spec/sentry/transaction_spec.rb b/sentry-ruby/spec/sentry/transaction_spec.rb index 7cc83aa64..fd640aa15 100644 --- a/sentry-ruby/spec/sentry/transaction_spec.rb +++ b/sentry-ruby/spec/sentry/transaction_spec.rb @@ -206,7 +206,7 @@ before do perform_basic_setup do |config| - config.logger = logger + config.sdk_logger = logger end end @@ -327,7 +327,7 @@ end it "uses the genereted rate for sampling (positive)" do - expect(Sentry.configuration.logger).to receive(:debug).exactly(3).and_call_original + expect(Sentry.configuration.sdk_logger).to receive(:debug).exactly(3).and_call_original Sentry.configuration.traces_sampler = ->(_) { true } subject = described_class.new(hub: Sentry.get_current_hub) @@ -353,7 +353,7 @@ end it "uses the genereted rate for sampling (negative)" do - expect(Sentry.configuration.logger).to receive(:debug).exactly(2).and_call_original + expect(Sentry.configuration.sdk_logger).to receive(:debug).exactly(2).and_call_original Sentry.configuration.traces_sampler = ->(_) { false } subject = described_class.new(hub: Sentry.get_current_hub) diff --git a/sentry-ruby/spec/sentry/transport/http_transport_rate_limiting_spec.rb b/sentry-ruby/spec/sentry/transport/http_transport_rate_limiting_spec.rb index aff057345..64ac79ef1 100644 --- a/sentry-ruby/spec/sentry/transport/http_transport_rate_limiting_spec.rb +++ b/sentry-ruby/spec/sentry/transport/http_transport_rate_limiting_spec.rb @@ -8,7 +8,7 @@ before do perform_basic_setup do |config| - config.logger = Logger.new(string_io) + config.sdk_logger = Logger.new(string_io) end end diff --git a/sentry-ruby/spec/sentry/transport/http_transport_spec.rb b/sentry-ruby/spec/sentry/transport/http_transport_spec.rb index bfbfd1063..1606a562e 100644 --- a/sentry-ruby/spec/sentry/transport/http_transport_spec.rb +++ b/sentry-ruby/spec/sentry/transport/http_transport_spec.rb @@ -9,7 +9,7 @@ let(:configuration) do Sentry::Configuration.new.tap do |config| config.dsn = Sentry::TestHelper::DUMMY_DSN - config.logger = Logger.new(nil) + config.sdk_logger = Logger.new(nil) end end let(:client) { Sentry::Client.new(configuration) } @@ -24,7 +24,7 @@ it "logs a debug message only during initialization" do sentry_stub_request(build_fake_response("200")) string_io = StringIO.new - configuration.logger = Logger.new(string_io) + configuration.sdk_logger = Logger.new(string_io) subject @@ -55,7 +55,7 @@ let(:configuration) do Sentry::Configuration.new.tap do |config| config.dsn = dsn - config.logger = Logger.new(nil) + config.sdk_logger = Logger.new(nil) end end diff --git a/sentry-ruby/spec/sentry/transport/spotlight_transport_spec.rb b/sentry-ruby/spec/sentry/transport/spotlight_transport_spec.rb index fc095efeb..1a1beb761 100644 --- a/sentry-ruby/spec/sentry/transport/spotlight_transport_spec.rb +++ b/sentry-ruby/spec/sentry/transport/spotlight_transport_spec.rb @@ -6,14 +6,14 @@ let(:configuration) do Sentry::Configuration.new.tap do |config| config.spotlight = true - config.logger = Logger.new(nil) + config.sdk_logger = Logger.new(nil) end end let(:custom_configuration) do Sentry::Configuration.new.tap do |config| config.spotlight = 'http://foobar@test.com' - config.logger = Logger.new(nil) + config.sdk_logger = Logger.new(nil) end end @@ -27,7 +27,7 @@ it 'logs a debug message during initialization' do string_io = StringIO.new - configuration.logger = Logger.new(string_io) + configuration.sdk_logger = Logger.new(string_io) subject @@ -60,8 +60,8 @@ describe '#send_data' do it 'fails a maximum of three times and logs disable once' do string_io = StringIO.new - configuration.logger = Logger.new(string_io) - configuration.logger.level = :debug + configuration.sdk_logger = Logger.new(string_io) + configuration.sdk_logger.level = :debug allow(::Net::HTTP).to receive(:new).and_raise(Errno::ECONNREFUSED) diff --git a/sentry-ruby/spec/sentry/transport_spec.rb b/sentry-ruby/spec/sentry/transport_spec.rb index 5ffc0e24c..558963f3c 100644 --- a/sentry-ruby/spec/sentry/transport_spec.rb +++ b/sentry-ruby/spec/sentry/transport_spec.rb @@ -8,7 +8,7 @@ let(:configuration) do Sentry::Configuration.new.tap do |config| config.server = 'http://12345:67890@sentry.localdomain/sentry/42' - config.logger = logger + config.sdk_logger = logger end end diff --git a/sentry-ruby/spec/sentry_spec.rb b/sentry-ruby/spec/sentry_spec.rb index f8f768c2d..bd97cdc6c 100644 --- a/sentry-ruby/spec/sentry_spec.rb +++ b/sentry-ruby/spec/sentry_spec.rb @@ -141,7 +141,7 @@ let(:string_io) { StringIO.new } before do perform_basic_setup do |config| - config.logger = Logger.new(string_io) + config.sdk_logger = Logger.new(string_io) config.transport.transport_class = Sentry::HTTPTransport end @@ -576,7 +576,7 @@ ::Logger.new(string_io) end before do - Sentry.configuration.logger = logger + Sentry.configuration.sdk_logger = logger Sentry.configuration.enabled_environments = ["production"] end @@ -1104,7 +1104,7 @@ logger = Logger.new(string_io) described_class.init do |config| - config.logger = logger + config.sdk_logger = logger end expect(described_class.configuration.release).to eq(nil) @@ -1130,7 +1130,7 @@ allow(Sentry::ReleaseDetector).to receive(:detect_release_from_git).and_raise(TypeError.new) described_class.init do |config| - config.logger = logger + config.sdk_logger = logger end expect(string_io.string).to include("ERROR -- sentry: Error detecting release: TypeError") diff --git a/sentry-ruby/spec/spec_helper.rb b/sentry-ruby/spec/spec_helper.rb index 6fd9ee565..3dc57f956 100644 --- a/sentry-ruby/spec/spec_helper.rb +++ b/sentry-ruby/spec/spec_helper.rb @@ -156,7 +156,7 @@ def build_exception_with_recursive_cause def perform_basic_setup Sentry.init do |config| - config.logger = Logger.new(nil) + config.sdk_logger = Logger.new(nil) config.dsn = Sentry::TestHelper::DUMMY_DSN config.transport.transport_class = Sentry::DummyTransport # so the events will be sent synchronously for testing diff --git a/sentry-ruby/spec/support/Rakefile.rb b/sentry-ruby/spec/support/Rakefile.rb index 77b245297..b57c45793 100644 --- a/sentry-ruby/spec/support/Rakefile.rb +++ b/sentry-ruby/spec/support/Rakefile.rb @@ -6,7 +6,7 @@ Sentry.init do |config| config.dsn = 'http://12345:67890@sentry.localdomain/sentry/42' config.background_worker_threads = 0 - config.logger.level = Logger::DEBUG + config.sdk_logger.level = Logger::DEBUG end task :raise_exception do diff --git a/sentry-sidekiq/spec/spec_helper.rb b/sentry-sidekiq/spec/spec_helper.rb index 5a8877f5a..6aaf3c765 100644 --- a/sentry-sidekiq/spec/spec_helper.rb +++ b/sentry-sidekiq/spec/spec_helper.rb @@ -341,7 +341,7 @@ def process_work(processor, work) def perform_basic_setup Sentry.init do |config| config.dsn = DUMMY_DSN - config.logger = ::Logger.new(nil) + config.sdk_logger = ::Logger.new(nil) config.background_worker_threads = 0 config.transport.transport_class = Sentry::DummyTransport yield config if block_given?