import { Session } from '../sessions/SessionManager'; import { MetaData } from '../events/meta-data'; import { Config } from '../orchestration/config'; import { PageAttributes } from '../sessions/PageManager'; import { AppMonitorDetails, UserDetails, RumEvent } from '../dispatch/dataplane'; import EventBus, { Topic } from '../event-bus/EventBus'; import { EventMetadataHook, RecordEvent } from '../plugins/types'; /** * A cache which stores events generated by telemetry plugins. * * The event cache stores meta data and events until they are dispatched to the * data plane. The event cache removes the oldest event once the cache is full * and a new event is added. */ export declare class EventCache { private eventBus; private appMonitorDetails; private config; private events; private candidates; private sessionManager; private pageManager; private enabled; private installationMethod; private pluginFlushHook?; private readonly applicationAttributes; private eventMetadataHook?; private droppedEvent; private sessionLimitExceeded; /** * @param applicationDetails Application identity and version. * @param batchLimit The maximum number of events that will be returned in a batch. * @param eventCacheSize The maximum number of events the cache can contain before dropping events. * @param sessionManager The sessionManager returns user id, session id and handles session timeout. * @param pageManager The pageManager returns page id. */ constructor(applicationDetails: AppMonitorDetails, config: Config, eventBus?: EventBus); /** * The event cache will record new events or new meta data. */ enable(): void; /** * The event cache will not record new events or new meta data. Events and * meta data which are already in the cache will still be accessible. */ disable(): void; setPluginFlushHook(fn: () => void): void; /** * Update the current page interaction for the session. */ recordPageView: (payload: string | PageAttributes) => void; /** * Returns true if the session is sampled, false otherwise. */ isSessionSampled(): boolean; /** * Add an event to the cache and reset the session timer. * * If the session is being recorded, the event will be recorded. * If the session is not being recorded, the event will not be recorded. * * @param type The event schema. * @param eventData The event data. */ recordEvent: RecordEvent; /** * Adds a candidate to the cache and reset session timer * * @param eventType The event schema. * @param eventData The event data. */ recordCandidate: RecordEvent; /** * Returns the current session (1) if a session exists and (2) if the * current URL is allowed. Returns undefined otherwise. */ getSession: () => Session | undefined; /** * Returns the current session ID, minting a new one if needed. */ getSessionId: () => string; /** * Adopt an externally-minted session ID. Delegates to SessionManager. */ pinSessionId: (sessionId: string) => void; /** * Begin a new session immediately. Delegates to SessionManager. */ startSession: (options?: { sessionId?: string; userId?: string; }) => string; /** * Returns the current anonymous user ID, or NIL_UUID when cookies are * disabled and no manual userId has been seeded. */ getUserId: () => string; /** * Adopt an externally-supplied user ID. Delegates to SessionManager. */ pinUserId: (userId: string) => void; /** * Returns true if there are one or more events in the cache. */ hasEvents(): boolean; /** * Returns true if there are one or more event candidates in the cache. */ hasCandidates(): boolean; /** * Removes and returns the next batch of events. */ getEventBatch(flush?: boolean): RumEvent[]; /** * Returns an object containing the AppMonitor ID and application version. */ getAppMonitorDetails(): AppMonitorDetails; /** * Returns an object containing the session ID and user ID. */ getUserDetails(): UserDetails; /** * Set custom session attributes to add them to all event metadata. * * @param payload object containing custom attribute data in the form of key, value pairs */ addSessionAttributes(sessionAttributes: { [k: string]: string | number | boolean; }): void; /** * Add an event to the cache. * * @param type The event schema. */ private addRecordToCache; /** Returns session-level metadata common to all events in a batch. */ getCommonMetadata(): MetaData; /** * Register a hook that decorates every recorded event's metadata. The * hook receives the in-progress merged metadata (page attributes only — * manual metadata is applied after the hook) and returns additional * keys. Manual metadata always wins over hook output. Replaces any * previously set hook. */ setEventMetadataHook(hook: EventMetadataHook): void; /** Remove a previously registered event metadata hook. */ clearEventMetadataHook(): void; /** Creates a RumEvent and a ParsedRumEvent from a type and details. */ private createEvent; /** * Returns {@code true} if the current url matches one of the allowedPages * and does not match any of the deniedPages; returns {@code false} * otherwise. */ private isCurrentUrlAllowed; }