Skip to content

Commit

Permalink
Make sure sending_allowed? is respected irrespective of spotlight con…
Browse files Browse the repository at this point in the history
…figuration (#2231)
  • Loading branch information
sl0thentr0py committed Mar 13, 2024
1 parent 213e2ab commit b69e4eb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
- Only instantiate SessionFlusher when the SDK is enabled under the current env [#2245](https://github.com/getsentry/sentry-ruby/pull/2245)
- Fixes [#2234](https://github.com/getsentry/sentry-ruby/issues/2234)
- Update backtrace parsing regexp to support Ruby 3.4 ([#2252](https://github.com/getsentry/sentry-ruby/pull/2252))
- Make sure ``sending_allowed?`` is respected irrespective of spotlight configuration ([#2231](https://github.com/getsentry/sentry-ruby/pull/2231))
- Fixes [#2226](https://github.com/getsentry/sentry-ruby/issues/2226)

## 5.16.1

Expand Down
4 changes: 2 additions & 2 deletions sentry-ruby/lib/sentry/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ def send_event(event, hint = nil)
end
end

transport.send_event(event)
spotlight_transport&.send_event(event)
transport.send_event(event) if configuration.sending_to_dsn_allowed?
spotlight_transport.send_event(event) if spotlight_transport

event
rescue => e
Expand Down
6 changes: 5 additions & 1 deletion sentry-ruby/lib/sentry/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,13 @@ def profiles_sample_rate=(profiles_sample_rate)
end

def sending_allowed?
spotlight || sending_to_dsn_allowed?
end

def sending_to_dsn_allowed?
@errors = []

spotlight || (valid? && capture_in_environment?)
valid? && capture_in_environment?
end

def sample_allowed?
Expand Down
11 changes: 11 additions & 0 deletions sentry-ruby/spec/sentry/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,17 @@
subject.spotlight = true
expect(subject.sending_allowed?).to eq(true)
end

it "true when sending to dsn allowed" do
allow(subject).to receive(:sending_to_dsn_allowed?).and_return(true)
expect(subject.sending_allowed?).to eq(true)
end

it "false when no spotlight and sending to dsn not allowed" do
allow(subject).to receive(:sending_to_dsn_allowed?).and_return(false)
subject.spotlight = false
expect(subject.sending_allowed?).to eq(false)
end
end

context 'configuring for async' do
Expand Down
16 changes: 12 additions & 4 deletions sentry-ruby/spec/sentry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,22 @@
capture_subject
end

it "doesn't send the event nor assign last_event_id" do
# don't even initialize Event objects
it "doesn't build the event" do
# don't even initialize event objects
expect(Sentry::Event).not_to receive(:new)

described_class.send(capture_helper, capture_subject)
end
end

context "with sending allowed but sending to dsn not allowed" do
before do
allow(Sentry.configuration).to receive(:sending_allowed?).and_return(true)
allow(Sentry.configuration).to receive(:sending_to_dsn_allowed?).and_return(false)
end

it "doesn't send the event nor assign last_event_id" do
described_class.send(capture_helper, capture_subject)
expect(sentry_events).to be_empty
expect(subject.last_event_id).to eq(nil)
end
end

Expand Down

0 comments on commit b69e4eb

Please sign in to comment.