From 9130bcc15efb5ac9f7b10050ce45042e807b2972 Mon Sep 17 00:00:00 2001 From: Neel Shah Date: Tue, 2 Apr 2024 17:42:03 +0200 Subject: [PATCH] move mechanism inside hint --- sentry-ruby/lib/sentry/client.rb | 6 +++--- sentry-ruby/lib/sentry/hub.rb | 3 +-- sentry-ruby/lib/sentry/integrable.rb | 2 +- sentry-ruby/lib/sentry/rack/capture_exceptions.rb | 2 +- sentry-ruby/lib/sentry/rake.rb | 2 +- sentry-ruby/spec/sentry/client_spec.rb | 2 +- sentry-ruby/spec/sentry_spec.rb | 2 +- 7 files changed, 9 insertions(+), 10 deletions(-) diff --git a/sentry-ruby/lib/sentry/client.rb b/sentry-ruby/lib/sentry/client.rb index 65a91ea4e..d5e633739 100644 --- a/sentry-ruby/lib/sentry/client.rb +++ b/sentry-ruby/lib/sentry/client.rb @@ -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 diff --git a/sentry-ruby/lib/sentry/hub.rb b/sentry-ruby/lib/sentry/hub.rb index 74e82167d..a2e82445f 100644 --- a/sentry-ruby/lib/sentry/hub.rb +++ b/sentry-ruby/lib/sentry/hub.rb @@ -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 diff --git a/sentry-ruby/lib/sentry/integrable.rb b/sentry-ruby/lib/sentry/integrable.rb index 44d74b169..a45dd7839 100644 --- a/sentry-ruby/lib/sentry/integrable.rb +++ b/sentry-ruby/lib/sentry/integrable.rb @@ -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 diff --git a/sentry-ruby/lib/sentry/rack/capture_exceptions.rb b/sentry-ruby/lib/sentry/rack/capture_exceptions.rb index 9b07707ea..99a84a0fe 100644 --- a/sentry-ruby/lib/sentry/rack/capture_exceptions.rb +++ b/sentry-ruby/lib/sentry/rack/capture_exceptions.rb @@ -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 diff --git a/sentry-ruby/lib/sentry/rake.rb b/sentry-ruby/lib/sentry/rake.rb index 8b7042b0e..0e3e6e8c7 100644 --- a/sentry-ruby/lib/sentry/rake.rb +++ b/sentry-ruby/lib/sentry/rake.rb @@ -10,7 +10,7 @@ module Application def display_error_message(ex) mechanism = Sentry::Mechanism.new(type: 'rake', handled: false) - 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) diff --git a/sentry-ruby/spec/sentry/client_spec.rb b/sentry-ruby/spec/sentry/client_spec.rb index 181bd7294..4d98b456e 100644 --- a/sentry-ruby/spec/sentry/client_spec.rb +++ b/sentry-ruby/spec/sentry/client_spec.rb @@ -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 }) diff --git a/sentry-ruby/spec/sentry_spec.rb b/sentry-ruby/spec/sentry_spec.rb index eb4a5e410..976ad213b 100644 --- a/sentry-ruby/spec/sentry_spec.rb +++ b/sentry-ruby/spec/sentry_spec.rb @@ -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')