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

Don't initialize Event objects when they won't be sent #1687

Merged
merged 2 commits into from
Jan 14, 2022
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 @@ -4,6 +4,8 @@

- Add workaround for ConnectionStub's missing interface [#1686](https://github.com/getsentry/sentry-ruby/pull/1686)
- Fixes [#1685](https://github.com/getsentry/sentry-ruby/issues/1685)
- Don't initialize Event objects when they won't be sent [#1687](https://github.com/getsentry/sentry-ruby/pull/1687)
- Fixes [#1683](https://github.com/getsentry/sentry-ruby/issues/1683)

## 4.9.0

Expand Down
5 changes: 4 additions & 1 deletion sentry-ruby/lib/sentry/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ 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? && @configuration.exception_class_allowed?(exception)

integration_meta = Sentry.integrations[hint[:integration]]
return unless @configuration.exception_class_allowed?(exception)

Event.new(configuration: configuration, integration_meta: integration_meta).tap do |event|
event.add_exception_interface(exception)
Expand All @@ -90,6 +91,8 @@ 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?

integration_meta = Sentry.integrations[hint[:integration]]
event = Event.new(configuration: configuration, integration_meta: integration_meta, message: message)
event.add_threads_interface(backtrace: backtrace || caller)
Expand Down
3 changes: 3 additions & 0 deletions sentry-ruby/lib/sentry/hub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ def capture_message(message, **options, &block)
options[:hint][:message] = message
backtrace = options.delete(:backtrace)
event = current_client.event_from_message(message, options[:hint], backtrace: backtrace)

return unless event

capture_event(event, **options, &block)
end

Expand Down
4 changes: 4 additions & 0 deletions sentry-ruby/spec/sentry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,13 @@
context "with sending_allowed? condition" do
before do
expect(Sentry.configuration).to receive(:sending_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
expect(Sentry::Event).not_to receive(:new)

described_class.send(capture_helper, capture_subject)

expect(transport.events).to be_empty
Expand Down