Skip to content

Commit 497a8e0

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

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -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_to_dsn_allowed?
176+
spotlight_transport.send_event(event) if spotlight_transport
177177

178178
event
179179
rescue => e

sentry-ruby/lib/sentry/configuration.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,13 @@ def profiles_sample_rate=(profiles_sample_rate)
485485
end
486486

487487
def sending_allowed?
488+
spotlight || sending_to_dsn_allowed?
489+
end
490+
491+
def sending_to_dsn_allowed?
488492
@errors = []
489493

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

493497
def sample_allowed?

sentry-ruby/spec/sentry/configuration_spec.rb

+11
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,17 @@
276276
subject.spotlight = true
277277
expect(subject.sending_allowed?).to eq(true)
278278
end
279+
280+
it "true when sending to dsn allowed" do
281+
allow(subject).to receive(:sending_to_dsn_allowed?).and_return(true)
282+
expect(subject.sending_allowed?).to eq(true)
283+
end
284+
285+
it "false when no spotlight and sending to dsn not allowed" do
286+
allow(subject).to receive(:sending_to_dsn_allowed?).and_return(false)
287+
subject.spotlight = false
288+
expect(subject.sending_allowed?).to eq(false)
289+
end
279290
end
280291

281292
context 'configuring for async' do

sentry-ruby/spec/sentry_spec.rb

+12-4
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,22 @@
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 sending allowed but sending to dsn not allowed" do
127+
before do
128+
allow(Sentry.configuration).to receive(:sending_allowed?).and_return(true)
129+
allow(Sentry.configuration).to receive(:sending_to_dsn_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)