sentry-ruby-setup
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSentry Ruby Setup
Sentry Ruby 配置
Install and configure Sentry in Ruby projects.
在Ruby项目中安装并配置Sentry。
Invoke This Skill When
何时调用此技能
- User asks to "add Sentry to Ruby" or "install Sentry" in a Ruby app
- User wants error monitoring, logging, or tracing in Ruby
- User mentions "sentry-ruby" gem or Ruby on Rails
- 用户要求在Ruby应用中「添加Sentry」或「安装Sentry」
- 用户需要在Ruby中实现错误监控、日志记录或追踪功能
- 用户提及「sentry-ruby」gem或Ruby on Rails
Requirements
要求
- Ruby 2.4+ or recent JRuby versions
- Ruby 2.4+ 或最新版JRuby
Install
安装
Add to :
Gemfileruby
gem "sentry-ruby"在中添加:
Gemfileruby
gem "sentry-ruby"For profiling, also add:
如需性能分析,还需添加:
gem "stackprof"
Then run:
```bash
bundle installgem "stackprof"
然后运行:
```bash
bundle installConfigure
配置
Initialize as early as possible:
ruby
require "sentry-ruby"
Sentry.init do |config|
config.dsn = "YOUR_SENTRY_DSN"
config.send_default_pii = true
# Breadcrumbs from logs
config.breadcrumbs_logger = [:sentry_logger, :http_logger]
# Tracing
config.traces_sample_rate = 1.0
# Profiling (requires stackprof gem)
config.profiles_sample_rate = 1.0
# Logs
config.enable_logs = true
end尽早初始化Sentry:
ruby
require "sentry-ruby"
Sentry.init do |config|
config.dsn = "YOUR_SENTRY_DSN"
config.send_default_pii = true
# 从日志生成面包屑
config.breadcrumbs_logger = [:sentry_logger, :http_logger]
# 追踪配置
config.traces_sample_rate = 1.0
# 性能分析(需要stackprof gem)
config.profiles_sample_rate = 1.0
# 日志配置
config.enable_logs = true
endRails Integration
Rails集成
For Rails, add to :
config/initializers/sentry.rbruby
Sentry.init do |config|
config.dsn = ENV["SENTRY_DSN"]
config.send_default_pii = true
config.breadcrumbs_logger = [:active_support_logger, :http_logger]
config.traces_sample_rate = 1.0
config.profiles_sample_rate = 1.0
config.enable_logs = true
end对于Rails项目,在中添加:
config/initializers/sentry.rbruby
Sentry.init do |config|
config.dsn = ENV["SENTRY_DSN"]
config.send_default_pii = true
config.breadcrumbs_logger = [:active_support_logger, :http_logger]
config.traces_sample_rate = 1.0
config.profiles_sample_rate = 1.0
config.enable_logs = true
endRails-specific Gems
Rails专属Gem
ruby
undefinedruby
undefinedGemfile
Gemfile
gem "sentry-ruby"
gem "sentry-rails" # Rails integration
gem "sentry-sidekiq" # If using Sidekiq
gem "sentry-delayed_job" # If using Delayed Job
gem "sentry-resque" # If using Resque
undefinedgem "sentry-ruby"
gem "sentry-rails" # Rails集成插件
gem "sentry-sidekiq" # 若使用Sidekiq
gem "sentry-delayed_job" # 若使用Delayed Job
gem "sentry-resque" # 若使用Resque
undefinedConfiguration Options
配置选项
| Option | Description | Default |
|---|---|---|
| Sentry DSN | Required |
| Include user data | |
| % of transactions traced | |
| % of traces profiled | |
| Send logs to Sentry | |
| Environment name | Auto-detected |
| Release version | Auto-detected |
| 选项 | 说明 | 默认值 |
|---|---|---|
| Sentry DSN地址 | 必填 |
| 是否包含用户隐私数据 | |
| 事务追踪采样率 | |
| 性能分析采样率 | |
| 是否将日志发送至Sentry | |
| 环境名称 | 自动检测 |
| 版本号 | 自动检测 |
Breadcrumb Loggers
面包屑日志器
| Logger | Description |
|---|---|
| Sentry's own logger |
| HTTP request breadcrumbs |
| Rails ActiveSupport (Rails only) |
| 日志器 | 说明 |
|---|---|
| Sentry内置日志器 |
| HTTP请求面包屑 |
| Rails ActiveSupport日志器(仅Rails可用) |
Environment Variables
环境变量
bash
SENTRY_DSN=https://xxx@o123.ingest.sentry.io/456
SENTRY_AUTH_TOKEN=sntrys_xxx
SENTRY_ORG=my-org
SENTRY_PROJECT=my-projectbash
SENTRY_DSN=https://xxx@o123.ingest.sentry.io/456
SENTRY_AUTH_TOKEN=sntrys_xxx
SENTRY_ORG=my-org
SENTRY_PROJECT=my-projectVerification
验证
ruby
undefinedruby
undefinedCapture test message
捕获测试消息
Sentry.capture_message("Test message from Ruby")
Sentry.capture_message("Test message from Ruby")
Or trigger intentional error
或触发故意错误
1 / 0
undefined1 / 0
undefinedTroubleshooting
问题排查
| Issue | Solution |
|---|---|
| Errors not appearing | Ensure |
| No traces | Set |
| No profiles | Add |
| Rails errors missing | Use |
| 问题 | 解决方案 |
|---|---|
| 错误未显示 | 确保 |
| 无追踪数据 | 设置 |
| 无性能分析数据 | 添加 |
| Rails错误未捕获 | 使用 |