@github/failbot

中文文档
1.1.1发布于 2026/08/06MITTypeScriptCommonJS近 30 天下载 4.5万

A Failbot client for JavaScript

原始使用文档
文档目录4 节
  1. Installation
  2. Usage:
  3. Report delivery
  4. Exception payloads

Failbot JS

A Failbotg client for JavaScript.

Installation

This package is published to npm as @github/failbot.

❯ npm install @github/failbot

Usage:

const {Failbot, HTTPBackend, LogBackend} = require('@github/failbot')

const failbot = new Failbot({
  app: 'my-cool-app',
  backends: [new HTTPBackend({haystackURL: process.env.HAYSTACK_URL}), new LogBackend({log: console.log.bind(console)})]
})

try {
  riskyThing()
} catch (error) {
  failbot.report(error, {
    extra: 'metadata',
    can: 'be',
    passed: 'as well'
  })
}

Report delivery

Failbot.report(error, metadata?, options?) returns one promise for each configured backend. Reporting is best effort by default, so delivery failures resolve to undefined. Configuration and payload preparation errors, including redaction errors, throw synchronously.

Set rejectOnError to reject with backend delivery errors:

await Promise.all(failbot.report(error, metadata, {rejectOnError: true}))

HTTPBackend treats fetch errors, timeouts, and non-2xx responses as delivery failures. Requests time out after 5 seconds by default. Set timeoutMs to configure the timeout:

const backend = new HTTPBackend({
  haystackURL: process.env.HAYSTACK_URL,
  timeoutMs: 1_000
})

Exception payloads

HTTP and log reports include a runtime-specific platform ("node" in Node.js and "javascript" in browsers) and a structured exception_detail by default. Stack frames from V8/Node/Chrome and Firefox/Safari are normalized to caller-first order for Failbotg. The legacy class, message, and string backtrace fields are also included for compatibility.

Consumers can override the default platform and exception_detail through metadata passed to report. The formatter continues to own the legacy error fields, timestamp, and JavaScript environment.

Generated structured exception fields redact the known credential patterns covered by Failbotg's global context filters, including URL basic-auth credentials, cookie values, sensitive key-value pairs, and GitHub tokens. This filtering intentionally preserves other exception content, such as email addresses and identifiers. Caller-provided exception_detail values are preserved verbatim by default, and legacy fields retain their existing values.

Application owners are responsible for keeping service-specific sensitive data out of exceptions. Configure a redact function when the application handles values that the default credential patterns cannot identify:

const failbot = new Failbot({
  app: 'my-cool-app',
  backends: [new HTTPBackend({haystackURL: process.env.HAYSTACK_URL})],
  redact(value) {
    return value.replace(/service-specific-sensitive-pattern/g, '[app redacted]')
  }
})

Built-in filtering runs on generated structured details. The custom function then runs on every JSON-serializable string in the outbound payload, including generated and caller-provided structured details, legacy fields, and metadata. It is not applied to sensitive_context. Use it for additional formats called out by GitHub's secure exception handling guidance, such as authorization and HMAC headers, JWTs, service credentials, and application-specific serialized data. The function must always return a string and must not throw. Add tests for application redaction rules, and record a metric or safe log entry when a rule matches so the underlying exception can be fixed.

Custom backend implementations receive the configured function as the third argument to report and must apply it before transporting exception data. The bundled HTTP and log backends do this automatically.

Exception metadata should use registered semantic conventions. Data that must be available in Splunk but must not reach Sentry can be placed in the Failbotg sensitive_context object:

failbot.report(error, {
  context: {'gh.example.repository.id': repositoryId},
  sensitive_context: {'gh.example.repository.path': repositoryPath}
})

Only use sensitive_context when retaining the value is necessary. Authentication data and other restricted content must be removed before reporting rather than sent through either context.

In order to attribute reported exceptions to service catalog services, the catalog_service tag is included in all exceptions reported via this library. Since all moda deployments have an OTEL_SERVICE_NAME environment variable, catalog_service is included in every failbot report payload as the value of OTEL_SERVICE_NAME.

You should not need to override this value but, if you do, you can pass catalogService to the Failbot constructor: const failbot = new Failbot({app: 'my-app', catalogService: 'my-catalog', backends: ...}). Be aware that overriding this value may make it impossible for your team to receive alerts related to high volumes of exceptions.

版本与发布记录

@github/failbot 共发布 7 个版本,首次发布于 2021/10/21;过去 12 个月发布了 1 个版本。

版本发布日期距今
1.1.1latest2026/08/063 个月前
0.9.12025/09/241.1 年前
0.8.32023/02/203 年前
0.8.22022/11/114 年前
0.8.12022/11/114 年前
0.8.02021/11/304 年前

关于 @github/failbot 的常见问题

@github/failbot 是什么?

A Failbot client for JavaScript

如何安装 @github/failbot?

在项目目录运行 npm install @github/failbot,或使用 pnpm add / yarn add / bun add。

@github/failbot 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@github/failbot 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@github/failbot 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 22.x。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@github/failbot 可以商用吗?

@github/failbot 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@github/failbot 的下载量有多少?

根据 npm 官方下载统计,@github/failbot 在 2026/10/17 – 2026/11/15 这 30 天内被下载 44,855 次,日均约 1,495 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@github/failbot 还在维护吗?

最新版本 1.1.1 发布于 2026/08/06(3 个月前);至今共发布 7 个版本,其中过去 12 个月发布了 1 个;首次发布于 2021/10/21。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。