Skip to content

How to exclude exceptions client side before .send_event? #1908

Closed
@moenodedev

Description

@moenodedev

We use a Sidekiq job with async to filter exceptions and run other commands (like statsd) before and after reporting the event to Sentry.

When running rails console we see a deprecation warning about the Sentry async config.

$ bin/rails console
W, [2022-09-30T14:46:29.718291 #306]  WARN -- sentry: 
  sentry-ruby now sends events asynchronously by default with its background worker (supported since 4.1.0).
  The `config.async` callback has become redundant while continuing to cause issues.
  (The problems of `async` are detailed in https://github.com/getsentry/sentry-ruby/issues/1522)

  Therefore, we encourage you to remove it and let the background worker take care of async job sending.
It's deprecation is planned in the next major release (6.0), which is scheduled around the 3rd quarter of 2022.

Loading production environment (Rails 7.0.4)
irb(main):001:0> 

How do we do we filter events and run custom commands after reporting client side? How can old code be converted to the new system?

# config/initializers/sentry.rb

Sentry.init do |config|
  config.async = ->(event, hint) {
    SentryJob.perform_later(event, hint)
  }
end
# app/jobs/sentry_job.rb

class SentryJob < ApplicationJob
  queue_as :default

  def perform(event, hint)
    # filter noisy exceptions that would push us over the Sentry account exception limit
    if event["transaction"] == "DataJob"
      return if event["exception"]["values"].any? { |e| e["type"] == "DataJobError" }
    end

    Sentry.send_event(event, hint)

    # increment the sentry exception metric for our statsd dashboard
    StatsD.increment("sentry.exception")
  rescue Exception => e
    Rails.logger.error "#{e.class.name} - #{e.message}"
  end

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions