error-tracking-angular

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

PostHog error tracking for Angular

适用于Angular的PostHog错误追踪

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

Reference files

参考文件

  • references/angular.md
    - Angular 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/angular.md
    - Angular错误追踪安装文档
  • 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

框架指南

  • Use inject() instead of constructor injection. PostHog service should be injected via inject() in components/services that need it.
  • Create a dedicated PosthogService as a singleton root service that wraps the PostHog SDK.
  • Always use standalone components over NgModules.
  • Configure PostHog credentials in src/environments/environment.ts files, as Angular reads environment variables from these configuration files
  • 使用inject()而非构造函数注入。需要PostHog服务的组件/服务应通过inject()注入该服务。
  • 创建专用的PosthogService作为单例根服务,用于封装PostHog SDK。
  • 优先使用独立组件而非NgModules。
  • 在src/environments/environment.ts文件中配置PostHog凭据,因为Angular会从这些配置文件读取环境变量