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
  • Loading branch information
sl0thentr0py committed Mar 13, 2024
1 parent 213e2ab commit 42d4ce3
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 18 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
12 changes: 6 additions & 6 deletions sentry-ruby/lib/sentry/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def initialize(configuration)
# @param hint [Hash] the hint data that'll be passed to `before_send` callback and the scope's event processors.
# @return [Event, nil]
def capture_event(event, scope, hint = {})
return unless configuration.sending_allowed?
return unless configuration.event_building_allowed?

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

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

integration_meta = Sentry.integrations[hint[:integration]]
event = ErrorEvent.new(configuration: configuration, integration_meta: integration_meta, message: message)
Expand All @@ -128,7 +128,7 @@ def event_from_check_in(
monitor_config: nil,
check_in_id: nil
)
return unless configuration.sending_allowed?
return unless configuration.event_building_allowed?

CheckInEvent.new(
configuration: configuration,
Expand Down 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_allowed?
spotlight_transport.send_event(event) if spotlight_transport

event
rescue => e
Expand Down
12 changes: 8 additions & 4 deletions sentry-ruby/lib/sentry/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,14 @@ def profiles_sample_rate=(profiles_sample_rate)
@profiles_sample_rate = profiles_sample_rate
end

def event_building_allowed?
spotlight || sending_allowed?
end

def sending_allowed?
@errors = []

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

def sample_allowed?
Expand Down Expand Up @@ -525,13 +529,13 @@ def valid_sample_rate?(sample_rate)
def tracing_enabled?
valid_sampler = !!((valid_sample_rate?(@traces_sample_rate)) || @traces_sampler)

(@enable_tracing != false) && valid_sampler && sending_allowed?
(@enable_tracing != false) && valid_sampler && event_building_allowed?
end

def profiling_enabled?
valid_sampler = !!(valid_sample_rate?(@profiles_sample_rate))

tracing_enabled? && valid_sampler && sending_allowed?
tracing_enabled? && valid_sampler && event_building_allowed?
end

# @return [String, nil]
Expand All @@ -557,7 +561,7 @@ def stacktrace_builder

# @api private
def detect_release
return unless sending_allowed?
return unless event_building_allowed?

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

Expand Down
15 changes: 13 additions & 2 deletions sentry-ruby/spec/sentry/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,21 @@
end
end

describe "#sending_allowed?" do
describe "#event_building_allowed?" do
it "true when spotlight" do
subject.spotlight = true
expect(subject.sending_allowed?).to eq(true)
expect(subject.event_building_allowed?).to eq(true)
end

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

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

Expand Down
20 changes: 14 additions & 6 deletions sentry-ruby/spec/sentry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,28 @@
end

shared_examples "capture_helper" do
context "with sending_allowed? condition" do
context "with event building allowed" do
before do
expect(Sentry.configuration).to receive(:sending_allowed?).and_return(false)
expect(Sentry.configuration).to receive(:event_building_allowed?).and_return(false)
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 event building allowed but sending not allowed" do
before do
allow(Sentry.configuration).to receive(:event_building_allowed?).and_return(true)
allow(Sentry.configuration).to receive(:sending_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 42d4ce3

Please sign in to comment.