Skip to content

Commit

Permalink
move mechanism inside hint
Browse files Browse the repository at this point in the history
  • Loading branch information
sl0thentr0py committed Apr 2, 2024
1 parent 5eb6f42 commit 9130bcc
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 10 deletions.
6 changes: 3 additions & 3 deletions sentry-ruby/lib/sentry/client.rb
Expand Up @@ -80,18 +80,18 @@ def capture_event(event, scope, hint = {})
# Initializes an Event object with the given exception. Returns `nil` if the exception's class is excluded from reporting.
# @param exception [Exception] the exception to be reported.
# @param hint [Hash] the hint data that'll be passed to `before_send` callback and the scope's event processors.
# @param mechanism [Mechanism] the mechanism that holds a type and whether the exception was handled or not.
# @return [Event, nil]
def event_from_exception(exception, hint = {}, mechanism = nil)
def event_from_exception(exception, hint = {})
return unless @configuration.sending_allowed?

ignore_exclusions = hint.delete(:ignore_exclusions) { false }
return if !ignore_exclusions && !@configuration.exception_class_allowed?(exception)

integration_meta = Sentry.integrations[hint[:integration]]
mechanism = hint.delete(:mechanism) { Mechanism.new }

ErrorEvent.new(configuration: configuration, integration_meta: integration_meta).tap do |event|
event.add_exception_interface(exception, mechanism: mechanism || Mechanism.new)
event.add_exception_interface(exception, mechanism: mechanism)
event.add_threads_interface(crashed: true)
event.level = :error
end
Expand Down
3 changes: 1 addition & 2 deletions sentry-ruby/lib/sentry/hub.rb
Expand Up @@ -128,9 +128,8 @@ def capture_exception(exception, **options, &block)

options[:hint] ||= {}
options[:hint][:exception] = exception
mechanism = options.delete(:mechanism)

event = current_client.event_from_exception(exception, options[:hint], mechanism)
event = current_client.event_from_exception(exception, options[:hint])

return unless event

Expand Down
2 changes: 1 addition & 1 deletion sentry-ruby/lib/sentry/integrable.rb
Expand Up @@ -16,7 +16,7 @@ def capture_exception(exception, **options, &block)
options[:hint][:integration] = integration_name

# within an integration, we usually intercept uncaught exceptions so we set handled to false.
options[:mechanism] ||= Sentry::Mechanism.new(type: integration_name, handled: false)
options[:hint][:mechanism] ||= Sentry::Mechanism.new(type: integration_name, handled: false)

Sentry.capture_exception(exception, **options, &block)
end
Expand Down
2 changes: 1 addition & 1 deletion sentry-ruby/lib/sentry/rack/capture_exceptions.rb
Expand Up @@ -57,7 +57,7 @@ def transaction_op
end

def capture_exception(exception, env)
Sentry.capture_exception(exception, mechanism: mechanism).tap do |event|
Sentry.capture_exception(exception, hint: { mechanism: mechanism }).tap do |event|
env[ERROR_EVENT_ID_KEY] = event.event_id if event
end
end
Expand Down
2 changes: 1 addition & 1 deletion sentry-ruby/lib/sentry/rake.rb
Expand Up @@ -10,7 +10,7 @@ module Application
def display_error_message(ex)
mechanism = Sentry::Mechanism.new(type: 'rake', handled: false)

Check warning on line 11 in sentry-ruby/lib/sentry/rake.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/rake.rb#L11

Added line #L11 was not covered by tests

Sentry.capture_exception(ex, mechanism: mechanism) do |scope|
Sentry.capture_exception(ex, hint: { mechanism: mechanism }) do |scope|
task_name = top_level_tasks.join(' ')
scope.set_transaction_name(task_name, source: :task)
scope.set_tag("rake_task", task_name)
Expand Down
2 changes: 1 addition & 1 deletion sentry-ruby/spec/sentry/client_spec.rb
Expand Up @@ -574,7 +574,7 @@ module ExcTag; end

it 'has correct custom mechanism when passed' do
mech = Sentry::Mechanism.new(type: 'custom', handled: false)
event = subject.event_from_exception(exception, {}, mech)
event = subject.event_from_exception(exception, mechanism: mech)
hash = event.to_hash
mechanism = hash[:exception][:values][0][:mechanism]
expect(mechanism).to eq({ type: 'custom', handled: false })
Expand Down
2 changes: 1 addition & 1 deletion sentry-ruby/spec/sentry_spec.rb
Expand Up @@ -263,7 +263,7 @@

it 'has custom mechanism if passed' do
mech = Sentry::Mechanism.new(type: 'custom', handled: false)
event = described_class.capture_exception(exception, mechanism: mech)
event = described_class.capture_exception(exception, hint: { mechanism: mech })
mechanism = event.exception.values.first.mechanism
expect(mechanism).to be_a(Sentry::Mechanism)
expect(mechanism.type).to eq('custom')
Expand Down

0 comments on commit 9130bcc

Please sign in to comment.