RousselTMLEARNING

Observability

Faro: JavaScript errors, logs, business events and sessions

Use the Faro API: automatic error capture, manual error reporting, logs, business events and measurements, session and user identification, and source maps.

1. Errors #

Automatic and manual.

Capture #

Web instrumentations automatically capture unhandled exceptions (window.onerror) and rejected promises. For a handled error, send it explicitly:

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

try {
  await payer(panier);
} catch (err) {
  faro.api.pushError(err, { context: { etape: 'paiement', montant: String(panier.total) } });
  afficherMessage('Le paiement a échoué');
}

Source maps #

In production, code is minified: a stack trace points to main.4f3a.js:1:20345. With source maps, the stack is translated back to the original file and line. Alloy can download them from your site or read them from disk:

faro.receiver "front" {
  sourcemaps {
    download = false
    location {
      path                 = "/var/www/sourcemaps"
      minified_path_prefix = "https://boutique.example.org/assets/"
    }
  }
  // ...
}
Common mistake: You do not necessarily want to publish your source maps on the public site: they reveal the source code. Place them on the receiver's disk instead.

2. Logs, events, measurements #

Instrumenting the business.

API #

// Événement métier (tunnel de conversion)
faro.api.pushEvent('ajout_panier', { produit: 'casque-x', quantite: '1' });

// Mesure personnalisée (valeurs numériques)
faro.api.pushMeasurement({ type: 'panier', values: { articles: 3, total: 129.9 } });

// Log applicatif
faro.api.pushLog(['Filtre appliqué', JSON.stringify(filtres)]);

Events let you build funnels (page views → add to cart → payment) and link a drop in conversion to an error or slowness.

➜ To go further: Conversion funnels in RUM: building, reading and comparing funnels in Faro, Dynatrace, Datadog and New Relic.

3. Sessions and users #

With care.

Sessions #

Faro creates a session identifier and adds it to all signals: you can find everything a session went through (pages, errors, slow requests).

initializeFaro({
  // ...
  sessionTracking: { enabled: true, samplingRate: 0.2 },   // 20 % des sessions
});

// Après connexion : identifiant technique, jamais l'e-mail
faro.api.setUser({ id: 'u-7f3a', attributes: { offre: 'premium' } });
Common mistake: Send no email, name or form content. The identifier must be pseudonymous and the collection covered by your privacy policy (see the lesson on operations).

Related articles

Conversion funnels in RUM: measuring where users drop off

Building and reading a conversion funnel with RUM data: steps, rates, order, pitfalls, and implementation in …

Website monitoring: availability, HTTPS monitoring, certificates and performance

Set up website monitoring: availability and HTTPS checks, certificate expiry, response time, Core Web Vitals …

Real User Monitoring (RUM) and Core Web Vitals: measuring what users experience

Why observe the front end, what RUM measures, Core Web Vitals (LCP, INP, CLS) and their thresholds, and the d…

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!