Skip to content

Commit

Permalink
SDK should drop the event when any event processor returns nil (#1523)
Browse files Browse the repository at this point in the history
* Drop the event when any event processor returns nil

* Update changelog
  • Loading branch information
st0012 authored Aug 9, 2021
1 parent d050286 commit a1f1dbc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- SDK should drop the event when any event processor returns nil [#1523](https://github.com/getsentry/sentry-ruby/pull/1523)
- Add severity as `sentry_logger`'s breadcrumb hint [#1527](https://github.com/getsentry/sentry-ruby/pull/1527)

## 4.6.4
Expand Down
7 changes: 6 additions & 1 deletion sentry-ruby/lib/sentry/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ def initialize(configuration)
def capture_event(event, scope, hint = {})
return unless configuration.sending_allowed?

scope.apply_to_event(event, hint)
event = scope.apply_to_event(event, hint)

if event.nil?
log_info("Discarded event because one of the event processors returned nil")
return
end

if async_block = configuration.async
dispatch_async_event(async_block, event, hint)
Expand Down
14 changes: 14 additions & 0 deletions sentry-ruby/spec/sentry/client/event_sending_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,20 @@
configuration.async = prior_async
end

context "when scope.apply_to_event returns nil" do
before do
scope.add_event_processor do |event, hint|
nil
end
end

it "discards the event and logs a info" do
expect(subject.capture_event(event, scope)).to be_nil

expect(string_io.string).to match(/Discarded event because one of the event processors returned nil/)
end
end

context "when scope.apply_to_event fails" do
before do
scope.add_event_processor do
Expand Down

0 comments on commit a1f1dbc

Please sign in to comment.