From 33523d6ba4f646bf9dbdcd12d5971c7bd65db89d Mon Sep 17 00:00:00 2001 From: Peter Solnica Date: Mon, 16 Jun 2025 10:24:34 +0000 Subject: [PATCH 1/2] Skip creating LogEventBuffer if logging is not enabled --- sentry-ruby/lib/sentry/client.rb | 6 ++++-- sentry-ruby/spec/sentry/log_event_buffer_spec.rb | 1 + sentry-ruby/spec/sentry/session_flusher_spec.rb | 4 ++-- sentry-ruby/spec/sentry_spec.rb | 1 + 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/sentry-ruby/lib/sentry/client.rb b/sentry-ruby/lib/sentry/client.rb index 27dff3f92..cf8bb8c7d 100644 --- a/sentry-ruby/lib/sentry/client.rb +++ b/sentry-ruby/lib/sentry/client.rb @@ -42,7 +42,9 @@ def initialize(configuration) @spotlight_transport = SpotlightTransport.new(configuration) if configuration.spotlight - @log_event_buffer = LogEventBuffer.new(configuration, self).start + if configuration.enable_logs + @log_event_buffer = LogEventBuffer.new(configuration, self).start + end end # Applies the given scope's data to the event and sends it to Sentry. @@ -114,7 +116,7 @@ def capture_envelope(envelope) def flush transport.flush if configuration.sending_to_dsn_allowed? spotlight_transport.flush if spotlight_transport - @log_event_buffer.flush + @log_event_buffer&.flush end # Initializes an Event object with the given exception. Returns `nil` if the exception's class is excluded from reporting. diff --git a/sentry-ruby/spec/sentry/log_event_buffer_spec.rb b/sentry-ruby/spec/sentry/log_event_buffer_spec.rb index 3733e4b79..d1db43f5a 100644 --- a/sentry-ruby/spec/sentry/log_event_buffer_spec.rb +++ b/sentry-ruby/spec/sentry/log_event_buffer_spec.rb @@ -19,6 +19,7 @@ config.sdk_logger = logger config.background_worker_threads = 0 config.max_log_events = max_log_events + config.enable_logs = true end Sentry.background_worker = Sentry::BackgroundWorker.new(Sentry.configuration) diff --git a/sentry-ruby/spec/sentry/session_flusher_spec.rb b/sentry-ruby/spec/sentry/session_flusher_spec.rb index e0cf1cc2c..de91ea1bd 100644 --- a/sentry-ruby/spec/sentry/session_flusher_spec.rb +++ b/sentry-ruby/spec/sentry/session_flusher_spec.rb @@ -103,7 +103,7 @@ it "spawns new thread" do expect do subject.add_session(session) - end.to change { Thread.list.count }.by(2) + end.to change { Thread.list.count }.by(1) expect(subject.instance_variable_get(:@thread)).to be_a(Thread) end @@ -111,7 +111,7 @@ it "spawns only one thread" do expect do subject.add_session(session) - end.to change { Thread.list.count }.by(2) + end.to change { Thread.list.count }.by(1) thread = subject.instance_variable_get(:@thread) expect(thread).to receive(:alive?).and_return(true) diff --git a/sentry-ruby/spec/sentry_spec.rb b/sentry-ruby/spec/sentry_spec.rb index f413b19d0..f5b1f4aea 100644 --- a/sentry-ruby/spec/sentry_spec.rb +++ b/sentry-ruby/spec/sentry_spec.rb @@ -354,6 +354,7 @@ describe ".capture_log" do before do perform_basic_setup do |config| + config.enable_logs = true config.traces_sample_rate = 1.0 config.max_log_events = 1 end From f09ec3d3a7469b8d1e0de50c835e888861cd038f Mon Sep 17 00:00:00 2001 From: Peter Solnica Date: Tue, 17 Jun 2025 08:49:14 +0000 Subject: [PATCH 2/2] Update CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 139c2be07..3637dfc1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Unreleased + +- Skip creating `LogEventBuffer` if logging is not enabled ([#2652](https://github.com/getsentry/sentry-ruby/pull/2652)) + ## 5.25.0 ### Features