Skip to content

Commit 32ca39e

Browse files
authored
Skip creating LogEventBuffer if logging is not enabled (#2652)
* Skip creating LogEventBuffer if logging is not enabled * Update CHANGELOG
1 parent 5fdf3be commit 32ca39e

File tree

5 files changed

+12
-4
lines changed

5 files changed

+12
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Unreleased
2+
3+
- Skip creating `LogEventBuffer` if logging is not enabled ([#2652](https://github.com/getsentry/sentry-ruby/pull/2652))
4+
15
## 5.25.0
26

37
### Features

sentry-ruby/lib/sentry/client.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ def initialize(configuration)
4242

4343
@spotlight_transport = SpotlightTransport.new(configuration) if configuration.spotlight
4444

45-
@log_event_buffer = LogEventBuffer.new(configuration, self).start
45+
if configuration.enable_logs
46+
@log_event_buffer = LogEventBuffer.new(configuration, self).start
47+
end
4648
end
4749

4850
# Applies the given scope's data to the event and sends it to Sentry.
@@ -114,7 +116,7 @@ def capture_envelope(envelope)
114116
def flush
115117
transport.flush if configuration.sending_to_dsn_allowed?
116118
spotlight_transport.flush if spotlight_transport
117-
@log_event_buffer.flush
119+
@log_event_buffer&.flush
118120
end
119121

120122
# Initializes an Event object with the given exception. Returns `nil` if the exception's class is excluded from reporting.

sentry-ruby/spec/sentry/log_event_buffer_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
config.sdk_logger = logger
2020
config.background_worker_threads = 0
2121
config.max_log_events = max_log_events
22+
config.enable_logs = true
2223
end
2324

2425
Sentry.background_worker = Sentry::BackgroundWorker.new(Sentry.configuration)

sentry-ruby/spec/sentry/session_flusher_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@
103103
it "spawns new thread" do
104104
expect do
105105
subject.add_session(session)
106-
end.to change { Thread.list.count }.by(2)
106+
end.to change { Thread.list.count }.by(1)
107107

108108
expect(subject.instance_variable_get(:@thread)).to be_a(Thread)
109109
end
110110

111111
it "spawns only one thread" do
112112
expect do
113113
subject.add_session(session)
114-
end.to change { Thread.list.count }.by(2)
114+
end.to change { Thread.list.count }.by(1)
115115

116116
thread = subject.instance_variable_get(:@thread)
117117
expect(thread).to receive(:alive?).and_return(true)

sentry-ruby/spec/sentry_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@
354354
describe ".capture_log" do
355355
before do
356356
perform_basic_setup do |config|
357+
config.enable_logs = true
357358
config.traces_sample_rate = 1.0
358359
config.max_log_events = 1
359360
end

0 commit comments

Comments
 (0)