error-tracking-ruby

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

PostHog error tracking for Ruby

适用于Ruby的PostHog错误追踪

This skill helps you add PostHog error tracking to Ruby applications.
此技能可帮助你为Ruby应用添加PostHog错误追踪功能。

Reference files

参考文件

  • references/ruby.md
    - Ruby error tracking installation - docs
  • references/fingerprints.md
    - Fingerprints - docs
  • references/alerts.md
    - Send error tracking alerts - docs
  • references/monitoring.md
    - Monitor and search issues - docs
  • references/assigning-issues.md
    - Assign issues to teammates - docs
  • references/upload-source-maps.md
    - Upload source maps - docs
Consult the documentation for API details and framework-specific patterns.
  • references/ruby.md
    - Ruby错误追踪安装文档
  • references/fingerprints.md
    - 指纹标识文档
  • references/alerts.md
    - 发送错误追踪告警文档
  • references/monitoring.md
    - 监控与搜索问题文档
  • references/assigning-issues.md
    - 问题分配给团队成员文档
  • references/upload-source-maps.md
    - 上传源映射文档
如需API详情和特定框架的实现模式,请查阅相关文档。

Key principles

核心原则

  • Environment variables: Always use environment variables for PostHog keys and host URLs. Never hardcode them.
  • Minimal changes: Add error tracking alongside existing error handling. Don't replace or restructure existing error handling code.
  • Autocapture first: Enable exception autocapture in the SDK initialization before adding manual captures.
  • Source maps: Upload source maps so stack traces resolve to original source code, not minified bundles.
  • Manual capture for boundaries: Use
    captureException()
    at error boundaries and catch blocks for errors that don't propagate to the global handler.
  • 环境变量:始终使用环境变量存储PostHog密钥和主机URL,切勿硬编码。
  • 最小改动:在现有错误处理基础上添加错误追踪功能,不要替换或重构现有错误处理代码。
  • 自动捕获优先:在SDK初始化时启用异常自动捕获,再添加手动捕获逻辑。
  • 源映射:上传源映射,以便将堆栈追踪解析为原始源代码,而非压缩后的包文件。
  • 边界处手动捕获:在错误边界和catch块中使用
    captureException()
    捕获那些不会传播到全局处理器的错误。

Framework guidelines

框架指南

  • posthog-ruby is the Ruby SDK gem name (add
    gem 'posthog-ruby'
    to Gemfile) but require it with
    require 'posthog'
    (NOT
    require 'posthog-ruby'
    )
  • Use PostHog::Client.new(api_key: key, host: host) for instance-based initialization in scripts and CLIs
  • In CLIs and scripts: MUST call client.shutdown before exit or all events are lost
  • Use begin/rescue/ensure with shutdown in the ensure block for proper cleanup
  • capture and identify take a single hash argument: client.capture(distinct_id: 'user_123', event: 'my_event', properties: { key: 'value' })
  • capture_exception takes POSITIONAL args (not keyword): client.capture_exception(exception, distinct_id, additional_properties) — do NOT use
    distinct_id:
    keyword syntax
  • posthog-ruby是Ruby SDK的gem名称(需在Gemfile中添加
    gem 'posthog-ruby'
    ),但引用时使用
    require 'posthog'
    (而非
    require 'posthog-ruby'
  • 在脚本和CLI中,使用PostHog::Client.new(api_key: key, host: host)进行基于实例的初始化
  • 在CLI和脚本中:退出前必须调用client.shutdown,否则所有事件都会丢失
  • 使用begin/rescue/ensure结构,在ensure块中调用shutdown以确保正确清理
  • capture和identify方法接受单个哈希参数:client.capture(distinct_id: 'user_123', event: 'my_event', properties: { key: 'value' })
  • capture_exception方法接受位置参数(而非关键字参数):client.capture_exception(exception, distinct_id, additional_properties) — 请勿使用
    distinct_id:
    关键字语法