@uxf/sentry

Sentry wiring for UXF Next.js apps: what gets scrubbed before an event leaves the process, what session replay may record, and how the build uploads source maps.
When to use
Use it instead of copying instrumentation-client.ts, sentry.server.config.ts, sentry.edge.config.ts and the withSentryConfig block between projects. It is not a wrapper around the Sentry SDK — you still call captureException and friends from @sentry/nextjs directly.
Each runtime is a separate subpath import, so a browser entry point never pulls in server code:
@uxf/sentry/client — instrumentation-client.ts
@uxf/sentry/server — sentry.server.config.ts
@uxf/sentry/edge — sentry.edge.config.ts
@uxf/sentry/config — next.config.ts
@uxf/sentry/privacy — the scrubber and the privacy integration on their own
@uxf/sentry/constants — the defaults, for composing a config from scratch
@uxf/sentry/verify — a post-build check, also available as the uxf-sentry-verify binary
Installation
yarn add @uxf/sentry
Peers: @sentry/nextjs, @uxf/core, next.
Usage
// src/instrumentation-client.ts
import { initBrowserSentry } from "@uxf/sentry/client";
export const onRouterTransitionStart = initBrowserSentry({ tracesSampleRate: 0.1 });
// sentry.server.config.ts
import { initServerSentry } from "@uxf/sentry/server";
initServerSentry();
// next.config.ts
import { withUxfSentry } from "@uxf/sentry/config";
export default withUxfSentry(nextConfig, { project: "rehatab-web" });
withUxfSentry returns the function form of a Next.js config, because it needs the phase: next start loads the config too, on a server that rightly has no auth token, and only next build should ask for one. Next.js accepts a function export as it is, and withUxfSentry takes either an object or another config function. Put plugins that only accept an object inside it, not around it.
instrumentation.ts stays as Next.js generates it. Its dynamic imports exist for bundling and hiding them behind a helper would save nothing.
Masking
Replay masking is driven by two presets.
| preset |
what it does |
how you open it up |
strict |
masks all text, blocks all media |
data-sentry-unmask |
selective |
shows everything, masks only what is marked |
data-sentry-mask |
strict applies when privacy is omitted, so a project that configures nothing errs toward privacy. selective suits apps whose replays are unreadable otherwise, and which have gone through their screens marking sensitive areas.
initBrowserSentry({ privacy: "selective" });
// adjustments are appended to the preset, so its own selectors stay
initBrowserSentry({ privacy: { preset: "selective", mask: [".invoice-total"] } });
// a function takes the list over entirely
initBrowserSentry({ privacy: { preset: "strict", block: () => [] } });
mask, unmask, block, unblock and ignore follow the same rule as everywhere else in the package: an array is added to what the preset already has, a function receives it. Adding one selector therefore cannot silently remove [data-sentry-unmask] or stop blocking canvases.
data-sentry-mask and .sentry-mask are Sentry's own default selectors. data-sentry-unmask is not — it works because both presets pass it to unmask.
Anything portalled escapes an ancestor's marker. Modals, drawers, popovers, tooltips, toasts and the menus of selects and comboboxes render into a portal, outside the DOM subtree they belong to, so a data-sentry-mask on a page wrapper does not reach them. Mark the portalled content itself. The four select-like components from @uxf/ui and @uxf/form (Select, MultiSelect, Combobox, MultiCombobox) take a class for their menu:
import { SENTRY_MASK_CLASS_NAME } from "@uxf/sentry/constants";
<Combobox dropdownClassName={SENTRY_MASK_CLASS_NAME} … />;
The literal "sentry-mask" works just as well, but a typo in it disables the masking without any error, so the constant is worth the import.
Grid cells are masked by column, through @uxf/data-grid rather than here. Set isSensitive on the column config in the PHP grid type (->replaceConfig(isSensitive: true), uxf/datagrid 3.84.2 or newer), or pass sensitiveColumns to the DataGrid component. The data-grid README has the details. That marks the body cells of the table and nothing else: the chips of active filters show the filtered value, so a grid filtered by surname shows the surname above the masked column. Mark those where it matters.
Request and response bodies never enter a replay: both presets set networkDetailDenyUrls: [/.*/]. Overriding that takes an explicit networkDetail.
Extending
Nothing here is a black box. browserSentryOptions() composes the options and hands them back without calling init, and every default is exported from @uxf/sentry/constants.
Lists accept either an array, appended to the defaults, or a function that receives the defaults:
initBrowserSentry({
ignoreErrors: ["ResizeObserver loop limit exceeded"],
denyUrls: (defaults) => defaults.filter((url) => !String(url).includes("facebook")),
integrations: (defaults) => [...defaults, myIntegration()],
});
Sampling and noise
Defaults, taken from where the live projects actually settled rather than from the template:
| option |
default |
why |
tracesSampleRate |
0.1 |
10 of the 11 projects that set it use this |
replaysSessionSampleRate |
0.0 |
all 11 |
replaysOnErrorSampleRate |
1.0 |
all 11 |
A replay is sent only for a session in which an error was captured, so on a dev environment with a handful of visits Sentry sees almost nothing. That includes its own "Hydration Error" issues, which it finds in replay recordings. To check a change on dev, record every session there:
initBrowserSentry({ replaysSessionSampleRate: process.env.NEXT_PUBLIC_STAGE === "dev" ? 1.0 : 0.0 });
Noise groups
Third-party noise is grouped by where it comes from, and only the groups that cannot be first-party code are on by default:
| group |
default |
what it covers |
extensions |
on |
browser extensions injecting scripts, crypto wallets |
in-app-browsers |
on |
Seznam, iOS WKWebView and Android WebView JS bridges* |
cross-origin |
off |
blocked frames and storage, non-error promise rejections |
ads |
off |
GPT/AdSense, Sklik, viewability trackers, consent, embeds |
network |
off |
Failed to fetch, aborted requests |
* One of its entries, Seznam's injected touchmove handler, raises the generic V8 text Cannot read properties of undefined (reading 'touches'). A real bug in first-party gesture code raises the same text, so that entry drops an error only when none of its frames comes from a real file (ignoreFramelessErrors on the group). Everything else in the table matches by message or by script URL, the way ignoreErrors and denyUrls do, with one more exception: postMessage in ads, a word any embed or payment gateway code of the app can raise, is frameless-only too.
Two filters apply always, outside the groups: the rejection of Outlook's link scanner (Object Not Found Matching Id), and hydration errors raised in headless Chrome (UxfBotHydrationErrorFilter). Crawlers and prerender services hydrate with a skewed clock or a DOM they rewrote, and a mismatch real visitors hit still reports from their browsers. To see the headless ones as well, remove the integration by name:
initBrowserSentry({ integrations: (defaults) => defaults.filter((i) => i.name !== "UxfBotHydrationErrorFilter") });
initBrowserSentry({ noise: ["ads", "cross-origin"] });
// drop a default group
initBrowserSentry({ noise: (defaults) => defaults.filter((group) => group !== "in-app-browsers") });
The entries come from what production actually reports, not from a list of plausible vendors, so they are worth revisiting against Sentry now and then. A new vendor shows up as a cluster of low-count issues whose stack ends in one third-party file.
The three off-by-default groups each hide something an app might genuinely need to see: cross-origin matters to a widget embedded in someone else's page, ads can swallow a bug in your own ad callback, and network hides genuinely broken endpoints. Turn them on deliberately.
Project-specific filters stay in the project. A business error like Article does not exist or a cart-expiry message belongs in that app's ignoreErrors, not here.
GraphQL across versions
When the frontend and the API run different versions, every query that uses a field, argument, type or enum value the API's schema lacks fails validation: Cannot query field "discount" on type "Order". That happens for a few seconds in every deploy that replaces the web and the API as separate services, while the new web already talks to the old API, from the browser and from the server render alike. It also happens for as long as a tab keeps running an old bundle after a deploy that removed or renamed something in the schema, until the user reloads.
GRAPHQL_VERSION_SKEW_ERRORS from @uxf/sentry/constants matches those validation errors, as graphql-js and webonyx/graphql-php word them. An event is dropped only when every error Apollo Client joined into its message is one of them, so a real error in the same response is still reported. It is the app's own code failing, not third-party noise, so it is not a noise group, and nothing applies it by default. Pass it to ignoreErrors in every runtime that queries GraphQL:
// instrumentation-client.ts
import { initBrowserSentry } from "@uxf/sentry/client";
import { GRAPHQL_VERSION_SKEW_ERRORS } from "@uxf/sentry/constants";
export const onRouterTransitionStart = initBrowserSentry({ ignoreErrors: GRAPHQL_VERSION_SKEW_ERRORS });
// sentry.server.config.ts, and sentry.edge.config.ts with initEdgeSentry if middleware or an edge route queries GraphQL
import { GRAPHQL_VERSION_SKEW_ERRORS } from "@uxf/sentry/constants";
import { initServerSentry } from "@uxf/sentry/server";
initServerSentry({ ignoreErrors: GRAPHQL_VERSION_SKEW_ERRORS });
Only do it in an app whose codegen validates every GraphQL document against the schema in CI. That check rules out every other cause; without it these errors are real bugs. The price: Sentry no longer tells you about tabs stuck on an old bundle, nor about an API rolled back under a newer web. The pages using the missing fields visibly break in both cases, and an app that removes fields from its schema should prompt open tabs to reload rather than rely on Sentry to notice.
Two opt-ins
Both of these are off by default because neither works on the client alone, and both fail in a way the app cannot see.
Profiling. isProfilingEnabled adds browserProfilingIntegration together with profileLifecycle: "trace" and profileSessionSampleRate: 0.01. It needs the document to be served with Document-Policy: js-profiling, which is what withJsProfilingHeader adds, so turn both on together:
// next.config.ts
export default withJsProfilingHeader(withUxfSentry(nextConfig, { project: "rehatab-web" }));
// instrumentation-client.ts
export const onRouterTransitionStart = initBrowserSentry({ isProfilingEnabled: true });
The lifecycle is the part worth knowing. profileLifecycle defaults to "manual" in the SDK, which waits for a startProfiler() call. No UXF app makes one, so every project that set only profileSessionSampleRate was shipping the profiling integration and collecting nothing. Projects on the deprecated profilesSampleRate were unaffected, because that option predates the lifecycle split.
Third-party error filtering. isThirdPartyErrorFilterEnabled adds thirdPartyErrorFilterIntegration, which drops errors raised exclusively by code the bundler did not build. It recognises first-party frames by an application key the bundler plugin injects — withUxfSentry passes NEXT_PUBLIC_SENTRY_DSN as that key, and the filter looks for the same variable, never for a dsn passed to initBrowserSentry, which the build cannot see — and when nothing injects it, every frame reads as third-party and every error is dropped. Sentry goes quiet and nothing says why, which is why this is opt-in and the noise groups above, which need no build-time support, are not.
Turbopack injects the key since Next 16, the oldest version @uxf/sentry supports; webpack always does. uxf-sentry-verify does not check this — it checks debug IDs, which are a different injection.
URL scrubbing
Every event, breadcrumb and replay URL passes through a scrubber before it leaves the process: the request URL and query string, the Referer header, span descriptions and the URL keys of span data (the root span's included, which lives in the trace context), and the network and navigation frames of a replay recording. Query parameters are an allowlist (page, perPage, section, sort, tab, view); everything else becomes [Filtered]. Path segments are filtered when they look like identifiers: UUIDs, hex digests, anything made only of digits, anything containing @, and any segment of 16 characters or more that is not a kebab- or snake-cased route name. Segments are judged decoded, so editace-doplňkové-služby counts as a slug although it arrives percent-encoded. Credentials embedded in a URL (https://user:secret@host/) are dropped.
The fragment is scrubbed too, which is easy to forget because it never reaches the server: #access_token=… is the OAuth implicit-flow shape and hash routers put record ids there. A fragment is split at ? first, so a hash route keeps its shape while both halves are scrubbed: #/detail/<uuid>?tab=a becomes #/detail/[Filtered]?tab=a. Without the ?, a fragment containing = is treated as a query string and filtered by the same allowlist, and anything else is treated as a path, so #kontakt survives.
That last rule matters: a plain length threshold also matches ordinary route names, and /editace-doplnkove-sluzby/<uuid> reaching Sentry as /[Filtered]/[Filtered] costs you the transaction name for no privacy gain. It errs the other way now — a long single word is filtered, and so is a bare number, which loses a little grouping on date-shaped routes and is the right trade for a privacy layer. Projects using other id formats can tighten it:
initBrowserSentry({ scrub: { isOpaqueSegment: (segment) => segment.startsWith("ord_") } });
One URL cannot be scrubbed: the page URL inside a replay recording. The recording's meta event holds window.location.href verbatim, and Sentry offers no hook for it: beforeAddRecordingEvent receives custom frames only, and the recording never passes through an event processor. Whatever the address bar shows, path, query and fragment alike, is readable in every replay. The scrubber keeps an id out of an error event; only keeping it out of the URL keeps it out of the replay.
Pages replay must not record
A one-time token in the URL is worse than an id: whoever reads the replay can set the password of an account the invitation or recovery email was meant for, until someone uses the token. So replay stays away from those pages altogether. replayDenyUrls lists them, and a string matches anywhere in the decoded path, query and fragment:
initBrowserSentry({ replayDenyUrls: [/^\/token-check\//] });