Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure sending_allowed? is respected irrespective of spotlight configuration #2231

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading