diff --git a/sentry-ruby/lib/sentry/client.rb b/sentry-ruby/lib/sentry/client.rb index d23c23e6a..40d01c69d 100644 --- a/sentry-ruby/lib/sentry/client.rb +++ b/sentry-ruby/lib/sentry/client.rb @@ -21,7 +21,7 @@ def initialize(configuration) end def capture_event(event, scope, hint = {}) - return false unless configuration.sending_allowed? + return unless configuration.sending_allowed? scope.apply_to_event(event, hint) diff --git a/sentry-ruby/lib/sentry/hub.rb b/sentry-ruby/lib/sentry/hub.rb index 407ff34c1..d6cd10556 100644 --- a/sentry-ruby/lib/sentry/hub.rb +++ b/sentry-ruby/lib/sentry/hub.rb @@ -110,7 +110,7 @@ def capture_event(event, **options, &block) event = current_client.capture_event(event, scope, hint) - @last_event_id = event.event_id + @last_event_id = event&.event_id event end diff --git a/sentry-ruby/spec/sentry/client_spec.rb b/sentry-ruby/spec/sentry/client_spec.rb index a0c5e1a63..1c03e1893 100644 --- a/sentry-ruby/spec/sentry/client_spec.rb +++ b/sentry-ruby/spec/sentry/client_spec.rb @@ -55,7 +55,7 @@ def sentry_context returned = subject.capture_event(event, scope) - expect(returned).to eq(false) + expect(returned).to eq(nil) end context "when async raises an exception" do diff --git a/sentry-ruby/spec/sentry/hub_spec.rb b/sentry-ruby/spec/sentry/hub_spec.rb index 5dd80a39d..f1fd697ee 100644 --- a/sentry-ruby/spec/sentry/hub_spec.rb +++ b/sentry-ruby/spec/sentry/hub_spec.rb @@ -19,6 +19,19 @@ subject { described_class.new(client, scope) } shared_examples "capture_helper" do + context "with sending_allowed? condition" do + before do + expect(configuration).to receive(:sending_allowed?).and_return(false) + end + + it "doesn't send the event nor assign last_event_id" do + subject.send(capture_helper, capture_subject) + + expect(transport.events).to be_empty + expect(subject.last_event_id).to eq(nil) + end + end + context "with custom attributes" do it "updates the event with custom attributes" do subject.send(capture_helper, capture_subject, tags: { foo: "bar" }) @@ -147,7 +160,7 @@ describe '#capture_event' do let(:exception) { ZeroDivisionError.new("divided by 0") } let!(:event) do - subject.capture_exception(exception) + client.event_from_exception(exception) end it "returns an Event instance" do