Platforms
Browser
Add the SDK to a web app to collect errors, page loads, web vitals and requests.
The browser SDK reports errors, page loads, navigations, web vitals and HTTP requests from a web app. One call to init turns all of it on.
Install the SDK
npm i @openperf/sdkThe browser code is in the @openperf/sdk/browser entry point. It ships as an ES module, so import it from code that your bundler builds.
Copy the DSN
Open Settings → Projects, pick the project and copy the DSN from the Connection section. It looks like https://opf_…@ingest.example.com: the project key before the @, the host that receives the data after it.
Start the SDK
Call init once, as early as possible in your entry file:
import { init } from "@openperf/sdk/browser";
init({
dsn: import.meta.env.VITE_OPENPERF_DSN,
environment: "production",
release: "1.4.0",
});Only dsn is required. environment separates environments and release is needed for source maps. Without a DSN init does nothing. A malformed DSN throws a TypeError.
To check it, load a page with the network panel of your browser open, then wait about ten seconds or switch to another tab. You see POST requests to /v1/traces on the DSN host.
See the first page load
Open Traces in the dashboard. The page you loaded is listed under its path with the pageload label.
To check errors as well, report one by hand and look under Errors:
import { captureException } from "@openperf/sdk/browser";
captureException(new Error("OpenPerf test"));What the SDK collects
| Data | Details |
|---|---|
| Errors | Uncaught errors and unhandled promise rejections, marked Unhandled. A cross-origin script error that arrives without an error object is skipped. |
| Page loads | One trace per page load, named after the path. It starts with the navigation, stays open while requests and custom spans run, and closes after one second of quiet or after 30 seconds. |
| Navigations | One trace per route change in a single-page app: history.pushState, back and forward, and hash routes such as #/orders. A history.replaceState, or a pushState with no user input since the open trace started, counts as a redirect and renames that trace. |
| Web vitals | LCP, INP, CLS, FCP and TTFB. They are sent as one web vitals span per page load or soft navigation, when the page is hidden. |
| Requests | A span for every fetch and XMLHttpRequest call to an HTTP or HTTPS URL, with the method, URL and status. A status of 400 or higher and a network failure mark the span as failed. An aborted request does not. |
| Breadcrumbs | Clicks, console.log, console.warn, console.error, route changes and requests. The last 100 are attached to uncaught errors and to errors reported with captureException. |
Session replays are off until you set a replay sample rate.
Requests to your own origin also get a traceparent header, so a backend that runs the SDK continues the same trace. See Distributed tracing for other origins.
How data is sent
The SDK queues spans and errors and sends them gzipped to the DSN host: every five seconds, as soon as 100 items are queued, and when the page is hidden or closed. A batch that fails to send is dropped.
If your site sets a Content Security Policy, add the DSN host to connect-src.