ruby-on-rails - 我该如何告诉Sentry不要警告某些异常(exception)情况?

标签 ruby-on-rails ruby-on-rails-5 sentry

我有一个使用raven-ruby的Rails 5应用程序将异常发送到Sentry,然后将警报发送到我们的Slack。

Raven.configure do |config|
  config.dsn = ENV['SENTRY_DSN']
  config.environments = %w[ production development ]
  config.excluded_exceptions += []
  config.async = lambda { |event|
    SentryWorker.perform_async(event.to_hash)
  }
end

class SentryWorker < ApplicationWorker
  sidekiq_options queue: :default

  def perform(event)
    Raven.send_event(event)
  end
end

我们的Sidekiq作业抛出异常并被重试是正常的。这些大多是间歇性的API错误和超时,它们会在几分钟内自行清除。哨兵正将这些错误警报发送给我们的Slack。

我已经added the retry_count to the jobs了。如何防止Sentry向Slack发送retry_count
sidekiq: {
  context: Job raised exception,
  job: {
    args: [{...}],
    class: SomeWorker,
    created_at: 1540590745.3296254,
    enqueued_at: 1540607026.4979043,
    error_class: HTTP::TimeoutError,
    error_message: Timed out after using the allocated 13 seconds,
    failed_at: 1540590758.4266324,
    jid: b4c7a68c45b7aebcf7c2f577,
    queue: default,
    retried_at: 1540600397.5804272,
    retry: True,
    retry_count: 2
  },
}

完全不将其发送给Sentry与不将其发送给Sentry有什么优点和缺点?

最佳答案

如果retry_count

class SentryWorker < ApplicationWorker
  sidekiq_options queue: :default

  def perform(event)
    retry_count = event.dig(:extra, :sidekiq, :job, retry_count)
    if retry_count.nil? || retry_count > N
      Raven.send_event(event)
    end
  end
end

另一个想法是根据是否重试来设置不同的指纹。像这样:
class MyJobProcessor < Raven::Processor
  def process(data)
    retry_count = event.dig(:extra, :sidekiq, :job, retry_count)
    if (retry_count || 0) < N
      data["fingerprint"] = ["will-retry-again", "{{default}}"]
    end
  end
end

参见https://docs.sentry.io/learn/rollups/?platform=javascript#custom-grouping

我没有对此进行测试,但这将把您的问题分成两部分,具体取决于sidekiq是否重试它们。然后,您可以忽略一个组,但在需要数据时仍可以查看它。

关于ruby-on-rails - 我该如何告诉Sentry不要警告某些异常(exception)情况?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53018587/

相关文章:

ruby-on-rails - Rails : Polymorphism, String:Class 的未定义方法 `primary_key'

ruby-on-rails - 带有 Bootstrap 的带有 kaminari 的自定义 css

html - 在 Rails 中使用此 Web 模板

ruby-on-rails - 未找到门卫 new_oauth_application_path

typescript - Next.js 源映射与 Sentry 上的 typescript

ruby-on-rails - capistrano 在 [] 中找不到 bundler (>= 0) (Gem::LoadError)

ruby-on-rails - ruby rails : Deleting multiple attachments in paperclip on updates

ruby-on-rails - Ruby on Rails 测试 - ActiveRecord::StatementInvalid: PG::InvalidTextRepresentation: ERROR: 格式错误的数组文字:

django - Sentry 如何汇总错误?

javascript - 向 Sentry 发送警告消息(react-native-sentry)