Skip to content

add hint support to Sentry::Rails::ErrorSubscriber #2228

@modosc

Description

@modosc

if i want to explicitly send an exception to sentry that would otherwise be ignored because of Sentry.configuration.excluded_exceptions i can do this:

Sentry.capture_exception(ignored_exception, hint: { ignore_exclusions: true }) 

however, as far as i can tell this isn't possible if i'm using the rails error reporting interface.

it would be useful to expose this there.

i think it could be achieved the same way tags are handled here:

https://github.com/getsentry/sentry-ruby/blob/master/sentry-rails/lib/sentry/rails/error_subscriber.rb#L17C38-L20

so you could just provide a hint key in context::

Rails.error.report exception, e, handled: true, severity: :error, context: { hint: { ignore_exclusions: true } }

and you could then pass it in via this (untested) implementation:

      def report(error, handled:, severity:, context:, source: nil)
        tags = { handled: handled }

        if source
          return if SKIP_SOURCES.match?(source)
          tags[:source] = source
        end

        if context[:tags].is_a?(Hash)
          context = context.dup
          tags.merge!(context.delete(:tags))
        end

        hint = {}
        if context[:hint].is_a?(Hash)
          context = context.dup
          hint.merge!(context.delete(:hint)
       end

        Sentry::Rails.capture_exception(error, level: severity, contexts: { "rails.error" => context }, tags: tags, hint: hint)
      end

Metadata

Metadata

Assignees

No fields configured for issues without a type.

Projects

Status

Waiting for: Product Owner

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions