@grafana/faro-web-sdk

中文文档
2.14.0发布于 2026/11/10Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 638.6万

Faro instrumentations, metas, transports for web.

原始使用文档
文档目录5 节
  1. Get started
  2. Instrumentations
  3. Metas
  4. Transports
  5. Example

@grafana/faro-web-sdk

Faro is a SDK that can instrument frontend JavaScript applications to collect telemetry and forward it to the Grafana Alloy (with app agent receiver integration enabled).

Grafana Alloy can then send this data to either Loki or Tempo.

Get started

See quick start for web applications.

Alternatively, you can use the CDN version of the library. See use cdn library for details on how to do so.

Instrumentations

  • console - captures messages logged to console global object. Only warn, info and error levels by default.
  • errors - captures unhandled top level exceptions
  • web-vitals - captures performance metrics reported by web vitals API
  • session - sends session start event
  • view - sends view changed event
  • navigation - captures soft navigations and reports their URL changes and durations
  • frustration - sends an event for each rage click, dead click and error click, but not for ordinary clicks

Navigation instrumentation is enabled by default. To disable it, pass trackNavigation: false to getWebInstrumentations() when supplying custom instrumentations, or provide a custom instrumentations array without NavigationInstrumentation.

Metas

  • browser - captures browser metadata: name, version, etc
  • os - captures OS name and version parsed from the user agent
  • page - captures current URL
  • view - the web SDK enforces a default value for the view meta

Transports

  • console - logs events to global console
  • fetch - sends events over HTTP to a backend

Example

Basic set up, will automatically report errors and web vitals:

import { initializeFaro } from '@grafana/faro-web-sdk';

const faro = initializeFaro({
  url: 'https://agent.myapp/collect',
  apiKey: 'secret',
  app: {
    name: 'frontend',
    version: '1.0.0',
  },
});

// send a log message
faro.api.pushLog(['hello world']);

// will be captured
throw new Error('oh no');

// push error manually
faro.api.pushError(new Error('oh no'));

With OTel tracing and browser console capture:

import { ConsoleInstrumentation, getWebInstrumentations, initializeFaro } from '@grafana/faro-web-sdk';
import { TracingInstrumentation } from '@grafana/faro-web-tracing';

const faro = initializeFaro({
  url: 'https://agent.myapp/collect',
  apiKey: 'secret',
  instrumentations: [...getWebInstrumentations({ captureConsole: true }), new TracingInstrumentation()],
  app: {
    name: 'frontend',
    version: '1.0.0',
  },
});

// start a span
faro.api
  .getOTEL()
  ?.trace.getTracer('frontend')
  .startActiveSpan('hello world', (span) => {
    // send a log message
    faro.api.pushLog(['hello world']);
    span.end();
  });

// will be captured
throw new Error('oh no');

版本与发布记录

@grafana/faro-web-sdk 共发布 102 个版本,首次发布于 2022/10/31;过去 12 个月发布了 26 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.14.0latest2026/11/107 天前
2.13.02026/10/2225 天前
2.12.12026/09/221 个月前
2.12.02026/09/181 个月前
2.11.02026/08/272 个月前
2.10.02026/08/182 个月前

关于 @grafana/faro-web-sdk 的常见问题

@grafana/faro-web-sdk 是什么?

Faro instrumentations, metas, transports for web.

如何安装 @grafana/faro-web-sdk?

在项目目录运行 npm install @grafana/faro-web-sdk,或使用 pnpm add / yarn add / bun add。

@grafana/faro-web-sdk 支持 TypeScript 吗?

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

@grafana/faro-web-sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@grafana/faro-web-sdk 可以商用吗?

@grafana/faro-web-sdk 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@grafana/faro-web-sdk 的下载量有多少?

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

@grafana/faro-web-sdk 还在维护吗?

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