|
1 | 1 | # Faro JavaScript Bundler Plugins
|
2 | 2 |
|
3 |
| -A collection of plugins for various JavaScript bundlers. Used in conjunction with the [Faro Web SDK](https://github.com/grafana/faro-web-sdk) to unlock additional features in [Grafana Cloud Frontend Observability](https://grafana.com/docs/grafana-cloud/monitor-applications/frontend-observability/). |
| 3 | +A collection of plugins for various JavaScript bundlers. Used in conjunction with the [Faro Web SDK](https://github.com/grafana/faro-web-sdk) to unlock additional features in [Grafana Cloud Frontend Observability](https://grafana.com/docs/grafana-cloud/monitor-applications/frontend-observability/). |
| 4 | + |
| 5 | +## Getting started |
| 6 | + |
| 7 | +The Faro JavaScript Bundler Plugins are designed to be used with the [Faro Web SDK](https://github.com/grafana/faro-web-sdk) and [Grafana Cloud Frontend Observability](https://grafana.com/products/cloud/frontend-observability-for-real-user-monitoring/). To use these bundler plugins, you must first have instrumented your JavaScript application with Faro and be sending your telemetry data to a Faro Collector endpoint in Grafana Cloud. Follow the Frontend Observability [quickstart guide](https://grafana.com/docs/grafana-cloud/monitor-applications/frontend-observability/quickstart/javascript/) to get started. |
| 8 | + |
| 9 | +Once you have an insrumented JavaScript application sending data to Grafana Cloud, you are ready to get started. |
| 10 | + |
| 11 | +## Installation |
| 12 | + |
| 13 | +To install the Faro JavaScript Bundler Plugins, use the package manager of your choice. |
| 14 | + |
| 15 | +### Webpack |
| 16 | + |
| 17 | +To install the Webpack plugin with `npm`, run: |
| 18 | + |
| 19 | +```bash |
| 20 | +npm install @grafana/faro-bundler-plugin-webpack |
| 21 | +``` |
| 22 | + |
| 23 | +To install the Webpack plugin with `yarn`, run: |
| 24 | + |
| 25 | +```bash |
| 26 | +yarn add @grafana/faro-bundler-plugin-webpack |
| 27 | +``` |
| 28 | + |
| 29 | +### Rollup/Vite |
| 30 | + |
| 31 | +Rollup and Vite are both supported by the same plugin. |
| 32 | + |
| 33 | +To install the Rollup/Vite plugin with `npm`, run: |
| 34 | + |
| 35 | +```bash |
| 36 | +npm install @grafana/faro-bundler-plugin-rollup |
| 37 | +``` |
| 38 | + |
| 39 | +To install the Rollup/Vite plugin with `yarn`, run: |
| 40 | + |
| 41 | +```bash |
| 42 | +yarn add @grafana/faro-bundler-plugin-rollup |
| 43 | +``` |
| 44 | + |
| 45 | +## Obtaining API Key |
| 46 | + |
| 47 | +!! TODO - Add instructions on how to obtain API key !! |
| 48 | + |
| 49 | +## Usage |
| 50 | + |
| 51 | +Details of how to use the plugins with your bundler are provided in the Frontend Observability plugin under the "Web SDK Configuration" tab after clicking into your instrumented app. |
| 52 | + |
| 53 | +That tab includes the necessary configuration for the Faro JavaScript Bundler Plugins, including the `appName`, `appId`, and `endpoint` values that are required for the plugins to work with your app. The details provided below are general instructions for how to use the plugins with your bundler. |
| 54 | + |
| 55 | +### Webpack |
| 56 | + |
| 57 | +To use the Webpack plugin, add the following to your `webpack.config.js`: |
| 58 | + |
| 59 | +```javascript |
| 60 | +// other imports |
| 61 | +import FaroSourcemapUploaderPlugin from "@grafana/faro-webpack-plugin"; |
| 62 | + |
| 63 | +module.exports = { |
| 64 | + // other configs |
| 65 | + plugins: [ |
| 66 | + // other plugins |
| 67 | + new FaroSourcemapUploaderPlugin({ |
| 68 | + appName: "$your-app-name", |
| 69 | + endpoint: "$your-faro-collector-url", |
| 70 | + apiKey: "$your-api-key", |
| 71 | + appId: "$your-app-id", |
| 72 | + orgId: "$your-org-id", |
| 73 | + gzipContents: true, |
| 74 | + }), |
| 75 | + ], |
| 76 | +}; |
| 77 | +``` |
| 78 | + |
| 79 | +### Rollup/Vite |
| 80 | + |
| 81 | +To use the Rollup/Vite plugin, add the following to your `rollup.config.js` or `vite.config.js`: |
| 82 | + |
| 83 | +```javascript |
| 84 | +// other imports |
| 85 | +import faroUploader from '@grafana/faro-bundler-plugin-rollup'; |
| 86 | + |
| 87 | +export default defineConfig(({ mode }) => { |
| 88 | + return { |
| 89 | + // other configs |
| 90 | + plugins: [ |
| 91 | + // other plugins |
| 92 | + faroUploader({ |
| 93 | + appName: "$your-app-name", |
| 94 | + endpoint: "$your-faro-collector-url", |
| 95 | + apiKey: "$your-api-key", |
| 96 | + appId: "$your-app-id", |
| 97 | + orgId: "$your-org-id", |
| 98 | + gzipContents: true, |
| 99 | + }), |
| 100 | + ], |
| 101 | + }; |
| 102 | +``` |
| 103 | +
|
| 104 | +### Configuration Options |
| 105 | +
|
| 106 | +The following options are available for the Faro JavaScript Bundler Plugins: |
| 107 | +
|
| 108 | +- `appName: string` (required): The name of your application. This should match the `appName` value you are using in your Faro Web SDK configuration. |
| 109 | +- `endpoint: string` (required): The URL of your Faro Collector endpoint. This value is generated in the Frontend Observability plugin under "Web SDK Configuration". |
| 110 | +- `apiKey: string` (required): The API key for your Faro Collector. This value is generated on grafana.com by creating a new scope (details provided in the plugin and in the "Obtaining API Key" section of this document). |
| 111 | +- `appId: string` (required): The ID of your application. This should match the `appId` value you are using in your Faro Web SDK configuration. |
| 112 | +- `orgId: string` (required): The ID of your organization. This value is provided in the Frontend Observability plugin under "Web SDK Configuration". |
| 113 | +- `outputFiles: string[]` (optional): An array of sourcemap files to upload. By default, all sourcemaps are uploaded. |
| 114 | +- `bundleId: string` (optional): The ID of the bundle/build. You can specify this value to filter by bundle ID in the Frontend Observability plugin. Otherwise an auto-generated ID will be used. |
| 115 | +- `keepSourcemaps: boolean` (optional): Whether to keep the sourcemaps in your generated bundle after uploading. Defaults to `false`. |
| 116 | +- `gzipContents: boolean` (optional): Whether to tarball and gzip the contents of the sourcemaps before uploading. Defaults to `true`. |
| 117 | +- `verbose: boolean` (optional): Whether to log verbose output during the upload process. Defaults to `false`. |
| 118 | +
|
| 119 | +After initial configuration, the Faro JavaScript Bundler Plugins will automatically upload your source maps to Grafana Cloud when you build your application. You can verify that the source maps are being uploaded by "Sourcemaps" tab in the Frontend Observability plugin. From there you are able to see the source maps that have been uploaded. |
| 120 | +
|
| 121 | +Once you have completed all the required steps, you are done - the Faro Collector will begin processing your source maps and associating them with your telemetry data. The portions of your stacktraces with source maps that have been uploaded to the Faro Collector will be automatically deobfuscated and displayed in the Frontend Observability plugin when viewing your error data. |
0 commit comments