Skip to Content
OpenPerf

Guides

Sampling

Every SDK option that drops errors, samples traces or turns data off, with its default.

By default the SDK sends every trace and every error. The options on this page reduce what leaves your app.

main.ts
import { init } from "@openperf/sdk/browser";

init({
  dsn: import.meta.env.VITE_OPENPERF_DSN,
  tracesSampleRate: 0.2,
  ignoreErrors: ["ResizeObserver loop", /^AbortError: /],
  denyUrls: ["https://widgets.example.net/"],
});

All options

Prop

Type

Sample traces

tracesSampleRate: 0.2 sends about one trace in five. The decision is made once, when the trace starts, and every span of the trace follows it. With a DSN set, a value outside 0 to 1 makes init throw a RangeError.

  • Uncaught errors and errors reported with captureException are always sent, also from traces that were not sampled. An error that is only recorded on a span, such as one thrown inside a startSpan callback, is dropped with the unsampled span. Logs are not sampled either.
  • In the browser, web vitals travel with the page load trace. A lower rate means fewer web vitals samples.
  • A server follows the decision of the caller when a request carries a traceparent header. Its own rate applies to traces that start on the server. See Distributed tracing.

Sample replays

Replays are off by default. replaysSessionSampleRate and replaysOnErrorSampleRate pick the sessions to record, independently of tracesSampleRate. See Session replay.

Drop errors in the browser

The three options run in this order: ignoreErrors, denyUrls, beforeSend. They apply to uncaught errors, to captureException and to errors that fail a span.

  • ignoreErrors checks the message. A string matches a message that contains it, a RegExp a message it matches. Both are also tried against Type: message, so /^TypeError: / drops by type.
  • denyUrls checks the file of the top stack frame only. An error that starts in your code is kept, even when a deeper frame is in a listed file.
  • beforeSend gets the error and returns what to send.
main.ts
import { init } from "@openperf/sdk/browser";

init({
  dsn: import.meta.env.VITE_OPENPERF_DSN,
  beforeSend: (captured) => {
    if (captured.type === "AbortError") {
      return null;
    }

    return { ...captured, message: captured.message?.replace(/\d{6,}/g, "[number]") };
  },
});

captured holds error (the thrown value), message, type and stack. Return null to drop the error, or the object with a changed message, type or stack. When the callback throws, the error is sent unchanged. The callback runs once per error object.

These three options exist in the browser only. The server SDK has no options that filter errors.

Send less from the server

  • init({ dsn: process.env.OPENPERF_DSN, captureLogs: false }) keeps traces and errors and stops sending logs.
  • The SDK stays off when neither dsn nor the OPENPERF_DSN variable is set, or when OTEL_SDK_DISABLED=true, for example in local runs or tests.

What the SDK drops on its own

  • In the browser, the same error is sent once a minute at most, and no more than 100 different errors are sent per minute.
  • In the browser, script errors from other origins that arrive without an error object are skipped.
  • When the server answers 429, the browser SDK pauses for the time in Retry-After: 60 seconds when the header is missing, five minutes at most. Data collected during the pause is dropped.
  • On the server, the fs, dns, net and router instrumentations, host metrics and runtime metrics are off.

Filters in the project

A project has its own Inbound filters: Browser extensions, Known browser noise and Web crawlers. They run on the server after the data arrives. See Projects.

On this page