From a026ef5d75e89597e2e78321bd888a43170e3019 Mon Sep 17 00:00:00 2001 From: Aymeric Date: Thu, 7 Sep 2023 11:13:44 +0200 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=8E=A8=20Remove=20events=20collection?= =?UTF-8?q?=20folder=20level=20(#2411)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/logs/src/boot/startLogs.spec.ts | 2 +- packages/logs/src/boot/startLogs.ts | 10 ++++----- packages/logs/src/domain/assembly.ts | 2 +- .../console/consoleCollection.spec.ts | 10 ++++----- .../console/consoleCollection.ts | 8 +++---- .../logger/loggerCollection.spec.ts | 8 +++---- .../logger/loggerCollection.ts | 10 ++++----- .../networkErrorCollection.spec.ts | 10 ++++----- .../networkError/networkErrorCollection.ts | 8 +++---- .../report/reportCollection.spec.ts | 10 ++++----- .../report/reportCollection.ts | 8 +++---- .../runtimeErrorCollection.spec.ts | 10 ++++----- .../runtimeError/runtimeErrorCollection.ts | 8 +++---- packages/rum-core/src/boot/rumPublicApi.ts | 2 +- packages/rum-core/src/boot/startRum.spec.ts | 6 ++--- packages/rum-core/src/boot/startRum.ts | 14 ++++++------ .../src/browser/performanceCollection.ts | 2 +- .../action/actionCollection.spec.ts | 8 +++---- .../action/actionCollection.ts | 14 ++++++------ .../action/clickChain.spec.ts | 2 +- .../action/clickChain.ts | 0 .../action/computeFrustration.spec.ts | 6 ++--- .../action/computeFrustration.ts | 2 +- .../action/getActionNameFromElement.spec.ts | 4 ++-- .../action/getActionNameFromElement.ts | 0 .../action/getSelectorFromElement.spec.ts | 4 ++-- .../action/getSelectorFromElement.ts | 0 .../action/listenActionEvents.spec.ts | 2 +- .../action/listenActionEvents.ts | 2 +- .../action/trackClickActions.spec.ts | 12 +++++----- .../action/trackClickActions.ts | 14 ++++++------ packages/rum-core/src/domain/assembly.ts | 2 +- .../contexts/featureFlagContext.spec.ts | 2 +- .../domain/contexts/internalContext.spec.ts | 2 +- .../src/domain/contexts/internalContext.ts | 2 +- .../src/domain/contexts/urlContexts.spec.ts | 2 +- .../src/domain/contexts/viewContexts.spec.ts | 2 +- .../src/domain/contexts/viewContexts.ts | 2 +- .../error/errorCollection.spec.ts | 10 ++++----- .../error/errorCollection.ts | 16 +++++++------- .../error/trackConsoleError.spec.ts | 0 .../error/trackConsoleError.ts | 0 .../error/trackReportError.spec.ts | 2 +- .../error/trackReportError.ts | 2 +- packages/rum-core/src/domain/lifeCycle.ts | 4 ++-- .../longTask/longTaskCollection.spec.ts | 10 ++++----- .../longTask/longTaskCollection.ts | 10 ++++----- .../rum-core/src/domain/requestCollection.ts | 2 +- .../resource/matchRequestTiming.spec.ts | 6 ++--- .../resource/matchRequestTiming.ts | 4 ++-- .../resource/resourceCollection.spec.ts | 20 ++++++++--------- .../resource/resourceCollection.ts | 22 +++++++++---------- .../resource/resourceUtils.spec.ts | 6 ++--- .../resource/resourceUtils.ts | 6 ++--- .../view/setupViewTest.specHelper.ts | 8 +++---- .../view/startWebVitalTelemetryDebug.ts | 6 ++--- .../view/trackViewEventCounts.spec.ts | 10 ++++----- .../view/trackViewEventCounts.ts | 4 ++-- .../view/trackViews.spec.ts | 10 ++++----- .../view/trackViews.ts | 16 +++++++------- .../view/viewCollection.spec.ts | 14 ++++++------ .../view/viewCollection.ts | 20 ++++++++--------- .../viewMetrics/interactionCountPolyfill.ts | 2 +- .../viewMetrics/trackCommonViewMetrics.ts | 6 ++--- .../trackCumulativeLayoutShift.spec.ts | 8 +++---- .../viewMetrics/trackCumulativeLayoutShift.ts | 6 ++--- .../trackFirstContentfulPaint.spec.ts | 8 +++---- .../viewMetrics/trackFirstContentfulPaint.ts | 8 +++---- .../view/viewMetrics/trackFirstHidden.spec.ts | 2 +- .../view/viewMetrics/trackFirstHidden.ts | 2 +- .../trackFirstInputTimings.spec.ts | 8 +++---- .../viewMetrics/trackFirstInputTimings.ts | 8 +++---- .../trackInitialViewMetrics.spec.ts | 8 +++---- .../viewMetrics/trackInitialViewMetrics.ts | 4 ++-- .../trackInteractionToNextPaint.spec.ts | 12 +++++----- .../trackInteractionToNextPaint.ts | 8 +++---- .../trackLargestContentfulPaint.spec.ts | 10 ++++----- .../trackLargestContentfulPaint.ts | 6 ++--- .../view/viewMetrics/trackLoadingTime.spec.ts | 10 ++++----- .../view/viewMetrics/trackLoadingTime.ts | 8 +++---- .../trackNavigationTimings.spec.ts | 6 ++--- .../viewMetrics/trackNavigationTimings.ts | 4 ++-- .../viewMetrics/trackScrollMetrics.spec.ts | 8 +++---- .../view/viewMetrics/trackScrollMetrics.ts | 6 ++--- packages/rum-core/src/index.ts | 6 ++--- packages/rum-core/test/createFakeClick.ts | 2 +- packages/rum-core/test/testSetupBuilder.ts | 2 +- 87 files changed, 289 insertions(+), 289 deletions(-) rename packages/logs/src/domain/{logsCollection => }/console/consoleCollection.spec.ts (89%) rename packages/logs/src/domain/{logsCollection => }/console/consoleCollection.ts (87%) rename packages/logs/src/domain/{logsCollection => }/logger/loggerCollection.spec.ts (93%) rename packages/logs/src/domain/{logsCollection => }/logger/loggerCollection.ts (84%) rename packages/logs/src/domain/{logsCollection => }/networkError/networkErrorCollection.spec.ts (96%) rename packages/logs/src/domain/{logsCollection => }/networkError/networkErrorCollection.ts (96%) rename packages/logs/src/domain/{logsCollection => }/report/reportCollection.spec.ts (88%) rename packages/logs/src/domain/{logsCollection => }/report/reportCollection.ts (88%) rename packages/logs/src/domain/{logsCollection => }/runtimeError/runtimeErrorCollection.spec.ts (86%) rename packages/logs/src/domain/{logsCollection => }/runtimeError/runtimeErrorCollection.ts (85%) rename packages/rum-core/src/domain/{rumEventsCollection => }/action/actionCollection.spec.ts (93%) rename packages/rum-core/src/domain/{rumEventsCollection => }/action/actionCollection.ts (86%) rename packages/rum-core/src/domain/{rumEventsCollection => }/action/clickChain.spec.ts (98%) rename packages/rum-core/src/domain/{rumEventsCollection => }/action/clickChain.ts (100%) rename packages/rum-core/src/domain/{rumEventsCollection => }/action/computeFrustration.spec.ts (97%) rename packages/rum-core/src/domain/{rumEventsCollection => }/action/computeFrustration.ts (97%) rename packages/rum-core/src/domain/{rumEventsCollection => }/action/getActionNameFromElement.spec.ts (98%) rename packages/rum-core/src/domain/{rumEventsCollection => }/action/getActionNameFromElement.ts (100%) rename packages/rum-core/src/domain/{rumEventsCollection => }/action/getSelectorFromElement.spec.ts (98%) rename packages/rum-core/src/domain/{rumEventsCollection => }/action/getSelectorFromElement.ts (100%) rename packages/rum-core/src/domain/{rumEventsCollection => }/action/listenActionEvents.spec.ts (99%) rename packages/rum-core/src/domain/{rumEventsCollection => }/action/listenActionEvents.ts (97%) rename packages/rum-core/src/domain/{rumEventsCollection => }/action/trackClickActions.spec.ts (98%) rename packages/rum-core/src/domain/{rumEventsCollection => }/action/trackClickActions.ts (96%) rename packages/rum-core/src/domain/{rumEventsCollection => }/error/errorCollection.spec.ts (96%) rename packages/rum-core/src/domain/{rumEventsCollection => }/error/errorCollection.ts (86%) rename packages/rum-core/src/domain/{rumEventsCollection => }/error/trackConsoleError.spec.ts (100%) rename packages/rum-core/src/domain/{rumEventsCollection => }/error/trackConsoleError.ts (100%) rename packages/rum-core/src/domain/{rumEventsCollection => }/error/trackReportError.spec.ts (96%) rename packages/rum-core/src/domain/{rumEventsCollection => }/error/trackReportError.ts (92%) rename packages/rum-core/src/domain/{rumEventsCollection => }/longTask/longTaskCollection.spec.ts (91%) rename packages/rum-core/src/domain/{rumEventsCollection => }/longTask/longTaskCollection.ts (78%) rename packages/rum-core/src/domain/{rumEventsCollection => }/resource/matchRequestTiming.spec.ts (93%) rename packages/rum-core/src/domain/{rumEventsCollection => }/resource/matchRequestTiming.ts (91%) rename packages/rum-core/src/domain/{rumEventsCollection => }/resource/resourceCollection.spec.ts (96%) rename packages/rum-core/src/domain/{rumEventsCollection => }/resource/resourceCollection.ts (91%) rename packages/rum-core/src/domain/{rumEventsCollection => }/resource/resourceUtils.spec.ts (98%) rename packages/rum-core/src/domain/{rumEventsCollection => }/resource/resourceUtils.ts (96%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/setupViewTest.specHelper.ts (92%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/startWebVitalTelemetryDebug.ts (90%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/trackViewEventCounts.spec.ts (96%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/trackViewEventCounts.ts (93%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/trackViews.spec.ts (98%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/trackViews.ts (95%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/viewCollection.spec.ts (95%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/viewCollection.ts (88%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/viewMetrics/interactionCountPolyfill.ts (97%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/viewMetrics/trackCommonViewMetrics.ts (94%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/viewMetrics/trackCumulativeLayoutShift.spec.ts (96%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/viewMetrics/trackCumulativeLayoutShift.ts (95%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/viewMetrics/trackFirstContentfulPaint.spec.ts (90%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/viewMetrics/trackFirstContentfulPaint.ts (80%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/viewMetrics/trackFirstHidden.spec.ts (98%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/viewMetrics/trackFirstHidden.ts (95%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/viewMetrics/trackFirstInputTimings.spec.ts (91%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/viewMetrics/trackFirstInputTimings.ts (86%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/viewMetrics/trackInitialViewMetrics.spec.ts (91%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/viewMetrics/trackInitialViewMetrics.ts (96%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/viewMetrics/trackInteractionToNextPaint.spec.ts (94%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/viewMetrics/trackInteractionToNextPaint.ts (94%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/viewMetrics/trackLargestContentfulPaint.spec.ts (89%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/viewMetrics/trackLargestContentfulPaint.ts (90%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/viewMetrics/trackLoadingTime.spec.ts (95%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/viewMetrics/trackLoadingTime.ts (84%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/viewMetrics/trackNavigationTimings.spec.ts (88%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/viewMetrics/trackNavigationTimings.ts (91%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/viewMetrics/trackScrollMetrics.spec.ts (95%) rename packages/rum-core/src/domain/{rumEventsCollection => }/view/viewMetrics/trackScrollMetrics.ts (89%) diff --git a/packages/logs/src/boot/startLogs.spec.ts b/packages/logs/src/boot/startLogs.spec.ts index cca957bc5c..4125533f70 100644 --- a/packages/logs/src/boot/startLogs.spec.ts +++ b/packages/logs/src/boot/startLogs.spec.ts @@ -12,7 +12,7 @@ import { import type { LogsConfiguration } from '../domain/configuration' import { validateAndBuildLogsConfiguration } from '../domain/configuration' import { HandlerType, Logger, StatusType } from '../domain/logger' -import type { startLoggerCollection } from '../domain/logsCollection/logger/loggerCollection' +import type { startLoggerCollection } from '../domain/logger/loggerCollection' import type { LogsEvent } from '../logsEvent.types' import { startLogs } from './startLogs' diff --git a/packages/logs/src/boot/startLogs.ts b/packages/logs/src/boot/startLogs.ts index 9cbfbea49b..1e8ab4c6e1 100644 --- a/packages/logs/src/boot/startLogs.ts +++ b/packages/logs/src/boot/startLogs.ts @@ -17,12 +17,12 @@ import { startLogsSessionManager, startLogsSessionManagerStub } from '../domain/ import type { LogsConfiguration, LogsInitConfiguration } from '../domain/configuration' import { serializeLogsConfiguration } from '../domain/configuration' import { startLogsAssembly, getRUMInternalContext } from '../domain/assembly' -import { startConsoleCollection } from '../domain/logsCollection/console/consoleCollection' -import { startReportCollection } from '../domain/logsCollection/report/reportCollection' -import { startNetworkErrorCollection } from '../domain/logsCollection/networkError/networkErrorCollection' -import { startRuntimeErrorCollection } from '../domain/logsCollection/runtimeError/runtimeErrorCollection' +import { startConsoleCollection } from '../domain/console/consoleCollection' +import { startReportCollection } from '../domain/report/reportCollection' +import { startNetworkErrorCollection } from '../domain/networkError/networkErrorCollection' +import { startRuntimeErrorCollection } from '../domain/runtimeError/runtimeErrorCollection' import { LifeCycle, LifeCycleEventType } from '../domain/lifeCycle' -import { startLoggerCollection } from '../domain/logsCollection/logger/loggerCollection' +import { startLoggerCollection } from '../domain/logger/loggerCollection' import type { CommonContext } from '../rawLogsEvent.types' import { startLogsBatch } from '../transport/startLogsBatch' import { startLogsBridge } from '../transport/startLogsBridge' diff --git a/packages/logs/src/domain/assembly.ts b/packages/logs/src/domain/assembly.ts index 16f7ff21a1..91c20a48fd 100644 --- a/packages/logs/src/domain/assembly.ts +++ b/packages/logs/src/domain/assembly.ts @@ -16,7 +16,7 @@ import type { LifeCycle } from './lifeCycle' import { LifeCycleEventType } from './lifeCycle' import type { Logger } from './logger' import { STATUSES, HandlerType } from './logger' -import { isAuthorized } from './logsCollection/logger/loggerCollection' +import { isAuthorized } from './logger/loggerCollection' import type { LogsSessionManager } from './logsSessionManager' export function startLogsAssembly( diff --git a/packages/logs/src/domain/logsCollection/console/consoleCollection.spec.ts b/packages/logs/src/domain/console/consoleCollection.spec.ts similarity index 89% rename from packages/logs/src/domain/logsCollection/console/consoleCollection.spec.ts rename to packages/logs/src/domain/console/consoleCollection.spec.ts index 38ea5f667f..e8738e3ab0 100644 --- a/packages/logs/src/domain/logsCollection/console/consoleCollection.spec.ts +++ b/packages/logs/src/domain/console/consoleCollection.spec.ts @@ -1,9 +1,9 @@ import { ErrorSource, noop } from '@datadog/browser-core' -import type { RawConsoleLogsEvent } from '../../../rawLogsEvent.types' -import { validateAndBuildLogsConfiguration } from '../../configuration' -import type { RawLogsEventCollectedData } from '../../lifeCycle' -import { LifeCycle, LifeCycleEventType } from '../../lifeCycle' -import { StatusType } from '../../logger' +import type { RawConsoleLogsEvent } from '../../rawLogsEvent.types' +import { validateAndBuildLogsConfiguration } from '../configuration' +import type { RawLogsEventCollectedData } from '../lifeCycle' +import { LifeCycle, LifeCycleEventType } from '../lifeCycle' +import { StatusType } from '../logger' import { startConsoleCollection } from './consoleCollection' describe('console collection', () => { diff --git a/packages/logs/src/domain/logsCollection/console/consoleCollection.ts b/packages/logs/src/domain/console/consoleCollection.ts similarity index 87% rename from packages/logs/src/domain/logsCollection/console/consoleCollection.ts rename to packages/logs/src/domain/console/consoleCollection.ts index 8df499b3a9..af8941efca 100644 --- a/packages/logs/src/domain/logsCollection/console/consoleCollection.ts +++ b/packages/logs/src/domain/console/consoleCollection.ts @@ -1,9 +1,9 @@ import type { Context, ClocksState, ConsoleLog } from '@datadog/browser-core' import { timeStampNow, ConsoleApiName, ErrorSource, initConsoleObservable } from '@datadog/browser-core' -import type { LogsConfiguration } from '../../configuration' -import type { LifeCycle } from '../../lifeCycle' -import { LifeCycleEventType } from '../../lifeCycle' -import { StatusType } from '../../logger' +import type { LogsConfiguration } from '../configuration' +import type { LifeCycle } from '../lifeCycle' +import { LifeCycleEventType } from '../lifeCycle' +import { StatusType } from '../logger' export interface ProvidedError { startClocks: ClocksState diff --git a/packages/logs/src/domain/logsCollection/logger/loggerCollection.spec.ts b/packages/logs/src/domain/logger/loggerCollection.spec.ts similarity index 93% rename from packages/logs/src/domain/logsCollection/logger/loggerCollection.spec.ts rename to packages/logs/src/domain/logger/loggerCollection.spec.ts index b59d1f37c0..8b3a831539 100644 --- a/packages/logs/src/domain/logsCollection/logger/loggerCollection.spec.ts +++ b/packages/logs/src/domain/logger/loggerCollection.spec.ts @@ -2,10 +2,10 @@ import type { TimeStamp } from '@datadog/browser-core' import { ConsoleApiName, timeStampNow, display, ErrorSource } from '@datadog/browser-core' import type { Clock } from '@datadog/browser-core/test' import { mockClock } from '@datadog/browser-core/test' -import type { CommonContext, RawLoggerLogsEvent } from '../../../rawLogsEvent.types' -import type { RawLogsEventCollectedData } from '../../lifeCycle' -import { LifeCycle, LifeCycleEventType } from '../../lifeCycle' -import { HandlerType, Logger, StatusType } from '../../logger' +import type { CommonContext, RawLoggerLogsEvent } from '../../rawLogsEvent.types' +import type { RawLogsEventCollectedData } from '../lifeCycle' +import { LifeCycle, LifeCycleEventType } from '../lifeCycle' +import { HandlerType, Logger, StatusType } from '../logger' import { startLoggerCollection } from './loggerCollection' const COMMON_CONTEXT = {} as CommonContext diff --git a/packages/logs/src/domain/logsCollection/logger/loggerCollection.ts b/packages/logs/src/domain/logger/loggerCollection.ts similarity index 84% rename from packages/logs/src/domain/logsCollection/logger/loggerCollection.ts rename to packages/logs/src/domain/logger/loggerCollection.ts index 798faeeaf6..0ad924a389 100644 --- a/packages/logs/src/domain/logsCollection/logger/loggerCollection.ts +++ b/packages/logs/src/domain/logger/loggerCollection.ts @@ -1,10 +1,10 @@ import type { TimeStamp } from '@datadog/browser-core' import { includes, display, combine, ErrorSource, timeStampNow } from '@datadog/browser-core' -import type { CommonContext } from '../../../rawLogsEvent.types' -import type { LifeCycle } from '../../lifeCycle' -import { LifeCycleEventType } from '../../lifeCycle' -import type { Logger, LogsMessage } from '../../logger' -import { StatusType, HandlerType } from '../../logger' +import type { CommonContext } from '../../rawLogsEvent.types' +import type { LifeCycle } from '../lifeCycle' +import { LifeCycleEventType } from '../lifeCycle' +import type { Logger, LogsMessage } from '../logger' +import { StatusType, HandlerType } from '../logger' export const STATUS_PRIORITIES: { [key in StatusType]: number } = { [StatusType.debug]: 0, diff --git a/packages/logs/src/domain/logsCollection/networkError/networkErrorCollection.spec.ts b/packages/logs/src/domain/networkError/networkErrorCollection.spec.ts similarity index 96% rename from packages/logs/src/domain/logsCollection/networkError/networkErrorCollection.spec.ts rename to packages/logs/src/domain/networkError/networkErrorCollection.spec.ts index 44cfa550d5..22e073724d 100644 --- a/packages/logs/src/domain/logsCollection/networkError/networkErrorCollection.spec.ts +++ b/packages/logs/src/domain/networkError/networkErrorCollection.spec.ts @@ -1,11 +1,11 @@ import { isIE, ErrorSource } from '@datadog/browser-core' import type { FetchStub, FetchStubManager } from '@datadog/browser-core/test' import { SPEC_ENDPOINTS, ResponseStub, stubFetch } from '@datadog/browser-core/test' -import type { RawNetworkLogsEvent } from '../../../rawLogsEvent.types' -import type { LogsConfiguration } from '../../configuration' -import type { RawLogsEventCollectedData } from '../../lifeCycle' -import { LifeCycle, LifeCycleEventType } from '../../lifeCycle' -import { StatusType } from '../../logger' +import type { RawNetworkLogsEvent } from '../../rawLogsEvent.types' +import type { LogsConfiguration } from '../configuration' +import type { RawLogsEventCollectedData } from '../lifeCycle' +import { LifeCycle, LifeCycleEventType } from '../lifeCycle' +import { StatusType } from '../logger' import { computeFetchErrorText, diff --git a/packages/logs/src/domain/logsCollection/networkError/networkErrorCollection.ts b/packages/logs/src/domain/networkError/networkErrorCollection.ts similarity index 96% rename from packages/logs/src/domain/logsCollection/networkError/networkErrorCollection.ts rename to packages/logs/src/domain/networkError/networkErrorCollection.ts index 04f180bace..625e1ef36d 100644 --- a/packages/logs/src/domain/logsCollection/networkError/networkErrorCollection.ts +++ b/packages/logs/src/domain/networkError/networkErrorCollection.ts @@ -12,10 +12,10 @@ import { tryToClone, isServerError, } from '@datadog/browser-core' -import type { LogsConfiguration } from '../../configuration' -import type { LifeCycle } from '../../lifeCycle' -import { LifeCycleEventType } from '../../lifeCycle' -import { StatusType } from '../../logger' +import type { LogsConfiguration } from '../configuration' +import type { LifeCycle } from '../lifeCycle' +import { LifeCycleEventType } from '../lifeCycle' +import { StatusType } from '../logger' export function startNetworkErrorCollection(configuration: LogsConfiguration, lifeCycle: LifeCycle) { if (!configuration.forwardErrorsToLogs) { diff --git a/packages/logs/src/domain/logsCollection/report/reportCollection.spec.ts b/packages/logs/src/domain/report/reportCollection.spec.ts similarity index 88% rename from packages/logs/src/domain/logsCollection/report/reportCollection.spec.ts rename to packages/logs/src/domain/report/reportCollection.spec.ts index 5b5a4e0610..71b6c65689 100644 --- a/packages/logs/src/domain/logsCollection/report/reportCollection.spec.ts +++ b/packages/logs/src/domain/report/reportCollection.spec.ts @@ -1,10 +1,10 @@ import { ErrorSource, noop } from '@datadog/browser-core' import { stubReportingObserver } from '@datadog/browser-core/test' -import type { RawReportLogsEvent } from '../../../rawLogsEvent.types' -import { validateAndBuildLogsConfiguration } from '../../configuration' -import type { RawLogsEventCollectedData } from '../../lifeCycle' -import { LifeCycle, LifeCycleEventType } from '../../lifeCycle' -import { StatusType } from '../../logger' +import type { RawReportLogsEvent } from '../../rawLogsEvent.types' +import { validateAndBuildLogsConfiguration } from '../configuration' +import type { RawLogsEventCollectedData } from '../lifeCycle' +import { LifeCycle, LifeCycleEventType } from '../lifeCycle' +import { StatusType } from '../logger' import { startReportCollection } from './reportCollection' describe('reports', () => { diff --git a/packages/logs/src/domain/logsCollection/report/reportCollection.ts b/packages/logs/src/domain/report/reportCollection.ts similarity index 88% rename from packages/logs/src/domain/logsCollection/report/reportCollection.ts rename to packages/logs/src/domain/report/reportCollection.ts index 74a4d170ec..9f77639747 100644 --- a/packages/logs/src/domain/logsCollection/report/reportCollection.ts +++ b/packages/logs/src/domain/report/reportCollection.ts @@ -6,10 +6,10 @@ import { getFileFromStackTraceString, initReportObservable, } from '@datadog/browser-core' -import type { LogsConfiguration } from '../../configuration' -import type { LifeCycle } from '../../lifeCycle' -import { LifeCycleEventType } from '../../lifeCycle' -import { StatusType } from '../../logger' +import type { LogsConfiguration } from '../configuration' +import type { LifeCycle } from '../lifeCycle' +import { LifeCycleEventType } from '../lifeCycle' +import { StatusType } from '../logger' export interface ProvidedError { startClocks: ClocksState diff --git a/packages/logs/src/domain/logsCollection/runtimeError/runtimeErrorCollection.spec.ts b/packages/logs/src/domain/runtimeError/runtimeErrorCollection.spec.ts similarity index 86% rename from packages/logs/src/domain/logsCollection/runtimeError/runtimeErrorCollection.spec.ts rename to packages/logs/src/domain/runtimeError/runtimeErrorCollection.spec.ts index f2c5ce4190..b01f7b76e0 100644 --- a/packages/logs/src/domain/logsCollection/runtimeError/runtimeErrorCollection.spec.ts +++ b/packages/logs/src/domain/runtimeError/runtimeErrorCollection.spec.ts @@ -1,9 +1,9 @@ import { ErrorSource } from '@datadog/browser-core' -import type { RawRuntimeLogsEvent } from '../../../rawLogsEvent.types' -import type { LogsConfiguration } from '../../configuration' -import { StatusType } from '../../logger' -import type { RawLogsEventCollectedData } from '../../lifeCycle' -import { LifeCycle, LifeCycleEventType } from '../../lifeCycle' +import type { RawRuntimeLogsEvent } from '../../rawLogsEvent.types' +import type { LogsConfiguration } from '../configuration' +import { StatusType } from '../logger' +import type { RawLogsEventCollectedData } from '../lifeCycle' +import { LifeCycle, LifeCycleEventType } from '../lifeCycle' import { startRuntimeErrorCollection } from './runtimeErrorCollection' describe('runtime error collection', () => { diff --git a/packages/logs/src/domain/logsCollection/runtimeError/runtimeErrorCollection.ts b/packages/logs/src/domain/runtimeError/runtimeErrorCollection.ts similarity index 85% rename from packages/logs/src/domain/logsCollection/runtimeError/runtimeErrorCollection.ts rename to packages/logs/src/domain/runtimeError/runtimeErrorCollection.ts index 9d5fbac792..d99708d84c 100644 --- a/packages/logs/src/domain/logsCollection/runtimeError/runtimeErrorCollection.ts +++ b/packages/logs/src/domain/runtimeError/runtimeErrorCollection.ts @@ -1,9 +1,9 @@ import type { Context, RawError, ClocksState } from '@datadog/browser-core' import { noop, ErrorSource, trackRuntimeError, Observable } from '@datadog/browser-core' -import type { LogsConfiguration } from '../../configuration' -import type { LifeCycle } from '../../lifeCycle' -import { LifeCycleEventType } from '../../lifeCycle' -import { StatusType } from '../../logger' +import type { LogsConfiguration } from '../configuration' +import type { LifeCycle } from '../lifeCycle' +import { LifeCycleEventType } from '../lifeCycle' +import { StatusType } from '../logger' export interface ProvidedError { startClocks: ClocksState diff --git a/packages/rum-core/src/boot/rumPublicApi.ts b/packages/rum-core/src/boot/rumPublicApi.ts index 43d1099dee..4946f7cd5e 100644 --- a/packages/rum-core/src/boot/rumPublicApi.ts +++ b/packages/rum-core/src/boot/rumPublicApi.ts @@ -26,7 +26,7 @@ import type { ReplayStats } from '../rawRumEvent.types' import { ActionType } from '../rawRumEvent.types' import type { RumConfiguration, RumInitConfiguration } from '../domain/configuration' import { validateAndBuildRumConfiguration } from '../domain/configuration' -import type { ViewOptions } from '../domain/rumEventsCollection/view/trackViews' +import type { ViewOptions } from '../domain/view/trackViews' import { buildCommonContext } from '../domain/contexts/commonContext' import type { startRum } from './startRum' diff --git a/packages/rum-core/src/boot/startRum.spec.ts b/packages/rum-core/src/boot/startRum.spec.ts index 83bf80409a..08648898b1 100644 --- a/packages/rum-core/src/boot/startRum.spec.ts +++ b/packages/rum-core/src/boot/startRum.spec.ts @@ -21,11 +21,11 @@ import { createRumSessionManagerMock, noopRecorderApi, noopWebVitalTelemetryDebu import type { RumPerformanceNavigationTiming, RumPerformanceEntry } from '../browser/performanceCollection' import type { LifeCycle } from '../domain/lifeCycle' import { LifeCycleEventType } from '../domain/lifeCycle' -import { SESSION_KEEP_ALIVE_INTERVAL, THROTTLE_VIEW_UPDATE_PERIOD } from '../domain/rumEventsCollection/view/trackViews' -import { startViewCollection } from '../domain/rumEventsCollection/view/viewCollection' +import { SESSION_KEEP_ALIVE_INTERVAL, THROTTLE_VIEW_UPDATE_PERIOD } from '../domain/view/trackViews' +import { startViewCollection } from '../domain/view/viewCollection' import type { RumEvent, RumViewEvent } from '../rumEvent.types' import type { LocationChange } from '../browser/locationChangeObservable' -import { startLongTaskCollection } from '../domain/rumEventsCollection/longTask/longTaskCollection' +import { startLongTaskCollection } from '../domain/longTask/longTaskCollection' import type { RumSessionManager } from '..' import type { RumConfiguration, RumInitConfiguration } from '../domain/configuration' import { RumEventType } from '../rawRumEvent.types' diff --git a/packages/rum-core/src/boot/startRum.ts b/packages/rum-core/src/boot/startRum.ts index 6ca15c69a2..3308f59623 100644 --- a/packages/rum-core/src/boot/startRum.ts +++ b/packages/rum-core/src/boot/startRum.ts @@ -16,11 +16,11 @@ import { startInternalContext } from '../domain/contexts/internalContext' import { LifeCycle, LifeCycleEventType } from '../domain/lifeCycle' import { startViewContexts } from '../domain/contexts/viewContexts' import { startRequestCollection } from '../domain/requestCollection' -import { startActionCollection } from '../domain/rumEventsCollection/action/actionCollection' -import { startErrorCollection } from '../domain/rumEventsCollection/error/errorCollection' -import { startLongTaskCollection } from '../domain/rumEventsCollection/longTask/longTaskCollection' -import { startResourceCollection } from '../domain/rumEventsCollection/resource/resourceCollection' -import { startViewCollection } from '../domain/rumEventsCollection/view/viewCollection' +import { startActionCollection } from '../domain/action/actionCollection' +import { startErrorCollection } from '../domain/error/errorCollection' +import { startLongTaskCollection } from '../domain/longTask/longTaskCollection' +import { startResourceCollection } from '../domain/resource/resourceCollection' +import { startViewCollection } from '../domain/view/viewCollection' import type { RumSessionManager } from '../domain/rumSessionManager' import { startRumSessionManager, startRumSessionManagerStub } from '../domain/rumSessionManager' import { startRumBatch } from '../transport/startRumBatch' @@ -30,13 +30,13 @@ import type { LocationChange } from '../browser/locationChangeObservable' import { createLocationChangeObservable } from '../browser/locationChangeObservable' import type { RumConfiguration, RumInitConfiguration } from '../domain/configuration' import { serializeRumConfiguration } from '../domain/configuration' -import type { ViewOptions } from '../domain/rumEventsCollection/view/trackViews' +import type { ViewOptions } from '../domain/view/trackViews' import { startFeatureFlagContexts } from '../domain/contexts/featureFlagContext' import { startCustomerDataTelemetry } from '../domain/startCustomerDataTelemetry' import { startPageStateHistory } from '../domain/contexts/pageStateHistory' import type { CommonContext } from '../domain/contexts/commonContext' import { buildCommonContext } from '../domain/contexts/commonContext' -import { startWebVitalTelemetryDebug } from '../domain/rumEventsCollection/view/startWebVitalTelemetryDebug' +import { startWebVitalTelemetryDebug } from '../domain/view/startWebVitalTelemetryDebug' import type { RecorderApi } from './rumPublicApi' export function startRum( diff --git a/packages/rum-core/src/browser/performanceCollection.ts b/packages/rum-core/src/browser/performanceCollection.ts index adc4a2ce5d..beb45b5d98 100644 --- a/packages/rum-core/src/browser/performanceCollection.ts +++ b/packages/rum-core/src/browser/performanceCollection.ts @@ -16,7 +16,7 @@ import { import type { RumConfiguration } from '../domain/configuration' import type { LifeCycle } from '../domain/lifeCycle' import { LifeCycleEventType } from '../domain/lifeCycle' -import { FAKE_INITIAL_DOCUMENT, isAllowedRequestUrl } from '../domain/rumEventsCollection/resource/resourceUtils' +import { FAKE_INITIAL_DOCUMENT, isAllowedRequestUrl } from '../domain/resource/resourceUtils' import { getDocumentTraceId } from '../domain/tracing/getDocumentTraceId' import type { PerformanceEntryRepresentation } from '../domainContext.types' diff --git a/packages/rum-core/src/domain/rumEventsCollection/action/actionCollection.spec.ts b/packages/rum-core/src/domain/action/actionCollection.spec.ts similarity index 93% rename from packages/rum-core/src/domain/rumEventsCollection/action/actionCollection.spec.ts rename to packages/rum-core/src/domain/action/actionCollection.spec.ts index 9471c11ed8..f20adff0c8 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/action/actionCollection.spec.ts +++ b/packages/rum-core/src/domain/action/actionCollection.spec.ts @@ -1,9 +1,9 @@ import type { Duration, RelativeTime, ServerDuration, TimeStamp } from '@datadog/browser-core' import { createNewEvent } from '@datadog/browser-core/test' -import type { TestSetupBuilder } from '../../../../test' -import { setup } from '../../../../test' -import { RumEventType, ActionType } from '../../../rawRumEvent.types' -import { LifeCycleEventType } from '../../lifeCycle' +import type { TestSetupBuilder } from '../../../test' +import { setup } from '../../../test' +import { RumEventType, ActionType } from '../../rawRumEvent.types' +import { LifeCycleEventType } from '../lifeCycle' import { startActionCollection } from './actionCollection' describe('actionCollection', () => { diff --git a/packages/rum-core/src/domain/rumEventsCollection/action/actionCollection.ts b/packages/rum-core/src/domain/action/actionCollection.ts similarity index 86% rename from packages/rum-core/src/domain/rumEventsCollection/action/actionCollection.ts rename to packages/rum-core/src/domain/action/actionCollection.ts index 06ddc3d3b1..576236c1e2 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/action/actionCollection.ts +++ b/packages/rum-core/src/domain/action/actionCollection.ts @@ -1,13 +1,13 @@ import type { ClocksState, Context, Observable } from '@datadog/browser-core' import { noop, assign, combine, toServerDuration, generateUUID } from '@datadog/browser-core' -import type { RawRumActionEvent } from '../../../rawRumEvent.types' -import { ActionType, RumEventType } from '../../../rawRumEvent.types' -import type { LifeCycle, RawRumEventCollectedData } from '../../lifeCycle' -import { LifeCycleEventType } from '../../lifeCycle' -import type { RumConfiguration } from '../../configuration' -import type { CommonContext } from '../../contexts/commonContext' -import type { PageStateHistory } from '../../contexts/pageStateHistory' +import type { RawRumActionEvent } from '../../rawRumEvent.types' +import { ActionType, RumEventType } from '../../rawRumEvent.types' +import type { LifeCycle, RawRumEventCollectedData } from '../lifeCycle' +import { LifeCycleEventType } from '../lifeCycle' +import type { RumConfiguration } from '../configuration' +import type { CommonContext } from '../contexts/commonContext' +import type { PageStateHistory } from '../contexts/pageStateHistory' import type { ActionContexts, ClickAction } from './trackClickActions' import { trackClickActions } from './trackClickActions' diff --git a/packages/rum-core/src/domain/rumEventsCollection/action/clickChain.spec.ts b/packages/rum-core/src/domain/action/clickChain.spec.ts similarity index 98% rename from packages/rum-core/src/domain/rumEventsCollection/action/clickChain.spec.ts rename to packages/rum-core/src/domain/action/clickChain.spec.ts index ea933adee0..0b933206d7 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/action/clickChain.spec.ts +++ b/packages/rum-core/src/domain/action/clickChain.spec.ts @@ -1,6 +1,6 @@ import type { Clock } from '@datadog/browser-core/test' import { mockClock } from '@datadog/browser-core/test' -import { createFakeClick } from '../../../../test' +import { createFakeClick } from '../../../test' import type { ClickChain } from './clickChain' import { MAX_DISTANCE_BETWEEN_CLICKS, MAX_DURATION_BETWEEN_CLICKS, createClickChain } from './clickChain' diff --git a/packages/rum-core/src/domain/rumEventsCollection/action/clickChain.ts b/packages/rum-core/src/domain/action/clickChain.ts similarity index 100% rename from packages/rum-core/src/domain/rumEventsCollection/action/clickChain.ts rename to packages/rum-core/src/domain/action/clickChain.ts diff --git a/packages/rum-core/src/domain/rumEventsCollection/action/computeFrustration.spec.ts b/packages/rum-core/src/domain/action/computeFrustration.spec.ts similarity index 97% rename from packages/rum-core/src/domain/rumEventsCollection/action/computeFrustration.spec.ts rename to packages/rum-core/src/domain/action/computeFrustration.spec.ts index b19c1f52cb..78d2e40df1 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/action/computeFrustration.spec.ts +++ b/packages/rum-core/src/domain/action/computeFrustration.spec.ts @@ -1,9 +1,9 @@ import { ONE_SECOND } from '@datadog/browser-core' import type { Clock } from '@datadog/browser-core/test' import { mockClock } from '@datadog/browser-core/test' -import { FrustrationType } from '../../../rawRumEvent.types' -import type { FakeClick, IsolatedDom } from '../../../../test' -import { createFakeClick, createIsolatedDom } from '../../../../test' +import { FrustrationType } from '../../rawRumEvent.types' +import type { FakeClick, IsolatedDom } from '../../../test' +import { createFakeClick, createIsolatedDom } from '../../../test' import { computeFrustration, isRage, isDead } from './computeFrustration' describe('computeFrustration', () => { diff --git a/packages/rum-core/src/domain/rumEventsCollection/action/computeFrustration.ts b/packages/rum-core/src/domain/action/computeFrustration.ts similarity index 97% rename from packages/rum-core/src/domain/rumEventsCollection/action/computeFrustration.ts rename to packages/rum-core/src/domain/action/computeFrustration.ts index 565635abc7..80f12e3e82 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/action/computeFrustration.ts +++ b/packages/rum-core/src/domain/action/computeFrustration.ts @@ -1,5 +1,5 @@ import { elementMatches, ONE_SECOND } from '@datadog/browser-core' -import { FrustrationType } from '../../../rawRumEvent.types' +import { FrustrationType } from '../../rawRumEvent.types' import type { Click } from './trackClickActions' const MIN_CLICKS_PER_SECOND_TO_CONSIDER_RAGE = 3 diff --git a/packages/rum-core/src/domain/rumEventsCollection/action/getActionNameFromElement.spec.ts b/packages/rum-core/src/domain/action/getActionNameFromElement.spec.ts similarity index 98% rename from packages/rum-core/src/domain/rumEventsCollection/action/getActionNameFromElement.spec.ts rename to packages/rum-core/src/domain/action/getActionNameFromElement.spec.ts index 443683295e..30f39420c0 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/action/getActionNameFromElement.spec.ts +++ b/packages/rum-core/src/domain/action/getActionNameFromElement.spec.ts @@ -1,5 +1,5 @@ -import type { IsolatedDom } from '../../../../test' -import { createIsolatedDom } from '../../../../test' +import type { IsolatedDom } from '../../../test' +import { createIsolatedDom } from '../../../test' import { getActionNameFromElement } from './getActionNameFromElement' describe('getActionNameFromElement', () => { diff --git a/packages/rum-core/src/domain/rumEventsCollection/action/getActionNameFromElement.ts b/packages/rum-core/src/domain/action/getActionNameFromElement.ts similarity index 100% rename from packages/rum-core/src/domain/rumEventsCollection/action/getActionNameFromElement.ts rename to packages/rum-core/src/domain/action/getActionNameFromElement.ts diff --git a/packages/rum-core/src/domain/rumEventsCollection/action/getSelectorFromElement.spec.ts b/packages/rum-core/src/domain/action/getSelectorFromElement.spec.ts similarity index 98% rename from packages/rum-core/src/domain/rumEventsCollection/action/getSelectorFromElement.spec.ts rename to packages/rum-core/src/domain/action/getSelectorFromElement.spec.ts index c1e2f7d5ba..de4fb25303 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/action/getSelectorFromElement.spec.ts +++ b/packages/rum-core/src/domain/action/getSelectorFromElement.spec.ts @@ -1,5 +1,5 @@ -import type { IsolatedDom } from '../../../../test' -import { createIsolatedDom } from '../../../../test' +import type { IsolatedDom } from '../../../test' +import { createIsolatedDom } from '../../../test' import { getSelectorFromElement, supportScopeSelector } from './getSelectorFromElement' describe('getSelectorFromElement', () => { diff --git a/packages/rum-core/src/domain/rumEventsCollection/action/getSelectorFromElement.ts b/packages/rum-core/src/domain/action/getSelectorFromElement.ts similarity index 100% rename from packages/rum-core/src/domain/rumEventsCollection/action/getSelectorFromElement.ts rename to packages/rum-core/src/domain/action/getSelectorFromElement.ts diff --git a/packages/rum-core/src/domain/rumEventsCollection/action/listenActionEvents.spec.ts b/packages/rum-core/src/domain/action/listenActionEvents.spec.ts similarity index 99% rename from packages/rum-core/src/domain/rumEventsCollection/action/listenActionEvents.spec.ts rename to packages/rum-core/src/domain/action/listenActionEvents.spec.ts index 77daa4b271..e9663bcb41 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/action/listenActionEvents.spec.ts +++ b/packages/rum-core/src/domain/action/listenActionEvents.spec.ts @@ -1,5 +1,5 @@ import { createNewEvent } from '@datadog/browser-core/test' -import type { RumConfiguration } from '../../configuration' +import type { RumConfiguration } from '../configuration' import type { ActionEventsHooks } from './listenActionEvents' import { listenActionEvents } from './listenActionEvents' diff --git a/packages/rum-core/src/domain/rumEventsCollection/action/listenActionEvents.ts b/packages/rum-core/src/domain/action/listenActionEvents.ts similarity index 97% rename from packages/rum-core/src/domain/rumEventsCollection/action/listenActionEvents.ts rename to packages/rum-core/src/domain/action/listenActionEvents.ts index 42ea5d9772..4574ceff4b 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/action/listenActionEvents.ts +++ b/packages/rum-core/src/domain/action/listenActionEvents.ts @@ -1,5 +1,5 @@ import { addEventListener, DOM_EVENT } from '@datadog/browser-core' -import type { RumConfiguration } from '../../configuration' +import type { RumConfiguration } from '../configuration' export type MouseEventOnElement = PointerEvent & { target: Element } diff --git a/packages/rum-core/src/domain/rumEventsCollection/action/trackClickActions.spec.ts b/packages/rum-core/src/domain/action/trackClickActions.spec.ts similarity index 98% rename from packages/rum-core/src/domain/rumEventsCollection/action/trackClickActions.spec.ts rename to packages/rum-core/src/domain/action/trackClickActions.spec.ts index 198d89a428..96c19df0f4 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/action/trackClickActions.spec.ts +++ b/packages/rum-core/src/domain/action/trackClickActions.spec.ts @@ -1,12 +1,12 @@ import type { Context, Duration } from '@datadog/browser-core' import { addDuration, clocksNow, timeStampNow, relativeNow } from '@datadog/browser-core' import { createNewEvent } from '@datadog/browser-core/test' -import type { TestSetupBuilder } from '../../../../test' -import { setup, createFakeClick } from '../../../../test' -import { RumEventType, ActionType, FrustrationType } from '../../../rawRumEvent.types' -import type { RumEvent } from '../../../rumEvent.types' -import { LifeCycleEventType } from '../../lifeCycle' -import { PAGE_ACTIVITY_VALIDATION_DELAY } from '../../waitPageActivityEnd' +import type { TestSetupBuilder } from '../../../test' +import { setup, createFakeClick } from '../../../test' +import { RumEventType, ActionType, FrustrationType } from '../../rawRumEvent.types' +import type { RumEvent } from '../../rumEvent.types' +import { LifeCycleEventType } from '../lifeCycle' +import { PAGE_ACTIVITY_VALIDATION_DELAY } from '../waitPageActivityEnd' import type { ActionContexts } from './actionCollection' import type { ClickAction } from './trackClickActions' import { finalizeClicks, CLICK_ACTION_MAX_DURATION, trackClickActions } from './trackClickActions' diff --git a/packages/rum-core/src/domain/rumEventsCollection/action/trackClickActions.ts b/packages/rum-core/src/domain/action/trackClickActions.ts similarity index 96% rename from packages/rum-core/src/domain/rumEventsCollection/action/trackClickActions.ts rename to packages/rum-core/src/domain/action/trackClickActions.ts index fab6602f00..ba1e2ea708 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/action/trackClickActions.ts +++ b/packages/rum-core/src/domain/action/trackClickActions.ts @@ -12,13 +12,13 @@ import { ONE_SECOND, elapsed, } from '@datadog/browser-core' -import type { FrustrationType } from '../../../rawRumEvent.types' -import { ActionType } from '../../../rawRumEvent.types' -import type { RumConfiguration } from '../../configuration' -import type { LifeCycle } from '../../lifeCycle' -import { LifeCycleEventType } from '../../lifeCycle' -import { trackEventCounts } from '../../trackEventCounts' -import { PAGE_ACTIVITY_VALIDATION_DELAY, waitPageActivityEnd } from '../../waitPageActivityEnd' +import type { FrustrationType } from '../../rawRumEvent.types' +import { ActionType } from '../../rawRumEvent.types' +import type { RumConfiguration } from '../configuration' +import type { LifeCycle } from '../lifeCycle' +import { LifeCycleEventType } from '../lifeCycle' +import { trackEventCounts } from '../trackEventCounts' +import { PAGE_ACTIVITY_VALIDATION_DELAY, waitPageActivityEnd } from '../waitPageActivityEnd' import type { ClickChain } from './clickChain' import { createClickChain } from './clickChain' import { getActionNameFromElement } from './getActionNameFromElement' diff --git a/packages/rum-core/src/domain/assembly.ts b/packages/rum-core/src/domain/assembly.ts index bdf8846bc3..663d71e4df 100644 --- a/packages/rum-core/src/domain/assembly.ts +++ b/packages/rum-core/src/domain/assembly.ts @@ -28,7 +28,7 @@ import type { ViewContexts } from './contexts/viewContexts' import type { RumSessionManager } from './rumSessionManager' import type { UrlContexts } from './contexts/urlContexts' import type { RumConfiguration } from './configuration' -import type { ActionContexts } from './rumEventsCollection/action/actionCollection' +import type { ActionContexts } from './action/actionCollection' import { getDisplayContext } from './contexts/displayContext' import type { CommonContext } from './contexts/commonContext' import type { ModifiableFieldPaths } from './limitModification' diff --git a/packages/rum-core/src/domain/contexts/featureFlagContext.spec.ts b/packages/rum-core/src/domain/contexts/featureFlagContext.spec.ts index 364f121f1c..d88e82e277 100644 --- a/packages/rum-core/src/domain/contexts/featureFlagContext.spec.ts +++ b/packages/rum-core/src/domain/contexts/featureFlagContext.spec.ts @@ -12,7 +12,7 @@ import { setup } from '../../../test' import type { Clock } from '../../../../core/test' import type { LifeCycle } from '../lifeCycle' import { LifeCycleEventType } from '../lifeCycle' -import type { ViewCreatedEvent, ViewEndedEvent } from '../rumEventsCollection/view/trackViews' +import type { ViewCreatedEvent, ViewEndedEvent } from '../view/trackViews' import type { FeatureFlagContexts } from './featureFlagContext' import { BYTES_COMPUTATION_THROTTLING_DELAY, startFeatureFlagContexts } from './featureFlagContext' diff --git a/packages/rum-core/src/domain/contexts/internalContext.spec.ts b/packages/rum-core/src/domain/contexts/internalContext.spec.ts index 209b253216..f866849d8e 100644 --- a/packages/rum-core/src/domain/contexts/internalContext.spec.ts +++ b/packages/rum-core/src/domain/contexts/internalContext.spec.ts @@ -1,7 +1,7 @@ import type { RelativeTime } from '@datadog/browser-core' import { createRumSessionManagerMock, setup } from '../../../test' import type { TestSetupBuilder } from '../../../test' -import type { ActionContexts } from '../rumEventsCollection/action/actionCollection' +import type { ActionContexts } from '../action/actionCollection' import type { RumSessionManager } from '../rumSessionManager' import { startInternalContext } from './internalContext' import type { ViewContexts } from './viewContexts' diff --git a/packages/rum-core/src/domain/contexts/internalContext.ts b/packages/rum-core/src/domain/contexts/internalContext.ts index 4d9764bfde..f6df1794bd 100644 --- a/packages/rum-core/src/domain/contexts/internalContext.ts +++ b/packages/rum-core/src/domain/contexts/internalContext.ts @@ -1,5 +1,5 @@ import type { RelativeTime } from '@datadog/browser-core' -import type { ActionContexts } from '../rumEventsCollection/action/actionCollection' +import type { ActionContexts } from '../action/actionCollection' import type { RumSessionManager } from '../rumSessionManager' import type { ViewContexts } from './viewContexts' import type { UrlContexts } from './urlContexts' diff --git a/packages/rum-core/src/domain/contexts/urlContexts.spec.ts b/packages/rum-core/src/domain/contexts/urlContexts.spec.ts index 33dc4de96d..800f4b2346 100644 --- a/packages/rum-core/src/domain/contexts/urlContexts.spec.ts +++ b/packages/rum-core/src/domain/contexts/urlContexts.spec.ts @@ -3,7 +3,7 @@ import { relativeToClocks } from '@datadog/browser-core' import type { TestSetupBuilder } from '../../../test' import { setup } from '../../../test' import { LifeCycleEventType } from '../lifeCycle' -import type { ViewCreatedEvent, ViewEndedEvent } from '../rumEventsCollection/view/trackViews' +import type { ViewCreatedEvent, ViewEndedEvent } from '../view/trackViews' import type { UrlContexts } from './urlContexts' import { startUrlContexts } from './urlContexts' diff --git a/packages/rum-core/src/domain/contexts/viewContexts.spec.ts b/packages/rum-core/src/domain/contexts/viewContexts.spec.ts index 7b2a5288c6..89ff37e5a2 100644 --- a/packages/rum-core/src/domain/contexts/viewContexts.spec.ts +++ b/packages/rum-core/src/domain/contexts/viewContexts.spec.ts @@ -3,7 +3,7 @@ import { relativeToClocks, CLEAR_OLD_VALUES_INTERVAL } from '@datadog/browser-co import type { TestSetupBuilder } from '../../../test' import { setup } from '../../../test' import { LifeCycleEventType } from '../lifeCycle' -import type { ViewCreatedEvent } from '../rumEventsCollection/view/trackViews' +import type { ViewCreatedEvent } from '../view/trackViews' import type { ViewContexts } from './viewContexts' import { startViewContexts, VIEW_CONTEXT_TIME_OUT_DELAY } from './viewContexts' diff --git a/packages/rum-core/src/domain/contexts/viewContexts.ts b/packages/rum-core/src/domain/contexts/viewContexts.ts index bb423057d5..aba54ecd73 100644 --- a/packages/rum-core/src/domain/contexts/viewContexts.ts +++ b/packages/rum-core/src/domain/contexts/viewContexts.ts @@ -2,7 +2,7 @@ import type { RelativeTime, ClocksState } from '@datadog/browser-core' import { SESSION_TIME_OUT_DELAY, ValueHistory } from '@datadog/browser-core' import type { LifeCycle } from '../lifeCycle' import { LifeCycleEventType } from '../lifeCycle' -import type { ViewCreatedEvent } from '../rumEventsCollection/view/trackViews' +import type { ViewCreatedEvent } from '../view/trackViews' export const VIEW_CONTEXT_TIME_OUT_DELAY = SESSION_TIME_OUT_DELAY diff --git a/packages/rum-core/src/domain/rumEventsCollection/error/errorCollection.spec.ts b/packages/rum-core/src/domain/error/errorCollection.spec.ts similarity index 96% rename from packages/rum-core/src/domain/rumEventsCollection/error/errorCollection.spec.ts rename to packages/rum-core/src/domain/error/errorCollection.spec.ts index 4bdd437b95..47f8d243ea 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/error/errorCollection.spec.ts +++ b/packages/rum-core/src/domain/error/errorCollection.spec.ts @@ -1,10 +1,10 @@ import type { RelativeTime, TimeStamp, ErrorWithCause } from '@datadog/browser-core' import { ErrorHandling, ErrorSource, NO_ERROR_STACK_PRESENT_MESSAGE } from '@datadog/browser-core' -import type { TestSetupBuilder } from '../../../../test' -import { setup } from '../../../../test' -import type { RawRumErrorEvent } from '../../../rawRumEvent.types' -import { RumEventType } from '../../../rawRumEvent.types' -import { LifeCycleEventType } from '../../lifeCycle' +import type { TestSetupBuilder } from '../../../test' +import { setup } from '../../../test' +import type { RawRumErrorEvent } from '../../rawRumEvent.types' +import { RumEventType } from '../../rawRumEvent.types' +import { LifeCycleEventType } from '../lifeCycle' import { doStartErrorCollection } from './errorCollection' describe('error collection', () => { diff --git a/packages/rum-core/src/domain/rumEventsCollection/error/errorCollection.ts b/packages/rum-core/src/domain/error/errorCollection.ts similarity index 86% rename from packages/rum-core/src/domain/rumEventsCollection/error/errorCollection.ts rename to packages/rum-core/src/domain/error/errorCollection.ts index 564b7da90d..2fc5d57598 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/error/errorCollection.ts +++ b/packages/rum-core/src/domain/error/errorCollection.ts @@ -11,14 +11,14 @@ import { trackRuntimeError, NonErrorPrefix, } from '@datadog/browser-core' -import type { RumConfiguration } from '../../configuration' -import type { RawRumErrorEvent } from '../../../rawRumEvent.types' -import { RumEventType } from '../../../rawRumEvent.types' -import type { LifeCycle, RawRumEventCollectedData } from '../../lifeCycle' -import { LifeCycleEventType } from '../../lifeCycle' -import type { FeatureFlagContexts } from '../../contexts/featureFlagContext' -import type { CommonContext } from '../../contexts/commonContext' -import type { PageStateHistory } from '../../contexts/pageStateHistory' +import type { RumConfiguration } from '../configuration' +import type { RawRumErrorEvent } from '../../rawRumEvent.types' +import { RumEventType } from '../../rawRumEvent.types' +import type { LifeCycle, RawRumEventCollectedData } from '../lifeCycle' +import { LifeCycleEventType } from '../lifeCycle' +import type { FeatureFlagContexts } from '../contexts/featureFlagContext' +import type { CommonContext } from '../contexts/commonContext' +import type { PageStateHistory } from '../contexts/pageStateHistory' import { trackConsoleError } from './trackConsoleError' import { trackReportError } from './trackReportError' diff --git a/packages/rum-core/src/domain/rumEventsCollection/error/trackConsoleError.spec.ts b/packages/rum-core/src/domain/error/trackConsoleError.spec.ts similarity index 100% rename from packages/rum-core/src/domain/rumEventsCollection/error/trackConsoleError.spec.ts rename to packages/rum-core/src/domain/error/trackConsoleError.spec.ts diff --git a/packages/rum-core/src/domain/rumEventsCollection/error/trackConsoleError.ts b/packages/rum-core/src/domain/error/trackConsoleError.ts similarity index 100% rename from packages/rum-core/src/domain/rumEventsCollection/error/trackConsoleError.ts rename to packages/rum-core/src/domain/error/trackConsoleError.ts diff --git a/packages/rum-core/src/domain/rumEventsCollection/error/trackReportError.spec.ts b/packages/rum-core/src/domain/error/trackReportError.spec.ts similarity index 96% rename from packages/rum-core/src/domain/rumEventsCollection/error/trackReportError.spec.ts rename to packages/rum-core/src/domain/error/trackReportError.spec.ts index 12d9aa5296..0b89aeb54b 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/error/trackReportError.spec.ts +++ b/packages/rum-core/src/domain/error/trackReportError.spec.ts @@ -2,7 +2,7 @@ import type { RawError, Subscription } from '@datadog/browser-core' import { ErrorHandling, ErrorSource, Observable, clocksNow } from '@datadog/browser-core' import type { Clock } from '@datadog/browser-core/test' import { mockClock, stubReportingObserver } from '@datadog/browser-core/test' -import type { RumConfiguration } from '../../configuration' +import type { RumConfiguration } from '../configuration' import { trackReportError } from './trackReportError' describe('trackReportError', () => { diff --git a/packages/rum-core/src/domain/rumEventsCollection/error/trackReportError.ts b/packages/rum-core/src/domain/error/trackReportError.ts similarity index 92% rename from packages/rum-core/src/domain/rumEventsCollection/error/trackReportError.ts rename to packages/rum-core/src/domain/error/trackReportError.ts index 1e988f3c1f..953e1feb4b 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/error/trackReportError.ts +++ b/packages/rum-core/src/domain/error/trackReportError.ts @@ -1,6 +1,6 @@ import type { Observable, RawError } from '@datadog/browser-core' import { clocksNow, ErrorHandling, ErrorSource, initReportObservable, RawReportType } from '@datadog/browser-core' -import type { RumConfiguration } from '../../configuration' +import type { RumConfiguration } from '../configuration' export function trackReportError(configuration: RumConfiguration, errorObservable: Observable) { const subscription = initReportObservable(configuration, [ diff --git a/packages/rum-core/src/domain/lifeCycle.ts b/packages/rum-core/src/domain/lifeCycle.ts index 05e5fa72b4..58208fef6a 100644 --- a/packages/rum-core/src/domain/lifeCycle.ts +++ b/packages/rum-core/src/domain/lifeCycle.ts @@ -6,8 +6,8 @@ import type { RawRumEvent } from '../rawRumEvent.types' import type { RumEvent } from '../rumEvent.types' import type { CommonContext } from './contexts/commonContext' import type { RequestCompleteEvent, RequestStartEvent } from './requestCollection' -import type { AutoAction } from './rumEventsCollection/action/actionCollection' -import type { ViewEvent, ViewCreatedEvent, ViewEndedEvent } from './rumEventsCollection/view/trackViews' +import type { AutoAction } from './action/actionCollection' +import type { ViewEvent, ViewCreatedEvent, ViewEndedEvent } from './view/trackViews' export const enum LifeCycleEventType { PERFORMANCE_ENTRIES_COLLECTED, diff --git a/packages/rum-core/src/domain/rumEventsCollection/longTask/longTaskCollection.spec.ts b/packages/rum-core/src/domain/longTask/longTaskCollection.spec.ts similarity index 91% rename from packages/rum-core/src/domain/rumEventsCollection/longTask/longTaskCollection.spec.ts rename to packages/rum-core/src/domain/longTask/longTaskCollection.spec.ts index c700d934e7..c9bba45d70 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/longTask/longTaskCollection.spec.ts +++ b/packages/rum-core/src/domain/longTask/longTaskCollection.spec.ts @@ -1,9 +1,9 @@ import type { Duration, RelativeTime, ServerDuration } from '@datadog/browser-core' -import type { RumSessionManagerMock, TestSetupBuilder } from '../../../../test' -import { createRumSessionManagerMock, setup } from '../../../../test' -import type { RumPerformanceEntry, RumPerformanceLongTaskTiming } from '../../../browser/performanceCollection' -import { RumEventType } from '../../../rawRumEvent.types' -import { LifeCycleEventType } from '../../lifeCycle' +import type { RumSessionManagerMock, TestSetupBuilder } from '../../../test' +import { createRumSessionManagerMock, setup } from '../../../test' +import type { RumPerformanceEntry, RumPerformanceLongTaskTiming } from '../../browser/performanceCollection' +import { RumEventType } from '../../rawRumEvent.types' +import { LifeCycleEventType } from '../lifeCycle' import { startLongTaskCollection } from './longTaskCollection' const LONG_TASK: RumPerformanceLongTaskTiming = { diff --git a/packages/rum-core/src/domain/rumEventsCollection/longTask/longTaskCollection.ts b/packages/rum-core/src/domain/longTask/longTaskCollection.ts similarity index 78% rename from packages/rum-core/src/domain/rumEventsCollection/longTask/longTaskCollection.ts rename to packages/rum-core/src/domain/longTask/longTaskCollection.ts index a9cba29c9a..996b2e96b9 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/longTask/longTaskCollection.ts +++ b/packages/rum-core/src/domain/longTask/longTaskCollection.ts @@ -1,9 +1,9 @@ import { toServerDuration, relativeToClocks, generateUUID } from '@datadog/browser-core' -import type { RawRumLongTaskEvent } from '../../../rawRumEvent.types' -import { RumEventType } from '../../../rawRumEvent.types' -import type { LifeCycle } from '../../lifeCycle' -import { LifeCycleEventType } from '../../lifeCycle' -import type { RumSessionManager } from '../../rumSessionManager' +import type { RawRumLongTaskEvent } from '../../rawRumEvent.types' +import { RumEventType } from '../../rawRumEvent.types' +import type { LifeCycle } from '../lifeCycle' +import { LifeCycleEventType } from '../lifeCycle' +import type { RumSessionManager } from '../rumSessionManager' export function startLongTaskCollection(lifeCycle: LifeCycle, sessionManager: RumSessionManager) { lifeCycle.subscribe(LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED, (entries) => { diff --git a/packages/rum-core/src/domain/requestCollection.ts b/packages/rum-core/src/domain/requestCollection.ts index dd0830227a..88b8a84a61 100644 --- a/packages/rum-core/src/domain/requestCollection.ts +++ b/packages/rum-core/src/domain/requestCollection.ts @@ -19,7 +19,7 @@ import type { RumSessionManager } from '..' import type { RumConfiguration } from './configuration' import type { LifeCycle } from './lifeCycle' import { LifeCycleEventType } from './lifeCycle' -import { isAllowedRequestUrl } from './rumEventsCollection/resource/resourceUtils' +import { isAllowedRequestUrl } from './resource/resourceUtils' import type { TraceIdentifier, Tracer } from './tracing/tracer' import { startTracer } from './tracing/tracer' diff --git a/packages/rum-core/src/domain/rumEventsCollection/resource/matchRequestTiming.spec.ts b/packages/rum-core/src/domain/resource/matchRequestTiming.spec.ts similarity index 93% rename from packages/rum-core/src/domain/rumEventsCollection/resource/matchRequestTiming.spec.ts rename to packages/rum-core/src/domain/resource/matchRequestTiming.spec.ts index 90fc7ee3a1..bac930a4b0 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/resource/matchRequestTiming.spec.ts +++ b/packages/rum-core/src/domain/resource/matchRequestTiming.spec.ts @@ -1,8 +1,8 @@ import type { Duration, RelativeTime } from '@datadog/browser-core' import { isIE, relativeToClocks } from '@datadog/browser-core' -import { createResourceEntry } from '../../../../test' -import type { RumPerformanceResourceTiming } from '../../../browser/performanceCollection' -import type { RequestCompleteEvent } from '../../requestCollection' +import { createResourceEntry } from '../../../test' +import type { RumPerformanceResourceTiming } from '../../browser/performanceCollection' +import type { RequestCompleteEvent } from '../requestCollection' import { matchRequestTiming } from './matchRequestTiming' diff --git a/packages/rum-core/src/domain/rumEventsCollection/resource/matchRequestTiming.ts b/packages/rum-core/src/domain/resource/matchRequestTiming.ts similarity index 91% rename from packages/rum-core/src/domain/rumEventsCollection/resource/matchRequestTiming.ts rename to packages/rum-core/src/domain/resource/matchRequestTiming.ts index d89e334da9..763faedfc2 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/resource/matchRequestTiming.ts +++ b/packages/rum-core/src/domain/resource/matchRequestTiming.ts @@ -1,7 +1,7 @@ import type { Duration, RelativeTime } from '@datadog/browser-core' import { addDuration } from '@datadog/browser-core' -import type { RumPerformanceResourceTiming } from '../../../browser/performanceCollection' -import type { RequestCompleteEvent } from '../../requestCollection' +import type { RumPerformanceResourceTiming } from '../../browser/performanceCollection' +import type { RequestCompleteEvent } from '../requestCollection' import { toValidEntry } from './resourceUtils' interface Timing { diff --git a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts b/packages/rum-core/src/domain/resource/resourceCollection.spec.ts similarity index 96% rename from packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts rename to packages/rum-core/src/domain/resource/resourceCollection.spec.ts index 35c895e6b0..d0b51c3522 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts +++ b/packages/rum-core/src/domain/resource/resourceCollection.spec.ts @@ -7,16 +7,16 @@ import { ResourceType, ExperimentalFeature, } from '@datadog/browser-core' -import type { RumFetchResourceEventDomainContext } from '../../../domainContext.types' -import { createResourceEntry, setup, createRumSessionManagerMock } from '../../../../test' -import type { TestSetupBuilder } from '../../../../test' -import type { RawRumResourceEvent } from '../../../rawRumEvent.types' -import { RumEventType } from '../../../rawRumEvent.types' -import { LifeCycleEventType } from '../../lifeCycle' -import type { RequestCompleteEvent } from '../../requestCollection' -import { TraceIdentifier } from '../../tracing/tracer' -import { validateAndBuildRumConfiguration } from '../../configuration' -import { PageState } from '../../contexts/pageStateHistory' +import type { RumFetchResourceEventDomainContext } from '../../domainContext.types' +import { createResourceEntry, setup, createRumSessionManagerMock } from '../../../test' +import type { TestSetupBuilder } from '../../../test' +import type { RawRumResourceEvent } from '../../rawRumEvent.types' +import { RumEventType } from '../../rawRumEvent.types' +import { LifeCycleEventType } from '../lifeCycle' +import type { RequestCompleteEvent } from '../requestCollection' +import { TraceIdentifier } from '../tracing/tracer' +import { validateAndBuildRumConfiguration } from '../configuration' +import { PageState } from '../contexts/pageStateHistory' import { startResourceCollection } from './resourceCollection' describe('resourceCollection', () => { diff --git a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts b/packages/rum-core/src/domain/resource/resourceCollection.ts similarity index 91% rename from packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts rename to packages/rum-core/src/domain/resource/resourceCollection.ts index a62a4f801e..7853a81158 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.ts +++ b/packages/rum-core/src/domain/resource/resourceCollection.ts @@ -11,21 +11,21 @@ import { ExperimentalFeature, } from '@datadog/browser-core' import type { ClocksState, Duration } from '@datadog/browser-core' -import type { RumConfiguration } from '../../configuration' -import type { RumPerformanceEntry, RumPerformanceResourceTiming } from '../../../browser/performanceCollection' +import type { RumConfiguration } from '../configuration' +import type { RumPerformanceEntry, RumPerformanceResourceTiming } from '../../browser/performanceCollection' import type { PerformanceEntryRepresentation, RumXhrResourceEventDomainContext, RumFetchResourceEventDomainContext, -} from '../../../domainContext.types' -import type { RawRumResourceEvent } from '../../../rawRumEvent.types' -import { RumEventType } from '../../../rawRumEvent.types' -import type { LifeCycle, RawRumEventCollectedData } from '../../lifeCycle' -import { LifeCycleEventType } from '../../lifeCycle' -import type { RequestCompleteEvent } from '../../requestCollection' -import type { RumSessionManager } from '../../rumSessionManager' -import type { PageStateHistory } from '../../contexts/pageStateHistory' -import { PageState } from '../../contexts/pageStateHistory' +} from '../../domainContext.types' +import type { RawRumResourceEvent } from '../../rawRumEvent.types' +import { RumEventType } from '../../rawRumEvent.types' +import type { LifeCycle, RawRumEventCollectedData } from '../lifeCycle' +import { LifeCycleEventType } from '../lifeCycle' +import type { RequestCompleteEvent } from '../requestCollection' +import type { RumSessionManager } from '../rumSessionManager' +import type { PageStateHistory } from '../contexts/pageStateHistory' +import { PageState } from '../contexts/pageStateHistory' import { matchRequestTiming } from './matchRequestTiming' import { computePerformanceResourceDetails, diff --git a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceUtils.spec.ts b/packages/rum-core/src/domain/resource/resourceUtils.spec.ts similarity index 98% rename from packages/rum-core/src/domain/rumEventsCollection/resource/resourceUtils.spec.ts rename to packages/rum-core/src/domain/resource/resourceUtils.spec.ts index e2f0e3dc59..30fad8995d 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceUtils.spec.ts +++ b/packages/rum-core/src/domain/resource/resourceUtils.spec.ts @@ -1,8 +1,8 @@ import type { Duration, RelativeTime, ServerDuration } from '@datadog/browser-core' import { SPEC_ENDPOINTS } from '@datadog/browser-core/test' -import type { RumPerformanceResourceTiming } from '../../../browser/performanceCollection' -import type { RumConfiguration } from '../../configuration' -import { validateAndBuildRumConfiguration } from '../../configuration' +import type { RumPerformanceResourceTiming } from '../../browser/performanceCollection' +import type { RumConfiguration } from '../configuration' +import { validateAndBuildRumConfiguration } from '../configuration' import { computePerformanceResourceDetails, computePerformanceResourceDuration, diff --git a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceUtils.ts b/packages/rum-core/src/domain/resource/resourceUtils.ts similarity index 96% rename from packages/rum-core/src/domain/rumEventsCollection/resource/resourceUtils.ts rename to packages/rum-core/src/domain/resource/resourceUtils.ts index 869b80385a..82f93be22e 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceUtils.ts +++ b/packages/rum-core/src/domain/resource/resourceUtils.ts @@ -10,10 +10,10 @@ import { toServerDuration, } from '@datadog/browser-core' -import type { RumPerformanceResourceTiming } from '../../../browser/performanceCollection' +import type { RumPerformanceResourceTiming } from '../../browser/performanceCollection' -import type { PerformanceResourceDetailsElement } from '../../../rawRumEvent.types' -import type { RumConfiguration } from '../../configuration' +import type { PerformanceResourceDetailsElement } from '../../rawRumEvent.types' +import type { RumConfiguration } from '../configuration' export interface PerformanceResourceDetails { redirect?: PerformanceResourceDetailsElement diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/setupViewTest.specHelper.ts b/packages/rum-core/src/domain/view/setupViewTest.specHelper.ts similarity index 92% rename from packages/rum-core/src/domain/rumEventsCollection/view/setupViewTest.specHelper.ts rename to packages/rum-core/src/domain/view/setupViewTest.specHelper.ts index 49412bc971..2cb46f20ba 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/setupViewTest.specHelper.ts +++ b/packages/rum-core/src/domain/view/setupViewTest.specHelper.ts @@ -1,13 +1,13 @@ import type { Duration, RelativeTime } from '@datadog/browser-core' -import { noopWebVitalTelemetryDebug } from '../../../../test' -import type { BuildContext } from '../../../../test' -import { LifeCycleEventType } from '../../lifeCycle' +import { noopWebVitalTelemetryDebug } from '../../../test' +import type { BuildContext } from '../../../test' +import { LifeCycleEventType } from '../lifeCycle' import type { RumFirstInputTiming, RumLargestContentfulPaintTiming, RumPerformanceNavigationTiming, RumPerformancePaintTiming, -} from '../../../browser/performanceCollection' +} from '../../browser/performanceCollection' import type { ViewEvent, ViewOptions } from './trackViews' import { trackViews } from './trackViews' diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/startWebVitalTelemetryDebug.ts b/packages/rum-core/src/domain/view/startWebVitalTelemetryDebug.ts similarity index 90% rename from packages/rum-core/src/domain/rumEventsCollection/view/startWebVitalTelemetryDebug.ts rename to packages/rum-core/src/domain/view/startWebVitalTelemetryDebug.ts index 70dd2fbea4..e710467bfa 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/startWebVitalTelemetryDebug.ts +++ b/packages/rum-core/src/domain/view/startWebVitalTelemetryDebug.ts @@ -1,8 +1,8 @@ import { addTelemetryDebug, elapsed, noop, performDraw, relativeNow, toServerDuration } from '@datadog/browser-core' import type { Telemetry, RelativeTime } from '@datadog/browser-core' -import type { RecorderApi } from '../../../boot/rumPublicApi' -import type { RumSessionManager } from '../../rumSessionManager' -import type { RumConfiguration } from '../../configuration' +import type { RecorderApi } from '../../boot/rumPublicApi' +import type { RumSessionManager } from '../rumSessionManager' +import type { RumConfiguration } from '../configuration' export type WebVitalTelemetryDebug = ReturnType diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/trackViewEventCounts.spec.ts b/packages/rum-core/src/domain/view/trackViewEventCounts.spec.ts similarity index 96% rename from packages/rum-core/src/domain/rumEventsCollection/view/trackViewEventCounts.spec.ts rename to packages/rum-core/src/domain/view/trackViewEventCounts.spec.ts index a200acbe4c..1c64bffc40 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/trackViewEventCounts.spec.ts +++ b/packages/rum-core/src/domain/view/trackViewEventCounts.spec.ts @@ -1,9 +1,9 @@ import type { Context } from '@datadog/browser-core' -import type { RumEvent } from '../../../rumEvent.types' -import { LifeCycleEventType } from '../../lifeCycle' -import type { TestSetupBuilder } from '../../../../test' -import { setup } from '../../../../test' -import { FrustrationType, RumEventType } from '../../../rawRumEvent.types' +import type { RumEvent } from '../../rumEvent.types' +import { LifeCycleEventType } from '../lifeCycle' +import type { TestSetupBuilder } from '../../../test' +import { setup } from '../../../test' +import { FrustrationType, RumEventType } from '../../rawRumEvent.types' import { THROTTLE_VIEW_UPDATE_PERIOD } from './trackViews' import type { ViewTest } from './setupViewTest.specHelper' import { setupViewTest } from './setupViewTest.specHelper' diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/trackViewEventCounts.ts b/packages/rum-core/src/domain/view/trackViewEventCounts.ts similarity index 93% rename from packages/rum-core/src/domain/rumEventsCollection/view/trackViewEventCounts.ts rename to packages/rum-core/src/domain/view/trackViewEventCounts.ts index 1694c63743..622140476d 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/trackViewEventCounts.ts +++ b/packages/rum-core/src/domain/view/trackViewEventCounts.ts @@ -1,6 +1,6 @@ import { ONE_MINUTE, setTimeout } from '@datadog/browser-core' -import type { LifeCycle } from '../../lifeCycle' -import { trackEventCounts } from '../../trackEventCounts' +import type { LifeCycle } from '../lifeCycle' +import { trackEventCounts } from '../trackEventCounts' // Some events are not being counted as they transcend views. To reduce the occurrence; // an arbitrary delay is added for stopping event counting after the view ends. diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/trackViews.spec.ts b/packages/rum-core/src/domain/view/trackViews.spec.ts similarity index 98% rename from packages/rum-core/src/domain/rumEventsCollection/view/trackViews.spec.ts rename to packages/rum-core/src/domain/view/trackViews.spec.ts index af7229d4a2..3d2e3e2174 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/trackViews.spec.ts +++ b/packages/rum-core/src/domain/view/trackViews.spec.ts @@ -7,11 +7,11 @@ import { relativeNow, resetExperimentalFeatures, } from '@datadog/browser-core' -import type { TestSetupBuilder } from '../../../../test' -import { setup } from '../../../../test' -import { RumEventType, ViewLoadingType } from '../../../rawRumEvent.types' -import type { RumEvent } from '../../../rumEvent.types' -import { LifeCycleEventType } from '../../lifeCycle' +import type { TestSetupBuilder } from '../../../test' +import { setup } from '../../../test' +import { RumEventType, ViewLoadingType } from '../../rawRumEvent.types' +import type { RumEvent } from '../../rumEvent.types' +import { LifeCycleEventType } from '../lifeCycle' import type { ViewEvent } from './trackViews' import { SESSION_KEEP_ALIVE_INTERVAL, THROTTLE_VIEW_UPDATE_PERIOD } from './trackViews' import type { ViewTest } from './setupViewTest.specHelper' diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/trackViews.ts b/packages/rum-core/src/domain/view/trackViews.ts similarity index 95% rename from packages/rum-core/src/domain/rumEventsCollection/view/trackViews.ts rename to packages/rum-core/src/domain/view/trackViews.ts index f2ed7ddff3..516df35def 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/trackViews.ts +++ b/packages/rum-core/src/domain/view/trackViews.ts @@ -16,14 +16,14 @@ import { clearInterval, } from '@datadog/browser-core' -import type { ViewCustomTimings } from '../../../rawRumEvent.types' -import { ViewLoadingType } from '../../../rawRumEvent.types' - -import type { LifeCycle } from '../../lifeCycle' -import { LifeCycleEventType } from '../../lifeCycle' -import type { EventCounts } from '../../trackEventCounts' -import type { LocationChange } from '../../../browser/locationChangeObservable' -import type { RumConfiguration } from '../../configuration' +import type { ViewCustomTimings } from '../../rawRumEvent.types' +import { ViewLoadingType } from '../../rawRumEvent.types' + +import type { LifeCycle } from '../lifeCycle' +import { LifeCycleEventType } from '../lifeCycle' +import type { EventCounts } from '../trackEventCounts' +import type { LocationChange } from '../../browser/locationChangeObservable' +import type { RumConfiguration } from '../configuration' import { trackViewEventCounts } from './trackViewEventCounts' import type { WebVitalTelemetryDebug } from './startWebVitalTelemetryDebug' import { trackInitialViewMetrics } from './viewMetrics/trackInitialViewMetrics' diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/viewCollection.spec.ts b/packages/rum-core/src/domain/view/viewCollection.spec.ts similarity index 95% rename from packages/rum-core/src/domain/rumEventsCollection/view/viewCollection.spec.ts rename to packages/rum-core/src/domain/view/viewCollection.spec.ts index 3220a62f06..bf8fef3276 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/viewCollection.spec.ts +++ b/packages/rum-core/src/domain/view/viewCollection.spec.ts @@ -1,12 +1,12 @@ import type { Duration, RelativeTime, ServerDuration, TimeStamp } from '@datadog/browser-core' import { resetExperimentalFeatures, ExperimentalFeature, addExperimentalFeatures } from '@datadog/browser-core' -import type { RecorderApi } from '../../../boot/rumPublicApi' -import type { TestSetupBuilder } from '../../../../test' -import { setup, noopRecorderApi, noopWebVitalTelemetryDebug } from '../../../../test' -import type { RawRumViewEvent } from '../../../rawRumEvent.types' -import { RumEventType, ViewLoadingType } from '../../../rawRumEvent.types' -import { LifeCycleEventType } from '../../lifeCycle' -import { PageState } from '../../contexts/pageStateHistory' +import type { RecorderApi } from '../../boot/rumPublicApi' +import type { TestSetupBuilder } from '../../../test' +import { setup, noopRecorderApi, noopWebVitalTelemetryDebug } from '../../../test' +import type { RawRumViewEvent } from '../../rawRumEvent.types' +import { RumEventType, ViewLoadingType } from '../../rawRumEvent.types' +import { LifeCycleEventType } from '../lifeCycle' +import { PageState } from '../contexts/pageStateHistory' import type { ViewEvent } from './trackViews' import { startViewCollection } from './viewCollection' diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/viewCollection.ts b/packages/rum-core/src/domain/view/viewCollection.ts similarity index 88% rename from packages/rum-core/src/domain/rumEventsCollection/view/viewCollection.ts rename to packages/rum-core/src/domain/view/viewCollection.ts index 24c29bae51..a582e5f8c1 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/viewCollection.ts +++ b/packages/rum-core/src/domain/view/viewCollection.ts @@ -7,16 +7,16 @@ import { toServerDuration, isNumber, } from '@datadog/browser-core' -import type { RecorderApi } from '../../../boot/rumPublicApi' -import type { RawRumViewEvent } from '../../../rawRumEvent.types' -import { RumEventType } from '../../../rawRumEvent.types' -import type { LifeCycle, RawRumEventCollectedData } from '../../lifeCycle' -import { LifeCycleEventType } from '../../lifeCycle' -import { mapToForegroundPeriods } from '../../contexts/foregroundContexts' -import type { LocationChange } from '../../../browser/locationChangeObservable' -import type { RumConfiguration } from '../../configuration' -import type { FeatureFlagContexts } from '../../contexts/featureFlagContext' -import type { PageStateHistory } from '../../contexts/pageStateHistory' +import type { RecorderApi } from '../../boot/rumPublicApi' +import type { RawRumViewEvent } from '../../rawRumEvent.types' +import { RumEventType } from '../../rawRumEvent.types' +import type { LifeCycle, RawRumEventCollectedData } from '../lifeCycle' +import { LifeCycleEventType } from '../lifeCycle' +import { mapToForegroundPeriods } from '../contexts/foregroundContexts' +import type { LocationChange } from '../../browser/locationChangeObservable' +import type { RumConfiguration } from '../configuration' +import type { FeatureFlagContexts } from '../contexts/featureFlagContext' +import type { PageStateHistory } from '../contexts/pageStateHistory' import type { ViewEvent, ViewOptions } from './trackViews' import { trackViews } from './trackViews' import type { WebVitalTelemetryDebug } from './startWebVitalTelemetryDebug' diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/interactionCountPolyfill.ts b/packages/rum-core/src/domain/view/viewMetrics/interactionCountPolyfill.ts similarity index 97% rename from packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/interactionCountPolyfill.ts rename to packages/rum-core/src/domain/view/viewMetrics/interactionCountPolyfill.ts index f80b38b846..e50d184ebf 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/interactionCountPolyfill.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/interactionCountPolyfill.ts @@ -16,7 +16,7 @@ import type { BrowserWindow, RumPerformanceEventTiming, RumPerformanceObserver, -} from '../../../../browser/performanceCollection' +} from '../../../browser/performanceCollection' let observer: RumPerformanceObserver | undefined diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackCommonViewMetrics.ts b/packages/rum-core/src/domain/view/viewMetrics/trackCommonViewMetrics.ts similarity index 94% rename from packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackCommonViewMetrics.ts rename to packages/rum-core/src/domain/view/viewMetrics/trackCommonViewMetrics.ts index 5a113f8e2d..6a96e95c09 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackCommonViewMetrics.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackCommonViewMetrics.ts @@ -1,8 +1,8 @@ import type { ClocksState, Duration, Observable } from '@datadog/browser-core' import { noop } from '@datadog/browser-core' -import type { ViewLoadingType } from '../../../../rawRumEvent.types' -import type { RumConfiguration } from '../../../configuration' -import type { LifeCycle } from '../../../lifeCycle' +import type { ViewLoadingType } from '../../../rawRumEvent.types' +import type { RumConfiguration } from '../../configuration' +import type { LifeCycle } from '../../lifeCycle' import type { WebVitalTelemetryDebug } from '../startWebVitalTelemetryDebug' import type { ScrollMetrics } from './trackScrollMetrics' import { computeScrollValues, trackScrollMetrics } from './trackScrollMetrics' diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackCumulativeLayoutShift.spec.ts b/packages/rum-core/src/domain/view/viewMetrics/trackCumulativeLayoutShift.spec.ts similarity index 96% rename from packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackCumulativeLayoutShift.spec.ts rename to packages/rum-core/src/domain/view/viewMetrics/trackCumulativeLayoutShift.spec.ts index ad85d2a3ef..227d79bf47 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackCumulativeLayoutShift.spec.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackCumulativeLayoutShift.spec.ts @@ -1,8 +1,8 @@ import { relativeNow } from '@datadog/browser-core' -import type { TestSetupBuilder } from '../../../../../test' -import { setup } from '../../../../../test' -import type { LifeCycle } from '../../../lifeCycle' -import { LifeCycleEventType } from '../../../lifeCycle' +import type { TestSetupBuilder } from '../../../../test' +import { setup } from '../../../../test' +import type { LifeCycle } from '../../lifeCycle' +import { LifeCycleEventType } from '../../lifeCycle' import { THROTTLE_VIEW_UPDATE_PERIOD } from '../trackViews' import type { ViewTest } from '../setupViewTest.specHelper' import { setupViewTest } from '../setupViewTest.specHelper' diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackCumulativeLayoutShift.ts b/packages/rum-core/src/domain/view/viewMetrics/trackCumulativeLayoutShift.ts similarity index 95% rename from packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackCumulativeLayoutShift.ts rename to packages/rum-core/src/domain/view/viewMetrics/trackCumulativeLayoutShift.ts index e45a511012..810da4a2f0 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackCumulativeLayoutShift.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackCumulativeLayoutShift.ts @@ -1,7 +1,7 @@ import { round, type RelativeTime, find, ONE_SECOND } from '@datadog/browser-core' -import type { LifeCycle } from '../../../lifeCycle' -import { LifeCycleEventType } from '../../../lifeCycle' -import { supportPerformanceTimingEvent, type RumLayoutShiftTiming } from '../../../../browser/performanceCollection' +import type { LifeCycle } from '../../lifeCycle' +import { LifeCycleEventType } from '../../lifeCycle' +import { supportPerformanceTimingEvent, type RumLayoutShiftTiming } from '../../../browser/performanceCollection' /** * Track the cumulative layout shifts (CLS). diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackFirstContentfulPaint.spec.ts b/packages/rum-core/src/domain/view/viewMetrics/trackFirstContentfulPaint.spec.ts similarity index 90% rename from packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackFirstContentfulPaint.spec.ts rename to packages/rum-core/src/domain/view/viewMetrics/trackFirstContentfulPaint.spec.ts index a2bba947ca..97ef974bf2 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackFirstContentfulPaint.spec.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackFirstContentfulPaint.spec.ts @@ -1,10 +1,10 @@ import type { RelativeTime } from '@datadog/browser-core' import { restorePageVisibility, setPageVisibility } from '@datadog/browser-core/test' import type { RumPerformancePaintTiming } from 'packages/rum-core/src/browser/performanceCollection' -import type { TestSetupBuilder } from '../../../../../test' -import { setup } from '../../../../../test' -import { LifeCycleEventType } from '../../../lifeCycle' -import type { RumConfiguration } from '../../../configuration' +import type { TestSetupBuilder } from '../../../../test' +import { setup } from '../../../../test' +import { LifeCycleEventType } from '../../lifeCycle' +import type { RumConfiguration } from '../../configuration' import { resetFirstHidden } from './trackFirstHidden' import { FCP_MAXIMUM_DELAY, trackFirstContentfulPaint } from './trackFirstContentfulPaint' diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackFirstContentfulPaint.ts b/packages/rum-core/src/domain/view/viewMetrics/trackFirstContentfulPaint.ts similarity index 80% rename from packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackFirstContentfulPaint.ts rename to packages/rum-core/src/domain/view/viewMetrics/trackFirstContentfulPaint.ts index 8f52000769..885c95c051 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackFirstContentfulPaint.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackFirstContentfulPaint.ts @@ -1,9 +1,9 @@ import type { RelativeTime } from '@datadog/browser-core' import { ONE_MINUTE, find } from '@datadog/browser-core' -import type { RumConfiguration } from '../../../configuration' -import type { LifeCycle } from '../../../lifeCycle' -import { LifeCycleEventType } from '../../../lifeCycle' -import type { RumPerformancePaintTiming } from '../../../../browser/performanceCollection' +import type { RumConfiguration } from '../../configuration' +import type { LifeCycle } from '../../lifeCycle' +import { LifeCycleEventType } from '../../lifeCycle' +import type { RumPerformancePaintTiming } from '../../../browser/performanceCollection' import { trackFirstHidden } from './trackFirstHidden' // Discard FCP timings above a certain delay to avoid incorrect data diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackFirstHidden.spec.ts b/packages/rum-core/src/domain/view/viewMetrics/trackFirstHidden.spec.ts similarity index 98% rename from packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackFirstHidden.spec.ts rename to packages/rum-core/src/domain/view/viewMetrics/trackFirstHidden.spec.ts index b81d882142..ddb8bc46c4 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackFirstHidden.spec.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackFirstHidden.spec.ts @@ -1,7 +1,7 @@ import type { RelativeTime } from '@datadog/browser-core' import { DOM_EVENT } from '@datadog/browser-core' import { createNewEvent, restorePageVisibility, setPageVisibility } from '@datadog/browser-core/test' -import type { RumConfiguration } from '../../../configuration' +import type { RumConfiguration } from '../../configuration' import { resetFirstHidden, trackFirstHidden } from './trackFirstHidden' describe('trackFirstHidden', () => { diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackFirstHidden.ts b/packages/rum-core/src/domain/view/viewMetrics/trackFirstHidden.ts similarity index 95% rename from packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackFirstHidden.ts rename to packages/rum-core/src/domain/view/viewMetrics/trackFirstHidden.ts index e6fe411b0f..0cdecd25d9 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackFirstHidden.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackFirstHidden.ts @@ -1,6 +1,6 @@ import type { RelativeTime } from '@datadog/browser-core' import { addEventListeners, DOM_EVENT } from '@datadog/browser-core' -import type { RumConfiguration } from '../../../configuration' +import type { RumConfiguration } from '../../configuration' let trackFirstHiddenSingleton: { timeStamp: RelativeTime } | undefined let stopListeners: (() => void) | undefined diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackFirstInputTimings.spec.ts b/packages/rum-core/src/domain/view/viewMetrics/trackFirstInputTimings.spec.ts similarity index 91% rename from packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackFirstInputTimings.spec.ts rename to packages/rum-core/src/domain/view/viewMetrics/trackFirstInputTimings.spec.ts index cd487cfa2f..590f6076b9 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackFirstInputTimings.spec.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackFirstInputTimings.spec.ts @@ -1,9 +1,9 @@ import type { Duration, RelativeTime } from '@datadog/browser-core' import { restorePageVisibility, setPageVisibility } from '@datadog/browser-core/test' -import type { TestSetupBuilder } from '../../../../../test' -import { setup } from '../../../../../test' -import { LifeCycleEventType } from '../../../lifeCycle' -import type { RumConfiguration } from '../../../configuration' +import type { TestSetupBuilder } from '../../../../test' +import { setup } from '../../../../test' +import { LifeCycleEventType } from '../../lifeCycle' +import type { RumConfiguration } from '../../configuration' import { FAKE_FIRST_INPUT_ENTRY } from '../setupViewTest.specHelper' import { resetFirstHidden } from './trackFirstHidden' import { trackFirstInputTimings } from './trackFirstInputTimings' diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackFirstInputTimings.ts b/packages/rum-core/src/domain/view/viewMetrics/trackFirstInputTimings.ts similarity index 86% rename from packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackFirstInputTimings.ts rename to packages/rum-core/src/domain/view/viewMetrics/trackFirstInputTimings.ts index 72c7544794..b3872dc2bc 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackFirstInputTimings.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackFirstInputTimings.ts @@ -1,9 +1,9 @@ import type { Duration, RelativeTime } from '@datadog/browser-core' import { elapsed, find } from '@datadog/browser-core' -import type { RumConfiguration } from '../../../configuration' -import type { LifeCycle } from '../../../lifeCycle' -import { LifeCycleEventType } from '../../../lifeCycle' -import type { RumFirstInputTiming } from '../../../../browser/performanceCollection' +import type { RumConfiguration } from '../../configuration' +import type { LifeCycle } from '../../lifeCycle' +import { LifeCycleEventType } from '../../lifeCycle' +import type { RumFirstInputTiming } from '../../../browser/performanceCollection' import { trackFirstHidden } from './trackFirstHidden' /** diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackInitialViewMetrics.spec.ts b/packages/rum-core/src/domain/view/viewMetrics/trackInitialViewMetrics.spec.ts similarity index 91% rename from packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackInitialViewMetrics.spec.ts rename to packages/rum-core/src/domain/view/viewMetrics/trackInitialViewMetrics.spec.ts index 49bfc69456..ae301dc32b 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackInitialViewMetrics.spec.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackInitialViewMetrics.spec.ts @@ -1,8 +1,8 @@ import type { Duration } from '@datadog/browser-core' -import type { TestSetupBuilder } from '../../../../../test' -import { noopWebVitalTelemetryDebug, setup } from '../../../../../test' -import { LifeCycleEventType } from '../../../lifeCycle' -import type { RumConfiguration } from '../../../configuration' +import type { TestSetupBuilder } from '../../../../test' +import { noopWebVitalTelemetryDebug, setup } from '../../../../test' +import { LifeCycleEventType } from '../../lifeCycle' +import type { RumConfiguration } from '../../configuration' import { FAKE_FIRST_INPUT_ENTRY, FAKE_NAVIGATION_ENTRY, FAKE_PAINT_ENTRY } from '../setupViewTest.specHelper' import { KEEP_TRACKING_METRICS_AFTER_VIEW_DELAY, trackInitialViewMetrics } from './trackInitialViewMetrics' diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackInitialViewMetrics.ts b/packages/rum-core/src/domain/view/viewMetrics/trackInitialViewMetrics.ts similarity index 96% rename from packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackInitialViewMetrics.ts rename to packages/rum-core/src/domain/view/viewMetrics/trackInitialViewMetrics.ts index 26be24dacd..51c31b70de 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackInitialViewMetrics.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackInitialViewMetrics.ts @@ -1,7 +1,7 @@ import type { Duration } from '@datadog/browser-core' import { setTimeout, assign, ONE_MINUTE } from '@datadog/browser-core' -import type { RumConfiguration } from '../../../configuration' -import type { LifeCycle } from '../../../lifeCycle' +import type { RumConfiguration } from '../../configuration' +import type { LifeCycle } from '../../lifeCycle' import type { WebVitalTelemetryDebug } from '../startWebVitalTelemetryDebug' import { trackFirstContentfulPaint } from './trackFirstContentfulPaint' import { trackFirstInputTimings } from './trackFirstInputTimings' diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackInteractionToNextPaint.spec.ts b/packages/rum-core/src/domain/view/viewMetrics/trackInteractionToNextPaint.spec.ts similarity index 94% rename from packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackInteractionToNextPaint.spec.ts rename to packages/rum-core/src/domain/view/viewMetrics/trackInteractionToNextPaint.spec.ts index acde12e5d6..a8c0679eb7 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackInteractionToNextPaint.spec.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackInteractionToNextPaint.spec.ts @@ -5,16 +5,16 @@ import { relativeNow, resetExperimentalFeatures, } from '@datadog/browser-core' -import type { TestSetupBuilder } from '../../../../../test' -import { setup } from '../../../../../test' +import type { TestSetupBuilder } from '../../../../test' +import { setup } from '../../../../test' import type { BrowserWindow, RumFirstInputTiming, RumPerformanceEventTiming, -} from '../../../../browser/performanceCollection' -import { ViewLoadingType } from '../../../../rawRumEvent.types' -import type { LifeCycle } from '../../../lifeCycle' -import { LifeCycleEventType } from '../../../lifeCycle' +} from '../../../browser/performanceCollection' +import { ViewLoadingType } from '../../../rawRumEvent.types' +import type { LifeCycle } from '../../lifeCycle' +import { LifeCycleEventType } from '../../lifeCycle' import { trackInteractionToNextPaint, trackViewInteractionCount, diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackInteractionToNextPaint.ts b/packages/rum-core/src/domain/view/viewMetrics/trackInteractionToNextPaint.ts similarity index 94% rename from packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackInteractionToNextPaint.ts rename to packages/rum-core/src/domain/view/viewMetrics/trackInteractionToNextPaint.ts index 4196ba9f99..c89bae59c2 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackInteractionToNextPaint.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackInteractionToNextPaint.ts @@ -1,9 +1,9 @@ import { noop, isExperimentalFeatureEnabled, ExperimentalFeature } from '@datadog/browser-core' import type { Duration } from '@datadog/browser-core' -import { supportPerformanceTimingEvent } from '../../../../browser/performanceCollection' -import type { RumFirstInputTiming, RumPerformanceEventTiming } from '../../../../browser/performanceCollection' -import { LifeCycleEventType, type LifeCycle } from '../../../lifeCycle' -import { ViewLoadingType } from '../../../../rawRumEvent.types' +import { supportPerformanceTimingEvent } from '../../../browser/performanceCollection' +import type { RumFirstInputTiming, RumPerformanceEventTiming } from '../../../browser/performanceCollection' +import { LifeCycleEventType, type LifeCycle } from '../../lifeCycle' +import { ViewLoadingType } from '../../../rawRumEvent.types' import { getInteractionCount, initInteractionCountPolyfill } from './interactionCountPolyfill' // Arbitrary value to prevent unnecessary memory usage on views with lots of interactions. diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackLargestContentfulPaint.spec.ts b/packages/rum-core/src/domain/view/viewMetrics/trackLargestContentfulPaint.spec.ts similarity index 89% rename from packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackLargestContentfulPaint.spec.ts rename to packages/rum-core/src/domain/view/viewMetrics/trackLargestContentfulPaint.spec.ts index e2e70274f9..34aa514e27 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackLargestContentfulPaint.spec.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackLargestContentfulPaint.spec.ts @@ -1,11 +1,11 @@ import type { RelativeTime } from '@datadog/browser-core' import { DOM_EVENT } from '@datadog/browser-core' import { restorePageVisibility, setPageVisibility, createNewEvent } from '@datadog/browser-core/test' -import type { RumLargestContentfulPaintTiming } from '../../../../browser/performanceCollection' -import type { TestSetupBuilder } from '../../../../../test' -import { setup } from '../../../../../test' -import { LifeCycleEventType } from '../../../lifeCycle' -import type { RumConfiguration } from '../../../configuration' +import type { RumLargestContentfulPaintTiming } from '../../../browser/performanceCollection' +import type { TestSetupBuilder } from '../../../../test' +import { setup } from '../../../../test' +import { LifeCycleEventType } from '../../lifeCycle' +import type { RumConfiguration } from '../../configuration' import { resetFirstHidden } from './trackFirstHidden' import { LCP_MAXIMUM_DELAY, trackLargestContentfulPaint } from './trackLargestContentfulPaint' diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackLargestContentfulPaint.ts b/packages/rum-core/src/domain/view/viewMetrics/trackLargestContentfulPaint.ts similarity index 90% rename from packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackLargestContentfulPaint.ts rename to packages/rum-core/src/domain/view/viewMetrics/trackLargestContentfulPaint.ts index 24d6020556..979a437e8d 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackLargestContentfulPaint.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackLargestContentfulPaint.ts @@ -1,8 +1,8 @@ import type { RelativeTime } from '@datadog/browser-core' import { DOM_EVENT, ONE_MINUTE, addEventListeners, findLast } from '@datadog/browser-core' -import { LifeCycleEventType, type LifeCycle } from '../../../lifeCycle' -import type { RumConfiguration } from '../../../configuration' -import type { RumLargestContentfulPaintTiming } from '../../../../browser/performanceCollection' +import { LifeCycleEventType, type LifeCycle } from '../../lifeCycle' +import type { RumConfiguration } from '../../configuration' +import type { RumLargestContentfulPaintTiming } from '../../../browser/performanceCollection' import { trackFirstHidden } from './trackFirstHidden' // Discard LCP timings above a certain delay to avoid incorrect data diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackLoadingTime.spec.ts b/packages/rum-core/src/domain/view/viewMetrics/trackLoadingTime.spec.ts similarity index 95% rename from packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackLoadingTime.spec.ts rename to packages/rum-core/src/domain/view/viewMetrics/trackLoadingTime.spec.ts index 07341374b3..9a3c6f4cef 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackLoadingTime.spec.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackLoadingTime.spec.ts @@ -1,10 +1,10 @@ import type { RelativeTime, Duration } from '@datadog/browser-core' import { addDuration } from '@datadog/browser-core' -import type { TestSetupBuilder } from '../../../../../test' -import { setup } from '../../../../../test' -import type { RumPerformanceNavigationTiming } from '../../../../browser/performanceCollection' -import { LifeCycleEventType } from '../../../lifeCycle' -import { PAGE_ACTIVITY_END_DELAY, PAGE_ACTIVITY_VALIDATION_DELAY } from '../../../waitPageActivityEnd' +import type { TestSetupBuilder } from '../../../../test' +import { setup } from '../../../../test' +import type { RumPerformanceNavigationTiming } from '../../../browser/performanceCollection' +import { LifeCycleEventType } from '../../lifeCycle' +import { PAGE_ACTIVITY_END_DELAY, PAGE_ACTIVITY_VALIDATION_DELAY } from '../../waitPageActivityEnd' import { THROTTLE_VIEW_UPDATE_PERIOD } from '../trackViews' import type { ViewTest } from '../setupViewTest.specHelper' import { FAKE_NAVIGATION_ENTRY, setupViewTest } from '../setupViewTest.specHelper' diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackLoadingTime.ts b/packages/rum-core/src/domain/view/viewMetrics/trackLoadingTime.ts similarity index 84% rename from packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackLoadingTime.ts rename to packages/rum-core/src/domain/view/viewMetrics/trackLoadingTime.ts index d3ea07e908..d34ed787eb 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackLoadingTime.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackLoadingTime.ts @@ -1,9 +1,9 @@ import type { ClocksState, Duration, Observable } from '@datadog/browser-core' import { elapsed } from '@datadog/browser-core' -import { waitPageActivityEnd } from '../../../waitPageActivityEnd' -import type { RumConfiguration } from '../../../configuration' -import type { LifeCycle } from '../../../lifeCycle' -import { ViewLoadingType } from '../../../../rawRumEvent.types' +import { waitPageActivityEnd } from '../../waitPageActivityEnd' +import type { RumConfiguration } from '../../configuration' +import type { LifeCycle } from '../../lifeCycle' +import { ViewLoadingType } from '../../../rawRumEvent.types' export function trackLoadingTime( lifeCycle: LifeCycle, diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackNavigationTimings.spec.ts b/packages/rum-core/src/domain/view/viewMetrics/trackNavigationTimings.spec.ts similarity index 88% rename from packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackNavigationTimings.spec.ts rename to packages/rum-core/src/domain/view/viewMetrics/trackNavigationTimings.spec.ts index 7299eb1c91..69b408e31f 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackNavigationTimings.spec.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackNavigationTimings.spec.ts @@ -1,7 +1,7 @@ import type { Duration } from '@datadog/browser-core' -import type { TestSetupBuilder } from '../../../../../test' -import { setup } from '../../../../../test' -import { LifeCycleEventType } from '../../../lifeCycle' +import type { TestSetupBuilder } from '../../../../test' +import { setup } from '../../../../test' +import { LifeCycleEventType } from '../../lifeCycle' import { FAKE_NAVIGATION_ENTRY } from '../setupViewTest.specHelper' import type { InitialViewMetrics } from './trackInitialViewMetrics' import { trackNavigationTimings } from './trackNavigationTimings' diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackNavigationTimings.ts b/packages/rum-core/src/domain/view/viewMetrics/trackNavigationTimings.ts similarity index 91% rename from packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackNavigationTimings.ts rename to packages/rum-core/src/domain/view/viewMetrics/trackNavigationTimings.ts index b4bf9c88ee..1de0b3fc47 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackNavigationTimings.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackNavigationTimings.ts @@ -1,7 +1,7 @@ import type { Duration } from '@datadog/browser-core' import { relativeNow } from '@datadog/browser-core' -import type { LifeCycle } from '../../../lifeCycle' -import { LifeCycleEventType } from '../../../lifeCycle' +import type { LifeCycle } from '../../lifeCycle' +import { LifeCycleEventType } from '../../lifeCycle' export interface NavigationTimings { domComplete: Duration diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackScrollMetrics.spec.ts b/packages/rum-core/src/domain/view/viewMetrics/trackScrollMetrics.spec.ts similarity index 95% rename from packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackScrollMetrics.spec.ts rename to packages/rum-core/src/domain/view/viewMetrics/trackScrollMetrics.spec.ts index 2cb1a0a6d7..f9f11d9eab 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackScrollMetrics.spec.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackScrollMetrics.spec.ts @@ -2,10 +2,10 @@ import type { RelativeTime, TimeStamp, Duration } from '@datadog/browser-core' import { DOM_EVENT } from '@datadog/browser-core' import type { Clock } from '@datadog/browser-core/test' import { createNewEvent, mockClock } from '@datadog/browser-core/test' -import type { TestSetupBuilder } from '../../../../../test' -import { setup } from '../../../../../test' -import { PAGE_ACTIVITY_END_DELAY, PAGE_ACTIVITY_VALIDATION_DELAY } from '../../../waitPageActivityEnd' -import type { RumConfiguration } from '../../../configuration' +import type { TestSetupBuilder } from '../../../../test' +import { setup } from '../../../../test' +import { PAGE_ACTIVITY_END_DELAY, PAGE_ACTIVITY_VALIDATION_DELAY } from '../../waitPageActivityEnd' +import type { RumConfiguration } from '../../configuration' import { THROTTLE_VIEW_UPDATE_PERIOD } from '../trackViews' import type { ViewTest } from '../setupViewTest.specHelper' import { setupViewTest } from '../setupViewTest.specHelper' diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackScrollMetrics.ts b/packages/rum-core/src/domain/view/viewMetrics/trackScrollMetrics.ts similarity index 89% rename from packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackScrollMetrics.ts rename to packages/rum-core/src/domain/view/viewMetrics/trackScrollMetrics.ts index 564f329387..518c0f46c9 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/viewMetrics/trackScrollMetrics.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackScrollMetrics.ts @@ -1,8 +1,8 @@ import type { ClocksState, Duration } from '@datadog/browser-core' import { ONE_SECOND, elapsed, relativeNow, throttle, addEventListener, DOM_EVENT } from '@datadog/browser-core' -import type { RumConfiguration } from '../../../configuration' -import { getScrollY } from '../../../../browser/scroll' -import { getViewportDimension } from '../../../../browser/viewportObservable' +import type { RumConfiguration } from '../../configuration' +import { getScrollY } from '../../../browser/scroll' +import { getViewportDimension } from '../../../browser/viewportObservable' /** Arbitrary scroll throttle duration */ export const THROTTLE_SCROLL_DURATION = ONE_SECOND diff --git a/packages/rum-core/src/index.ts b/packages/rum-core/src/index.ts index 2680370340..638e7113b1 100644 --- a/packages/rum-core/src/index.ts +++ b/packages/rum-core/src/index.ts @@ -21,14 +21,14 @@ export { export { ReplayStats, ActionType, RumEventType, FrustrationType, RawRumActionEvent } from './rawRumEvent.types' export { startRum } from './boot/startRum' export { LifeCycle, LifeCycleEventType } from './domain/lifeCycle' -export { ViewCreatedEvent } from './domain/rumEventsCollection/view/trackViews' +export { ViewCreatedEvent } from './domain/view/trackViews' export { ViewContexts, ViewContext } from './domain/contexts/viewContexts' export { RumSessionManager, RumSessionPlan, RumSession } from './domain/rumSessionManager' export { getMutationObserverConstructor } from './browser/domMutationObservable' export { initViewportObservable, getViewportDimension } from './browser/viewportObservable' export { getScrollX, getScrollY } from './browser/scroll' export { RumInitConfiguration, RumConfiguration } from './domain/configuration' -export { DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE } from './domain/rumEventsCollection/action/getActionNameFromElement' -export { STABLE_ATTRIBUTES } from './domain/rumEventsCollection/action/getSelectorFromElement' +export { DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE } from './domain/action/getActionNameFromElement' +export { STABLE_ATTRIBUTES } from './domain/action/getSelectorFromElement' export * from './browser/htmlDomUtils' export { getSessionReplayUrl } from './domain/getSessionReplayUrl' diff --git a/packages/rum-core/test/createFakeClick.ts b/packages/rum-core/test/createFakeClick.ts index c5eef7adcc..6fc65016c3 100644 --- a/packages/rum-core/test/createFakeClick.ts +++ b/packages/rum-core/test/createFakeClick.ts @@ -1,6 +1,6 @@ import { clocksNow, Observable, timeStampNow } from '@datadog/browser-core' import { createNewEvent } from '@datadog/browser-core/test' -import type { Click } from '../src/domain/rumEventsCollection/action/trackClickActions' +import type { Click } from '../src/domain/action/trackClickActions' export type FakeClick = Readonly> diff --git a/packages/rum-core/test/testSetupBuilder.ts b/packages/rum-core/test/testSetupBuilder.ts index 48e360522a..5f0903d48d 100644 --- a/packages/rum-core/test/testSetupBuilder.ts +++ b/packages/rum-core/test/testSetupBuilder.ts @@ -11,7 +11,7 @@ import type { UrlContexts } from '../src/domain/contexts/urlContexts' import type { ViewContexts } from '../src/domain/contexts/viewContexts' import type { RawRumEventCollectedData } from '../src/domain/lifeCycle' import { LifeCycle, LifeCycleEventType } from '../src/domain/lifeCycle' -import type { ActionContexts } from '../src/domain/rumEventsCollection/action/actionCollection' +import type { ActionContexts } from '../src/domain/action/actionCollection' import type { RumSessionManager } from '../src/domain/rumSessionManager' import { RumSessionPlan } from '../src/domain/rumSessionManager' import type { RawRumEvent, RumContext } from '../src/rawRumEvent.types' From fc86c9580fb19b6046fe987d5a0f553a8838ecfe Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 7 Sep 2023 14:53:03 +0200 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=91=B7=20Update=20dependency=20eslint?= =?UTF-8?q?-plugin-local-rules=20to=20v2=20(#2392)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index a17a202cfb..68096622f8 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "eslint-plugin-import": "2.28.1", "eslint-plugin-jasmine": "4.1.3", "eslint-plugin-jsdoc": "46.5.1", - "eslint-plugin-local-rules": "1.3.2", + "eslint-plugin-local-rules": "2.0.0", "eslint-plugin-prefer-arrow": "1.2.3", "eslint-plugin-unicorn": "48.0.1", "express": "4.18.2", diff --git a/yarn.lock b/yarn.lock index 11f972df3f..bbde542c8c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3871,7 +3871,7 @@ __metadata: eslint-plugin-import: 2.28.1 eslint-plugin-jasmine: 4.1.3 eslint-plugin-jsdoc: 46.5.1 - eslint-plugin-local-rules: 1.3.2 + eslint-plugin-local-rules: 2.0.0 eslint-plugin-prefer-arrow: 1.2.3 eslint-plugin-unicorn: 48.0.1 express: 4.18.2 @@ -6254,10 +6254,10 @@ __metadata: languageName: node linkType: hard -"eslint-plugin-local-rules@npm:1.3.2": - version: 1.3.2 - resolution: "eslint-plugin-local-rules@npm:1.3.2" - checksum: d1d94c0832d7a5e1686c4d685614c407998e7a60318893a405fb8c97c3856b05a8d9479c20ad2799667a59ebfebc4c4f3268528d21d849d2062dee2041b9e909 +"eslint-plugin-local-rules@npm:2.0.0": + version: 2.0.0 + resolution: "eslint-plugin-local-rules@npm:2.0.0" + checksum: 597a052a93de1fe9e9bfc7187db43f8ed66ceaf0e12bb759a931fe02607da42a70d1e1029bef2ee6ac221ad205ab63c18827e375ae5e88061bf7f24325479c11 languageName: node linkType: hard From e50a493356779dd028e18baed554365868e8516b Mon Sep 17 00:00:00 2001 From: Bastien Caudan <1331991+bcaudan@users.noreply.github.com> Date: Thu, 7 Sep 2023 17:06:59 +0200 Subject: [PATCH 3/4] =?UTF-8?q?=E2=99=BB=EF=B8=8F=E2=9C=85=20prevent=20eve?= =?UTF-8?q?nt=20listener=20leaks=20in=20unit=20tests=20(#2402)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ✅ add event listener leak detection * ♻️ cleanup worker and encoder * ♻️ extract display context as a dependency * ♻️ cleanup view collection * ✅ cleanup some tests * ♻️ cleanup batch * ♻️ cleanup startRum * ♻️ cleanup startLogs * 👌 stop worker in reset * 👌 move leak detection to test code * 👌 introduce registerCleanupTask apply across code base in future PR * ♻️ switch firstHidden from singleton to dependency Remove from firstHidden the responsibility to handle multiple usages. firstHidden is initialized by a higher component and passed to dependants. * 👌 avoid to leak view references in production - centralize concept of views stopping completely after 5 min - maintain list of active views to stop them all during the tests - when a view stop, it is removed from the active views list to avoid memeory leak * 👌 use a Set of views * 👌 fix type * 👌 simplify cleanup * 🐛 disable leak detection for IE --- packages/core/src/browser/addEventListener.ts | 6 +- .../src/browser/pageExitObservable.spec.ts | 9 +-- packages/core/src/transport/batch.ts | 8 +- .../core/src/transport/flushController.ts | 9 ++- .../src/transport/startBatchWithReplica.ts | 5 ++ packages/core/test/forEach.spec.ts | 3 + packages/core/test/index.ts | 1 + packages/core/test/leakDetection.ts | 58 ++++++++++++++ packages/core/test/registerCleanupTask.ts | 9 +++ packages/logs/src/boot/startLogs.spec.ts | 29 ++++--- packages/logs/src/boot/startLogs.ts | 38 +++++++-- packages/logs/src/transport/startLogsBatch.ts | 2 + .../rum-core/src/boot/rumPublicApi.spec.ts | 1 + packages/rum-core/src/boot/startRum.spec.ts | 15 ++-- packages/rum-core/src/boot/startRum.ts | 33 +++++++- packages/rum-core/src/domain/assembly.spec.ts | 35 ++++---- packages/rum-core/src/domain/assembly.ts | 5 +- .../domain/contexts/displayContext.spec.ts | 9 ++- .../src/domain/contexts/displayContext.ts | 25 ++---- .../contexts/foregroundContexts.spec.ts | 5 +- .../domain/contexts/pageStateHistory.spec.ts | 6 +- .../domain/view/trackViewEventCounts.spec.ts | 45 ----------- .../src/domain/view/trackViewEventCounts.ts | 22 +---- .../src/domain/view/trackViews.spec.ts | 80 +++++++++++++++++-- .../rum-core/src/domain/view/trackViews.ts | 47 ++++++++--- .../src/domain/view/viewCollection.spec.ts | 2 +- .../src/domain/view/viewCollection.ts | 4 +- .../trackFirstContentfulPaint.spec.ts | 17 ++-- .../viewMetrics/trackFirstContentfulPaint.ts | 37 +++++---- .../view/viewMetrics/trackFirstHidden.spec.ts | 22 ++--- .../view/viewMetrics/trackFirstHidden.ts | 58 +++++++------- .../trackFirstInputTimings.spec.ts | 15 +++- .../viewMetrics/trackFirstInputTimings.ts | 44 +++++----- .../trackInitialViewMetrics.spec.ts | 17 +--- .../viewMetrics/trackInitialViewMetrics.ts | 21 ++--- .../trackLargestContentfulPaint.spec.ts | 23 ++++-- .../trackLargestContentfulPaint.ts | 5 +- packages/rum-core/test/testSetupBuilder.ts | 7 ++ packages/rum/src/boot/startRecording.spec.ts | 20 ++++- .../rum/src/domain/deflate/deflateEncoder.ts | 5 ++ .../rum/src/domain/deflate/deflateWorker.ts | 33 +++++--- 41 files changed, 525 insertions(+), 310 deletions(-) create mode 100644 packages/core/test/leakDetection.ts create mode 100644 packages/core/test/registerCleanupTask.ts diff --git a/packages/core/src/browser/addEventListener.ts b/packages/core/src/browser/addEventListener.ts index d4211afc2d..c121c41d59 100644 --- a/packages/core/src/browser/addEventListener.ts +++ b/packages/core/src/browser/addEventListener.ts @@ -111,7 +111,7 @@ export function addEventListeners[EventName]) => void, { once, capture, passive }: AddEventListenerOptions = {} ) { - const wrappedListener = monitor( + const listenerWithMonitor = monitor( once ? (event: Event) => { stop() @@ -123,11 +123,11 @@ export function addEventListeners add.call(eventTarget, eventName, wrappedListener, options)) + eventNames.forEach((eventName) => add.call(eventTarget, eventName, listenerWithMonitor, options)) function stop() { const remove = getZoneJsOriginalValue(eventTarget, 'removeEventListener') - eventNames.forEach((eventName) => remove.call(eventTarget, eventName, wrappedListener, options)) + eventNames.forEach((eventName) => remove.call(eventTarget, eventName, listenerWithMonitor, options)) } return { diff --git a/packages/core/src/browser/pageExitObservable.spec.ts b/packages/core/src/browser/pageExitObservable.spec.ts index e2382b6ca9..b81e8efb80 100644 --- a/packages/core/src/browser/pageExitObservable.spec.ts +++ b/packages/core/src/browser/pageExitObservable.spec.ts @@ -1,23 +1,20 @@ import type { Configuration } from '../domain/configuration' -import { createNewEvent, restorePageVisibility, setPageVisibility } from '../../test' +import { createNewEvent, restorePageVisibility, setPageVisibility, registerCleanupTask } from '../../test' import { resetExperimentalFeatures, addExperimentalFeatures, ExperimentalFeature } from '../tools/experimentalFeatures' -import type { Subscription } from '../tools/observable' import type { PageExitEvent } from './pageExitObservable' import { PageExitReason, createPageExitObservable } from './pageExitObservable' describe('createPageExitObservable', () => { - let pageExitSubscription: Subscription let onExitSpy: jasmine.Spy<(event: PageExitEvent) => void> let configuration: Configuration beforeEach(() => { onExitSpy = jasmine.createSpy() configuration = {} as Configuration - pageExitSubscription = createPageExitObservable(configuration).subscribe(onExitSpy) + registerCleanupTask(createPageExitObservable(configuration).subscribe(onExitSpy).unsubscribe) }) afterEach(() => { - pageExitSubscription.unsubscribe() restorePageVisibility() resetExperimentalFeatures() }) @@ -25,7 +22,7 @@ describe('createPageExitObservable', () => { it('notifies when the page fires pagehide if ff pagehide is enabled', () => { addExperimentalFeatures([ExperimentalFeature.PAGEHIDE]) onExitSpy = jasmine.createSpy() - pageExitSubscription = createPageExitObservable(configuration).subscribe(onExitSpy) + registerCleanupTask(createPageExitObservable(configuration).subscribe(onExitSpy).unsubscribe) window.dispatchEvent(createNewEvent('pagehide')) window.dispatchEvent(createNewEvent('beforeunload')) diff --git a/packages/core/src/transport/batch.ts b/packages/core/src/transport/batch.ts index e4b68727d1..066ae9a8fd 100644 --- a/packages/core/src/transport/batch.ts +++ b/packages/core/src/transport/batch.ts @@ -4,19 +4,21 @@ import { objectValues } from '../tools/utils/polyfills' import { isPageExitReason } from '../browser/pageExitObservable' import { computeBytesCount } from '../tools/utils/byteUtils' import { jsonStringify } from '../tools/serialisation/jsonStringify' +import type { Subscription } from '../tools/observable' import type { HttpRequest } from './httpRequest' import type { FlushController, FlushEvent } from './flushController' export class Batch { private pushOnlyBuffer: string[] = [] private upsertBuffer: { [key: string]: string } = {} + private flushSubscription: Subscription constructor( private request: HttpRequest, public flushController: FlushController, private messageBytesLimit: number ) { - this.flushController.flushObservable.subscribe((event) => this.flush(event)) + this.flushSubscription = this.flushController.flushObservable.subscribe((event) => this.flush(event)) } add(message: Context) { @@ -27,6 +29,10 @@ export class Batch { this.addOrUpdate(message, key) } + stop() { + this.flushSubscription.unsubscribe() + } + private flush(event: FlushEvent) { const messages = this.pushOnlyBuffer.concat(objectValues(this.upsertBuffer)) diff --git a/packages/core/src/transport/flushController.ts b/packages/core/src/transport/flushController.ts index dfbe7d26d3..25ca95e139 100644 --- a/packages/core/src/transport/flushController.ts +++ b/packages/core/src/transport/flushController.ts @@ -33,10 +33,13 @@ export function createFlushController({ pageExitObservable, sessionExpireObservable, }: FlushControllerOptions) { - const flushObservable = new Observable() + const pageExitSubscription = pageExitObservable.subscribe((event) => flush(event.reason)) + const sessionExpireSubscription = sessionExpireObservable.subscribe(() => flush('session_expire')) - pageExitObservable.subscribe((event) => flush(event.reason)) - sessionExpireObservable.subscribe(() => flush('session_expire')) + const flushObservable = new Observable(() => () => { + pageExitSubscription.unsubscribe() + sessionExpireSubscription.unsubscribe() + }) let currentBytesCount = 0 let currentMessagesCount = 0 diff --git a/packages/core/src/transport/startBatchWithReplica.ts b/packages/core/src/transport/startBatchWithReplica.ts index 55bcea76fb..fe61d9591e 100644 --- a/packages/core/src/transport/startBatchWithReplica.ts +++ b/packages/core/src/transport/startBatchWithReplica.ts @@ -48,5 +48,10 @@ export function startBatchWithReplica( replicaBatch.upsert(replica.transformMessage ? replica.transformMessage(message) : message, key) } }, + + stop: () => { + primaryBatch.stop() + replicaBatch?.stop() + }, } } diff --git a/packages/core/test/forEach.spec.ts b/packages/core/test/forEach.spec.ts index 2c9eeb3acc..cec5d47a05 100644 --- a/packages/core/test/forEach.spec.ts +++ b/packages/core/test/forEach.spec.ts @@ -1,4 +1,5 @@ import type { BuildEnvWindow } from './buildEnv' +import { startLeakDetection, stopLeakDetection } from './leakDetection' beforeEach(() => { ;(window as unknown as BuildEnvWindow).__BUILD_ENV__SDK_VERSION__ = 'test' @@ -7,10 +8,12 @@ beforeEach(() => { ;(window as any).DD_RUM = {} // prevent 'Some of your tests did a full page reload!' issue window.onbeforeunload = () => 'stop' + startLeakDetection() }) afterEach(() => { clearAllCookies() + stopLeakDetection() }) function clearAllCookies() { diff --git a/packages/core/test/index.ts b/packages/core/test/index.ts index 4e37843f2b..2e4544eee2 100644 --- a/packages/core/test/index.ts +++ b/packages/core/test/index.ts @@ -1,6 +1,7 @@ export * from './browserChecks' export * from './buildEnv' export * from './collectAsyncCalls' +export * from './registerCleanupTask' export * from './requests' export * from './emulate/createNewEvent' export * from './emulate/location' diff --git a/packages/core/test/leakDetection.ts b/packages/core/test/leakDetection.ts new file mode 100644 index 0000000000..d4922de657 --- /dev/null +++ b/packages/core/test/leakDetection.ts @@ -0,0 +1,58 @@ +import { display } from '../src/tools/display' +import { isIE } from '../src/tools/utils/browserDetection' +import { getCurrentJasmineSpec } from './getCurrentJasmineSpec' + +let originalAddEventListener: typeof EventTarget.prototype.addEventListener +let originalRemoveEventListener: typeof EventTarget.prototype.removeEventListener +let wrappedListeners: { + [key: string]: Map +} + +export function startLeakDetection() { + if (isIE()) { + return + } + wrappedListeners = {} + + // eslint-disable-next-line @typescript-eslint/unbound-method + originalAddEventListener = EventTarget.prototype.addEventListener + // eslint-disable-next-line @typescript-eslint/unbound-method + originalRemoveEventListener = EventTarget.prototype.removeEventListener + + EventTarget.prototype.addEventListener = function (event, listener, options) { + if (!wrappedListeners[event]) { + wrappedListeners[event] = new Map() + } + const wrappedListener = withLeakDetection(event, listener as EventListener) + wrappedListeners[event].set(listener, wrappedListener) + return originalAddEventListener.call(this, event, wrappedListener, options) + } + EventTarget.prototype.removeEventListener = function (event, listener, options) { + const wrappedListener = wrappedListeners[event]?.get(listener) + wrappedListeners[event]?.delete(listener) + return originalRemoveEventListener.call(this, event, wrappedListener || listener, options) + } +} + +export function stopLeakDetection() { + if (isIE()) { + return + } + EventTarget.prototype.addEventListener = originalAddEventListener + EventTarget.prototype.removeEventListener = originalRemoveEventListener + wrappedListeners = {} +} + +function withLeakDetection(eventName: string, listener: EventListener) { + const specWhenAdded = getCurrentJasmineSpec()!.fullName + return (event: Event) => { + const currentSpec = getCurrentJasmineSpec()!.fullName + if (specWhenAdded !== currentSpec) { + display.error(`Leaked listener + event names: "${eventName}" + attached with: "${specWhenAdded}" + executed with: "${currentSpec}"`) + } + listener(event) + } +} diff --git a/packages/core/test/registerCleanupTask.ts b/packages/core/test/registerCleanupTask.ts new file mode 100644 index 0000000000..29c00403db --- /dev/null +++ b/packages/core/test/registerCleanupTask.ts @@ -0,0 +1,9 @@ +const cleanupTasks: Array<() => void> = [] + +export function registerCleanupTask(task: () => void) { + cleanupTasks.push(task) +} + +afterEach(() => { + cleanupTasks.splice(0).forEach((task) => task()) +}) diff --git a/packages/logs/src/boot/startLogs.spec.ts b/packages/logs/src/boot/startLogs.spec.ts index 4125533f70..d7a14a6f26 100644 --- a/packages/logs/src/boot/startLogs.spec.ts +++ b/packages/logs/src/boot/startLogs.spec.ts @@ -7,6 +7,7 @@ import { initEventBridgeStub, cleanupSyntheticsWorkerValues, mockSyntheticsWorkerValues, + registerCleanupTask, } from '@datadog/browser-core/test' import type { LogsConfiguration } from '../domain/configuration' @@ -43,6 +44,7 @@ describe('logs', () => { let interceptor: ReturnType let requests: Request[] let handleLog: ReturnType['handleLog'] + let stopLogs: () => void let logger: Logger let consoleLogSpy: jasmine.Spy let displayLogSpy: jasmine.Spy @@ -69,7 +71,8 @@ describe('logs', () => { describe('request', () => { it('should send the needed data', () => { - ;({ handleLog: handleLog } = startLogs(initConfiguration, baseConfiguration, () => COMMON_CONTEXT, logger)) + ;({ handleLog, stop: stopLogs } = startLogs(initConfiguration, baseConfiguration, () => COMMON_CONTEXT, logger)) + registerCleanupTask(stopLogs) handleLog({ message: 'message', status: StatusType.warn, context: { foo: 'bar' } }, logger, COMMON_CONTEXT) @@ -91,12 +94,13 @@ describe('logs', () => { }) it('should all use the same batch', () => { - ;({ handleLog } = startLogs( + ;({ handleLog, stop: stopLogs } = startLogs( initConfiguration, { ...baseConfiguration, batchMessagesLimit: 3 }, () => COMMON_CONTEXT, logger )) + registerCleanupTask(stopLogs) handleLog(DEFAULT_MESSAGE, logger) handleLog(DEFAULT_MESSAGE, logger) @@ -107,7 +111,8 @@ describe('logs', () => { it('should send bridge event when bridge is present', () => { const sendSpy = spyOn(initEventBridgeStub(), 'send') - ;({ handleLog: handleLog } = startLogs(initConfiguration, baseConfiguration, () => COMMON_CONTEXT, logger)) + ;({ handleLog, stop: stopLogs } = startLogs(initConfiguration, baseConfiguration, () => COMMON_CONTEXT, logger)) + registerCleanupTask(stopLogs) handleLog(DEFAULT_MESSAGE, logger) @@ -126,13 +131,15 @@ describe('logs', () => { const sendSpy = spyOn(initEventBridgeStub(), 'send') let configuration = { ...baseConfiguration, sessionSampleRate: 0 } - ;({ handleLog } = startLogs(initConfiguration, configuration, () => COMMON_CONTEXT, logger)) + ;({ handleLog, stop: stopLogs } = startLogs(initConfiguration, configuration, () => COMMON_CONTEXT, logger)) + registerCleanupTask(stopLogs) handleLog(DEFAULT_MESSAGE, logger) expect(sendSpy).not.toHaveBeenCalled() configuration = { ...baseConfiguration, sessionSampleRate: 100 } - ;({ handleLog } = startLogs(initConfiguration, configuration, () => COMMON_CONTEXT, logger)) + ;({ handleLog, stop: stopLogs } = startLogs(initConfiguration, configuration, () => COMMON_CONTEXT, logger)) + registerCleanupTask(stopLogs) handleLog(DEFAULT_MESSAGE, logger) expect(sendSpy).toHaveBeenCalled() @@ -141,12 +148,13 @@ describe('logs', () => { it('should not print the log twice when console handler is enabled', () => { logger.setHandler([HandlerType.console]) - ;({ handleLog } = startLogs( + ;({ handleLog, stop: stopLogs } = startLogs( initConfiguration, { ...baseConfiguration, forwardConsoleLogs: ['log'] }, () => COMMON_CONTEXT, logger )) + registerCleanupTask(stopLogs) /* eslint-disable-next-line no-console */ console.log('foo', 'bar') @@ -161,21 +169,24 @@ describe('logs', () => { }) it('creates a session on normal conditions', () => { - ;({ handleLog } = startLogs(initConfiguration, baseConfiguration, () => COMMON_CONTEXT, logger)) + ;({ handleLog, stop: stopLogs } = startLogs(initConfiguration, baseConfiguration, () => COMMON_CONTEXT, logger)) + registerCleanupTask(stopLogs) expect(getCookie(SESSION_STORE_KEY)).not.toBeUndefined() }) it('does not create a session if event bridge is present', () => { initEventBridgeStub() - ;({ handleLog } = startLogs(initConfiguration, baseConfiguration, () => COMMON_CONTEXT, logger)) + ;({ handleLog, stop: stopLogs } = startLogs(initConfiguration, baseConfiguration, () => COMMON_CONTEXT, logger)) + registerCleanupTask(stopLogs) expect(getCookie(SESSION_STORE_KEY)).toBeUndefined() }) it('does not create a session if synthetics worker will inject RUM', () => { mockSyntheticsWorkerValues({ injectsRum: true }) - ;({ handleLog } = startLogs(initConfiguration, baseConfiguration, () => COMMON_CONTEXT, logger)) + ;({ handleLog, stop: stopLogs } = startLogs(initConfiguration, baseConfiguration, () => COMMON_CONTEXT, logger)) + registerCleanupTask(stopLogs) expect(getCookie(SESSION_STORE_KEY)).toBeUndefined() }) diff --git a/packages/logs/src/boot/startLogs.ts b/packages/logs/src/boot/startLogs.ts index 1e8ab4c6e1..d6c850e747 100644 --- a/packages/logs/src/boot/startLogs.ts +++ b/packages/logs/src/boot/startLogs.ts @@ -37,6 +37,7 @@ export function startLogs( mainLogger: Logger ) { const lifeCycle = new LifeCycle() + const cleanupTasks: Array<() => void> = [] lifeCycle.subscribe(LifeCycleEventType.LOG_COLLECTED, (log) => sendToExtension('logs', log)) @@ -61,7 +62,13 @@ export function startLogs( ? startLogsSessionManager(configuration) : startLogsSessionManagerStub(configuration) - const telemetry = startLogsTelemetry(configuration, reportError, pageExitObservable, session.expireObservable) + const { telemetry, stop: stopLogsTelemetry } = startLogsTelemetry( + configuration, + reportError, + pageExitObservable, + session.expireObservable + ) + cleanupTasks.push(() => stopLogsTelemetry()) telemetry.setContextProvider(() => ({ application: { id: getRUMInternalContext()?.application_id, @@ -86,7 +93,14 @@ export function startLogs( startLogsAssembly(session, configuration, lifeCycle, buildCommonContext, mainLogger, reportError) if (!canUseEventBridge()) { - startLogsBatch(configuration, lifeCycle, reportError, pageExitObservable, session.expireObservable) + const { stop: stopLogsBatch } = startLogsBatch( + configuration, + lifeCycle, + reportError, + pageExitObservable, + session.expireObservable + ) + cleanupTasks.push(() => stopLogsBatch()) } else { startLogsBridge(lifeCycle) } @@ -97,6 +111,9 @@ export function startLogs( return { handleLog, getInternalContext: internalContext.get, + stop: () => { + cleanupTasks.forEach((task) => task()) + }, } } @@ -107,9 +124,11 @@ function startLogsTelemetry( sessionExpireObservable: Observable ) { const telemetry = startTelemetry(TelemetryService.LOGS, configuration) + const cleanupTasks: Array<() => void> = [] if (canUseEventBridge()) { const bridge = getEventBridge<'internal_telemetry', TelemetryEvent>()! - telemetry.observable.subscribe((event) => bridge.send('internal_telemetry', event)) + const telemetrySubscription = telemetry.observable.subscribe((event) => bridge.send('internal_telemetry', event)) + cleanupTasks.push(() => telemetrySubscription.unsubscribe()) } else { const telemetryBatch = startBatchWithReplica( configuration, @@ -123,7 +142,16 @@ function startLogsTelemetry( pageExitObservable, sessionExpireObservable ) - telemetry.observable.subscribe((event) => telemetryBatch.add(event, isTelemetryReplicationAllowed(configuration))) + cleanupTasks.push(() => telemetryBatch.stop()) + const telemetrySubscription = telemetry.observable.subscribe((event) => + telemetryBatch.add(event, isTelemetryReplicationAllowed(configuration)) + ) + cleanupTasks.push(() => telemetrySubscription.unsubscribe()) + } + return { + telemetry, + stop: () => { + cleanupTasks.forEach((task) => task()) + }, } - return telemetry } diff --git a/packages/logs/src/transport/startLogsBatch.ts b/packages/logs/src/transport/startLogsBatch.ts index 5fc95fcf78..2afd3f255b 100644 --- a/packages/logs/src/transport/startLogsBatch.ts +++ b/packages/logs/src/transport/startLogsBatch.ts @@ -28,4 +28,6 @@ export function startLogsBatch( lifeCycle.subscribe(LifeCycleEventType.LOG_COLLECTED, (serverLogsEvent: LogsEvent & Context) => { batch.add(serverLogsEvent) }) + + return batch } diff --git a/packages/rum-core/src/boot/rumPublicApi.spec.ts b/packages/rum-core/src/boot/rumPublicApi.spec.ts index a23afba31f..1575b367e0 100644 --- a/packages/rum-core/src/boot/rumPublicApi.spec.ts +++ b/packages/rum-core/src/boot/rumPublicApi.spec.ts @@ -24,6 +24,7 @@ const noopStartRum = (): ReturnType => ({ viewContexts: {} as any, session: {} as any, stopSession: () => undefined, + stop: () => undefined, }) const DEFAULT_INIT_CONFIGURATION = { applicationId: 'xxx', clientToken: 'xxx' } const INVALID_INIT_CONFIGURATION = { clientToken: 'yes' } as RumInitConfiguration diff --git a/packages/rum-core/src/boot/startRum.spec.ts b/packages/rum-core/src/boot/startRum.spec.ts index 08648898b1..74c8beca49 100644 --- a/packages/rum-core/src/boot/startRum.spec.ts +++ b/packages/rum-core/src/boot/startRum.spec.ts @@ -132,15 +132,18 @@ describe('rum session', () => { expect(serverRumEvents[0].type).toEqual('view') expect(serverRumEvents[0].session.id).toEqual('42') + lifeCycle.notify(LifeCycleEventType.SESSION_EXPIRED) + expect(serverRumEvents.length).toEqual(2) + session.setId('43') lifeCycle.notify(LifeCycleEventType.SESSION_RENEWED) - expect(serverRumEvents.length).toEqual(2) + expect(serverRumEvents.length).toEqual(3) // New view event - expect(serverRumEvents[1].type).toEqual('view') - expect(serverRumEvents[1].session.id).toEqual('43') - expect(serverRumEvents[1].view.id).not.toEqual(serverRumEvents[0].view.id) + expect(serverRumEvents[2].type).toEqual('view') + expect(serverRumEvents[2].session.id).toEqual('43') + expect(serverRumEvents[2].view.id).not.toEqual(serverRumEvents[0].view.id) }) }) @@ -333,7 +336,7 @@ describe('view events', () => { let interceptor: ReturnType beforeEach(() => { - setupBuilder = setup().beforeBuild(({ configuration }) => { + setupBuilder = setup().beforeBuild(({ configuration }) => startRum( {} as RumInitConfiguration, configuration, @@ -341,7 +344,7 @@ describe('view events', () => { createContextManager(CustomerDataType.GlobalContext), createContextManager(CustomerDataType.User) ) - }) + ) interceptor = interceptRequests() }) diff --git a/packages/rum-core/src/boot/startRum.ts b/packages/rum-core/src/boot/startRum.ts index 3308f59623..80505caa82 100644 --- a/packages/rum-core/src/boot/startRum.ts +++ b/packages/rum-core/src/boot/startRum.ts @@ -37,6 +37,7 @@ import { startPageStateHistory } from '../domain/contexts/pageStateHistory' import type { CommonContext } from '../domain/contexts/commonContext' import { buildCommonContext } from '../domain/contexts/commonContext' import { startWebVitalTelemetryDebug } from '../domain/view/startWebVitalTelemetryDebug' +import { startDisplayContext } from '../domain/contexts/displayContext' import type { RecorderApi } from './rumPublicApi' export function startRum( @@ -47,6 +48,7 @@ export function startRum( userContextManager: ContextManager, initialViewOptions?: ViewOptions ) { + const cleanupTasks: Array<() => void> = [] const lifeCycle = new LifeCycle() lifeCycle.subscribe(LifeCycleEventType.RUM_EVENT_COLLECTED, (event) => sendToExtension('rum', event)) @@ -74,9 +76,10 @@ export function startRum( const featureFlagContexts = startFeatureFlagContexts(lifeCycle) const pageExitObservable = createPageExitObservable(configuration) - pageExitObservable.subscribe((event) => { + const pageExitSubscription = pageExitObservable.subscribe((event) => { lifeCycle.notify(LifeCycleEventType.PAGE_EXITED, event) }) + cleanupTasks.push(() => pageExitSubscription.unsubscribe()) const session = !canUseEventBridge() ? startRumSessionManager(configuration, lifeCycle) : startRumSessionManagerStub() if (!canUseEventBridge()) { @@ -88,6 +91,7 @@ export function startRum( pageExitObservable, session.expireObservable ) + cleanupTasks.push(() => batch.stop()) startCustomerDataTelemetry( configuration, telemetry, @@ -104,7 +108,14 @@ export function startRum( const domMutationObservable = createDOMMutationObservable() const locationChangeObservable = createLocationChangeObservable(configuration, location) - const { viewContexts, pageStateHistory, urlContexts, actionContexts, addAction } = startRumEventCollection( + const { + viewContexts, + pageStateHistory, + urlContexts, + actionContexts, + addAction, + stop: stopRumEventCollection, + } = startRumEventCollection( lifeCycle, configuration, location, @@ -114,6 +125,7 @@ export function startRum( () => buildCommonContext(globalContextManager, userContextManager, recorderApi), reportError ) + cleanupTasks.push(stopRumEventCollection) addTelemetryConfiguration(serializeRumConfiguration(initConfiguration)) @@ -121,7 +133,11 @@ export function startRum( startResourceCollection(lifeCycle, configuration, session, pageStateHistory) const webVitalTelemetryDebug = startWebVitalTelemetryDebug(configuration, telemetry, recorderApi, session) - const { addTiming, startView } = startViewCollection( + const { + addTiming, + startView, + stop: stopViewCollection, + } = startViewCollection( lifeCycle, configuration, location, @@ -133,6 +149,8 @@ export function startRum( webVitalTelemetryDebug, initialViewOptions ) + cleanupTasks.push(stopViewCollection) + const { addError } = startErrorCollection(lifeCycle, configuration, pageStateHistory, featureFlagContexts) startRequestCollection(lifeCycle, configuration, session) @@ -157,6 +175,9 @@ export function startRum( session, stopSession: () => session.expire(), getInternalContext: internalContext.get, + stop: () => { + cleanupTasks.forEach((task) => task()) + }, } } @@ -191,6 +212,8 @@ export function startRumEventCollection( pageStateHistory ) + const displayContext = startDisplayContext(configuration) + startRumAssembly( configuration, lifeCycle, @@ -198,6 +221,7 @@ export function startRumEventCollection( viewContexts, urlContexts, actionContexts, + displayContext, buildCommonContext, reportError ) @@ -209,6 +233,9 @@ export function startRumEventCollection( addAction, actionContexts, stop: () => { + displayContext.stop() + pageStateHistory.stop() + urlContexts.stop() viewContexts.stop() pageStateHistory.stop() }, diff --git a/packages/rum-core/src/domain/assembly.spec.ts b/packages/rum-core/src/domain/assembly.spec.ts index d36f595bb3..7ac3a4ad72 100644 --- a/packages/rum-core/src/domain/assembly.spec.ts +++ b/packages/rum-core/src/domain/assembly.spec.ts @@ -52,22 +52,25 @@ describe('rum assembly', () => { .withActionContexts({ findActionId: () => '7890', }) - .beforeBuild(({ configuration, lifeCycle, sessionManager, viewContexts, urlContexts, actionContexts }) => { - serverRumEvents = [] - lifeCycle.subscribe(LifeCycleEventType.RUM_EVENT_COLLECTED, (serverRumEvent) => - serverRumEvents.push(serverRumEvent) - ) - startRumAssembly( - { ...configuration, ...extraConfigurationOptions }, - lifeCycle, - sessionManager, - viewContexts, - urlContexts, - actionContexts, - () => commonContext, - reportErrorSpy - ) - }) + .beforeBuild( + ({ configuration, lifeCycle, sessionManager, viewContexts, urlContexts, actionContexts, displayContext }) => { + serverRumEvents = [] + lifeCycle.subscribe(LifeCycleEventType.RUM_EVENT_COLLECTED, (serverRumEvent) => + serverRumEvents.push(serverRumEvent) + ) + startRumAssembly( + { ...configuration, ...extraConfigurationOptions }, + lifeCycle, + sessionManager, + viewContexts, + urlContexts, + actionContexts, + displayContext, + () => commonContext, + reportErrorSpy + ) + } + ) }) afterEach(() => { diff --git a/packages/rum-core/src/domain/assembly.ts b/packages/rum-core/src/domain/assembly.ts index 663d71e4df..343e87424d 100644 --- a/packages/rum-core/src/domain/assembly.ts +++ b/packages/rum-core/src/domain/assembly.ts @@ -29,7 +29,7 @@ import type { RumSessionManager } from './rumSessionManager' import type { UrlContexts } from './contexts/urlContexts' import type { RumConfiguration } from './configuration' import type { ActionContexts } from './action/actionCollection' -import { getDisplayContext } from './contexts/displayContext' +import type { DisplayContext } from './contexts/displayContext' import type { CommonContext } from './contexts/commonContext' import type { ModifiableFieldPaths } from './limitModification' import { limitModification } from './limitModification' @@ -64,6 +64,7 @@ export function startRumAssembly( viewContexts: ViewContexts, urlContexts: UrlContexts, actionContexts: ActionContexts, + displayContext: DisplayContext, buildCommonContext: () => CommonContext, reportError: (error: RawError) => void ) { @@ -154,7 +155,7 @@ export function startRumAssembly( action: needToAssembleWithAction(rawRumEvent) && actionId ? { id: actionId } : undefined, synthetics: syntheticsContext, ci_test: ciTestContext, - display: getDisplayContext(configuration), + display: displayContext.get(), } const serverRumEvent = combine(rumContext as RumContext & Context, rawRumEvent) as RumEvent & Context diff --git a/packages/rum-core/src/domain/contexts/displayContext.spec.ts b/packages/rum-core/src/domain/contexts/displayContext.spec.ts index c9d170410e..0b9d2b8b03 100644 --- a/packages/rum-core/src/domain/contexts/displayContext.spec.ts +++ b/packages/rum-core/src/domain/contexts/displayContext.spec.ts @@ -1,19 +1,22 @@ import type { RumConfiguration } from '../configuration' -import { getDisplayContext, resetDisplayContext } from './displayContext' +import type { DisplayContext } from './displayContext' +import { startDisplayContext } from './displayContext' describe('displayContext', () => { let configuration: RumConfiguration + let displayContext: DisplayContext beforeEach(() => { configuration = {} as RumConfiguration + displayContext = startDisplayContext(configuration) }) afterEach(() => { - resetDisplayContext() + displayContext.stop() }) it('should return current display context', () => { - expect(getDisplayContext(configuration)).toEqual({ + expect(displayContext.get()).toEqual({ viewport: { width: jasmine.any(Number), height: jasmine.any(Number), diff --git a/packages/rum-core/src/domain/contexts/displayContext.ts b/packages/rum-core/src/domain/contexts/displayContext.ts index 633e49f16f..0f9e7eed33 100644 --- a/packages/rum-core/src/domain/contexts/displayContext.ts +++ b/packages/rum-core/src/domain/contexts/displayContext.ts @@ -1,25 +1,16 @@ import type { RumConfiguration } from '../configuration' import { getViewportDimension, initViewportObservable } from '../../browser/viewportObservable' -let viewport: { width: number; height: number } | undefined -let stopListeners: (() => void) | undefined +export type DisplayContext = ReturnType -export function getDisplayContext(configuration: RumConfiguration) { - if (!viewport) { - viewport = getViewportDimension() - stopListeners = initViewportObservable(configuration).subscribe((viewportDimension) => { - viewport = viewportDimension - }).unsubscribe - } +export function startDisplayContext(configuration: RumConfiguration) { + let viewport = getViewportDimension() + const unsubscribeViewport = initViewportObservable(configuration).subscribe((viewportDimension) => { + viewport = viewportDimension + }).unsubscribe return { - viewport, - } -} - -export function resetDisplayContext() { - if (stopListeners) { - stopListeners() + get: () => ({ viewport }), + stop: unsubscribeViewport, } - viewport = undefined } diff --git a/packages/rum-core/src/domain/contexts/foregroundContexts.spec.ts b/packages/rum-core/src/domain/contexts/foregroundContexts.spec.ts index 388a1ee401..f4e77408b4 100644 --- a/packages/rum-core/src/domain/contexts/foregroundContexts.spec.ts +++ b/packages/rum-core/src/domain/contexts/foregroundContexts.spec.ts @@ -49,8 +49,8 @@ describe('foreground context', () => { describe('when the page do not have the focus when starting', () => { beforeEach(() => { spyOn(Document.prototype, 'hasFocus').and.callFake(() => false) - pageStateHistory = startPageStateHistory(configuration) }) + describe('without any focus nor blur event', () => { describe('isInForegroundAt', () => { it('should return false', () => { @@ -197,6 +197,8 @@ describe('foreground context', () => { }) it('after starting with a blur even, should not be in foreground', () => { + setupBuilder.build() + pageStateHistory.addPageState(PageState.PASSIVE) expect(isInForegroundAt(relativeNow())).toEqual(false) @@ -206,7 +208,6 @@ describe('foreground context', () => { describe('when the page has focus when starting', () => { beforeEach(() => { spyOn(Document.prototype, 'hasFocus').and.callFake(() => true) - pageStateHistory = startPageStateHistory(configuration) }) describe('when there is no focus event', () => { diff --git a/packages/rum-core/src/domain/contexts/pageStateHistory.spec.ts b/packages/rum-core/src/domain/contexts/pageStateHistory.spec.ts index 98625ecf5f..792bf12b71 100644 --- a/packages/rum-core/src/domain/contexts/pageStateHistory.spec.ts +++ b/packages/rum-core/src/domain/contexts/pageStateHistory.spec.ts @@ -1,6 +1,6 @@ import type { RelativeTime, ServerDuration } from '@datadog/browser-core' import type { Clock } from '../../../../core/test' -import { mockClock } from '../../../../core/test' +import { mockClock, registerCleanupTask } from '../../../../core/test' import type { RumConfiguration } from '../configuration' import type { PageStateHistory } from './pageStateHistory' import { startPageStateHistory, PageState } from './pageStateHistory' @@ -14,10 +14,10 @@ describe('pageStateHistory', () => { configuration = {} as RumConfiguration clock = mockClock() pageStateHistory = startPageStateHistory(configuration) + registerCleanupTask(pageStateHistory.stop) }) afterEach(() => { - pageStateHistory.stop() clock.cleanup() }) @@ -72,6 +72,7 @@ describe('pageStateHistory', () => { it('should limit the number of selectable entries', () => { const maxPageStateEntriesSelectable = 1 pageStateHistory = startPageStateHistory(configuration, maxPageStateEntriesSelectable) + registerCleanupTask(pageStateHistory.stop) pageStateHistory.addPageState(PageState.ACTIVE) clock.tick(10) @@ -96,6 +97,7 @@ describe('pageStateHistory', () => { it('should return false if the page was not active at the given time', () => { const maxPageStateEntriesSelectable = 1 pageStateHistory = startPageStateHistory(configuration, maxPageStateEntriesSelectable) + registerCleanupTask(pageStateHistory.stop) pageStateHistory.addPageState(PageState.ACTIVE) clock.tick(10) diff --git a/packages/rum-core/src/domain/view/trackViewEventCounts.spec.ts b/packages/rum-core/src/domain/view/trackViewEventCounts.spec.ts index 1c64bffc40..4c08efdb51 100644 --- a/packages/rum-core/src/domain/view/trackViewEventCounts.spec.ts +++ b/packages/rum-core/src/domain/view/trackViewEventCounts.spec.ts @@ -7,7 +7,6 @@ import { FrustrationType, RumEventType } from '../../rawRumEvent.types' import { THROTTLE_VIEW_UPDATE_PERIOD } from './trackViews' import type { ViewTest } from './setupViewTest.specHelper' import { setupViewTest } from './setupViewTest.specHelper' -import { KEEP_TRACKING_EVENT_COUNTS_AFTER_VIEW_DELAY } from './trackViewEventCounts' describe('trackViewEventCounts', () => { let setupBuilder: TestSetupBuilder @@ -209,48 +208,4 @@ describe('trackViewEventCounts', () => { frustrationCount: 0, }) }) - - it('should keep updating the view event counters for 5 min after view end', () => { - const { lifeCycle, clock } = setupBuilder.withFakeClock().build() - const { getViewUpdate, getViewUpdateCount, getLatestViewContext, stop } = viewTest - - expect(getViewUpdateCount()).toEqual(1) - expect(getViewUpdate(0).eventCounts.resourceCount).toEqual(0) - - stop() // end the view - - clock.tick(KEEP_TRACKING_EVENT_COUNTS_AFTER_VIEW_DELAY - 1) - - lifeCycle.notify(LifeCycleEventType.RUM_EVENT_COLLECTED, { - type: RumEventType.RESOURCE, - view: getLatestViewContext(), - } as RumEvent & Context) - - clock.tick(THROTTLE_VIEW_UPDATE_PERIOD) - - expect(getViewUpdate(0).id).toEqual(getViewUpdate(1).id) - expect(getViewUpdate(1).eventCounts.resourceCount).toEqual(1) - }) - - it('should not keep updating the view event counters 5 min after view end', () => { - const { lifeCycle, clock } = setupBuilder.withFakeClock().build() - const { getViewUpdate, getViewUpdateCount, getLatestViewContext, stop } = viewTest - - expect(getViewUpdateCount()).toEqual(1) - expect(getViewUpdate(0).eventCounts.resourceCount).toEqual(0) - - stop() // end the view - - clock.tick(KEEP_TRACKING_EVENT_COUNTS_AFTER_VIEW_DELAY) - - lifeCycle.notify(LifeCycleEventType.RUM_EVENT_COLLECTED, { - type: RumEventType.RESOURCE, - view: getLatestViewContext(), - } as RumEvent & Context) - - clock.tick(THROTTLE_VIEW_UPDATE_PERIOD) - - expect(getViewUpdate(0).id).toEqual(getViewUpdate(1).id) - expect(getViewUpdate(1).eventCounts.resourceCount).toEqual(0) - }) }) diff --git a/packages/rum-core/src/domain/view/trackViewEventCounts.ts b/packages/rum-core/src/domain/view/trackViewEventCounts.ts index 622140476d..65c9e25843 100644 --- a/packages/rum-core/src/domain/view/trackViewEventCounts.ts +++ b/packages/rum-core/src/domain/view/trackViewEventCounts.ts @@ -1,24 +1,6 @@ -import { ONE_MINUTE, setTimeout } from '@datadog/browser-core' import type { LifeCycle } from '../lifeCycle' import { trackEventCounts } from '../trackEventCounts' -// Some events are not being counted as they transcend views. To reduce the occurrence; -// an arbitrary delay is added for stopping event counting after the view ends. -// -// Ideally, we would not stop and keep counting events until the end of the session. -// But this might have a small performance impact if there are many many views: -// we would need to go through each event to see if the related view matches. -// So let's have a fairly short delay to avoid impacting performances too much. -// -// In the future, we could have views stored in a data structure similar to ContextHistory. Whenever -// a child event is collected, we could look into this history to find the matching view and -// increase the associated and increase its counter. Having a centralized data structure for it -// would allow us to look for views more efficiently. -// -// For now, having a small cleanup delay will already improve the situation in most cases. - -export const KEEP_TRACKING_EVENT_COUNTS_AFTER_VIEW_DELAY = 5 * ONE_MINUTE - export function trackViewEventCounts(lifeCycle: LifeCycle, viewId: string, onChange: () => void) { const { stop, eventCounts } = trackEventCounts({ lifeCycle, @@ -27,9 +9,7 @@ export function trackViewEventCounts(lifeCycle: LifeCycle, viewId: string, onCha }) return { - scheduleStop: () => { - setTimeout(stop, KEEP_TRACKING_EVENT_COUNTS_AFTER_VIEW_DELAY) - }, + stop, eventCounts, } } diff --git a/packages/rum-core/src/domain/view/trackViews.spec.ts b/packages/rum-core/src/domain/view/trackViews.spec.ts index 3d2e3e2174..595a42b354 100644 --- a/packages/rum-core/src/domain/view/trackViews.spec.ts +++ b/packages/rum-core/src/domain/view/trackViews.spec.ts @@ -13,7 +13,7 @@ import { RumEventType, ViewLoadingType } from '../../rawRumEvent.types' import type { RumEvent } from '../../rumEvent.types' import { LifeCycleEventType } from '../lifeCycle' import type { ViewEvent } from './trackViews' -import { SESSION_KEEP_ALIVE_INTERVAL, THROTTLE_VIEW_UPDATE_PERIOD } from './trackViews' +import { SESSION_KEEP_ALIVE_INTERVAL, THROTTLE_VIEW_UPDATE_PERIOD, KEEP_TRACKING_AFTER_VIEW_DELAY } from './trackViews' import type { ViewTest } from './setupViewTest.specHelper' import { FAKE_LARGEST_CONTENTFUL_PAINT_ENTRY, @@ -21,7 +21,6 @@ import { FAKE_PAINT_ENTRY, setupViewTest, } from './setupViewTest.specHelper' -import { KEEP_TRACKING_METRICS_AFTER_VIEW_DELAY } from './viewMetrics/trackInitialViewMetrics' describe('track views automatically', () => { let setupBuilder: TestSetupBuilder @@ -242,25 +241,86 @@ describe('initial view', () => { }) }) - it('should not update initial view metrics long after the view ended', () => { + it('should keep updating the initial view metrics for 5 min after view end', () => { const { lifeCycle, clock } = setupBuilder.withFakeClock().build() - const { getViewUpdateCount, startView } = viewTest - + const { getViewCreateCount, getViewUpdate, getViewUpdateCount, startView } = viewTest startView() + expect(getViewCreateCount()).toEqual(2) - clock.tick(KEEP_TRACKING_METRICS_AFTER_VIEW_DELAY) + clock.tick(KEEP_TRACKING_AFTER_VIEW_DELAY - 1) + lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED, [ + FAKE_PAINT_ENTRY, + FAKE_LARGEST_CONTENTFUL_PAINT_ENTRY, + FAKE_NAVIGATION_ENTRY, + ]) + clock.tick(THROTTLE_VIEW_UPDATE_PERIOD) - expect(getViewUpdateCount()).toEqual(4) + const latestUpdate = getViewUpdate(getViewUpdateCount() - 1) + const firstView = getViewUpdate(0) + expect(latestUpdate.id).toBe(firstView.id) + expect(latestUpdate.initialViewMetrics.largestContentfulPaint).toEqual( + FAKE_LARGEST_CONTENTFUL_PAINT_ENTRY.startTime + ) + }) + it('should not update the initial view metrics 5 min after view end', () => { + const { lifeCycle, clock } = setupBuilder.withFakeClock().build() + const { getViewCreateCount, getViewUpdate, getViewUpdateCount, startView } = viewTest + startView() + expect(getViewCreateCount()).toEqual(2) + + clock.tick(KEEP_TRACKING_AFTER_VIEW_DELAY) lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED, [ FAKE_PAINT_ENTRY, FAKE_LARGEST_CONTENTFUL_PAINT_ENTRY, FAKE_NAVIGATION_ENTRY, ]) + clock.tick(THROTTLE_VIEW_UPDATE_PERIOD) + + const latestUpdate = getViewUpdate(getViewUpdateCount() - 1) + const firstView = getViewUpdate(0) + expect(latestUpdate.id).not.toBe(firstView.id) + }) + + it('should keep updating the view event counters for 5 min after view end', () => { + const { lifeCycle, clock } = setupBuilder.withFakeClock().build() + const { getViewUpdate, getViewUpdateCount, getViewCreateCount, startView } = viewTest + startView() + expect(getViewCreateCount()).toEqual(2) + const firstView = getViewUpdate(0) + + clock.tick(KEEP_TRACKING_AFTER_VIEW_DELAY - 1) + + lifeCycle.notify(LifeCycleEventType.RUM_EVENT_COLLECTED, { + type: RumEventType.RESOURCE, + view: { id: firstView.id }, + } as RumEvent & Context) + + clock.tick(THROTTLE_VIEW_UPDATE_PERIOD) + + const latestUpdate = getViewUpdate(getViewUpdateCount() - 1) + expect(latestUpdate.id).toEqual(firstView.id) + expect(latestUpdate.eventCounts.resourceCount).toEqual(1) + }) + + it('should not update the view event counters 5 min after view end', () => { + const { lifeCycle, clock } = setupBuilder.withFakeClock().build() + const { getViewUpdate, getViewUpdateCount, getViewCreateCount, startView } = viewTest + startView() + expect(getViewCreateCount()).toEqual(2) + const firstView = getViewUpdate(0) + + clock.tick(KEEP_TRACKING_AFTER_VIEW_DELAY) + + lifeCycle.notify(LifeCycleEventType.RUM_EVENT_COLLECTED, { + type: RumEventType.RESOURCE, + view: { id: firstView.id }, + } as RumEvent & Context) clock.tick(THROTTLE_VIEW_UPDATE_PERIOD) - expect(getViewUpdateCount()).toEqual(4) + const latestUpdate = getViewUpdate(getViewUpdateCount() - 1) + expect(latestUpdate.id).not.toEqual(firstView.id) }) }) }) @@ -345,6 +405,7 @@ describe('view lifecycle', () => { expect(getViewCreateCount()).toBe(1) + lifeCycle.notify(LifeCycleEventType.SESSION_EXPIRED) lifeCycle.notify(LifeCycleEventType.SESSION_RENEWED) expect(getViewCreateCount()).toBe(2) @@ -354,14 +415,17 @@ describe('view lifecycle', () => { const { lifeCycle, changeLocation } = setupBuilder.build() const { getViewCreateCount, getViewCreate, startView } = viewTest + lifeCycle.notify(LifeCycleEventType.SESSION_EXPIRED) lifeCycle.notify(LifeCycleEventType.SESSION_RENEWED) startView({ name: 'view 1', service: 'service 1', version: 'version 1' }) startView({ name: 'view 2', service: 'service 2', version: 'version 2' }) + lifeCycle.notify(LifeCycleEventType.SESSION_EXPIRED) lifeCycle.notify(LifeCycleEventType.SESSION_RENEWED) startView({ name: 'view 3', service: 'service 3', version: 'version 3' }) changeLocation('/bar') + lifeCycle.notify(LifeCycleEventType.SESSION_EXPIRED) lifeCycle.notify(LifeCycleEventType.SESSION_RENEWED) expect(getViewCreateCount()).toBe(8) diff --git a/packages/rum-core/src/domain/view/trackViews.ts b/packages/rum-core/src/domain/view/trackViews.ts index 516df35def..8eff40caca 100644 --- a/packages/rum-core/src/domain/view/trackViews.ts +++ b/packages/rum-core/src/domain/view/trackViews.ts @@ -1,4 +1,4 @@ -import type { Duration, ClocksState, TimeStamp, Observable, Subscription, RelativeTime } from '@datadog/browser-core' +import type { Duration, ClocksState, TimeStamp, Subscription, RelativeTime } from '@datadog/browser-core' import { noop, PageExitReason, @@ -14,6 +14,8 @@ import { looksLikeRelativeTime, setInterval, clearInterval, + setTimeout, + Observable, } from '@datadog/browser-core' import type { ViewCustomTimings } from '../../rawRumEvent.types' @@ -26,10 +28,10 @@ import type { LocationChange } from '../../browser/locationChangeObservable' import type { RumConfiguration } from '../configuration' import { trackViewEventCounts } from './trackViewEventCounts' import type { WebVitalTelemetryDebug } from './startWebVitalTelemetryDebug' -import { trackInitialViewMetrics } from './viewMetrics/trackInitialViewMetrics' import type { InitialViewMetrics } from './viewMetrics/trackInitialViewMetrics' -import { trackCommonViewMetrics } from './viewMetrics/trackCommonViewMetrics' +import { trackInitialViewMetrics } from './viewMetrics/trackInitialViewMetrics' import type { CommonViewMetrics } from './viewMetrics/trackCommonViewMetrics' +import { trackCommonViewMetrics } from './viewMetrics/trackCommonViewMetrics' export interface ViewEvent { id: string @@ -64,6 +66,14 @@ export interface ViewEndedEvent { export const THROTTLE_VIEW_UPDATE_PERIOD = 3000 export const SESSION_KEEP_ALIVE_INTERVAL = 5 * ONE_MINUTE +// Some events or metrics can be captured after the end of the view. To avoid missing those; +// an arbitrary delay is added for stopping their tracking after the view ends. +// +// Ideally, we would not stop and keep tracking events or metrics until the end of the session. +// But this might have a small performance impact if there are many many views. +// So let's have a fairly short delay improving the situation in most cases and avoid impacting performances too much. +export const KEEP_TRACKING_AFTER_VIEW_DELAY = 5 * ONE_MINUTE + export interface ViewOptions { name?: string service?: string @@ -80,6 +90,7 @@ export function trackViews( webVitalTelemetryDebug: WebVitalTelemetryDebug, initialViewOptions?: ViewOptions ) { + const activeViews: Set> = new Set() let currentView = startNewView(ViewLoadingType.INITIAL_LOAD, clocksOrigin(), initialViewOptions) startViewLifeCycle() @@ -90,7 +101,7 @@ export function trackViews( } function startNewView(loadingType: ViewLoadingType, startClocks?: ClocksState, viewOptions?: ViewOptions) { - return newView( + const newlyCreatedView = newView( lifeCycle, domMutationObservable, configuration, @@ -100,6 +111,11 @@ export function trackViews( startClocks, viewOptions ) + activeViews.add(newlyCreatedView) + newlyCreatedView.stopObservable.subscribe(() => { + activeViews.delete(newlyCreatedView) + }) + return newlyCreatedView } function startViewLifeCycle() { @@ -144,6 +160,7 @@ export function trackViews( stop: () => { locationChangeSubscription?.unsubscribe() currentView.end() + activeViews.forEach((view) => view.stop()) }, } } @@ -160,6 +177,7 @@ function newView( ) { // Setup initial values const id = generateUUID() + const stopObservable = new Observable() const customTimings: ViewCustomTimings = {} let documentVersion = 0 let endClocks: ClocksState | undefined @@ -206,16 +224,12 @@ function newView( webVitalTelemetryDebug ) - const { scheduleStop: scheduleStopInitialViewMetricsTracking, initialViewMetrics } = + const { stop: stopInitialViewMetricsTracking, initialViewMetrics } = loadingType === ViewLoadingType.INITIAL_LOAD ? trackInitialViewMetrics(lifeCycle, configuration, webVitalTelemetryDebug, setLoadEvent, scheduleViewUpdate) - : { scheduleStop: noop, initialViewMetrics: {} as InitialViewMetrics } + : { stop: noop, initialViewMetrics: {} as InitialViewMetrics } - const { scheduleStop: scheduleStopEventCountsTracking, eventCounts } = trackViewEventCounts( - lifeCycle, - id, - scheduleViewUpdate - ) + const { stop: stopEventCountsTracking, eventCounts } = trackViewEventCounts(lifeCycle, id, scheduleViewUpdate) // Session keep alive const keepAliveIntervalId = setInterval(triggerViewUpdate, SESSION_KEEP_ALIVE_INTERVAL) @@ -251,6 +265,7 @@ function newView( name, service, version, + stopObservable, end(options: { endClocks?: ClocksState; sessionIsActive?: boolean } = {}) { if (endClocks) { // view already ended @@ -262,9 +277,15 @@ function newView( lifeCycle.notify(LifeCycleEventType.VIEW_ENDED, { endClocks }) clearInterval(keepAliveIntervalId) stopCommonViewMetricsTracking() - scheduleStopInitialViewMetricsTracking() - scheduleStopEventCountsTracking() triggerViewUpdate() + setTimeout(() => { + this.stop() + }, KEEP_TRACKING_AFTER_VIEW_DELAY) + }, + stop() { + stopInitialViewMetricsTracking() + stopEventCountsTracking() + stopObservable.notify() }, addTiming(name: string, time: RelativeTime | TimeStamp) { if (endClocks) { diff --git a/packages/rum-core/src/domain/view/viewCollection.spec.ts b/packages/rum-core/src/domain/view/viewCollection.spec.ts index bf8fef3276..0c415ef6e9 100644 --- a/packages/rum-core/src/domain/view/viewCollection.spec.ts +++ b/packages/rum-core/src/domain/view/viewCollection.spec.ts @@ -77,7 +77,7 @@ describe('viewCollection', () => { pageStateHistory, }) => { getReplayStatsSpy = jasmine.createSpy() - startViewCollection( + return startViewCollection( lifeCycle, configuration, location, diff --git a/packages/rum-core/src/domain/view/viewCollection.ts b/packages/rum-core/src/domain/view/viewCollection.ts index a582e5f8c1..2ff2ab2867 100644 --- a/packages/rum-core/src/domain/view/viewCollection.ts +++ b/packages/rum-core/src/domain/view/viewCollection.ts @@ -39,7 +39,7 @@ export function startViewCollection( processViewUpdate(view, configuration, featureFlagContexts, recorderApi, pageStateHistory) ) ) - const trackViewResult = trackViews( + return trackViews( location, lifeCycle, domMutationObservable, @@ -49,8 +49,6 @@ export function startViewCollection( webVitalTelemetryDebug, initialViewOptions ) - - return trackViewResult } function processViewUpdate( diff --git a/packages/rum-core/src/domain/view/viewMetrics/trackFirstContentfulPaint.spec.ts b/packages/rum-core/src/domain/view/viewMetrics/trackFirstContentfulPaint.spec.ts index 97ef974bf2..223f27a5a6 100644 --- a/packages/rum-core/src/domain/view/viewMetrics/trackFirstContentfulPaint.spec.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackFirstContentfulPaint.spec.ts @@ -5,8 +5,8 @@ import type { TestSetupBuilder } from '../../../../test' import { setup } from '../../../../test' import { LifeCycleEventType } from '../../lifeCycle' import type { RumConfiguration } from '../../configuration' -import { resetFirstHidden } from './trackFirstHidden' import { FCP_MAXIMUM_DELAY, trackFirstContentfulPaint } from './trackFirstContentfulPaint' +import { trackFirstHidden } from './trackFirstHidden' const FAKE_PAINT_ENTRY: RumPerformancePaintTiming = { entryType: 'paint', @@ -22,16 +22,21 @@ describe('trackFirstContentfulPaint', () => { beforeEach(() => { configuration = {} as RumConfiguration fcpCallback = jasmine.createSpy() - setupBuilder = setup().beforeBuild(({ lifeCycle }) => - trackFirstContentfulPaint(lifeCycle, configuration, fcpCallback) - ) - resetFirstHidden() + setupBuilder = setup().beforeBuild(({ lifeCycle }) => { + const firstHidden = trackFirstHidden(configuration) + const firstContentfulPaint = trackFirstContentfulPaint(lifeCycle, firstHidden, fcpCallback) + return { + stop() { + firstHidden.stop() + firstContentfulPaint.stop() + }, + } + }) }) afterEach(() => { setupBuilder.cleanup() restorePageVisibility() - resetFirstHidden() }) it('should provide the first contentful paint timing', () => { diff --git a/packages/rum-core/src/domain/view/viewMetrics/trackFirstContentfulPaint.ts b/packages/rum-core/src/domain/view/viewMetrics/trackFirstContentfulPaint.ts index 885c95c051..0697c495cd 100644 --- a/packages/rum-core/src/domain/view/viewMetrics/trackFirstContentfulPaint.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackFirstContentfulPaint.ts @@ -1,10 +1,9 @@ import type { RelativeTime } from '@datadog/browser-core' import { ONE_MINUTE, find } from '@datadog/browser-core' -import type { RumConfiguration } from '../../configuration' import type { LifeCycle } from '../../lifeCycle' import { LifeCycleEventType } from '../../lifeCycle' import type { RumPerformancePaintTiming } from '../../../browser/performanceCollection' -import { trackFirstHidden } from './trackFirstHidden' +import type { FirstHidden } from './trackFirstHidden' // Discard FCP timings above a certain delay to avoid incorrect data // It happens in some cases like sleep mode or some browser implementations @@ -12,22 +11,26 @@ export const FCP_MAXIMUM_DELAY = 10 * ONE_MINUTE export function trackFirstContentfulPaint( lifeCycle: LifeCycle, - configuration: RumConfiguration, + firstHidden: FirstHidden, callback: (fcpTiming: RelativeTime) => void ) { - const firstHidden = trackFirstHidden(configuration) - const { unsubscribe: stop } = lifeCycle.subscribe(LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED, (entries) => { - const fcpEntry = find( - entries, - (entry): entry is RumPerformancePaintTiming => - entry.entryType === 'paint' && - entry.name === 'first-contentful-paint' && - entry.startTime < firstHidden.timeStamp && - entry.startTime < FCP_MAXIMUM_DELAY - ) - if (fcpEntry) { - callback(fcpEntry.startTime) + const { unsubscribe: unsubscribeLifeCycle } = lifeCycle.subscribe( + LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED, + (entries) => { + const fcpEntry = find( + entries, + (entry): entry is RumPerformancePaintTiming => + entry.entryType === 'paint' && + entry.name === 'first-contentful-paint' && + entry.startTime < firstHidden.timeStamp && + entry.startTime < FCP_MAXIMUM_DELAY + ) + if (fcpEntry) { + callback(fcpEntry.startTime) + } } - }) - return { stop } + ) + return { + stop: unsubscribeLifeCycle, + } } diff --git a/packages/rum-core/src/domain/view/viewMetrics/trackFirstHidden.spec.ts b/packages/rum-core/src/domain/view/viewMetrics/trackFirstHidden.spec.ts index ddb8bc46c4..b9aaabbf58 100644 --- a/packages/rum-core/src/domain/view/viewMetrics/trackFirstHidden.spec.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackFirstHidden.spec.ts @@ -2,30 +2,33 @@ import type { RelativeTime } from '@datadog/browser-core' import { DOM_EVENT } from '@datadog/browser-core' import { createNewEvent, restorePageVisibility, setPageVisibility } from '@datadog/browser-core/test' import type { RumConfiguration } from '../../configuration' -import { resetFirstHidden, trackFirstHidden } from './trackFirstHidden' +import { trackFirstHidden } from './trackFirstHidden' describe('trackFirstHidden', () => { let configuration: RumConfiguration + let firstHidden: { timeStamp: RelativeTime; stop: () => void } beforeEach(() => { configuration = {} as RumConfiguration }) afterEach(() => { - resetFirstHidden() restorePageVisibility() + firstHidden.stop() }) describe('the page is initially hidden', () => { it('should return 0', () => { setPageVisibility('hidden') - expect(trackFirstHidden(configuration).timeStamp).toBe(0 as RelativeTime) + firstHidden = trackFirstHidden(configuration) + + expect(firstHidden.timeStamp).toBe(0 as RelativeTime) }) it('should ignore events', () => { setPageVisibility('hidden') const eventTarget = createWindowEventTarget() - const firstHidden = trackFirstHidden(configuration, eventTarget) + firstHidden = trackFirstHidden(configuration, eventTarget) eventTarget.dispatchEvent(createNewEvent(DOM_EVENT.PAGE_HIDE, { timeStamp: 100 })) eventTarget.dispatchEvent(createNewEvent(DOM_EVENT.VISIBILITY_CHANGE, { timeStamp: 100 })) @@ -42,12 +45,13 @@ describe('trackFirstHidden', () => { }) it('should return Infinity if the page was not hidden yet', () => { - expect(trackFirstHidden(configuration).timeStamp).toBe(Infinity as RelativeTime) + firstHidden = trackFirstHidden(configuration) + expect(firstHidden.timeStamp).toBe(Infinity as RelativeTime) }) it('should return the timestamp of the first pagehide event', () => { const eventTarget = createWindowEventTarget() - const firstHidden = trackFirstHidden(configuration, eventTarget) + firstHidden = trackFirstHidden(configuration, eventTarget) eventTarget.dispatchEvent(createNewEvent(DOM_EVENT.PAGE_HIDE, { timeStamp: 100 })) @@ -56,7 +60,7 @@ describe('trackFirstHidden', () => { it('should return the timestamp of the first visibilitychange event if the page is hidden', () => { const eventTarget = createWindowEventTarget() - const firstHidden = trackFirstHidden(configuration, eventTarget) + firstHidden = trackFirstHidden(configuration, eventTarget) setPageVisibility('hidden') eventTarget.dispatchEvent(createNewEvent(DOM_EVENT.VISIBILITY_CHANGE, { timeStamp: 100 })) @@ -66,7 +70,7 @@ describe('trackFirstHidden', () => { it('should ignore visibilitychange event if the page is visible', () => { const eventTarget = createWindowEventTarget() - const firstHidden = trackFirstHidden(configuration, eventTarget) + firstHidden = trackFirstHidden(configuration, eventTarget) eventTarget.dispatchEvent(createNewEvent(DOM_EVENT.VISIBILITY_CHANGE, { timeStamp: 100 })) @@ -75,7 +79,7 @@ describe('trackFirstHidden', () => { it('should ignore subsequent events', () => { const eventTarget = createWindowEventTarget() - const firstHidden = trackFirstHidden(configuration, eventTarget) + firstHidden = trackFirstHidden(configuration, eventTarget) eventTarget.dispatchEvent(createNewEvent(DOM_EVENT.PAGE_HIDE, { timeStamp: 100 })) diff --git a/packages/rum-core/src/domain/view/viewMetrics/trackFirstHidden.ts b/packages/rum-core/src/domain/view/viewMetrics/trackFirstHidden.ts index 0cdecd25d9..0254b18813 100644 --- a/packages/rum-core/src/domain/view/viewMetrics/trackFirstHidden.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackFirstHidden.ts @@ -2,40 +2,36 @@ import type { RelativeTime } from '@datadog/browser-core' import { addEventListeners, DOM_EVENT } from '@datadog/browser-core' import type { RumConfiguration } from '../../configuration' -let trackFirstHiddenSingleton: { timeStamp: RelativeTime } | undefined -let stopListeners: (() => void) | undefined +export type FirstHidden = ReturnType export function trackFirstHidden(configuration: RumConfiguration, eventTarget: Window = window) { - if (!trackFirstHiddenSingleton) { - if (document.visibilityState === 'hidden') { - trackFirstHiddenSingleton = { - timeStamp: 0 as RelativeTime, - } - } else { - trackFirstHiddenSingleton = { - timeStamp: Infinity as RelativeTime, - } - ;({ stop: stopListeners } = addEventListeners( - configuration, - eventTarget, - [DOM_EVENT.PAGE_HIDE, DOM_EVENT.VISIBILITY_CHANGE], - (event) => { - if (event.type === 'pagehide' || document.visibilityState === 'hidden') { - trackFirstHiddenSingleton!.timeStamp = event.timeStamp as RelativeTime - stopListeners!() - } - }, - { capture: true } - )) - } - } + let timeStamp: RelativeTime + let stopListeners: () => void | undefined - return trackFirstHiddenSingleton -} + if (document.visibilityState === 'hidden') { + timeStamp = 0 as RelativeTime + } else { + timeStamp = Infinity as RelativeTime + ;({ stop: stopListeners } = addEventListeners( + configuration, + eventTarget, + [DOM_EVENT.PAGE_HIDE, DOM_EVENT.VISIBILITY_CHANGE], + (event) => { + if (event.type === 'pagehide' || document.visibilityState === 'hidden') { + timeStamp = event.timeStamp as RelativeTime + stopListeners() + } + }, + { capture: true } + )) + } -export function resetFirstHidden() { - if (stopListeners) { - stopListeners() + return { + get timeStamp() { + return timeStamp + }, + stop() { + stopListeners?.() + }, } - trackFirstHiddenSingleton = undefined } diff --git a/packages/rum-core/src/domain/view/viewMetrics/trackFirstInputTimings.spec.ts b/packages/rum-core/src/domain/view/viewMetrics/trackFirstInputTimings.spec.ts index 590f6076b9..809ba4a0e6 100644 --- a/packages/rum-core/src/domain/view/viewMetrics/trackFirstInputTimings.spec.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackFirstInputTimings.spec.ts @@ -5,8 +5,8 @@ import { setup } from '../../../../test' import { LifeCycleEventType } from '../../lifeCycle' import type { RumConfiguration } from '../../configuration' import { FAKE_FIRST_INPUT_ENTRY } from '../setupViewTest.specHelper' -import { resetFirstHidden } from './trackFirstHidden' import { trackFirstInputTimings } from './trackFirstInputTimings' +import { trackFirstHidden } from './trackFirstHidden' describe('firstInputTimings', () => { let setupBuilder: TestSetupBuilder @@ -25,14 +25,21 @@ describe('firstInputTimings', () => { beforeEach(() => { configuration = {} as RumConfiguration fitCallback = jasmine.createSpy() - setupBuilder = setup().beforeBuild(({ lifeCycle }) => trackFirstInputTimings(lifeCycle, configuration, fitCallback)) - resetFirstHidden() + setupBuilder = setup().beforeBuild(({ lifeCycle }) => { + const firstHidden = trackFirstHidden(configuration) + const firstInputTimings = trackFirstInputTimings(lifeCycle, firstHidden, fitCallback) + return { + stop() { + firstHidden.stop() + firstInputTimings.stop() + }, + } + }) }) afterEach(() => { setupBuilder.cleanup() restorePageVisibility() - resetFirstHidden() }) it('should provide the first input timings', () => { diff --git a/packages/rum-core/src/domain/view/viewMetrics/trackFirstInputTimings.ts b/packages/rum-core/src/domain/view/viewMetrics/trackFirstInputTimings.ts index b3872dc2bc..caf1ac7628 100644 --- a/packages/rum-core/src/domain/view/viewMetrics/trackFirstInputTimings.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackFirstInputTimings.ts @@ -1,10 +1,9 @@ import type { Duration, RelativeTime } from '@datadog/browser-core' import { elapsed, find } from '@datadog/browser-core' -import type { RumConfiguration } from '../../configuration' import type { LifeCycle } from '../../lifeCycle' import { LifeCycleEventType } from '../../lifeCycle' import type { RumFirstInputTiming } from '../../../browser/performanceCollection' -import { trackFirstHidden } from './trackFirstHidden' +import type { FirstHidden } from './trackFirstHidden' /** * Track the first input occurring during the initial View to return: @@ -17,7 +16,7 @@ import { trackFirstHidden } from './trackFirstHidden' export function trackFirstInputTimings( lifeCycle: LifeCycle, - configuration: RumConfiguration, + firstHidden: FirstHidden, callback: ({ firstInputDelay, firstInputTime, @@ -28,27 +27,28 @@ export function trackFirstInputTimings( firstInputTarget: Node | undefined }) => void ) { - const firstHidden = trackFirstHidden(configuration) - - const { unsubscribe: stop } = lifeCycle.subscribe(LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED, (entries) => { - const firstInputEntry = find( - entries, - (entry): entry is RumFirstInputTiming => - entry.entryType === 'first-input' && entry.startTime < firstHidden.timeStamp - ) - if (firstInputEntry) { - const firstInputDelay = elapsed(firstInputEntry.startTime, firstInputEntry.processingStart) - callback({ - // Ensure firstInputDelay to be positive, see - // https://bugs.chromium.org/p/chromium/issues/detail?id=1185815 - firstInputDelay: firstInputDelay >= 0 ? firstInputDelay : (0 as Duration), - firstInputTime: firstInputEntry.startTime, - firstInputTarget: firstInputEntry.target, - }) + const { unsubscribe: unsubscribeLifeCycle } = lifeCycle.subscribe( + LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED, + (entries) => { + const firstInputEntry = find( + entries, + (entry): entry is RumFirstInputTiming => + entry.entryType === 'first-input' && entry.startTime < firstHidden.timeStamp + ) + if (firstInputEntry) { + const firstInputDelay = elapsed(firstInputEntry.startTime, firstInputEntry.processingStart) + callback({ + // Ensure firstInputDelay to be positive, see + // https://bugs.chromium.org/p/chromium/issues/detail?id=1185815 + firstInputDelay: firstInputDelay >= 0 ? firstInputDelay : (0 as Duration), + firstInputTime: firstInputEntry.startTime, + firstInputTarget: firstInputEntry.target, + }) + } } - }) + ) return { - stop, + stop: unsubscribeLifeCycle, } } diff --git a/packages/rum-core/src/domain/view/viewMetrics/trackInitialViewMetrics.spec.ts b/packages/rum-core/src/domain/view/viewMetrics/trackInitialViewMetrics.spec.ts index ae301dc32b..d48a15ace1 100644 --- a/packages/rum-core/src/domain/view/viewMetrics/trackInitialViewMetrics.spec.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackInitialViewMetrics.spec.ts @@ -4,7 +4,7 @@ import { noopWebVitalTelemetryDebug, setup } from '../../../../test' import { LifeCycleEventType } from '../../lifeCycle' import type { RumConfiguration } from '../../configuration' import { FAKE_FIRST_INPUT_ENTRY, FAKE_NAVIGATION_ENTRY, FAKE_PAINT_ENTRY } from '../setupViewTest.specHelper' -import { KEEP_TRACKING_METRICS_AFTER_VIEW_DELAY, trackInitialViewMetrics } from './trackInitialViewMetrics' +import { trackInitialViewMetrics } from './trackInitialViewMetrics' describe('trackInitialViewMetrics', () => { let setupBuilder: TestSetupBuilder @@ -56,21 +56,6 @@ describe('trackInitialViewMetrics', () => { }) }) - it('allows delaying the stop logic', () => { - const { lifeCycle, clock } = setupBuilder.withFakeClock().build() - trackInitialViewMetricsResult.scheduleStop() - - lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED, [FAKE_NAVIGATION_ENTRY]) - - expect(scheduleViewUpdateSpy).toHaveBeenCalledTimes(1) - - clock.tick(KEEP_TRACKING_METRICS_AFTER_VIEW_DELAY) - - lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED, [FAKE_PAINT_ENTRY]) - - expect(scheduleViewUpdateSpy).toHaveBeenCalledTimes(1) - }) - it('calls the `setLoadEvent` callback when the loadEvent timing is known', () => { const { lifeCycle } = setupBuilder.build() diff --git a/packages/rum-core/src/domain/view/viewMetrics/trackInitialViewMetrics.ts b/packages/rum-core/src/domain/view/viewMetrics/trackInitialViewMetrics.ts index 51c31b70de..88e7b1bbb6 100644 --- a/packages/rum-core/src/domain/view/viewMetrics/trackInitialViewMetrics.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackInitialViewMetrics.ts @@ -1,5 +1,5 @@ import type { Duration } from '@datadog/browser-core' -import { setTimeout, assign, ONE_MINUTE } from '@datadog/browser-core' +import { assign } from '@datadog/browser-core' import type { RumConfiguration } from '../../configuration' import type { LifeCycle } from '../../lifeCycle' import type { WebVitalTelemetryDebug } from '../startWebVitalTelemetryDebug' @@ -7,14 +7,7 @@ import { trackFirstContentfulPaint } from './trackFirstContentfulPaint' import { trackFirstInputTimings } from './trackFirstInputTimings' import { trackNavigationTimings } from './trackNavigationTimings' import { trackLargestContentfulPaint } from './trackLargestContentfulPaint' - -/** - * The initial view can finish quickly, before some metrics can be produced (ex: before the page load - * event, or the first input). Also, we don't want to trigger a view update indefinitely, to avoid - * updates on views that ended a long time ago. Keep watching for metrics after the view ends for a - * limited amount of time. - */ -export const KEEP_TRACKING_METRICS_AFTER_VIEW_DELAY = 5 * ONE_MINUTE +import { trackFirstHidden } from './trackFirstHidden' export interface InitialViewMetrics { firstContentfulPaint?: Duration @@ -46,12 +39,14 @@ export function trackInitialViewMetrics( setLoadEvent(navigationTimings.loadEvent) setMetrics(navigationTimings) }) - const { stop: stopFCPTracking } = trackFirstContentfulPaint(lifeCycle, configuration, (firstContentfulPaint) => + const firstHidden = trackFirstHidden(configuration) + const { stop: stopFCPTracking } = trackFirstContentfulPaint(lifeCycle, firstHidden, (firstContentfulPaint) => setMetrics({ firstContentfulPaint }) ) const { stop: stopLCPTracking } = trackLargestContentfulPaint( lifeCycle, configuration, + firstHidden, window, (largestContentfulPaint, lcpElement) => { webVitalTelemetryDebug.addWebVitalTelemetryDebug('LCP', lcpElement, largestContentfulPaint) @@ -64,7 +59,7 @@ export function trackInitialViewMetrics( const { stop: stopFIDTracking } = trackFirstInputTimings( lifeCycle, - configuration, + firstHidden, ({ firstInputDelay, firstInputTime, firstInputTarget }) => { webVitalTelemetryDebug.addWebVitalTelemetryDebug('FID', firstInputTarget, firstInputTime) @@ -80,13 +75,11 @@ export function trackInitialViewMetrics( stopFCPTracking() stopLCPTracking() stopFIDTracking() + firstHidden.stop() } return { stop, initialViewMetrics, - scheduleStop: () => { - setTimeout(stop, KEEP_TRACKING_METRICS_AFTER_VIEW_DELAY) - }, } } diff --git a/packages/rum-core/src/domain/view/viewMetrics/trackLargestContentfulPaint.spec.ts b/packages/rum-core/src/domain/view/viewMetrics/trackLargestContentfulPaint.spec.ts index 34aa514e27..5d0651c971 100644 --- a/packages/rum-core/src/domain/view/viewMetrics/trackLargestContentfulPaint.spec.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackLargestContentfulPaint.spec.ts @@ -6,8 +6,8 @@ import type { TestSetupBuilder } from '../../../../test' import { setup } from '../../../../test' import { LifeCycleEventType } from '../../lifeCycle' import type { RumConfiguration } from '../../configuration' -import { resetFirstHidden } from './trackFirstHidden' import { LCP_MAXIMUM_DELAY, trackLargestContentfulPaint } from './trackLargestContentfulPaint' +import { trackFirstHidden } from './trackFirstHidden' describe('trackLargestContentfulPaint', () => { let setupBuilder: TestSetupBuilder @@ -19,16 +19,27 @@ describe('trackLargestContentfulPaint', () => { configuration = {} as RumConfiguration lcpCallback = jasmine.createSpy() eventTarget = document.createElement('div') as unknown as Window - setupBuilder = setup().beforeBuild(({ lifeCycle }) => - trackLargestContentfulPaint(lifeCycle, configuration, eventTarget, lcpCallback) - ) - resetFirstHidden() + setupBuilder = setup().beforeBuild(({ lifeCycle }) => { + const firstHidden = trackFirstHidden(configuration) + const largestContentfulPaint = trackLargestContentfulPaint( + lifeCycle, + configuration, + firstHidden, + eventTarget, + lcpCallback + ) + return { + stop() { + firstHidden.stop() + largestContentfulPaint.stop() + }, + } + }) }) afterEach(() => { setupBuilder.cleanup() restorePageVisibility() - resetFirstHidden() }) it('should provide the largest contentful paint timing', () => { diff --git a/packages/rum-core/src/domain/view/viewMetrics/trackLargestContentfulPaint.ts b/packages/rum-core/src/domain/view/viewMetrics/trackLargestContentfulPaint.ts index 979a437e8d..89455afe81 100644 --- a/packages/rum-core/src/domain/view/viewMetrics/trackLargestContentfulPaint.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackLargestContentfulPaint.ts @@ -3,7 +3,7 @@ import { DOM_EVENT, ONE_MINUTE, addEventListeners, findLast } from '@datadog/bro import { LifeCycleEventType, type LifeCycle } from '../../lifeCycle' import type { RumConfiguration } from '../../configuration' import type { RumLargestContentfulPaintTiming } from '../../../browser/performanceCollection' -import { trackFirstHidden } from './trackFirstHidden' +import type { FirstHidden } from './trackFirstHidden' // Discard LCP timings above a certain delay to avoid incorrect data // It happens in some cases like sleep mode or some browser implementations @@ -18,11 +18,10 @@ export const LCP_MAXIMUM_DELAY = 10 * ONE_MINUTE export function trackLargestContentfulPaint( lifeCycle: LifeCycle, configuration: RumConfiguration, + firstHidden: FirstHidden, eventTarget: Window, callback: (lcpTiming: RelativeTime, lcpElement?: Element) => void ) { - const firstHidden = trackFirstHidden(configuration) - // Ignore entries that come after the first user interaction. According to the documentation, the // browser should not send largest-contentful-paint entries after a user interact with the page, // but the web-vitals reference implementation uses this as a safeguard. diff --git a/packages/rum-core/test/testSetupBuilder.ts b/packages/rum-core/test/testSetupBuilder.ts index 5f0903d48d..5ed21ace6c 100644 --- a/packages/rum-core/test/testSetupBuilder.ts +++ b/packages/rum-core/test/testSetupBuilder.ts @@ -15,6 +15,7 @@ import type { ActionContexts } from '../src/domain/action/actionCollection' import type { RumSessionManager } from '../src/domain/rumSessionManager' import { RumSessionPlan } from '../src/domain/rumSessionManager' import type { RawRumEvent, RumContext } from '../src/rawRumEvent.types' +import type { DisplayContext } from '../src/domain/contexts/displayContext' import { validateRumFormat } from './formatValidation' import { createRumSessionManagerMock } from './mockRumSessionManager' @@ -47,6 +48,7 @@ export interface BuildContext { applicationId: string viewContexts: ViewContexts actionContexts: ActionContexts + displayContext: DisplayContext pageStateHistory: PageStateHistory featureFlagContexts: FeatureFlagContexts urlContexts: UrlContexts @@ -92,6 +94,10 @@ export function setup(): TestSetupBuilder { let actionContexts: ActionContexts = { findActionId: noop as () => undefined, } + const displayContext: DisplayContext = { + get: () => ({ viewport: { height: 0, width: 0 } }), + stop: noop, + } const globalContextManager = createContextManager(CustomerDataType.GlobalContext) const userContextManager = createContextManager(CustomerDataType.User) @@ -174,6 +180,7 @@ export function setup(): TestSetupBuilder { viewContexts, urlContexts, actionContexts, + displayContext, pageStateHistory, featureFlagContexts, sessionManager, diff --git a/packages/rum/src/boot/startRecording.spec.ts b/packages/rum/src/boot/startRecording.spec.ts index 1a2d9149db..2069bb7af0 100644 --- a/packages/rum/src/boot/startRecording.spec.ts +++ b/packages/rum/src/boot/startRecording.spec.ts @@ -9,7 +9,12 @@ import { createRumSessionManagerMock, setup } from '../../../rum-core/test' import { recordsPerFullSnapshot, readReplayPayload } from '../../test' import { setSegmentBytesLimit } from '../domain/segmentCollection' -import { DeflateEncoderStreamId, startDeflateWorker, createDeflateEncoder } from '../domain/deflate' +import { + DeflateEncoderStreamId, + startDeflateWorker, + createDeflateEncoder, + resetDeflateWorkerState, +} from '../domain/deflate' import { RecordType } from '../types' import { resetReplayStats } from '../domain/replayStats' @@ -42,7 +47,7 @@ describe('startRecording', () => { textField = document.createElement('input') sandbox.appendChild(textField) - const worker = startDeflateWorker(configuration, noop)! + const worker = startDeflateWorker(configuration, noop) setupBuilder = setup() .withViewContexts({ @@ -61,16 +66,22 @@ describe('startRecording', () => { sendOnExit: requestSendSpy, } + const deflateEncoder = createDeflateEncoder(configuration, worker!, DeflateEncoderStreamId.REPLAY) const recording = startRecording( lifeCycle, configuration, sessionManager, viewContexts, - createDeflateEncoder(configuration, worker, DeflateEncoderStreamId.REPLAY), + deflateEncoder, httpRequest ) stopRecording = recording ? recording.stop : noop - return { stop: stopRecording } + return { + stop: () => { + stopRecording() + deflateEncoder.stop() + }, + } }) }) @@ -79,6 +90,7 @@ describe('startRecording', () => { setSegmentBytesLimit() setupBuilder.cleanup() clock?.cleanup() + resetDeflateWorkerState() }) it('sends recorded segments with valid context', async () => { diff --git a/packages/rum/src/domain/deflate/deflateEncoder.ts b/packages/rum/src/domain/deflate/deflateEncoder.ts index 87612afca9..e4a0ee77fd 100644 --- a/packages/rum/src/domain/deflate/deflateEncoder.ts +++ b/packages/rum/src/domain/deflate/deflateEncoder.ts @@ -6,6 +6,7 @@ import type { DeflateWorker } from './deflateWorker' export interface DeflateEncoder { write(data: string, callback: () => void): void reset(): void + stop(): void encodedBytesCount: number encodedBytes: Uint8Array rawBytesCount: number @@ -97,5 +98,9 @@ export function createDeflateEncoder( }) nextWriteActionId = 0 }, + + stop() { + removeMessageListener() + }, } } diff --git a/packages/rum/src/domain/deflate/deflateWorker.ts b/packages/rum/src/domain/deflate/deflateWorker.ts index 5a3bc437d2..197e710cf2 100644 --- a/packages/rum/src/domain/deflate/deflateWorker.ts +++ b/packages/rum/src/domain/deflate/deflateWorker.ts @@ -25,6 +25,7 @@ type DeflateWorkerState = | { status: DeflateWorkerStatus.Loading worker: DeflateWorker + stop: () => void initializationFailureCallbacks: Array<() => void> } | { @@ -33,6 +34,7 @@ type DeflateWorkerState = | { status: DeflateWorkerStatus.Initialized worker: DeflateWorker + stop: () => void version: string } @@ -68,6 +70,9 @@ export function startDeflateWorker( } export function resetDeflateWorkerState() { + if (state.status === DeflateWorkerStatus.Initialized || state.status === DeflateWorkerStatus.Loading) { + state.stop() + } state = { status: DeflateWorkerStatus.Nil } } @@ -87,19 +92,29 @@ export function getDeflateWorkerStatus() { export function doStartDeflateWorker(configuration: RumConfiguration, createDeflateWorkerImpl = createDeflateWorker) { try { const worker = createDeflateWorkerImpl(configuration) - addEventListener(configuration, worker, 'error', (error) => { + const { stop: removeErrorListener } = addEventListener(configuration, worker, 'error', (error) => { onError(configuration, error) }) - addEventListener(configuration, worker, 'message', ({ data }: MessageEvent) => { - if (data.type === 'errored') { - onError(configuration, data.error, data.streamId) - } else if (data.type === 'initialized') { - onInitialized(data.version) + const { stop: removeMessageListener } = addEventListener( + configuration, + worker, + 'message', + ({ data }: MessageEvent) => { + if (data.type === 'errored') { + onError(configuration, data.error, data.streamId) + } else if (data.type === 'initialized') { + onInitialized(data.version) + } } - }) + ) worker.postMessage({ action: 'init' }) setTimeout(onTimeout, INITIALIZATION_TIME_OUT_DELAY) - state = { status: DeflateWorkerStatus.Loading, worker, initializationFailureCallbacks: [] } + const stop = () => { + removeErrorListener() + removeMessageListener() + } + + state = { status: DeflateWorkerStatus.Loading, worker, stop, initializationFailureCallbacks: [] } } catch (error) { onError(configuration, error) } @@ -115,7 +130,7 @@ function onTimeout() { function onInitialized(version: string) { if (state.status === DeflateWorkerStatus.Loading) { - state = { status: DeflateWorkerStatus.Initialized, worker: state.worker, version } + state = { status: DeflateWorkerStatus.Initialized, worker: state.worker, stop: state.stop, version } } } From 2cae4210a0ab5fb1b9a5703afcf6e5a9b4cf428b Mon Sep 17 00:00:00 2001 From: Bastien Caudan <1331991+bcaudan@users.noreply.github.com> Date: Fri, 8 Sep 2023 10:07:29 +0200 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=91=B7=20Misc=20cleanup=20(#2419)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * avoid warning in unit test log * update telemetry message to something more specific to exclude --- .../record/serialization/serializeAttributes.spec.ts | 8 +++++--- packages/rum/test/toto.css | 1 + test/e2e/scenario/telemetry.scenario.ts | 8 ++++---- test/unit/karma.base.conf.js | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 packages/rum/test/toto.css diff --git a/packages/rum/src/domain/record/serialization/serializeAttributes.spec.ts b/packages/rum/src/domain/record/serialization/serializeAttributes.spec.ts index b74ea7e69d..328672291c 100644 --- a/packages/rum/src/domain/record/serialization/serializeAttributes.spec.ts +++ b/packages/rum/src/domain/record/serialization/serializeAttributes.spec.ts @@ -1,6 +1,8 @@ import { isIE } from '@datadog/browser-core' import { getCssRulesString } from './serializeAttributes' +const CSS_FILE_URL = '/base/packages/rum/test/toto.css' + describe('getCssRulesString', () => { let styleNode: HTMLStyleElement @@ -22,7 +24,7 @@ describe('getCssRulesString', () => { }) it('inlines imported external stylesheets', () => { - styleNode.sheet!.insertRule('@import url("toto.css");') + styleNode.sheet!.insertRule(`@import url("${CSS_FILE_URL}");`) // Simulates an accessible external stylesheet spyOnProperty(styleNode.sheet!.cssRules[0] as CSSImportRule, 'styleSheet').and.returnValue({ @@ -33,7 +35,7 @@ describe('getCssRulesString', () => { }) it('does not skip the @import rules if the external stylesheet is inaccessible', () => { - styleNode.sheet!.insertRule('@import url("toto.css");') + styleNode.sheet!.insertRule(`@import url("${CSS_FILE_URL}");`) // Simulates an inaccessible external stylesheet spyOnProperty(styleNode.sheet!.cssRules[0] as CSSImportRule, 'styleSheet').and.returnValue({ @@ -42,6 +44,6 @@ describe('getCssRulesString', () => { }, } as CSSStyleSheet) - expect(getCssRulesString(styleNode.sheet)).toBe('@import url("toto.css");') + expect(getCssRulesString(styleNode.sheet)).toBe(`@import url("${CSS_FILE_URL}");`) }) }) diff --git a/packages/rum/test/toto.css b/packages/rum/test/toto.css new file mode 100644 index 0000000000..0dfed97a5b --- /dev/null +++ b/packages/rum/test/toto.css @@ -0,0 +1 @@ +/* avoid warning in unit test */ diff --git a/test/e2e/scenario/telemetry.scenario.ts b/test/e2e/scenario/telemetry.scenario.ts index d94c7e01e5..3bc0a70fa3 100644 --- a/test/e2e/scenario/telemetry.scenario.ts +++ b/test/e2e/scenario/telemetry.scenario.ts @@ -9,7 +9,7 @@ describe('telemetry', () => { await browserExecute(() => { const context = { get foo() { - throw new window.Error('bar') + throw new window.Error('expected error') }, } window.DD_LOGS!.logger.log('hop', context as any) @@ -18,7 +18,7 @@ describe('telemetry', () => { expect(intakeRegistry.telemetryErrorEvents.length).toBe(1) const event = intakeRegistry.telemetryErrorEvents[0] expect(event.service).toEqual('browser-logs-sdk') - expect(event.telemetry.message).toBe('bar') + expect(event.telemetry.message).toBe('expected error') expect(event.telemetry.error!.kind).toBe('Error') expect(event.telemetry.status).toBe('error') intakeRegistry.empty() @@ -31,7 +31,7 @@ describe('telemetry', () => { await browserExecute(() => { const context = { get foo() { - throw new window.Error('bar') + throw new window.Error('expected error') }, } window.DD_RUM!.addAction('hop', context as any) @@ -40,7 +40,7 @@ describe('telemetry', () => { expect(intakeRegistry.telemetryErrorEvents.length).toBe(1) const event = intakeRegistry.telemetryErrorEvents[0] expect(event.service).toEqual('browser-rum-sdk') - expect(event.telemetry.message).toBe('bar') + expect(event.telemetry.message).toBe('expected error') expect(event.telemetry.error!.kind).toBe('Error') expect(event.telemetry.status).toBe('error') intakeRegistry.empty() diff --git a/test/unit/karma.base.conf.js b/test/unit/karma.base.conf.js index 5ba8c11fe0..02650f85f0 100644 --- a/test/unit/karma.base.conf.js +++ b/test/unit/karma.base.conf.js @@ -16,7 +16,7 @@ if (testReportDirectory) { module.exports = { basePath: '../..', - files: ['packages/*/+(src|test)/**/*.spec.ts'], + files: ['packages/*/+(src|test)/**/*.spec.ts', 'packages/rum/test/toto.css'], frameworks: ['jasmine', 'webpack'], client: { jasmine: {