Skip to content

Commit 42d4ce3

Browse files
committed
Make sure sending_allowed? is respected irrespective of spotlight configuration
1 parent 213e2ab commit 42d4ce3

File tree

5 files changed

+43
-18
lines changed

5 files changed

+43
-18
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@
7979
- Only instantiate SessionFlusher when the SDK is enabled under the current env [#2245](https://github.com/getsentry/sentry-ruby/pull/2245)
8080
- Fixes [#2234](https://github.com/getsentry/sentry-ruby/issues/2234)
8181
- Update backtrace parsing regexp to support Ruby 3.4 ([#2252](https://github.com/getsentry/sentry-ruby/pull/2252))
82+
- Make sure ``sending_allowed?`` is respected irrespective of spotlight configuration ([#2231](https://github.com/getsentry/sentry-ruby/pull/2231))
83+
- Fixes [#2226](https://github.com/getsentry/sentry-ruby/issues/2226)
8284

8385
## 5.16.1
8486

sentry-ruby/lib/sentry/client.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def initialize(configuration)
4646
# @param hint [Hash] the hint data that'll be passed to `before_send` callback and the scope's event processors.
4747
# @return [Event, nil]
4848
def capture_event(event, scope, hint = {})
49-
return unless configuration.sending_allowed?
49+
return unless configuration.event_building_allowed?
5050

5151
if event.is_a?(ErrorEvent) && !configuration.sample_allowed?
5252
transport.record_lost_event(:sample_rate, 'event')
@@ -82,7 +82,7 @@ def capture_event(event, scope, hint = {})
8282
# @param hint [Hash] the hint data that'll be passed to `before_send` callback and the scope's event processors.
8383
# @return [Event, nil]
8484
def event_from_exception(exception, hint = {})
85-
return unless @configuration.sending_allowed?
85+
return unless @configuration.event_building_allowed?
8686

8787
ignore_exclusions = hint.delete(:ignore_exclusions) { false }
8888
return if !ignore_exclusions && !@configuration.exception_class_allowed?(exception)
@@ -101,7 +101,7 @@ def event_from_exception(exception, hint = {})
101101
# @param hint [Hash] the hint data that'll be passed to `before_send` callback and the scope's event processors.
102102
# @return [Event]
103103
def event_from_message(message, hint = {}, backtrace: nil)
104-
return unless @configuration.sending_allowed?
104+
return unless @configuration.event_building_allowed?
105105

106106
integration_meta = Sentry.integrations[hint[:integration]]
107107
event = ErrorEvent.new(configuration: configuration, integration_meta: integration_meta, message: message)
@@ -128,7 +128,7 @@ def event_from_check_in(
128128
monitor_config: nil,
129129
check_in_id: nil
130130
)
131-
return unless configuration.sending_allowed?
131+
return unless configuration.event_building_allowed?
132132

133133
CheckInEvent.new(
134134
configuration: configuration,
@@ -172,8 +172,8 @@ def send_event(event, hint = nil)
172172
end
173173
end
174174

175-
transport.send_event(event)
176-
spotlight_transport&.send_event(event)
175+
transport.send_event(event) if configuration.sending_allowed?
176+
spotlight_transport.send_event(event) if spotlight_transport
177177

178178
event
179179
rescue => e

sentry-ruby/lib/sentry/configuration.rb

+8-4
Original file line numberDiff line numberDiff line change
@@ -484,10 +484,14 @@ def profiles_sample_rate=(profiles_sample_rate)
484484
@profiles_sample_rate = profiles_sample_rate
485485
end
486486

487+
def event_building_allowed?
488+
spotlight || sending_allowed?
489+
end
490+
487491
def sending_allowed?
488492
@errors = []
489493

490-
spotlight || (valid? && capture_in_environment?)
494+
valid? && capture_in_environment?
491495
end
492496

493497
def sample_allowed?
@@ -525,13 +529,13 @@ def valid_sample_rate?(sample_rate)
525529
def tracing_enabled?
526530
valid_sampler = !!((valid_sample_rate?(@traces_sample_rate)) || @traces_sampler)
527531

528-
(@enable_tracing != false) && valid_sampler && sending_allowed?
532+
(@enable_tracing != false) && valid_sampler && event_building_allowed?
529533
end
530534

531535
def profiling_enabled?
532536
valid_sampler = !!(valid_sample_rate?(@profiles_sample_rate))
533537

534-
tracing_enabled? && valid_sampler && sending_allowed?
538+
tracing_enabled? && valid_sampler && event_building_allowed?
535539
end
536540

537541
# @return [String, nil]
@@ -557,7 +561,7 @@ def stacktrace_builder
557561

558562
# @api private
559563
def detect_release
560-
return unless sending_allowed?
564+
return unless event_building_allowed?
561565

562566
@release ||= ReleaseDetector.detect_release(project_root: project_root, running_on_heroku: running_on_heroku?)
563567

sentry-ruby/spec/sentry/configuration_spec.rb

+13-2
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,21 @@
271271
end
272272
end
273273

274-
describe "#sending_allowed?" do
274+
describe "#event_building_allowed?" do
275275
it "true when spotlight" do
276276
subject.spotlight = true
277-
expect(subject.sending_allowed?).to eq(true)
277+
expect(subject.event_building_allowed?).to eq(true)
278+
end
279+
280+
it "true when sending allowed" do
281+
allow(subject).to receive(:sending_allowed?).and_return(true)
282+
expect(subject.event_building_allowed?).to eq(true)
283+
end
284+
285+
it "false when no spotlight and sending not allowed" do
286+
allow(subject).to receive(:sending_allowed?).and_return(false)
287+
subject.spotlight = false
288+
expect(subject.event_building_allowed?).to eq(false)
278289
end
279290
end
280291

sentry-ruby/spec/sentry_spec.rb

+14-6
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,28 @@
110110
end
111111

112112
shared_examples "capture_helper" do
113-
context "with sending_allowed? condition" do
113+
context "with event building allowed" do
114114
before do
115-
expect(Sentry.configuration).to receive(:sending_allowed?).and_return(false)
115+
expect(Sentry.configuration).to receive(:event_building_allowed?).and_return(false)
116116
capture_subject
117117
end
118118

119-
it "doesn't send the event nor assign last_event_id" do
120-
# don't even initialize Event objects
119+
it "doesn't build the event" do
120+
# don't even initialize event objects
121121
expect(Sentry::Event).not_to receive(:new)
122-
123122
described_class.send(capture_helper, capture_subject)
123+
end
124+
end
124125

126+
context "with event building allowed but sending not allowed" do
127+
before do
128+
allow(Sentry.configuration).to receive(:event_building_allowed?).and_return(true)
129+
allow(Sentry.configuration).to receive(:sending_allowed?).and_return(false)
130+
end
131+
132+
it "doesn't send the event nor assign last_event_id" do
133+
described_class.send(capture_helper, capture_subject)
125134
expect(sentry_events).to be_empty
126-
expect(subject.last_event_id).to eq(nil)
127135
end
128136
end
129137

0 commit comments

Comments
 (0)