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

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

Closed
modosc opened this issue Jan 13, 2024 · 2 comments · Fixed by #2235
Closed

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

modosc opened this issue Jan 13, 2024 · 2 comments · Fixed by #2235

Comments

@modosc
Copy link
Contributor

modosc commented Jan 13, 2024

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
@sl0thentr0py
Copy link
Member

@modosc yep this makes sense to have, will add it when I have some time or feel free to PR!

@modosc
Copy link
Contributor Author

modosc commented Jan 16, 2024

@sl0thentr0py i opened #2235 - i just copied the code/spec pattern from the existing tags: implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants