import { PrivacyConfig } from "./privacy.js"; import { E as ErrorTrackingConfig, a as trace, g as FrustrationConfig, i as getTraceparent, n as extractContext, o as ConsoleLogsConfig, r as getActiveContext, t as TraceContext, x as BreadcrumbsConfig } from "./functional-BxmUx0Y6.js"; import { Sampler, SpanProcessor } from "@opentelemetry/sdk-trace-base"; import { context } from "@opentelemetry/api"; //#region src/error-tracking/index.d.ts /** * Manually capture an exception. * Use this for caught errors you want to track. */ declare function captureException(error: unknown): void; //#endregion //#region src/full.d.ts interface AutotelWebFullConfig { /** Service name for the browser application */ service: string; /** * OTLP endpoint URL for trace export (e.g. https://api.example.com/v1/traces). * If not set, no export (spans still created; use spanProcessor for custom export). */ endpoint?: string; /** * Treat every request to the collector's origin as telemetry, not only the * OTLP paths. * * Set this when the collector serves more than OTLP - autotel's devtools * collector serves its own UI and query API beside `/v1/traces` - so the * widget that displays the traces is itself a fetch from this page. Tracing * that makes the tool a source of the data it displays: every poll of the * trace list writes another trace to the list. * * Off by default, because nothing in the URL can tell a dedicated collector * from an OTLP endpoint proxied through the application's own server, and * getting that wrong silences the requests the page exists to make. The * page's own origin is never excluded, whatever this says. * * @example * ```typescript * init({ * service: 'my-spa', * endpoint: 'http://localhost:4848', // devtools collector, nothing else * collectorOwnsOrigin: true, * }); * ``` * * @default false */ collectorOwnsOrigin?: boolean; /** * Custom span processor(s). If provided, used instead of default BatchSpanProcessor + OTLP exporter. * When endpoint is set, this is ignored. */ spanProcessor?: SpanProcessor; /** * Processors that decorate spans on the way out rather than export them. * * Separate from `spanProcessor` on purpose: that one *replaces* the pipeline, * so passing an enricher there silently switches off the export that was just * configured. These are added to the pipeline, and ordered ahead of the * exporter so an attribute they add is one the exporter actually sends. * * ```ts * import { posthogCompatibility } from 'autotel-posthog'; * initFull({ service: 'web', endpoint, spanEnrichers: [posthogCompatibility()] }); * ``` */ spanEnrichers?: SpanProcessor[]; /** * Session identity stamped on every span as `session.id`, so a visit's * navigation, fetches, vitals, clicks and errors can be reassembled into one * journey. Tab-scoped random UUID, no user-derived data; a gap longer than * `timeoutMs` starts a new session linked by `session.previous_id`. * * Pass `false` to emit no session attributes. * * @default { timeoutMs: 1_800_000 } */ session?: false | { timeoutMs?: number; /** Emit `session.start` / `session.end` events. @default false */ emitEvents?: boolean; }; /** * Sample rate 0–1. Default 1.0. Use e.g. 0.1 in production. * * Decided by hashing the session id, so a sampled session is sampled whole. * Sampling per span instead would keep a tenth of every visit and leave none * of them reconstructable. Overridden by `remoteConfigUrl` when that supplies * a rate. */ sampleRate?: number; /** * Custom sampler. If set, `sampleRate` is ignored — for every signal, not * just spans. * * A sampler decides about spans, and there is nothing to ask it about a log * record or an event, so those are exported unsampled. Use `sampleRate` * instead where events and logs need sampling too. */ sampler?: Sampler; /** Enable document load / navigation spans. @default true */ captureNavigation?: boolean; /** * Keep the one `resourceFetch` span per script, stylesheet and image that * document-load instrumentation records under `documentLoad`. * * Off in development by default: a dev server serves every module as its * own request, so one page load becomes hundreds of spans that describe the * bundler rather than the app. `documentLoad` and `documentFetch` stay. * Development is `process.env.NODE_ENV !== 'production'` where a bundler * substituted one, else a page served from localhost. * * @default true in production, false in development */ captureResourceTiming?: boolean; /** Enable fetch instrumentation. @default true */ captureFetch?: boolean; /** Enable XMLHttpRequest instrumentation. @default true */ captureXHR?: boolean; /** * Emit http.client.network_timing events from Resource Timing API. * @default true */ captureNetworkTiming?: boolean; /** * Copy original HTTP span attributes onto network_timing event for backends that need them. * @default false */ copyHttpSpanAttributesToEvent?: boolean; /** Optional click capture, emitted as `app.widget.click` events. */ userInteraction?: { enabled: boolean; /** CSS selectors for elements to track (e.g. ['button', '[data-track]']). Default: ['button', 'a'] */ selectors?: string[]; }; /** * Record unhandled errors (window.onerror, unhandledrejection) on active span or create unhandled_error span. * @default true */ captureErrors?: boolean; /** * Capture Web Vitals (LCP, INP, CLS, FCP, TTFB), one `browser.web_vital` * event per metric. * @default true */ captureWebVitals?: boolean; /** * Options for Web Vitals. reportAllChanges: pass through to web-vitals (default false for stability). */ webVitals?: { reportAllChanges?: boolean; }; /** * Capture long tasks (main thread blocking >= 50ms) as `app.jank` events. * Opt-in; can be noisy. * @default false */ captureLongTasks?: boolean; /** * Advanced error tracking configuration. * When captureErrors is true (default), this configures rate limiting, suppression, etc. */ errorTracking?: Omit; /** * Report clicks that achieved nothing (`dead`) and clicks repeated in * frustration (`rage`) as `app.widget.click.frustration` events. * * The one browser signal a tracer cannot produce for itself: a click that * does nothing runs no code, so the trace is empty exactly where the user is * stuck. Off by default — it installs a document-wide MutationObserver. * * @default false */ captureFrustration?: boolean | Omit; /** * Report how far down each page anyone actually got, as a * `browser.page_engagement` event on page hide and route change. * * @default false */ captureEngagement?: boolean; /** * Keep a bounded trail of what happened before an error — clicks, console * output, whatever you add via `addBreadcrumb` — and attach it to the * exception as `exception.breadcrumbs`. * * @default false */ breadcrumbs?: boolean | (BreadcrumbsConfig & { console?: boolean; clicks?: boolean; }); /** * Export `console.*` output as OpenTelemetry log records, under the * instrumentation scope `console`. * * Distinct from `breadcrumbs`: this feeds the log pipeline, breadcrumbs * attach the same output to an exception for whoever reads the error. * Enabling both is reasonable. * * Lean-mode only for now — it rides the hand-rolled OTLP transport in * `span-exporter`, so it needs `endpoint` to be set. * * @default false */ captureConsoleLogs?: boolean | ConsoleLogsConfig; /** * URL of a JSON file that can change capture settings without a release — * sampling rate, which signals are on, which errors to suppress. * * Served from wherever the app already is; autotel has nothing to serve it * from. The last good copy is cached and applied synchronously on the next * visit, so a failed fetch changes nothing. */ remoteConfigUrl?: string; /** Redact PII from error messages and stack traces before export. Preset or custom config. */ attributeRedactor?: 'default' | 'strict' | 'pci-dss' | { valuePatterns?: Array<{ name: string; pattern: RegExp; replacement?: string; }>; replacement?: string; }; /** * Cross-origin destinations allowed to receive `traceparent` and `baggage`. * Same-origin always propagates; everything else is opt-in, because an * unexpected header makes the browser preflight and a server that does not * allow it rejects the request. Spans are recorded either way. * * Same field, same meaning, as lean mode's `propagateTo`. */ propagateTo?: string[]; /** Privacy controls (origin filtering, DNT, GPC). Applied to which requests get traced. */ privacy?: PrivacyConfig; /** * W3C `baggage` header injection for `setBaggage()` (from `autotel-web/baggage`). * * Same-origin requests receive the header. Cross-origin destinations need * `allowedOrigins`. This is the same fail-closed rule as lean `init()`. */ baggage?: { allowedOrigins?: string[]; }; /** Enable debug logging. @default false */ debug?: boolean; } /** * Initialize full browser tracing (spans + optional export). * * Call once, client-side only. Uses OpenTelemetry WebTracerProvider; no Zone.js. * * @example * ```ts * import { initFull } from 'autotel-web/full' * initFull({ * service: 'my-app', * endpoint: 'https://api.example.com/v1/traces', * sampleRate: 0.1, * captureNetworkTiming: true, * userInteraction: { enabled: true, selectors: ['button', '[data-track]'] } * }) * ``` */ declare function initFull(config: AutotelWebFullConfig): void; /** * Create a span with the current context (full mode). */ declare function span(name: string, fn: (s: { setAttribute: (k: string, v: string | number | boolean) => void; end: () => void; }) => T): T; /** * Set attribute on the active span (full mode). */ declare function setAttribute(key: string, value: string | number | boolean): void; /** * Add an event to the active span (full mode). */ declare function addEvent(name: string, attributes?: Record): void; /** * Run a function with the given context (for manual async propagation in full mode). */ declare function runWithContext(ctx: ReturnType, fn: () => T): T; /** * Reset full initialization state (for testing). * @internal */ declare function resetFullForTesting(): void; //#endregion export { AutotelWebFullConfig, type TraceContext, addEvent, captureException, extractContext, getActiveContext, getTraceparent, initFull, resetFullForTesting, runWithContext, setAttribute, span, trace };