import { type PartialWithUndefined } from '@augment-vir/common'; import { type ErrorEvent, type EventHint, type TransactionEvent } from '@sentry/core'; import { type AnyDuration, type FullDate, type UtcTimezone } from 'date-vir'; import { FuzzyIndex, type FuzzyIndexKey } from 'fuzzy-vir'; /** * Type for entries in {@link throttleCache}. * * @category Internal */ export type ThrottleCacheEntry = { intervalCount: number; intervalStartAt: FullDate; }; /** * The current throttle cache, keyed by a fuzzy cluster key so near-duplicate error messages share a * throttle bucket. * * @category Internal */ export declare const throttleCache: Map; /** * Fuzzy index used to group near-duplicate error messages together so they share a single throttle * bucket. The `onEvict` hook keeps {@link throttleCache} in sync when a cluster is dropped. * * @category Internal */ export declare const fuzzyErrorIndex: FuzzyIndex; /** * Throttling options. * * @category Internal */ export type ThrottleOptions = { disableThrottling: boolean; /** Duration over which up to `throttleThreshold` events of the same message are allowed. */ thresholdInterval: AnyDuration; /** Disable the sentry log that fires the first time an error is throttled in an interval. */ disableThrottleLog: boolean; /** * Within `thresholdInterval`, if an error message is logged more than this many times, * additional events are dropped until the interval rolls over. */ throttleThreshold: number; }; /** * Default values for {@link ThrottleOptions}. * * @category Internal */ export declare const defaultThrottleOptions: ThrottleOptions; /** * The state transition (if any) that just occurred for an error key. Used by callers to decide * whether to emit a `"Throttling started"` or `"Throttling ended after suppressing N events"` log. * * @category Internal */ export type ThrottleTransition = { kind: 'none'; } | { kind: 'started'; } | { kind: 'ended'; suppressedCount: number; }; /** * Result of a single {@link shouldThrottleEvent} call: whether the event should be dropped, the * fuzzy cluster key it was bucketed into, and the state transition (if any) that the caller may * want to surface as a log. * * @category Internal */ export type ThrottleResult = { shouldThrottle: boolean; /** Undefined when throttling is disabled (the event isn't bucketed). */ errorKey: FuzzyIndexKey | undefined; transition: ThrottleTransition; }; /** * Determines whether an event should be throttled based on previous event counts.This does not emit * any logs itself, the caller is expected to interpret `result.transition` and emit logs as * appropriate. * * @category Internal */ export declare function shouldThrottleEvent( /** Event from Sentry. */ event: Pick, /** EventHint generated by Sentry. */ hint?: Readonly> | undefined, userOptions?: Readonly>): ThrottleResult; /** * Reserved key under `event.contexts` that `sendLog` and `handleError` set via `withScope` to tell * `handleSentrySend` to skip its own throttle check — they've already done the check synchronously * and the event passing through is one they chose to forward. Stripped from the event in * `handleSentrySend` so it never reaches Sentry. * * @category Internal */ export declare const skipBeforeSendThrottleContextKey = "__sentryVirSkipThrottle"; /** * Sets the throttle options consulted by `shouldThrottleSync` (in `send-log.ts`). Called by * `baseInitSentry`. * * @category Internal */ export declare function setActiveThrottleOptions(options: Readonly> | undefined): void; /** * Returns the throttle options registered by the most recent `baseInitSentry` call, or `undefined` * if Sentry has not yet been initialized. * * @category Internal */ export declare function getActiveThrottleOptions(): Readonly> | undefined; /** * Combines a per-call throttle threshold with the active global throttle options, taking the * minimum of the two so the per-call threshold can only ever tighten throttling. * * @category Internal */ export declare function combineThrottleThreshold(base: Readonly> | undefined, perCallThreshold: number | undefined): Readonly>;