Set up Faro ΒΆ

Add Grafana Faro to a frontend application running on Nais.

Prerequisites ΒΆ

  • A frontend application deployed on Nais (GCP only; on-premises is not supported)
  • Node.js and npm

Install ΒΆ

sh

If you want browser tracing (connects frontend spans with backend traces), also install:

sh

Bundle size

@grafana/faro-web-tracing adds ~500kB to your JavaScript bundle. Only include it if you need trace propagation.

Initialize Faro ΒΆ

Initialize Faro as early as possible in your application so it captures all errors and page loads.

js

Auto-configuration

Instead of hardcoding the collector URL, you can let the platform generate it for you. See auto-configuration below or the reference page for details.

Setting app.version ΒΆ

Setting a version lets you filter and compare metrics across deploys in Grafana. If you use auto-configuration, the version is extracted from your container image tag automatically.

For manual setup, inject the commit SHA from your CI pipeline:

js

Auto-configuration ΒΆ

The platform can generate the collector URL and app metadata for you. This is the recommended approach for static frontends (nginx, CDN) since the URL is set per cluster β€” no separate config for dev and prod.

Add this to your nais.yaml:

yaml

This generates a JavaScript file at the specified path containing the collector URL, your app name (from metadata.name), and version (from your image tag). The environment variable NAIS_FRONTEND_TELEMETRY_COLLECTOR_URL is also set in your pod.

See the auto-configuration reference for the full list of generated values.

Step 1: Create a local nais.js fallback ΒΆ

Create a nais.js file for local development. Nais replaces this file at deploy time with the real values.

js

Step 2: Import and use it ΒΆ

js

Step 3: Exclude nais.js from your bundler ΒΆ

The local fallback file must not be bundled into your production build. Exclude it in your bundler config:

js
js
js

Capture exceptions ΒΆ

Console errors are captured automatically. To get full stack traces for caught exceptions, push them to Faro:

js

Stack traces from pushed errors are automatically deobfuscated if sourcemaps are available.

React error boundaries ΒΆ

Use <FaroErrorBoundary> from @grafana/faro-react to catch React rendering errors. Without this, errors that happen during rendering are silently lost.

tsx

For Next.js, see the dedicated error boundary pattern using error.tsx.

Performance tuning ΒΆ

Faro generates a lot of data by default. Use these options to control the volume:

Session sampling ΒΆ

Only instrument a percentage of user sessions:

js

Disable console capture ΒΆ

If your app is verbose with console output, disable automatic capture:

js

Filter console levels ΒΆ

By default, Faro ignores console.debug, console.trace, and console.log. To change which levels are captured, use the top-level consoleInstrumentation config:

js

To capture all levels, pass an empty array: disabledLevels: [].

Content Security Policy (CSP) ΒΆ

If your application uses a Content Security Policy, add the collector endpoint to connect-src:

Plaintext

Without this, the browser blocks Faro's requests to the collector. See Troubleshooting for more details.

Privacy and sensitive data ΒΆ

Faro captures console output, errors, and HTTP request URLs automatically. Make sure you don't leak sensitive data:

  • Never log fΓΈdselsnummer, tokens, passwords, or other PII to the console
  • Watch URLs β€” query parameters and path segments may contain identifiers
  • Watch form input β€” don't send user input as custom events without redacting

Use the beforeSend hook to filter or redact telemetry:

js

Local development ΒΆ

Set paused: window.location.hostname === 'localhost' (shown in the init example above) to skip telemetry during local development.

For a full local observability stack, check out the tracing demo repository and run docker-compose up.

Verify it works ΒΆ

  1. Deploy your application
  2. Open it in a browser and interact with it
  3. Open your app in Grafana APM and go to the Frontend tab to see Core Web Vitals
  4. Or query Loki directly in Grafana Explore:
logql

Real-world examples ΒΆ

These navikt repositories use Faro with React Router:

Next steps ΒΆ