AgentSkillsCN

sentry-ruby-setup

在 Ruby 应用中配置 Sentry。当被要求在 Ruby 中集成 Sentry、安装 sentry-ruby gem,或为 Ruby 应用或 Rails 配置错误监控时,可使用此技能。

SKILL.md
--- frontmatter
name: sentry-ruby-setup
description: Setup Sentry in Ruby apps. Use when asked to add Sentry to Ruby, install sentry-ruby gem, or configure error monitoring for Ruby applications or Rails.

Sentry Ruby Setup

Install and configure Sentry in Ruby projects.

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

Requirements

  • Ruby 2.4+ or recent JRuby versions

Install

Add to Gemfile:

ruby
gem "sentry-ruby"

# For profiling, also add:
gem "stackprof"

Then run:

bash
bundle install

Configure

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

Rails Integration

For Rails, add to config/initializers/sentry.rb:

ruby
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-specific Gems

ruby
# 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

Configuration Options

OptionDescriptionDefault
dsnSentry DSNRequired
send_default_piiInclude user datafalse
traces_sample_rate% of transactions traced0
profiles_sample_rate% of traces profiled0
enable_logsSend logs to Sentryfalse
environmentEnvironment nameAuto-detected
releaseRelease versionAuto-detected

Breadcrumb Loggers

LoggerDescription
:sentry_loggerSentry's own logger
:http_loggerHTTP request breadcrumbs
:active_support_loggerRails ActiveSupport (Rails only)

Environment Variables

bash
SENTRY_DSN=https://xxx@o123.ingest.sentry.io/456
SENTRY_AUTH_TOKEN=sntrys_xxx
SENTRY_ORG=my-org
SENTRY_PROJECT=my-project

Verification

ruby
# Capture test message
Sentry.capture_message("Test message from Ruby")

# Or trigger intentional error
1 / 0

Troubleshooting

IssueSolution
Errors not appearingEnsure Sentry.init called early, check DSN
No tracesSet traces_sample_rate > 0
No profilesAdd stackprof gem, set profiles_sample_rate
Rails errors missingUse sentry-rails gem instead of sentry-ruby