import { ExceptionStackTrace, LogEvent, NetworkEvent, NavigationEvent, TracewayEvent } from '@tracewayapp/core'; export { CollectionFrame, CustomEvent, ExceptionStackTrace, LogEvent, NavigationEvent, NetworkEvent, ReportRequest, SessionRecordingPayload, TracewayEvent } from '@tracewayapp/core'; declare const DEFAULT_IGNORE_PATTERNS: Array; interface TracewayFrontendOptions { debug?: boolean; debounceMs?: number; retryDelayMs?: number; version?: string; sessionRecording?: boolean; sessionRecordingSegmentDuration?: number; /** * Upload every segment of the session regardless of whether an exception * fires. Each segment (default ~30 s, see `sessionRecordingSegmentDuration`) * becomes its own `session_recordings` row on the backend, all linked to a * parent `sessions` row by `sessionId`. * * - Inactivity timeout: 15 min ends the session. * - Max duration: 60 min ends the session. * - `pagehide` ends the session and triggers a final flush. * * Defaults to false to preserve the existing exception-only behaviour. */ recordAllSessions?: boolean; ignoreErrors?: Array; beforeCapture?: (exception: ExceptionStackTrace) => boolean; /** Mirror console.{log,info,warn,error,debug} into the rolling log buffer. Default true. */ captureLogs?: boolean; /** Record fetch / XHR requests as network actions. Default true. */ captureNetwork?: boolean; /** Record History API push/replace/pop as navigation actions. Default true. */ captureNavigation?: boolean; /** Window kept in the rolling log/action buffers. Default 10_000ms. */ eventsWindowMs?: number; /** Hard cap applied independently to logs and actions. Default 200. */ eventsMaxCount?: number; /** * When `true`, every `fetch` / `XHR` response with `status >= 500` is also * reported to Traceway as a synthetic exception (in addition to the network * action it already records). 4xx responses are intentionally not captured * by this flag — see `DEFAULT_IGNORE_PATTERNS`. Default `false`. */ captureHttpServerErrors?: boolean; } declare class TracewayFrontendClient { private apiUrl; private token; private debug; private debounceMs; private retryDelayMs; private version; private pendingExceptions; private pendingRecordings; private pendingSessions; private isSyncing; private debounceTimer; private retryTimer; private recorder; private lifecycle; private readonly recordAllSessions; private sessionId; private sessionStartedAt; private segmentIndex; /** * App-defined attributes attached to every session and exception emitted by * this client. Set via setAttribute() / setAttributes(). Auto-collected * defaults take a back seat to these; per-call exception attributes win * over both. */ private globalAttributes; /** * Set true once the page begins unloading (`pagehide`). Forces the next * sync to dispatch via `fetch(..., { keepalive: true })` with a raw JSON * body so the closing-session payload survives the navigation. */ private unloading; private ignoreErrors; private beforeCapture; readonly captureLogs: boolean; readonly captureNetwork: boolean; readonly captureNavigation: boolean; readonly captureHttpServerErrors: boolean; private readonly logs; private readonly actions; constructor(connectionString: string, options?: TracewayFrontendOptions); private beginSession; /** * Merge browser defaults with whatever app-level scope was set via * setAttribute(). App attrs override defaults on key collision. */ private composedSessionAttributes; /** * Attach a key/value attribute to every subsequent session and exception * emitted by this client. If a session is already open, its attributes are * refreshed on the backend immediately. Setting the same key replaces the * previous value. */ setAttribute(key: string, value: string): void; /** * Bulk version of setAttribute. Caller's keys override existing scope. * Triggers one session refresh after the merge, not one per key. */ setAttributes(attrs: Record): void; removeAttribute(key: string): void; clearAttributes(): void; /** @internal — exposed for tests. */ currentAttributes(): Record; /** * When the global scope changes mid-session, push a session-refresh * payload (no endedAt) so the backend's ON CONFLICT update writes the new * attribute blob into the existing row. Without this the new attrs would * only land at session close. */ private refreshOpenSessionAttributes; private endSession; /** * Begin a fresh session after the page came back from bfcache. The previous * session was closed by `pagehide`; we generate a new sessionId and reset * the unloading flag so subsequent syncs go back to the gzipped path. */ private restartSession; private handleSegmentReady; private queueSegment; /** @internal — exposed for tests. */ currentSessionId(): string | null; recordLog(level: LogEvent["level"], message: string): void; recordNetworkEvent(event: Omit & { timestamp?: string; }): void; private isOwnReportUrl; recordNavigationEvent(event: Omit & { timestamp?: string; }): void; /** * Records a custom user-defined breadcrumb. Use to log any app-level action * that should ride along with the next exception ("user_tapped_pay", * "cart_synced", etc.). Always recorded — there is no per-category opt-out. */ recordAction(category: string, name: string, data?: Record): void; /** @internal — exposed for tests. */ bufferedLogs(): LogEvent[]; /** @internal — exposed for tests. */ bufferedActions(): TracewayEvent[]; /** * Promote a 5xx HTTP response into a captured exception. Called from the * fetch / XHR wrappers when `captureHttpServerErrors` is enabled. */ captureHttpServerError(method: string, url: string, statusCode: number): void; addException(exception: ExceptionStackTrace): void; private shouldIgnore; private scheduleSync; private doSync; private scheduleRetry; flush(timeoutMs?: number): Promise; } declare function formatBrowserStackTrace(error: Error): string; declare function installGlobalHandlers(client: TracewayFrontendClient): void; /** * Mirrors `console.{debug,log,info,warn,error}` calls into the client's log * buffer. The original console output is preserved — we only piggyback on the * call. */ declare function installConsoleInstrumentation(client: TracewayFrontendClient): void; /** * Records SPA navigation transitions reported via the History API. * * Patches `history.pushState` / `history.replaceState` and listens for * `popstate`. Hash-only changes are also captured via `hashchange`. * * Static ``-driven full-page loads do not flow through here (the document * unloads before we can record). Use server-side analytics for those. */ declare function installNavigationInstrumentation(client: TracewayFrontendClient): void; declare function getActiveDistributedTraceId(): string | null; declare function init(connectionString: string, options?: TracewayFrontendOptions): void; declare function captureException(error: Error, options?: { distributedTraceId?: string; }): void; declare function captureExceptionWithAttributes(error: Error, attributes?: Record, options?: { distributedTraceId?: string; }): void; declare function captureMessage(msg: string): void; /** * Records a custom user-defined breadcrumb. Use to log any app-level action * that should ride along with the next exception ("user_tapped_pay", * "cart_synced", etc.). */ declare function recordAction(category: string, name: string, data?: Record): void; declare function flush(timeoutMs?: number): Promise; /** * Attach a key/value attribute to every session and exception emitted from * here on (e.g. `setAttribute("userId", "42")`). Persists in memory until * cleared. If a session is already open, the attribute lands on it via a * refresh upsert. */ declare function setAttribute(key: string, value: string): void; /** Bulk version of setAttribute. Caller's keys overwrite existing scope. */ declare function setAttributes(attrs: Record): void; /** Remove a single key from the global scope. */ declare function removeAttribute(key: string): void; /** Clear all attributes set via setAttribute / setAttributes. */ declare function clearAttributes(): void; declare const DISTRIBUTED_TRACE_HEADER = "traceway-trace-id"; declare function createAxiosInterceptor(): (config: any) => any; export { DEFAULT_IGNORE_PATTERNS, DISTRIBUTED_TRACE_HEADER, TracewayFrontendClient, type TracewayFrontendOptions, captureException, captureExceptionWithAttributes, captureMessage, clearAttributes, createAxiosInterceptor, flush, formatBrowserStackTrace, getActiveDistributedTraceId, init, installConsoleInstrumentation, installGlobalHandlers, installNavigationInstrumentation, recordAction, removeAttribute, setAttribute, setAttributes };