手动报告从 Rails 到 Sentry 的错误



在我的ApiController中,我有:

rescue_from Exception, with: :render_exception_error
def render_exception_error(exception)
raise exception if Rails.env.test?
logger.error(exception)
render json: { error: 'An error occurred' }, status: 500 unless performed?
end

我希望该方法也向哨兵报告错误。 您知道通过执行logger.error(...)行是否也会自动将其记录在哨兵中吗?

还是我必须手动执行Raven.capture_exception(exception)或类似操作?这会在后台完成吗?

编辑 2022

乌鸦从几个月后就被弃用了,你应该使用新的哨兵宝石。

要回答这个问题,即从 Rails 手动报告错误到 Sentry,您可以查看此处的文档:https://docs.sentry.io/platforms/ruby/guides/rails/usage/

TL;您可以捕获异常的灾难恢复

Sentry.capture_exception(exception)

或者您可以使用

Sentry.capture_message('Something went wrong')

最新更新