@grafana/faro-rollup-plugin

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

Upload a source map to the Faro source map API from a Rollup build pipeline

原始使用文档
文档目录5 节
  1. Installation
  2. Usage
  3. Rollup/Vite
  4. Configuration Options
  5. Link errors to commits (Suspect commits)

Faro source map upload plugin - Rollup/Vite

This plugin uploads source maps to the Faro collector to enable de-obfuscation of stack traces in the Grafana Cloud Frontend Observability UI.

[!NOTE] The Faro JavaScript bundler plugins work with client-side rendered applications. Server-side rendering isn't yet supported.

Installation

To install the Faro JavaScript Bundler Plugins for Rollup/Vite, use the package manager of your choice.

To install the Rollup/Vite plugin with npm, run:

npm install --save-dev @grafana/faro-rollup-plugin

To install the Rollup/Vite plugin with yarn, run:

yarn add --dev @grafana/faro-rollup-plugin

Usage

Details of how to use the plugins with your bundler reside in the Frontend Observability plugin under the "Settings" -> "Source Maps" tab after clicking into your instrumented app.

That tab includes the necessary configuration for the Faro JavaScript bundler plugins, including the appName, appId, and endpoint values that you need for the plugins to work with your app. The details provided below are general instructions for how to use the plugins with your bundler.

Rollup/Vite

To use the Rollup/Vite plugin, add the following to your rollup.config.js or vite.config.js:

// other imports
import faroUploader from '@grafana/faro-rollup-plugin';

export default defineConfig(({ mode }) => {
  return {
    // other configs
    plugins: [
      // other plugins
      faroUploader({
        appName: "$your-app-name",
        // this URL is different from the Faro Collector URL - find this value in the Frontend Observability plugin under "Settings" -> "Source Maps" -> "Configure source map uploads"
        endpoint: "$your-faro-sourcemap-api-url",
        apiKey: "$your-api-key",
        appId: "$your-app-id",
        stackId: "$your-stack-id",
        gzipContents: true,
      }),
    ],
  };

Configuration Options

The following options are available for the Faro JavaScript bundler plugins:

  • appName: string required: The name of your application. This should match the appName value you are using in your Faro Web SDK configuration.
  • endpoint: string required: The URL of your Faro Collector endpoint. This value is in the Frontend Observability plugin under "Settings" -> "Source Maps" -> "Configure source map uploads".
  • apiKey: string required: The API key for your Faro Collector. This value gets generated on grafana.com by creating a new scope (details provided in the plugin and in the "Obtaining API key" section of this document).
  • appId: string required: The ID of your application. This should match the appId value you are using in your Faro Web SDK configuration.
  • stackId: string required: The ID of the stack, found in Frontend Observability under Settings -> Source Maps -> Configure source map uploads
  • outputFiles: string[] | RegExp optional: An array of source map files to upload or a regex pattern to match files, by default Faro uploads all source maps
  • bundleId: string optional: The ID of the bundle/build, by default auto-generated, or specify an ID to filter by bundle ID in Frontend Observability
  • gitHash: string optional: Git commit hash to inject into the bundle as window.__faroGitHash_<appName>. Auto-detected via git rev-parse HEAD if not provided. Use this to supply an explicit value when Git is unavailable at build time (for example, process.env.GITHUB_SHA). If unresolvable, no git hash is injected.
  • keepSourcemaps: boolean optional: Whether to keep the source maps in your generated bundle after uploading, default false
  • gzipContents: boolean optional: Whether to archive and compress the source maps before uploading, default true
  • uploadConcurrency: number optional: Maximum number of individual source map uploads to run at once, default 5. Only applies when gzipContents is false.
  • verbose: boolean optional: Whether to log verbose output during the upload process, default false
  • skipUpload: boolean optional: Whether to skip uploading source maps and only export the bundleId to an environment file, default false
  • maxUploadSize: number optional: Maximum upload size in bytes, default is 30MB. The Faro API has a 30MB limit for individual file uploads by default. In special circumstances, this limit may be changed by contacting Grafana Cloud support.
  • recursive: boolean optional: Whether to recursively search subdirectories for source maps, default false
  • proxy: string optional: Proxy URL to use for source map uploads. Supports both HTTP and HTTPS proxies. If your proxy requires authentication, include credentials in the URL format: http://username:[email protected]:8080. Example: http://proxy.example.com:8080 or https://user:[email protected]:8080
  • prefixPath: string optional: Prefix to prepend to the file property in source maps. This is useful when files in the browser appear in a hierarchy different than how the bundler is aware of. For example, if a CDN is used, stack traces might have file paths starting with cdn/index.js, but the source map's file property only shows index.js. By adding the cdn/ prefix, the source map decoder can correctly match stack traces to source maps. Examples: "cdn/", "robo/assets/", etc.
  • prefixPathBasenameOnly: boolean optional: When true, strips any directory path from the source map file property before prepending prefixPath, keeping only the filename. Useful when assets are deployed flat to a CDN with no subdirectory structure. For example, if the source map's file is assets/index.js and prefixPath is https://cdn.example.com/assets/, enabling this option produces https://cdn.example.com/assets/index.js instead of https://cdn.example.com/assets/assets/index.js. Only applies when prefixPath is set. Default false.

The plugin injects the current git commit hash into your bundle at build time. The Faro Web SDK reads this value and includes it in every telemetry payload, enabling Frontend Observability to associate errors with the commit that introduced them.

Resolution order:

  1. Explicit gitHash option
  2. Auto-detected via git rev-parse HEAD

Default (auto-detection) — works in most local and CI environments with a .git directory:

faroUploader({
  // ... required options
  // gitHash is auto-detected from git rev-parse HEAD
});

Explicit override — use when HEAD is a synthetic merge commit (GitHub Actions pull_request events) or .git is unavailable:

faroUploader({
  // ... required options
  gitHash: process.env.GITHUB_SHA,      // GitHub Actions
  // gitHash: process.env.GIT_COMMIT,   // Jenkins
  // gitHash: process.env.CI_COMMIT_SHA, // GitLab CI
});

After initial configuration, the Faro JavaScript bundler plugins automatically uploads your source maps to Grafana Cloud when you build your application. You can verify that the source maps upload successfully by in the "Settings" -> "Source Maps" tab in the Frontend Observability plugin. From there you are able to see the source maps that you have uploaded.

After you have completed all the required steps, you have finished - the Faro Collector begins processing your source maps and associating them with your telemetry data. The portions of your stack traces with source maps uploaded to the Faro Collector are automatically de-obfuscated and displayed in the Frontend Observability plugin when viewing your error data.

版本与发布记录

@grafana/faro-rollup-plugin 共发布 44 个版本,首次发布于 2024/05/15;过去 12 个月发布了 14 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.13.2latest2026/10/151 个月前
0.13.12026/10/061 个月前
0.13.02026/09/221 个月前
0.12.02026/08/292 个月前
0.11.02026/06/025 个月前
0.10.12026/05/156 个月前

关于 @grafana/faro-rollup-plugin 的常见问题

@grafana/faro-rollup-plugin 是什么?

Upload a source map to the Faro source map API from a Rollup build pipeline

如何安装 @grafana/faro-rollup-plugin?

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

@grafana/faro-rollup-plugin 支持 TypeScript 吗?

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

@grafana/faro-rollup-plugin 支持 ESM 还是 CommonJS?

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

@grafana/faro-rollup-plugin 可以商用吗?

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

@grafana/faro-rollup-plugin 的下载量有多少?

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

@grafana/faro-rollup-plugin 还在维护吗?

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