/** * Option resolution for `@onepatch/rum`. * * Everything a caller can get wrong is caught HERE, at startup, with a message * that names the fix. The OnePatch agent writes these calls from the * `rum-instrument` skill, so a silently-wrong option would surface days later * as "there is no RUM data" rather than as something anyone can act on. */ import type { RumIdentity, RumUser, RumUserResolver } from "./user.js"; export type RumTraceDestination = { /** Full OTLP HTTP traces endpoint, including its /v1/traces path. */ url: string; /** Browser-safe, write-only ingest credentials for this destination. */ headers?: Record; }; export type RumOptions = { /** Your tenant's OnePatch ingest URL, e.g. `https://acme.logger.onepatch.dev`. */ ingestUrl: string; /** * Your tenant's `op_…` ingest token. Write-only, append-only, scoped to one * tenant — it is designed to ship in a frontend bundle, like a Sentry DSN. */ ingestToken: string; /** * Keep existing OTLP destinations when RUM replaces a browser tracing SDK. * Every destination receives the same session-tagged, redacted spans. Their * origins are excluded from tracing automatically. Do not also initialize * the old tracer provider or its document/fetch/XHR instrumentations. */ additionalTraceDestinations?: RumTraceDestination[]; /** * Apply the app's existing URL redaction before ANY trace destination sees a * span. Called for URL attributes, including page and previous-route URLs. * A throwing callback or non-string result replaces that value with * "[redacted]". Runs before optional scrubQueryStrings. */ redactUrl?: (url: string) => string; /** * A name for this frontend. Becomes `service.name`. Keep it stable: it is * the first column of the telemetry sort key, so every query pivots on it. */ appName: string; /** * `production`, `staging`, … Becomes `deployment.environment.name`. * * Read it from the same source your backend reads its own environment from. * Two halves of one trace labelled differently means every env-filtered query * returns half an answer. */ environment?: string; /** * The build this is. Becomes `service.version`, and should be the commit sha — * every framework exposes one at build time (`VERCEL_GIT_COMMIT_SHA`, * `GITHUB_SHA`, `git rev-parse HEAD`). * * Required, because without it "did the error rate rise?" has no companion * question "which deploy?", and that is the question anyone actually asks. */ appVersion: string; /** * Who is using the app. Required — see `RumIdentity`. One of: * * - the person: `user: { id: session.userId, email: session.email }` * - a resolver, called once and awaited, for when the session lands after * this call: `user: async () => (await me())?.user ?? null` * - `user: "anonymous"`, if this app genuinely has no signed-in user * * Pass it here even if you also call `identifyUser` later; a resolver that * returns `null` on a cold load is the normal shape, and `identifyUser` * updates it. */ user: RumIdentity; /** * Cross-origin backends whose traces should join the browser's, as bare * origins: `["https://api.acme.com"]`. * * Same-origin requests are always joined and do not belong here. Listing an * origin is a request, not a guarantee — see `skipBackendCheck`. */ connectTracesTo?: string[]; /** * Skip the startup check that each `connectTracesTo` origin actually accepts * the `traceparent` header. Only set this if you already know they do: * sending the header to a backend whose CORS policy rejects it makes the * browser block the request outright, which breaks your app, not just its * telemetry. */ skipBackendCheck?: boolean; /** * URLs to leave untraced entirely. Exact strings, or patterns. * * Your OnePatch ingest origin is always added to this list — telemetry that * traces its own delivery is a feedback loop, not data. */ ignoreUrls?: (string | RegExp)[]; /** * Drop the query string and fragment from every recorded URL, leaving * `…/path?`. Off by default. * * It is off because the query and the fragment are frequently the only place * the URL says *which thing* — `?workflow=42`, or a hash route like * `#/workflows/42/runs/abc`. Scrubbing them turns "which workflow was the user * on" into an unanswerable question, and that question is most of why anyone * reads browser telemetry. * * Turn it on when your URLs carry secrets rather than identifiers — * password-reset tokens, magic-link codes, invite codes, email addresses. That * is a real risk and telemetry storage is permanent; it is just not the default * risk, and it is fixable at the source in a way that a lost route is not. */ scrubQueryStrings?: boolean; /** * How slow a page asset — a stylesheet, font or chunk — has to be before its * span is worth keeping, in milliseconds. Defaults to 100. Set `0` to record * every one. * * A page load emits one span per asset, and on a warm cache they are all the * same handful of near-instant hits, re-recorded on every visit by every * visitor. The slow ones are the point: `documentLoad` says the page took * 1.6s and only the asset span says which font it waited on. An asset that * failed is always kept, however fast it failed. */ assetFloorMs?: number; /** * Also forward `console.*` calls. Off by default: console lines carry * personal data far more often than spans do. */ captureConsole?: boolean; /** Log what the SDK is doing. Useful while wiring this up; noisy after. */ debug?: boolean; }; export type ResolvedRumOptions = { tracesUrl: string; ingestToken: string; additionalTraceDestinations: RumTraceDestination[]; redactUrl: ((url: string) => string) | undefined; appName: string; environment: string | undefined; appVersion: string | undefined; /** The person, a resolver for them, or `null` for a deliberate `"anonymous"`. */ user: RumUser | RumUserResolver | null; /** Normalised, de-duplicated, same-origin entries removed. */ crossOriginBackends: string[]; checkBackends: boolean; /** The caller's list, plus a matcher for our own ingest origin. */ ignoreUrls: (string | RegExp)[]; scrubQueryStrings: boolean; /** Resolved asset floor in ms; `0` means keep every asset span. */ assetFloorMs: number; captureConsole: boolean; debug: boolean; /** True when `tracesUrl` is plain http, which the underlying SDK gates. */ insecureIngest: boolean; /** * Things that will make the data harder to use later but are not worth * refusing to start over. Reported once, at startup. */ warnings: string[]; }; export declare class RumConfigError extends Error { constructor(message: string); } /** * Cross-origin propagation targets must be explicit origins. A wildcard here * would attach `traceparent` to every third-party request the page makes — * Stripe, analytics, a CDN — and any one of them refusing the header breaks * that request. There is no safe way to express "everywhere", so we refuse to * let anyone write it. */ export declare function resolveBackends(raw: string[] | undefined, pageOrigin: string | undefined): string[]; export declare function resolveOptions(options: RumOptions, pageOrigin?: string | undefined): ResolvedRumOptions; //# sourceMappingURL=options.d.ts.map