Rails Informant
Self-hosted error monitoring for Rails, built for AI agents
Quick Start ◆ Configuration ◆ Noise Suppression ◆ MCP Server ◆ Data and Privacy
______________________________________________________________________
捕获异常,将其存储在具有丰富上下文(回溯、面包屑、请求数据)的应用程序数据库中,发送通知,并通过捆绑的MCP服务器公开错误数据,因此AI代理可以直接查询、分类和修复生产错误。
没有仪表板。代理人 *是* 界面。
- 本地代理 --14个MCP工具允许AI代理在没有浏览器的情况下列出、检查、解决和修复错误。
- 自托管 --错误会留在数据库中。没有外部服务,没有数据离开您的基础设施。
- 零配置捕获 --自动通过
Rails.error用户和机架中间件。面包屑来自ActiveSupport::Notifications提供结构化的调试上下文。 - 轻量级 --两个数据库表,没有Redis,除了ActiveJob之外没有后台worker。
快速开始
添加到您的Gemfile:
gem "rails-informant"安装:
bundle install
bin/rails generate rails_informant:install
bin/rails db:migrate设置身份验证令牌:
bin/rails credentials:editrails_informant:
api_token: your-secret-token # generate with: openssl rand -hex 32安装Claude Code集成:
bin/rails generate rails_informant:skill错误会自动捕获。要手动捕获,请执行以下操作:
RailsInformant.capture(exception, context: { order_id: 42 })配置
# config/initializers/rails_informant.rb
RailsInformant.configure do |config|
config.capture_errors = !Rails.env.local?
config.api_token = Rails.application.credentials.dig(:rails_informant, :api_token)
config.slack_webhook_url = Rails.application.credentials.dig(:rails_informant, :slack_webhook_url)
config.retention_days = 30
end每个选项都可以通过环境变量进行设置。初始化器优先。
| 选项 | 环境变量 | 默认值 | 描述 |
|---|---|---|---|
api_token | INFORMANT_API_TOKEN | nil | API/MCP访问的身份验证令牌 |
capture_errors | INFORMANT_CAPTURE_ERRORS | true | 启用/禁用错误捕获 |
capture_user_email | _(无)_ | false | 捕获检测到的用户的电子邮件(PII--选择加入) |
ignored_exceptions | INFORMANT_IGNORED_EXCEPTIONS | [] | 要跳过的异常类(行走导致链) |
ignored_paths | INFORMANT_IGNORED_PATHS | [] | 请求跳过的路径(精确匹配或分段匹配) |
job_attempt_threshold | INFORMANT_JOB_ATTEMPT_THRESHOLD | nil | 抑制作业错误,直到第N次重试 |
retention_days | INFORMANT_RETENTION_DAYS | nil | N天后自动清除错误 |
slack_webhook_url | INFORMANT_SLACK_WEBHOOK_URL | nil | Slack传入webhook URL |
spike_protection | _(无)_ | nil | 每个错误组的速率限制: { threshold: 50, window: 1.minute } |
webhook_url | INFORMANT_WEBHOOK_URL | nil | 通知的通用webhook URL |
连接令牌: 这api_token在您的Rails凭据中INFORMANT_PRODUCTION_TOKEN一定是 相同的价值。第一个对应用程序的传入请求进行身份验证;第二个告诉MCP服务器要发送什么令牌。
噪声抑制
静音块
RailsInformant.silence do
risky_operation_you_dont_care_about
end线程安全通过 CurrentAttributes。支持嵌套。
在记录回调之前
连接到记录管道以过滤、修改指纹或覆盖严重性:
config.before_record do |event|
event.halt! if event.message.include?("timeout")
event.fingerprint = "stripe-errors" if event.error_class.start_with?("Stripe::")
event.severity = "warning" if event.error_class == "Net::ReadTimeout"
end这 event 暴露: error, error_class, message, severity, controller_action, job_class, request_path, fingerprint引发的回调会被记录并跳过。
自定义异常上下文
例外情况实施 to_informant_context 将它们的上下文自动合并到事件中:
class PaymentError
export INFORMANT_STAGING_URL=https://staging.myapp.com
export INFORMANT_STAGING_TOKEN=工具
| 工具 | 说明 |
|---|---|
annotate_error | 添加调查笔记 |
delete_error | 删除组和事件 |
get_error | 最近发生的完整错误详细信息 |
get_informant_status | 包含计数和主要错误的摘要 |
ignore_error | 标记为忽略 |
list_environments | 列出已配置的环境 |
list_errors | 列出具有筛选和分页功能的错误组 |
list_occurrences | 使用筛选列出事件 |
mark_duplicate | 标记为另一组的副本 |
mark_fix_pending | 标记修复SHA以在部署时自动解析 |
notify_deploy | 通知部署以自动解决过时错误 |
reopen_error | 重新打开已解决/忽略的错误 |
resolve_error | 标记为已解决 |
verify_pending_fixes | 检查已部署的修复程序并自动解析已验证的修复程序 |
本地开发
默认情况下,MCP服务器强制使用HTTPS。对于本地HTTP URL,请传递 --allow-insecure:
{
"mcpServers": {
"informant": {
"command": "informant-mcp",
"args": ["--allow-insecure"]
}
}
}建筑
Development Machine Remote Servers
+-----------------------+ +-----------------------+
| Claude Code | | Production |
| | | | /informant |
| | stdio | +-----------------------+
| v | HTTPS+Token
| MCP Server | -----------> +-----------------------+
| (exe/informant-mcp) | | Staging |
| | | /informant |
+-----------------------+ +-----------------------+错误组生命周期
unresolved --> fix_pending --> resolved (auto, on deploy)
unresolved --> resolved (manual)
unresolved --> ignored
unresolved --> duplicate
resolved --> unresolved [REGRESSION]数据和隐私
事件存储:用户ID(始终)、电子邮件(通过选择加入 capture_user_email)、IP地址和自定义上下文。所有上下文都通过 ActiveSupport::ParameterFilter --将密钥添加到 filter_parameters 压制他们。
RailsInformant::Current.user_context = { id: current_user.id }安全
- 令牌身份验证(
secure_compare),默认情况下强制使用HTTPS - 所有上下文均已过滤
ActiveSupport::ParameterFilter - 安全标头:
Cache-Control: no-store,X-Content-Type-Options: nosniff - 错误捕获永远不会破坏主机应用程序
- 无内置速率限制--使用 机架::攻击 上
/informant/
许可证
MIT许可证——见 许可证.
______________________________________________________________________
Made in Tokyo with ❤️ and 🤖
