Your organisation runs 25 web applications (React SPAs, a Next.js storefront and a few legacy server-rendered pages) built by 35 teams, with roughly 8 million page views per day. Today each team does something different: some use Sentry, some log to the console in production, one has a home-grown beacon. When something breaks, nobody can tell whether a slow checkout is the browser, the CDN or a back-end service.
Design a front-end observability platform that gives every team:
Discuss the client SDK, the ingestion pipeline, sampling and cost control, privacy, and whether to build on OpenTelemetry or buy Sentry, Datadog RUM or similar. Explain how you would roll it out across teams and measure success.
Front-end observability is harder than back-end observability for three reasons: the runtime is untrusted and heterogeneous (thousands of device, browser, extension and network combinations), data must leave the client over an unreliable connection without hurting the page it is measuring, and the code is minified, so raw errors are unreadable. On top of that, at 8 million page views a day, sending everything is expensive, so sampling and cost control are part of the architecture, not an afterthought.
The platform's job is to answer three questions quickly for any team: Is my app broken? Is it slow? Where in the stack is the problem? Everything in the design traces back to one of those.
Components:
The SDK emits a single envelope format containing typed items. Aligning field names with OpenTelemetry semantic conventions lets front-end and back-end data join.
{
"sdk": { "name": "acme-rum", "version": "3.1.0" },
"resource": {
"service.name": "storefront-web",
"service.version": "2025.06.02-a1b2c3",
"deployment.environment": "production"
},
"session": { "id": "s_7c1e", "sampled": { "errors": true, "rum": true, "replay": false } },
"context": {
"route": "/product/:id",
"userAgent": "Mozilla/5.0 ...",
"connection": { "effectiveType": "4g", "rtt": 100 },
"flags": { "checkout.new-payment-sheet": "treatment" }
},
"items": [
{
"type": "web-vital",
"name": "INP",
"value": 312,
"rating": "needs-improvement",
"attribution": { "interactionTarget": "button#add-to-cart", "inputDelay": 18, "processingDuration": 240, "presentationDelay": 54 },
"navigationType": "navigate"
},
{
"type": "error",
"message": "Cannot read properties of undefined (reading 'price')",
"stack": "TypeError: ...\n at t.render (https://cdn.acme.com/app.4f3a.js:1:20431)",
"mechanism": "react-error-boundary",
"breadcrumbs": [{ "t": 1717322103, "category": "navigation", "data": { "to": "/product/:id" } }],
"traceId": "4bf92f3577b34da6a3ce929d0e0e4736"
}
]
}
Key decisions:
/product/:id), never raw URLs, which keeps cardinality bounded and avoids leaking IDs.CI uploads source maps keyed by service.name + service.version (and ideally a debug ID embedded in the bundle
and the map, which removes ambiguity when file names repeat across releases). Maps are never served publicly; the
build either strips the sourceMappingURL comment or points it at an authenticated location.
interface ObservabilityConfig {
service: string;
version: string;
environment: 'production' | 'staging' | 'development';
endpoint: string; // first-party, e.g. https://www.acme.com/_o/ingest
sampleRates: { errors: number; rum: number; traces: number; replayOnError: number };
propagateTraceTo: (string | RegExp)[]; // only these origins receive traceparent headers
beforeSend?: (event: TelemetryEvent) => TelemetryEvent | null; // scrubbing hook
consent?: () => 'granted' | 'denied' | 'pending';
}
declare function init(config: ObservabilityConfig): void;
declare function captureError(error: unknown, ctx?: Record<string, unknown>): void;
declare function addBreadcrumb(b: { category: string; message?: string; data?: Record<string, unknown> }): void;
declare function mark(name: string): void; // custom timing start
declare function measure(name: string, startMark: string): void; // custom timing end
declare function startSpan<T>(name: string, fn: (span: Span) => Promise<T> | T): Promise<T>;
declare function setContext(key: 'user' | 'flags' | 'tenant', value: Record<string, unknown>): void;
React integration: an <ObservabilityErrorBoundary fallback={...}> that captures with the component stack, a router
integration that emits route-change spans and resets per-route vitals, and a useMeasure('search-results') hook.
acme-observe sourcemaps upload ./dist --service storefront-web --release $GIT_SHA
acme-observe release finalize --service storefront-web --release $GIT_SHA --deploy production
Finalizing a release lets the platform show "new in this release" error groups and compare vitals before and after the deploy.
web-vitals library (attribution build) rather than hand-rolling PerformanceObserver logic; it
handles edge cases such as back/forward cache restores, prerendering and reporting INP at page hide. Note that INP
and CLS are only final when the page is hidden, so the SDK must flush on visibilitychange to hidden.window.onerror/error event, unhandledrejection, error boundaries, and wrapped fetch/XHR for
failed requests. Cross-origin scripts produce opaque "Script error." unless served with CORS headers and
crossorigin="anonymous"; that is a platform checklist item for every app's CDN.Batch events and send them with fetch(url, { method: 'POST', keepalive: true }) or navigator.sendBeacon on page
hide. Keep payloads under 64 KB (the keepalive body budget). Compress large batches with CompressionStream('gzip')
where supported. Never retry aggressively: a failing ingest endpoint must not turn into a self-inflicted DDoS. Use
exponential backoff with a small in-memory queue, and drop on overflow.
Sampling is the main cost lever and must be designed to keep data statistically useful:
traceparent so
back-end spans follow the same decision. Tail-based sampling ("keep all traces with errors or above p99 latency")
is done in the OpenTelemetry Collector, at the cost of buffering.Expected volume after sampling: errors around 5–20M events/day before grouping, vitals around 8M page views × 10% × a handful of metrics, traces a few million spans. That is affordable on either a vendor or a self-hosted ClickHouse.
The SDK injects a W3C traceparent header on requests to allow-listed origins only (propagateTraceTo). Sending it to
third parties leaks IDs and can break CORS preflights because it is not a safelisted header, so every API must allow
traceparent (and tracestate) in Access-Control-Allow-Headers. Server-rendered pages can emit the server trace ID
in a Server-Timing header or a meta tag, so the browser's page-load span joins the server render span. The result is
one trace: click, front-end span, BFF, services, database.
| Option | Strengths | Weaknesses |
|---|---|---|
| Sentry | Best-in-class error grouping, source maps, release health, replay; open-source self-hosting possible | RUM and dashboards less flexible than full APM; cost grows with event volume |
| Datadog RUM, New Relic, Dynatrace | Unified with back-end APM, logs and infra; strong correlation | Expensive at high session volume; vendor lock-in for queries and dashboards |
| Grafana Faro + Grafana stack, Elastic | Open-source front-end SDK with OTel alignment; self-host or Grafana Cloud | More assembly and operations work |
| OpenTelemetry JS (browser) | Vendor-neutral standard, rich instrumentation | Browser support is still less mature than server-side; larger bundle; you build the RUM UX yourself |
| SpeedCurve, DebugBear, Akamai mPulse | Specialist RUM and performance analytics | Performance only, not errors |
| Build in house | Total control | Error grouping, symbolication and alerting UX are years of work |
Recommendation: a thin in-house facade SDK (the API above) so apps never import a vendor directly. Behind it, use a vendor for errors and replay (commonly Sentry), and route vitals and traces into the same backend the back-end teams already use (Datadog, Grafana or Honeycomb) via OTLP where possible, so traces join. Revisit self-hosting when annual vendor spend exceeds the cost of a 3–4 person team. The facade also enforces privacy and sampling policy centrally.
beforeSend and again server-side (defence in depth).doctor check in CI verifies SDK version, source maps uploaded and CORS headers for cross-origin scripts.traceparent
CORS requirements, release-matched source maps.How do you group errors so that one bug is one issue? Fingerprint on the normalised, symbolicated top in-app frames plus error type, ignoring line/column changes across releases where function names match. Allow teams to add custom fingerprint rules for known noisy cases.
Why do lab tools like Lighthouse disagree with RUM? Lab tests use one device and network profile with no user interaction; INP cannot be measured in the lab at all. RUM is the source of truth for user experience; lab is for regression detection in CI.
How do you measure INP for a single-page app's route changes? INP covers all interactions over the page's life, including those in client-side navigations, and is reported at page hide. Use the attribution data to tag the route where the worst interaction happened.
Ad-blockers block your telemetry. What now? Serve ingest from your own domain and path, avoid well-known vendor URLs and script names, and accept some loss. Never try to evade a user's explicit privacy choice.
How do you keep the SDK from causing errors itself? Wrap all SDK code in try/catch with self-reporting at a low sample rate, lazy-load optional plugins, and test the SDK against old browsers in CI. The SDK must fail silent.
Spotted a mistake or a rights concern? Report an issue