Sentry 的使用
1. 安装
gem 'sentry-ruby'
2. 配置
# config/initializers/sentry_config.rb
Sentry.init do |config|
# 配置 dsn
config.dsn = ENV['SENTRY_DSN']
# 配置 environment
config.environment = ENV['SENTRY_ENVIRONMENT']
end
3. 使用
class ApplicationApi < Grape::API
....
# 放在最后, 打印所有异常
rescue_from StandardError do |e|
Sentry.capture_exception(e)
...
end
....
end
4. 参考文档:
https://docs.sentry.io/platforms/ruby/performance/