@datadog/browser-rum-core
Advanced tools
Comparing version 4.10.4 to 4.11.0
@@ -49,3 +49,3 @@ "use strict"; | ||
}, | ||
browser_sdk_version: (0, browser_core_1.canUseEventBridge)() ? "4.10.4" : undefined, | ||
browser_sdk_version: (0, browser_core_1.canUseEventBridge)() ? "4.11.0" : undefined, | ||
}, | ||
@@ -52,0 +52,0 @@ application: { |
@@ -9,2 +9,3 @@ import type { Configuration, InitConfiguration } from '@datadog/browser-core'; | ||
premiumSampleRate?: number | undefined; | ||
excludedActivityUrls?: ReadonlyArray<string | RegExp> | undefined; | ||
allowedTracingOrigins?: ReadonlyArray<string | RegExp> | undefined; | ||
@@ -27,2 +28,3 @@ tracingSampleRate?: number | undefined; | ||
tracingSampleRate: number; | ||
excludedActivityUrls: Array<string | RegExp>; | ||
applicationId: string; | ||
@@ -29,0 +31,0 @@ defaultPrivacyLevel: DefaultPrivacyLevel; |
@@ -6,3 +6,3 @@ "use strict"; | ||
function validateAndBuildRumConfiguration(initConfiguration) { | ||
var _a, _b, _c; | ||
var _a, _b, _c, _d; | ||
if (!initConfiguration.applicationId) { | ||
@@ -32,2 +32,6 @@ browser_core_1.display.error('Application ID is not configured, no RUM data will be collected.'); | ||
} | ||
if (initConfiguration.excludedActivityUrls !== undefined && !Array.isArray(initConfiguration.excludedActivityUrls)) { | ||
browser_core_1.display.error('Excluded Activity Urls should be an array'); | ||
return; | ||
} | ||
var baseConfiguration = (0, browser_core_1.validateAndBuildConfiguration)(initConfiguration); | ||
@@ -45,2 +49,3 @@ if (!baseConfiguration) { | ||
tracingSampleRate: (_c = initConfiguration.tracingSampleRate) !== null && _c !== void 0 ? _c : 100, | ||
excludedActivityUrls: (_d = initConfiguration.excludedActivityUrls) !== null && _d !== void 0 ? _d : [], | ||
trackInteractions: !!initConfiguration.trackInteractions || trackFrustrations, | ||
@@ -47,0 +52,0 @@ trackFrustrations: trackFrustrations, |
@@ -23,2 +23,3 @@ import type { Duration, XhrCompleteContext, XhrStartContext, ClocksState, FetchStartContext, FetchCompleteContext } from '@datadog/browser-core'; | ||
requestIndex: number; | ||
url: string; | ||
} | ||
@@ -25,0 +26,0 @@ export interface RequestCompleteEvent { |
@@ -26,2 +26,3 @@ "use strict"; | ||
requestIndex: context.requestIndex, | ||
url: context.url, | ||
}); | ||
@@ -62,2 +63,3 @@ break; | ||
requestIndex: context.requestIndex, | ||
url: context.url, | ||
}); | ||
@@ -64,0 +66,0 @@ break; |
@@ -27,3 +27,3 @@ import type { Duration, ClocksState, RelativeTime, TimeStamp } from '@datadog/browser-core'; | ||
export declare const ACTION_CONTEXT_TIME_OUT_DELAY: number; | ||
export declare function trackClickActions(lifeCycle: LifeCycle, domMutationObservable: Observable<void>, { actionNameAttribute, trackFrustrations }: RumConfiguration): { | ||
export declare function trackClickActions(lifeCycle: LifeCycle, domMutationObservable: Observable<void>, configuration: RumConfiguration): { | ||
stop: () => void; | ||
@@ -30,0 +30,0 @@ actionContexts: ActionContexts; |
@@ -12,6 +12,6 @@ "use strict"; | ||
exports.ACTION_CONTEXT_TIME_OUT_DELAY = 5 * browser_core_1.ONE_MINUTE; // arbitrary | ||
function trackClickActions(lifeCycle, domMutationObservable, _a) { | ||
var actionNameAttribute = _a.actionNameAttribute, trackFrustrations = _a.trackFrustrations; | ||
function trackClickActions(lifeCycle, domMutationObservable, configuration) { | ||
var history = new browser_core_1.ContextHistory(exports.ACTION_CONTEXT_TIME_OUT_DELAY); | ||
var stopObservable = new browser_core_1.Observable(); | ||
var trackFrustrations = configuration.trackFrustrations; | ||
var currentRageClickChain; | ||
@@ -48,3 +48,3 @@ lifeCycle.subscribe(8 /* SESSION_RENEWED */, function () { | ||
} | ||
var name = (0, getActionNameFromElement_1.getActionNameFromElement)(event.target, actionNameAttribute); | ||
var name = (0, getActionNameFromElement_1.getActionNameFromElement)(event.target, configuration.actionNameAttribute); | ||
if (!trackFrustrations && !name) { | ||
@@ -64,3 +64,3 @@ // TODO: remove this in a future major version. To keep retrocompatibility, ignore any action | ||
} | ||
var stopWaitPageActivityEnd = (0, waitPageActivityEnd_1.waitPageActivityEnd)(lifeCycle, domMutationObservable, function (pageActivityEndEvent) { | ||
var stopWaitPageActivityEnd = (0, waitPageActivityEnd_1.waitPageActivityEnd)(lifeCycle, domMutationObservable, configuration, function (pageActivityEndEvent) { | ||
if (!pageActivityEndEvent.hadActivity) { | ||
@@ -67,0 +67,0 @@ // If it has no activity, consider it as a dead click. |
import type { Duration, Observable, ClocksState } from '@datadog/browser-core'; | ||
import { ViewLoadingType } from '../../../rawRumEvent.types'; | ||
import type { RumConfiguration } from '../../configuration'; | ||
import type { LifeCycle } from '../../lifeCycle'; | ||
@@ -10,3 +11,3 @@ import type { EventCounts } from '../../trackEventCounts'; | ||
} | ||
export declare function trackViewMetrics(lifeCycle: LifeCycle, domMutationObservable: Observable<void>, scheduleViewUpdate: () => void, loadingType: ViewLoadingType, viewStart: ClocksState): { | ||
export declare function trackViewMetrics(lifeCycle: LifeCycle, domMutationObservable: Observable<void>, configuration: RumConfiguration, scheduleViewUpdate: () => void, loadingType: ViewLoadingType, viewStart: ClocksState): { | ||
stop: () => void; | ||
@@ -13,0 +14,0 @@ setLoadEvent: (loadEvent: Duration) => void; |
@@ -8,3 +8,3 @@ "use strict"; | ||
var waitPageActivityEnd_1 = require("../../waitPageActivityEnd"); | ||
function trackViewMetrics(lifeCycle, domMutationObservable, scheduleViewUpdate, loadingType, viewStart) { | ||
function trackViewMetrics(lifeCycle, domMutationObservable, configuration, scheduleViewUpdate, loadingType, viewStart) { | ||
var viewMetrics = { | ||
@@ -23,3 +23,3 @@ eventCounts: { | ||
}).stop; | ||
var _a = trackLoadingTime(lifeCycle, domMutationObservable, loadingType, viewStart, function (newLoadingTime) { | ||
var _a = trackLoadingTime(lifeCycle, domMutationObservable, configuration, loadingType, viewStart, function (newLoadingTime) { | ||
viewMetrics.loadingTime = newLoadingTime; | ||
@@ -50,3 +50,3 @@ scheduleViewUpdate(); | ||
exports.trackViewMetrics = trackViewMetrics; | ||
function trackLoadingTime(lifeCycle, domMutationObservable, loadType, viewStart, callback) { | ||
function trackLoadingTime(lifeCycle, domMutationObservable, configuration, loadType, viewStart, callback) { | ||
var isWaitingForLoadEvent = loadType === "initial_load" /* INITIAL_LOAD */; | ||
@@ -60,3 +60,3 @@ var isWaitingForActivityLoadingTime = true; | ||
} | ||
var stop = (0, waitPageActivityEnd_1.waitPageActivityEnd)(lifeCycle, domMutationObservable, function (event) { | ||
var stop = (0, waitPageActivityEnd_1.waitPageActivityEnd)(lifeCycle, domMutationObservable, configuration, function (event) { | ||
if (isWaitingForActivityLoadingTime) { | ||
@@ -63,0 +63,0 @@ isWaitingForActivityLoadingTime = false; |
@@ -7,2 +7,3 @@ import type { Duration, ClocksState, TimeStamp, Observable, RelativeTime } from '@datadog/browser-core'; | ||
import type { LocationChange } from '../../../browser/locationChangeObservable'; | ||
import type { RumConfiguration } from '../../configuration'; | ||
import type { Timings } from './trackInitialViewTimings'; | ||
@@ -43,3 +44,3 @@ export interface ViewEvent { | ||
} | ||
export declare function trackViews(location: Location, lifeCycle: LifeCycle, domMutationObservable: Observable<void>, locationChangeObservable: Observable<LocationChange>, areViewsTrackedAutomatically: boolean, initialViewOptions?: ViewOptions): { | ||
export declare function trackViews(location: Location, lifeCycle: LifeCycle, domMutationObservable: Observable<void>, configuration: RumConfiguration, locationChangeObservable: Observable<LocationChange>, areViewsTrackedAutomatically: boolean, initialViewOptions?: ViewOptions): { | ||
addTiming: (name: string, time?: RelativeTime | TimeStamp) => void; | ||
@@ -46,0 +47,0 @@ startView: (options?: ViewOptions | undefined, startClocks?: ClocksState | undefined) => void; |
@@ -9,3 +9,3 @@ "use strict"; | ||
exports.SESSION_KEEP_ALIVE_INTERVAL = 5 * browser_core_1.ONE_MINUTE; | ||
function trackViews(location, lifeCycle, domMutationObservable, locationChangeObservable, areViewsTrackedAutomatically, initialViewOptions) { | ||
function trackViews(location, lifeCycle, domMutationObservable, configuration, locationChangeObservable, areViewsTrackedAutomatically, initialViewOptions) { | ||
var _a = trackInitialView(initialViewOptions), stopInitialViewTracking = _a.stop, initialView = _a.initialView; | ||
@@ -19,3 +19,3 @@ var currentView = initialView; | ||
function trackInitialView(options) { | ||
var initialView = newView(lifeCycle, domMutationObservable, location, "initial_load" /* INITIAL_LOAD */, (0, browser_core_1.clocksOrigin)(), options); | ||
var initialView = newView(lifeCycle, domMutationObservable, configuration, location, "initial_load" /* INITIAL_LOAD */, (0, browser_core_1.clocksOrigin)(), options); | ||
var stop = (0, trackInitialViewTimings_1.trackInitialViewTimings)(lifeCycle, function (timings) { | ||
@@ -28,3 +28,3 @@ initialView.updateTimings(timings); | ||
function trackViewChange(startClocks, viewOptions) { | ||
return newView(lifeCycle, domMutationObservable, location, "route_change" /* ROUTE_CHANGE */, startClocks, viewOptions); | ||
return newView(lifeCycle, domMutationObservable, configuration, location, "route_change" /* ROUTE_CHANGE */, startClocks, viewOptions); | ||
} | ||
@@ -88,3 +88,3 @@ function startViewLifeCycle() { | ||
exports.trackViews = trackViews; | ||
function newView(lifeCycle, domMutationObservable, initialLocation, loadingType, startClocks, viewOptions) { | ||
function newView(lifeCycle, domMutationObservable, configuration, initialLocation, loadingType, startClocks, viewOptions) { | ||
if (startClocks === void 0) { startClocks = (0, browser_core_1.clocksNow)(); } | ||
@@ -111,3 +111,3 @@ // Setup initial values | ||
}), scheduleViewUpdate = _a.throttled, cancelScheduleViewUpdate = _a.cancel; | ||
var _b = (0, trackViewMetrics_1.trackViewMetrics)(lifeCycle, domMutationObservable, scheduleViewUpdate, loadingType, startClocks), setLoadEvent = _b.setLoadEvent, stopViewMetricsTracking = _b.stop, viewMetrics = _b.viewMetrics; | ||
var _b = (0, trackViewMetrics_1.trackViewMetrics)(lifeCycle, domMutationObservable, configuration, scheduleViewUpdate, loadingType, startClocks), setLoadEvent = _b.setLoadEvent, stopViewMetricsTracking = _b.stop, viewMetrics = _b.viewMetrics; | ||
// Initial view update | ||
@@ -114,0 +114,0 @@ triggerViewUpdate(); |
@@ -10,3 +10,3 @@ "use strict"; | ||
}); | ||
return (0, trackViews_1.trackViews)(location, lifeCycle, domMutationObservable, locationChangeObservable, !configuration.trackViewsManually, initialViewOptions); | ||
return (0, trackViews_1.trackViews)(location, lifeCycle, domMutationObservable, configuration, locationChangeObservable, !configuration.trackViewsManually, initialViewOptions); | ||
} | ||
@@ -13,0 +13,0 @@ exports.startViewCollection = startViewCollection; |
@@ -85,10 +85,3 @@ "use strict"; | ||
function isAllowedUrl(configuration, requestUrl) { | ||
var requestOrigin = (0, browser_core_1.getOrigin)(requestUrl); | ||
for (var _i = 0, _a = configuration.allowedTracingOrigins; _i < _a.length; _i++) { | ||
var allowedOrigin = _a[_i]; | ||
if (requestOrigin === allowedOrigin || (allowedOrigin instanceof RegExp && allowedOrigin.test(requestOrigin))) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
return (0, browser_core_1.matchList)(configuration.allowedTracingOrigins, (0, browser_core_1.getOrigin)(requestUrl)); | ||
} | ||
@@ -95,0 +88,0 @@ function isTracingSupported() { |
import type { TimeStamp } from '@datadog/browser-core'; | ||
import { Observable } from '@datadog/browser-core'; | ||
import type { RumConfiguration } from './configuration'; | ||
import type { LifeCycle } from './lifeCycle'; | ||
@@ -45,3 +46,3 @@ export declare const PAGE_ACTIVITY_VALIDATION_DELAY = 100; | ||
*/ | ||
export declare function waitPageActivityEnd(lifeCycle: LifeCycle, domMutationObservable: Observable<void>, pageActivityEndCallback: (event: PageActivityEndEvent) => void, maxDuration?: number): { | ||
export declare function waitPageActivityEnd(lifeCycle: LifeCycle, domMutationObservable: Observable<void>, configuration: RumConfiguration, pageActivityEndCallback: (event: PageActivityEndEvent) => void, maxDuration?: number): { | ||
stop: () => void; | ||
@@ -52,2 +53,2 @@ }; | ||
}; | ||
export declare function createPageActivityObservable(lifeCycle: LifeCycle, domMutationObservable: Observable<void>): Observable<PageActivityEvent>; | ||
export declare function createPageActivityObservable(lifeCycle: LifeCycle, domMutationObservable: Observable<void>, configuration: RumConfiguration): Observable<PageActivityEvent>; |
@@ -39,4 +39,4 @@ "use strict"; | ||
*/ | ||
function waitPageActivityEnd(lifeCycle, domMutationObservable, pageActivityEndCallback, maxDuration) { | ||
var pageActivityObservable = createPageActivityObservable(lifeCycle, domMutationObservable); | ||
function waitPageActivityEnd(lifeCycle, domMutationObservable, configuration, pageActivityEndCallback, maxDuration) { | ||
var pageActivityObservable = createPageActivityObservable(lifeCycle, domMutationObservable, configuration); | ||
return doWaitPageActivityEnd(pageActivityObservable, pageActivityEndCallback, maxDuration); | ||
@@ -77,3 +77,3 @@ } | ||
exports.doWaitPageActivityEnd = doWaitPageActivityEnd; | ||
function createPageActivityObservable(lifeCycle, domMutationObservable) { | ||
function createPageActivityObservable(lifeCycle, domMutationObservable, configuration) { | ||
var observable = new browser_core_1.Observable(function () { | ||
@@ -84,9 +84,9 @@ var subscriptions = []; | ||
subscriptions.push(domMutationObservable.subscribe(function () { return notifyPageActivity(pendingRequestsCount); }), lifeCycle.subscribe(0 /* PERFORMANCE_ENTRIES_COLLECTED */, function (entries) { | ||
if (entries.some(function (_a) { | ||
var entryType = _a.entryType; | ||
return entryType === 'resource'; | ||
})) { | ||
if (entries.some(function (entry) { return entry.entryType === 'resource' && !isExcludedUrl(configuration, entry.name); })) { | ||
notifyPageActivity(pendingRequestsCount); | ||
} | ||
}), lifeCycle.subscribe(5 /* REQUEST_STARTED */, function (startEvent) { | ||
if (isExcludedUrl(configuration, startEvent.url)) { | ||
return; | ||
} | ||
if (firstRequestIndex === undefined) { | ||
@@ -97,4 +97,6 @@ firstRequestIndex = startEvent.requestIndex; | ||
}), lifeCycle.subscribe(6 /* REQUEST_COMPLETED */, function (request) { | ||
// If the request started before the tracking start, ignore it | ||
if (firstRequestIndex === undefined || request.requestIndex < firstRequestIndex) { | ||
if (isExcludedUrl(configuration, request.url) || | ||
firstRequestIndex === undefined || | ||
// If the request started before the tracking start, ignore it | ||
request.requestIndex < firstRequestIndex) { | ||
return; | ||
@@ -112,2 +114,5 @@ } | ||
exports.createPageActivityObservable = createPageActivityObservable; | ||
function isExcludedUrl(configuration, requestUrl) { | ||
return (0, browser_core_1.matchList)(configuration.excludedActivityUrls, requestUrl); | ||
} | ||
//# sourceMappingURL=waitPageActivityEnd.js.map |
@@ -46,3 +46,3 @@ import { combine, isEmptyObject, limitModification, timeStampNow, currentDrift, display, createEventRateLimiter, canUseEventBridge, isExperimentalFeatureEnabled, } from '@datadog/browser-core'; | ||
}, | ||
browser_sdk_version: canUseEventBridge() ? "4.10.4" : undefined, | ||
browser_sdk_version: canUseEventBridge() ? "4.11.0" : undefined, | ||
}, | ||
@@ -49,0 +49,0 @@ application: { |
@@ -9,2 +9,3 @@ import type { Configuration, InitConfiguration } from '@datadog/browser-core'; | ||
premiumSampleRate?: number | undefined; | ||
excludedActivityUrls?: ReadonlyArray<string | RegExp> | undefined; | ||
allowedTracingOrigins?: ReadonlyArray<string | RegExp> | undefined; | ||
@@ -27,2 +28,3 @@ tracingSampleRate?: number | undefined; | ||
tracingSampleRate: number; | ||
excludedActivityUrls: Array<string | RegExp>; | ||
applicationId: string; | ||
@@ -29,0 +31,0 @@ defaultPrivacyLevel: DefaultPrivacyLevel; |
import { isExperimentalFeatureEnabled, assign, DefaultPrivacyLevel, display, isPercentage, objectHasValue, validateAndBuildConfiguration, } from '@datadog/browser-core'; | ||
export function validateAndBuildRumConfiguration(initConfiguration) { | ||
var _a, _b, _c; | ||
var _a, _b, _c, _d; | ||
if (!initConfiguration.applicationId) { | ||
@@ -28,2 +28,6 @@ display.error('Application ID is not configured, no RUM data will be collected.'); | ||
} | ||
if (initConfiguration.excludedActivityUrls !== undefined && !Array.isArray(initConfiguration.excludedActivityUrls)) { | ||
display.error('Excluded Activity Urls should be an array'); | ||
return; | ||
} | ||
var baseConfiguration = validateAndBuildConfiguration(initConfiguration); | ||
@@ -41,2 +45,3 @@ if (!baseConfiguration) { | ||
tracingSampleRate: (_c = initConfiguration.tracingSampleRate) !== null && _c !== void 0 ? _c : 100, | ||
excludedActivityUrls: (_d = initConfiguration.excludedActivityUrls) !== null && _d !== void 0 ? _d : [], | ||
trackInteractions: !!initConfiguration.trackInteractions || trackFrustrations, | ||
@@ -43,0 +48,0 @@ trackFrustrations: trackFrustrations, |
@@ -23,2 +23,3 @@ import type { Duration, XhrCompleteContext, XhrStartContext, ClocksState, FetchStartContext, FetchCompleteContext } from '@datadog/browser-core'; | ||
requestIndex: number; | ||
url: string; | ||
} | ||
@@ -25,0 +26,0 @@ export interface RequestCompleteEvent { |
@@ -22,2 +22,3 @@ import { initFetchObservable, initXhrObservable } from '@datadog/browser-core'; | ||
requestIndex: context.requestIndex, | ||
url: context.url, | ||
}); | ||
@@ -57,2 +58,3 @@ break; | ||
requestIndex: context.requestIndex, | ||
url: context.url, | ||
}); | ||
@@ -59,0 +61,0 @@ break; |
@@ -27,3 +27,3 @@ import type { Duration, ClocksState, RelativeTime, TimeStamp } from '@datadog/browser-core'; | ||
export declare const ACTION_CONTEXT_TIME_OUT_DELAY: number; | ||
export declare function trackClickActions(lifeCycle: LifeCycle, domMutationObservable: Observable<void>, { actionNameAttribute, trackFrustrations }: RumConfiguration): { | ||
export declare function trackClickActions(lifeCycle: LifeCycle, domMutationObservable: Observable<void>, configuration: RumConfiguration): { | ||
stop: () => void; | ||
@@ -30,0 +30,0 @@ actionContexts: ActionContexts; |
@@ -9,6 +9,6 @@ import { setToArray, Observable, assign, getRelativeTime, ONE_MINUTE, ContextHistory, addEventListener, generateUUID, clocksNow, ONE_SECOND, elapsed, } from '@datadog/browser-core'; | ||
export var ACTION_CONTEXT_TIME_OUT_DELAY = 5 * ONE_MINUTE; // arbitrary | ||
export function trackClickActions(lifeCycle, domMutationObservable, _a) { | ||
var actionNameAttribute = _a.actionNameAttribute, trackFrustrations = _a.trackFrustrations; | ||
export function trackClickActions(lifeCycle, domMutationObservable, configuration) { | ||
var history = new ContextHistory(ACTION_CONTEXT_TIME_OUT_DELAY); | ||
var stopObservable = new Observable(); | ||
var trackFrustrations = configuration.trackFrustrations; | ||
var currentRageClickChain; | ||
@@ -45,3 +45,3 @@ lifeCycle.subscribe(8 /* SESSION_RENEWED */, function () { | ||
} | ||
var name = getActionNameFromElement(event.target, actionNameAttribute); | ||
var name = getActionNameFromElement(event.target, configuration.actionNameAttribute); | ||
if (!trackFrustrations && !name) { | ||
@@ -61,3 +61,3 @@ // TODO: remove this in a future major version. To keep retrocompatibility, ignore any action | ||
} | ||
var stopWaitPageActivityEnd = waitPageActivityEnd(lifeCycle, domMutationObservable, function (pageActivityEndEvent) { | ||
var stopWaitPageActivityEnd = waitPageActivityEnd(lifeCycle, domMutationObservable, configuration, function (pageActivityEndEvent) { | ||
if (!pageActivityEndEvent.hadActivity) { | ||
@@ -64,0 +64,0 @@ // If it has no activity, consider it as a dead click. |
import type { Duration, Observable, ClocksState } from '@datadog/browser-core'; | ||
import { ViewLoadingType } from '../../../rawRumEvent.types'; | ||
import type { RumConfiguration } from '../../configuration'; | ||
import type { LifeCycle } from '../../lifeCycle'; | ||
@@ -10,3 +11,3 @@ import type { EventCounts } from '../../trackEventCounts'; | ||
} | ||
export declare function trackViewMetrics(lifeCycle: LifeCycle, domMutationObservable: Observable<void>, scheduleViewUpdate: () => void, loadingType: ViewLoadingType, viewStart: ClocksState): { | ||
export declare function trackViewMetrics(lifeCycle: LifeCycle, domMutationObservable: Observable<void>, configuration: RumConfiguration, scheduleViewUpdate: () => void, loadingType: ViewLoadingType, viewStart: ClocksState): { | ||
stop: () => void; | ||
@@ -13,0 +14,0 @@ setLoadEvent: (loadEvent: Duration) => void; |
@@ -5,3 +5,3 @@ import { noop, round, ONE_SECOND, elapsed } from '@datadog/browser-core'; | ||
import { waitPageActivityEnd } from '../../waitPageActivityEnd'; | ||
export function trackViewMetrics(lifeCycle, domMutationObservable, scheduleViewUpdate, loadingType, viewStart) { | ||
export function trackViewMetrics(lifeCycle, domMutationObservable, configuration, scheduleViewUpdate, loadingType, viewStart) { | ||
var viewMetrics = { | ||
@@ -20,3 +20,3 @@ eventCounts: { | ||
}).stop; | ||
var _a = trackLoadingTime(lifeCycle, domMutationObservable, loadingType, viewStart, function (newLoadingTime) { | ||
var _a = trackLoadingTime(lifeCycle, domMutationObservable, configuration, loadingType, viewStart, function (newLoadingTime) { | ||
viewMetrics.loadingTime = newLoadingTime; | ||
@@ -46,3 +46,3 @@ scheduleViewUpdate(); | ||
} | ||
function trackLoadingTime(lifeCycle, domMutationObservable, loadType, viewStart, callback) { | ||
function trackLoadingTime(lifeCycle, domMutationObservable, configuration, loadType, viewStart, callback) { | ||
var isWaitingForLoadEvent = loadType === "initial_load" /* INITIAL_LOAD */; | ||
@@ -56,3 +56,3 @@ var isWaitingForActivityLoadingTime = true; | ||
} | ||
var stop = waitPageActivityEnd(lifeCycle, domMutationObservable, function (event) { | ||
var stop = waitPageActivityEnd(lifeCycle, domMutationObservable, configuration, function (event) { | ||
if (isWaitingForActivityLoadingTime) { | ||
@@ -59,0 +59,0 @@ isWaitingForActivityLoadingTime = false; |
@@ -7,2 +7,3 @@ import type { Duration, ClocksState, TimeStamp, Observable, RelativeTime } from '@datadog/browser-core'; | ||
import type { LocationChange } from '../../../browser/locationChangeObservable'; | ||
import type { RumConfiguration } from '../../configuration'; | ||
import type { Timings } from './trackInitialViewTimings'; | ||
@@ -43,3 +44,3 @@ export interface ViewEvent { | ||
} | ||
export declare function trackViews(location: Location, lifeCycle: LifeCycle, domMutationObservable: Observable<void>, locationChangeObservable: Observable<LocationChange>, areViewsTrackedAutomatically: boolean, initialViewOptions?: ViewOptions): { | ||
export declare function trackViews(location: Location, lifeCycle: LifeCycle, domMutationObservable: Observable<void>, configuration: RumConfiguration, locationChangeObservable: Observable<LocationChange>, areViewsTrackedAutomatically: boolean, initialViewOptions?: ViewOptions): { | ||
addTiming: (name: string, time?: RelativeTime | TimeStamp) => void; | ||
@@ -46,0 +47,0 @@ startView: (options?: ViewOptions | undefined, startClocks?: ClocksState | undefined) => void; |
@@ -6,3 +6,3 @@ import { shallowClone, assign, elapsed, generateUUID, monitor, ONE_MINUTE, throttle, clocksNow, clocksOrigin, timeStampNow, display, looksLikeRelativeTime, } from '@datadog/browser-core'; | ||
export var SESSION_KEEP_ALIVE_INTERVAL = 5 * ONE_MINUTE; | ||
export function trackViews(location, lifeCycle, domMutationObservable, locationChangeObservable, areViewsTrackedAutomatically, initialViewOptions) { | ||
export function trackViews(location, lifeCycle, domMutationObservable, configuration, locationChangeObservable, areViewsTrackedAutomatically, initialViewOptions) { | ||
var _a = trackInitialView(initialViewOptions), stopInitialViewTracking = _a.stop, initialView = _a.initialView; | ||
@@ -16,3 +16,3 @@ var currentView = initialView; | ||
function trackInitialView(options) { | ||
var initialView = newView(lifeCycle, domMutationObservable, location, "initial_load" /* INITIAL_LOAD */, clocksOrigin(), options); | ||
var initialView = newView(lifeCycle, domMutationObservable, configuration, location, "initial_load" /* INITIAL_LOAD */, clocksOrigin(), options); | ||
var stop = trackInitialViewTimings(lifeCycle, function (timings) { | ||
@@ -25,3 +25,3 @@ initialView.updateTimings(timings); | ||
function trackViewChange(startClocks, viewOptions) { | ||
return newView(lifeCycle, domMutationObservable, location, "route_change" /* ROUTE_CHANGE */, startClocks, viewOptions); | ||
return newView(lifeCycle, domMutationObservable, configuration, location, "route_change" /* ROUTE_CHANGE */, startClocks, viewOptions); | ||
} | ||
@@ -84,3 +84,3 @@ function startViewLifeCycle() { | ||
} | ||
function newView(lifeCycle, domMutationObservable, initialLocation, loadingType, startClocks, viewOptions) { | ||
function newView(lifeCycle, domMutationObservable, configuration, initialLocation, loadingType, startClocks, viewOptions) { | ||
if (startClocks === void 0) { startClocks = clocksNow(); } | ||
@@ -107,3 +107,3 @@ // Setup initial values | ||
}), scheduleViewUpdate = _a.throttled, cancelScheduleViewUpdate = _a.cancel; | ||
var _b = trackViewMetrics(lifeCycle, domMutationObservable, scheduleViewUpdate, loadingType, startClocks), setLoadEvent = _b.setLoadEvent, stopViewMetricsTracking = _b.stop, viewMetrics = _b.viewMetrics; | ||
var _b = trackViewMetrics(lifeCycle, domMutationObservable, configuration, scheduleViewUpdate, loadingType, startClocks), setLoadEvent = _b.setLoadEvent, stopViewMetricsTracking = _b.stop, viewMetrics = _b.viewMetrics; | ||
// Initial view update | ||
@@ -110,0 +110,0 @@ triggerViewUpdate(); |
@@ -7,3 +7,3 @@ import { isEmptyObject, mapValues, toServerDuration, isNumber } from '@datadog/browser-core'; | ||
}); | ||
return trackViews(location, lifeCycle, domMutationObservable, locationChangeObservable, !configuration.trackViewsManually, initialViewOptions); | ||
return trackViews(location, lifeCycle, domMutationObservable, configuration, locationChangeObservable, !configuration.trackViewsManually, initialViewOptions); | ||
} | ||
@@ -10,0 +10,0 @@ function processViewUpdate(view, foregroundContexts, recorderApi) { |
@@ -1,2 +0,2 @@ | ||
import { getOrigin, objectEntries, shallowClone, performDraw } from '@datadog/browser-core'; | ||
import { getOrigin, matchList, objectEntries, shallowClone, performDraw } from '@datadog/browser-core'; | ||
/** | ||
@@ -80,10 +80,3 @@ * Clear tracing information to avoid incomplete traces. Ideally, we should do it when the | ||
function isAllowedUrl(configuration, requestUrl) { | ||
var requestOrigin = getOrigin(requestUrl); | ||
for (var _i = 0, _a = configuration.allowedTracingOrigins; _i < _a.length; _i++) { | ||
var allowedOrigin = _a[_i]; | ||
if (requestOrigin === allowedOrigin || (allowedOrigin instanceof RegExp && allowedOrigin.test(requestOrigin))) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
return matchList(configuration.allowedTracingOrigins, getOrigin(requestUrl)); | ||
} | ||
@@ -90,0 +83,0 @@ export function isTracingSupported() { |
import type { TimeStamp } from '@datadog/browser-core'; | ||
import { Observable } from '@datadog/browser-core'; | ||
import type { RumConfiguration } from './configuration'; | ||
import type { LifeCycle } from './lifeCycle'; | ||
@@ -45,3 +46,3 @@ export declare const PAGE_ACTIVITY_VALIDATION_DELAY = 100; | ||
*/ | ||
export declare function waitPageActivityEnd(lifeCycle: LifeCycle, domMutationObservable: Observable<void>, pageActivityEndCallback: (event: PageActivityEndEvent) => void, maxDuration?: number): { | ||
export declare function waitPageActivityEnd(lifeCycle: LifeCycle, domMutationObservable: Observable<void>, configuration: RumConfiguration, pageActivityEndCallback: (event: PageActivityEndEvent) => void, maxDuration?: number): { | ||
stop: () => void; | ||
@@ -52,2 +53,2 @@ }; | ||
}; | ||
export declare function createPageActivityObservable(lifeCycle: LifeCycle, domMutationObservable: Observable<void>): Observable<PageActivityEvent>; | ||
export declare function createPageActivityObservable(lifeCycle: LifeCycle, domMutationObservable: Observable<void>, configuration: RumConfiguration): Observable<PageActivityEvent>; |
@@ -1,2 +0,2 @@ | ||
import { monitor, Observable, timeStampNow } from '@datadog/browser-core'; | ||
import { matchList, monitor, Observable, timeStampNow } from '@datadog/browser-core'; | ||
// Delay to wait for a page activity to validate the tracking process | ||
@@ -36,4 +36,4 @@ export var PAGE_ACTIVITY_VALIDATION_DELAY = 100; | ||
*/ | ||
export function waitPageActivityEnd(lifeCycle, domMutationObservable, pageActivityEndCallback, maxDuration) { | ||
var pageActivityObservable = createPageActivityObservable(lifeCycle, domMutationObservable); | ||
export function waitPageActivityEnd(lifeCycle, domMutationObservable, configuration, pageActivityEndCallback, maxDuration) { | ||
var pageActivityObservable = createPageActivityObservable(lifeCycle, domMutationObservable, configuration); | ||
return doWaitPageActivityEnd(pageActivityObservable, pageActivityEndCallback, maxDuration); | ||
@@ -72,3 +72,3 @@ } | ||
} | ||
export function createPageActivityObservable(lifeCycle, domMutationObservable) { | ||
export function createPageActivityObservable(lifeCycle, domMutationObservable, configuration) { | ||
var observable = new Observable(function () { | ||
@@ -79,9 +79,9 @@ var subscriptions = []; | ||
subscriptions.push(domMutationObservable.subscribe(function () { return notifyPageActivity(pendingRequestsCount); }), lifeCycle.subscribe(0 /* PERFORMANCE_ENTRIES_COLLECTED */, function (entries) { | ||
if (entries.some(function (_a) { | ||
var entryType = _a.entryType; | ||
return entryType === 'resource'; | ||
})) { | ||
if (entries.some(function (entry) { return entry.entryType === 'resource' && !isExcludedUrl(configuration, entry.name); })) { | ||
notifyPageActivity(pendingRequestsCount); | ||
} | ||
}), lifeCycle.subscribe(5 /* REQUEST_STARTED */, function (startEvent) { | ||
if (isExcludedUrl(configuration, startEvent.url)) { | ||
return; | ||
} | ||
if (firstRequestIndex === undefined) { | ||
@@ -92,4 +92,6 @@ firstRequestIndex = startEvent.requestIndex; | ||
}), lifeCycle.subscribe(6 /* REQUEST_COMPLETED */, function (request) { | ||
// If the request started before the tracking start, ignore it | ||
if (firstRequestIndex === undefined || request.requestIndex < firstRequestIndex) { | ||
if (isExcludedUrl(configuration, request.url) || | ||
firstRequestIndex === undefined || | ||
// If the request started before the tracking start, ignore it | ||
request.requestIndex < firstRequestIndex) { | ||
return; | ||
@@ -106,2 +108,5 @@ } | ||
} | ||
function isExcludedUrl(configuration, requestUrl) { | ||
return matchList(configuration.excludedActivityUrls, requestUrl); | ||
} | ||
//# sourceMappingURL=waitPageActivityEnd.js.map |
{ | ||
"name": "@datadog/browser-rum-core", | ||
"version": "4.10.4", | ||
"version": "4.11.0", | ||
"license": "Apache-2.0", | ||
@@ -15,3 +15,3 @@ "main": "cjs/index.js", | ||
"dependencies": { | ||
"@datadog/browser-core": "4.10.4" | ||
"@datadog/browser-core": "4.11.0" | ||
}, | ||
@@ -26,3 +26,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "9a082831d321fad09e9a6f1f4c6c73b9449a9869" | ||
"gitHead": "b91c915869522bf295fc72a8ee909c7e4938f316" | ||
} |
@@ -120,2 +120,25 @@ import { | ||
describe('excludedActivityUrls', () => { | ||
it('defaults to an empty array', () => { | ||
expect(validateAndBuildRumConfiguration(DEFAULT_INIT_CONFIGURATION)!.excludedActivityUrls).toEqual([]) | ||
}) | ||
it('is set to provided value', () => { | ||
expect( | ||
validateAndBuildRumConfiguration({ | ||
...DEFAULT_INIT_CONFIGURATION, | ||
excludedActivityUrls: ['foo'], | ||
service: 'bar', | ||
})!.excludedActivityUrls | ||
).toEqual(['foo']) | ||
}) | ||
it('does not validate the configuration if an incorrect value is provided', () => { | ||
expect( | ||
validateAndBuildRumConfiguration({ ...DEFAULT_INIT_CONFIGURATION, excludedActivityUrls: 'foo' as any }) | ||
).toBeUndefined() | ||
expect(displaySpy).toHaveBeenCalledOnceWith('Excluded Activity Urls should be an array') | ||
}) | ||
}) | ||
describe('trackInteractions', () => { | ||
@@ -122,0 +145,0 @@ it('defaults to false', () => { |
@@ -19,2 +19,3 @@ import type { Configuration, InitConfiguration } from '@datadog/browser-core' | ||
premiumSampleRate?: number | undefined | ||
excludedActivityUrls?: ReadonlyArray<string | RegExp> | undefined | ||
@@ -48,2 +49,3 @@ // tracing options | ||
tracingSampleRate: number | ||
excludedActivityUrls: Array<string | RegExp> | ||
applicationId: string | ||
@@ -89,2 +91,7 @@ defaultPrivacyLevel: DefaultPrivacyLevel | ||
if (initConfiguration.excludedActivityUrls !== undefined && !Array.isArray(initConfiguration.excludedActivityUrls)) { | ||
display.error('Excluded Activity Urls should be an array') | ||
return | ||
} | ||
const baseConfiguration = validateAndBuildConfiguration(initConfiguration) | ||
@@ -105,2 +112,3 @@ if (!baseConfiguration) { | ||
tracingSampleRate: initConfiguration.tracingSampleRate ?? 100, | ||
excludedActivityUrls: initConfiguration.excludedActivityUrls ?? [], | ||
trackInteractions: !!initConfiguration.trackInteractions || trackFrustrations, | ||
@@ -107,0 +115,0 @@ trackFrustrations, |
@@ -62,3 +62,3 @@ import { isIE, RequestType } from '@datadog/browser-core' | ||
fetchStubManager.whenAllComplete(() => { | ||
expect(startSpy).toHaveBeenCalledWith({ requestIndex: jasmine.any(Number) as unknown as number }) | ||
expect(startSpy).toHaveBeenCalledWith({ requestIndex: jasmine.any(Number) as unknown as number, url: FAKE_URL }) | ||
done() | ||
@@ -186,3 +186,6 @@ }) | ||
onComplete() { | ||
expect(startSpy).toHaveBeenCalledWith({ requestIndex: jasmine.any(Number) as unknown as number }) | ||
expect(startSpy).toHaveBeenCalledWith({ | ||
requestIndex: jasmine.any(Number) as unknown as number, | ||
url: jasmine.stringMatching(/\/ok$/) as unknown as string, | ||
}) | ||
done() | ||
@@ -189,0 +192,0 @@ }, |
@@ -31,2 +31,3 @@ import type { | ||
requestIndex: number | ||
url: string | ||
} | ||
@@ -79,2 +80,3 @@ | ||
requestIndex: context.requestIndex, | ||
url: context.url, | ||
}) | ||
@@ -118,2 +120,3 @@ break | ||
requestIndex: context.requestIndex, | ||
url: context.url, | ||
}) | ||
@@ -120,0 +123,0 @@ break |
@@ -56,6 +56,7 @@ import type { Duration, ClocksState, RelativeTime, TimeStamp } from '@datadog/browser-core' | ||
domMutationObservable: Observable<void>, | ||
{ actionNameAttribute, trackFrustrations }: RumConfiguration | ||
configuration: RumConfiguration | ||
) { | ||
const history: ClickActionIdHistory = new ContextHistory(ACTION_CONTEXT_TIME_OUT_DELAY) | ||
const stopObservable = new Observable<void>() | ||
const { trackFrustrations } = configuration | ||
let currentRageClickChain: RageClickChain | undefined | ||
@@ -99,3 +100,3 @@ | ||
const name = getActionNameFromElement(event.target, actionNameAttribute) | ||
const name = getActionNameFromElement(event.target, configuration.actionNameAttribute) | ||
if (!trackFrustrations && !name) { | ||
@@ -122,2 +123,3 @@ // TODO: remove this in a future major version. To keep retrocompatibility, ignore any action | ||
domMutationObservable, | ||
configuration, | ||
(pageActivityEndEvent) => { | ||
@@ -124,0 +126,0 @@ if (!pageActivityEndEvent.hadActivity) { |
@@ -6,2 +6,3 @@ import type { Duration, RelativeTime, Observable, ClocksState } from '@datadog/browser-core' | ||
import { ViewLoadingType } from '../../../rawRumEvent.types' | ||
import type { RumConfiguration } from '../../configuration' | ||
import type { LifeCycle } from '../../lifeCycle' | ||
@@ -22,2 +23,3 @@ import { LifeCycleEventType } from '../../lifeCycle' | ||
domMutationObservable: Observable<void>, | ||
configuration: RumConfiguration, | ||
scheduleViewUpdate: () => void, | ||
@@ -44,2 +46,3 @@ loadingType: ViewLoadingType, | ||
domMutationObservable, | ||
configuration, | ||
loadingType, | ||
@@ -77,2 +80,3 @@ viewStart, | ||
domMutationObservable: Observable<void>, | ||
configuration: RumConfiguration, | ||
loadType: ViewLoadingType, | ||
@@ -92,3 +96,3 @@ viewStart: ClocksState, | ||
const { stop } = waitPageActivityEnd(lifeCycle, domMutationObservable, (event) => { | ||
const { stop } = waitPageActivityEnd(lifeCycle, domMutationObservable, configuration, (event) => { | ||
if (isWaitingForActivityLoadingTime) { | ||
@@ -95,0 +99,0 @@ isWaitingForActivityLoadingTime = false |
@@ -24,2 +24,3 @@ import type { Duration, ClocksState, TimeStamp, Observable, Subscription, RelativeTime } from '@datadog/browser-core' | ||
import type { LocationChange } from '../../../browser/locationChangeObservable' | ||
import type { RumConfiguration } from '../../configuration' | ||
import type { Timings } from './trackInitialViewTimings' | ||
@@ -72,2 +73,3 @@ import { trackInitialViewTimings } from './trackInitialViewTimings' | ||
domMutationObservable: Observable<void>, | ||
configuration: RumConfiguration, | ||
locationChangeObservable: Observable<LocationChange>, | ||
@@ -91,2 +93,3 @@ areViewsTrackedAutomatically: boolean, | ||
domMutationObservable, | ||
configuration, | ||
location, | ||
@@ -105,3 +108,11 @@ ViewLoadingType.INITIAL_LOAD, | ||
function trackViewChange(startClocks?: ClocksState, viewOptions?: ViewOptions) { | ||
return newView(lifeCycle, domMutationObservable, location, ViewLoadingType.ROUTE_CHANGE, startClocks, viewOptions) | ||
return newView( | ||
lifeCycle, | ||
domMutationObservable, | ||
configuration, | ||
location, | ||
ViewLoadingType.ROUTE_CHANGE, | ||
startClocks, | ||
viewOptions | ||
) | ||
} | ||
@@ -175,2 +186,3 @@ | ||
domMutationObservable: Observable<void>, | ||
configuration: RumConfiguration, | ||
initialLocation: Location, | ||
@@ -213,3 +225,3 @@ loadingType: ViewLoadingType, | ||
viewMetrics, | ||
} = trackViewMetrics(lifeCycle, domMutationObservable, scheduleViewUpdate, loadingType, startClocks) | ||
} = trackViewMetrics(lifeCycle, domMutationObservable, configuration, scheduleViewUpdate, loadingType, startClocks) | ||
@@ -216,0 +228,0 @@ // Initial view update |
@@ -35,2 +35,3 @@ import type { Duration, ServerDuration, Observable } from '@datadog/browser-core' | ||
domMutationObservable, | ||
configuration, | ||
locationChangeObservable, | ||
@@ -37,0 +38,0 @@ !configuration.trackViewsManually, |
@@ -1,2 +0,2 @@ | ||
import { getOrigin, objectEntries, shallowClone, performDraw } from '@datadog/browser-core' | ||
import { getOrigin, matchList, objectEntries, shallowClone, performDraw } from '@datadog/browser-core' | ||
import type { RumConfiguration } from '../configuration' | ||
@@ -101,9 +101,3 @@ import type { | ||
function isAllowedUrl(configuration: RumConfiguration, requestUrl: string) { | ||
const requestOrigin = getOrigin(requestUrl) | ||
for (const allowedOrigin of configuration.allowedTracingOrigins) { | ||
if (requestOrigin === allowedOrigin || (allowedOrigin instanceof RegExp && allowedOrigin.test(requestOrigin))) { | ||
return true | ||
} | ||
} | ||
return false | ||
return matchList(configuration.allowedTracingOrigins, getOrigin(requestUrl)) | ||
} | ||
@@ -110,0 +104,0 @@ |
@@ -1,8 +0,10 @@ | ||
import type { RelativeTime } from '@datadog/browser-core' | ||
import type { RelativeTime, Subscription } from '@datadog/browser-core' | ||
import { Observable, ONE_SECOND, getTimeStamp } from '@datadog/browser-core' | ||
import type { Clock } from '@datadog/browser-core/test/specHelper' | ||
import { mockClock } from '@datadog/browser-core/test/specHelper' | ||
import type { TestSetupBuilder } from '../../test/specHelper' | ||
import { setup } from '../../test/specHelper' | ||
import type { RumPerformanceNavigationTiming, RumPerformanceResourceTiming } from '../browser/performanceCollection' | ||
import { LifeCycle, LifeCycleEventType } from './lifeCycle' | ||
import type { RequestCompleteEvent } from './requestCollection' | ||
import { LifeCycleEventType } from './lifeCycle' | ||
import type { RequestCompleteEvent, RequestStartEvent } from './requestCollection' | ||
import type { PageActivityEvent, PageActivityEndEvent } from './waitPageActivityEnd' | ||
@@ -25,2 +27,5 @@ import { | ||
const FAKE_URL = 'https://example.com' | ||
const EXCLUDED_FAKE_URL = 'https://example.com/excluded' | ||
function eventsCollector<T>() { | ||
@@ -42,14 +47,20 @@ const events: T[] = [] | ||
let lifeCycle: LifeCycle | ||
let domMutationObservable: Observable<void> | ||
let pageActivityObservable: Observable<PageActivityEvent> | ||
let setupBuilder: TestSetupBuilder | ||
let pageActivitySubscription: Subscription | ||
beforeEach(() => { | ||
lifeCycle = new LifeCycle() | ||
domMutationObservable = new Observable() | ||
pageActivityObservable = createPageActivityObservable(lifeCycle, domMutationObservable) | ||
setupBuilder = setup() | ||
.withConfiguration({ excludedActivityUrls: [EXCLUDED_FAKE_URL] }) | ||
.beforeBuild(({ lifeCycle, domMutationObservable, configuration }) => { | ||
const pageActivityObservable = createPageActivityObservable(lifeCycle, domMutationObservable, configuration) | ||
pageActivitySubscription = pageActivityObservable.subscribe(pushEvent) | ||
}) | ||
}) | ||
afterEach(() => { | ||
setupBuilder.cleanup() | ||
}) | ||
it('emits an activity event on dom mutation', () => { | ||
pageActivityObservable.subscribe(pushEvent) | ||
const { domMutationObservable } = setupBuilder.build() | ||
domMutationObservable.notify() | ||
@@ -60,3 +71,3 @@ expect(events).toEqual([{ isBusy: false }]) | ||
it('emits an activity event on resource collected', () => { | ||
pageActivityObservable.subscribe(pushEvent) | ||
const { lifeCycle } = setupBuilder.build() | ||
const performanceTiming = { | ||
@@ -69,5 +80,15 @@ entryType: 'resource', | ||
it('does not emit an activity event when a navigation occurs', () => { | ||
pageActivityObservable.subscribe(pushEvent) | ||
it('emits an activity event on resource collected', () => { | ||
const { lifeCycle } = setupBuilder.build() | ||
const performanceTiming = { | ||
entryType: 'resource', | ||
name: EXCLUDED_FAKE_URL, | ||
} as RumPerformanceResourceTiming | ||
lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED, [performanceTiming]) | ||
expect(events).toEqual([]) | ||
}) | ||
it('ignores resources that should be excluded by configuration', () => { | ||
const { lifeCycle } = setupBuilder.build() | ||
const performanceTiming = { | ||
entryType: 'navigation', | ||
@@ -80,7 +101,7 @@ } as RumPerformanceNavigationTiming | ||
it('stops emitting activities after calling stop()', () => { | ||
const subscription = pageActivityObservable.subscribe(pushEvent) | ||
const { domMutationObservable } = setupBuilder.build() | ||
domMutationObservable.notify() | ||
expect(events).toEqual([{ isBusy: false }]) | ||
subscription.unsubscribe() | ||
pageActivitySubscription.unsubscribe() | ||
@@ -93,21 +114,6 @@ domMutationObservable.notify() | ||
describe('requests', () => { | ||
function makeFakeRequestCompleteEvent(requestIndex: number) { | ||
return { requestIndex } as RequestCompleteEvent | ||
} | ||
let lifeCycle: LifeCycle | ||
let domMutationObservable: Observable<void> | ||
let pageActivityObservable: Observable<PageActivityEvent> | ||
beforeEach(() => { | ||
lifeCycle = new LifeCycle() | ||
domMutationObservable = new Observable() | ||
pageActivityObservable = createPageActivityObservable(lifeCycle, domMutationObservable) | ||
}) | ||
describe('programmatic requests', () => { | ||
it('emits an activity event when a request starts', () => { | ||
pageActivityObservable.subscribe(pushEvent) | ||
lifeCycle.notify(LifeCycleEventType.REQUEST_STARTED, { | ||
requestIndex: 10, | ||
}) | ||
const { lifeCycle } = setupBuilder.build() | ||
lifeCycle.notify(LifeCycleEventType.REQUEST_STARTED, makeFakeRequestStartEvent(10)) | ||
expect(events).toEqual([{ isBusy: true }]) | ||
@@ -117,6 +123,4 @@ }) | ||
it('emits an activity event when a request completes', () => { | ||
pageActivityObservable.subscribe(pushEvent) | ||
lifeCycle.notify(LifeCycleEventType.REQUEST_STARTED, { | ||
requestIndex: 10, | ||
}) | ||
const { lifeCycle } = setupBuilder.build() | ||
lifeCycle.notify(LifeCycleEventType.REQUEST_STARTED, makeFakeRequestStartEvent(10)) | ||
lifeCycle.notify(LifeCycleEventType.REQUEST_COMPLETED, makeFakeRequestCompleteEvent(10)) | ||
@@ -127,3 +131,3 @@ expect(events).toEqual([{ isBusy: true }, { isBusy: false }]) | ||
it('ignores requests that has started before', () => { | ||
pageActivityObservable.subscribe(pushEvent) | ||
const { lifeCycle } = setupBuilder.build() | ||
lifeCycle.notify(LifeCycleEventType.REQUEST_COMPLETED, makeFakeRequestCompleteEvent(10)) | ||
@@ -134,9 +138,5 @@ expect(events).toEqual([]) | ||
it('keeps emitting busy events while all requests are not completed', () => { | ||
pageActivityObservable.subscribe(pushEvent) | ||
lifeCycle.notify(LifeCycleEventType.REQUEST_STARTED, { | ||
requestIndex: 10, | ||
}) | ||
lifeCycle.notify(LifeCycleEventType.REQUEST_STARTED, { | ||
requestIndex: 11, | ||
}) | ||
const { lifeCycle } = setupBuilder.build() | ||
lifeCycle.notify(LifeCycleEventType.REQUEST_STARTED, makeFakeRequestStartEvent(10)) | ||
lifeCycle.notify(LifeCycleEventType.REQUEST_STARTED, makeFakeRequestStartEvent(11)) | ||
lifeCycle.notify(LifeCycleEventType.REQUEST_COMPLETED, makeFakeRequestCompleteEvent(9)) | ||
@@ -147,2 +147,26 @@ lifeCycle.notify(LifeCycleEventType.REQUEST_COMPLETED, makeFakeRequestCompleteEvent(11)) | ||
}) | ||
describe('excludedActivityUrls', () => { | ||
it('ignores requests that should be excluded by configuration', () => { | ||
const { lifeCycle } = setupBuilder.build() | ||
lifeCycle.notify(LifeCycleEventType.REQUEST_STARTED, makeFakeRequestStartEvent(10, EXCLUDED_FAKE_URL)) | ||
lifeCycle.notify(LifeCycleEventType.REQUEST_COMPLETED, makeFakeRequestCompleteEvent(10, EXCLUDED_FAKE_URL)) | ||
expect(events).toEqual([]) | ||
}) | ||
it("ignored requests don't interfere with pending requests count", () => { | ||
const { lifeCycle } = setupBuilder.build() | ||
lifeCycle.notify(LifeCycleEventType.REQUEST_STARTED, makeFakeRequestStartEvent(9)) | ||
lifeCycle.notify(LifeCycleEventType.REQUEST_STARTED, makeFakeRequestStartEvent(10, EXCLUDED_FAKE_URL)) | ||
lifeCycle.notify(LifeCycleEventType.REQUEST_COMPLETED, makeFakeRequestCompleteEvent(10, EXCLUDED_FAKE_URL)) | ||
expect(events).toEqual([{ isBusy: true }]) | ||
}) | ||
}) | ||
function makeFakeRequestCompleteEvent(requestIndex: number, url = FAKE_URL) { | ||
return { requestIndex, url } as RequestCompleteEvent | ||
} | ||
function makeFakeRequestStartEvent(requestIndex: number, url = FAKE_URL): RequestStartEvent { | ||
return { requestIndex, url } | ||
} | ||
}) | ||
@@ -149,0 +173,0 @@ }) |
import type { Subscription, TimeoutId, TimeStamp } from '@datadog/browser-core' | ||
import { monitor, Observable, timeStampNow } from '@datadog/browser-core' | ||
import { matchList, monitor, Observable, timeStampNow } from '@datadog/browser-core' | ||
import type { RumConfiguration } from './configuration' | ||
import type { LifeCycle } from './lifeCycle' | ||
@@ -50,6 +51,7 @@ import { LifeCycleEventType } from './lifeCycle' | ||
domMutationObservable: Observable<void>, | ||
configuration: RumConfiguration, | ||
pageActivityEndCallback: (event: PageActivityEndEvent) => void, | ||
maxDuration?: number | ||
) { | ||
const pageActivityObservable = createPageActivityObservable(lifeCycle, domMutationObservable) | ||
const pageActivityObservable = createPageActivityObservable(lifeCycle, domMutationObservable, configuration) | ||
return doWaitPageActivityEnd(pageActivityObservable, pageActivityEndCallback, maxDuration) | ||
@@ -109,3 +111,4 @@ } | ||
lifeCycle: LifeCycle, | ||
domMutationObservable: Observable<void> | ||
domMutationObservable: Observable<void>, | ||
configuration: RumConfiguration | ||
): Observable<PageActivityEvent> { | ||
@@ -120,3 +123,3 @@ const observable = new Observable<PageActivityEvent>(() => { | ||
lifeCycle.subscribe(LifeCycleEventType.PERFORMANCE_ENTRIES_COLLECTED, (entries) => { | ||
if (entries.some(({ entryType }) => entryType === 'resource')) { | ||
if (entries.some((entry) => entry.entryType === 'resource' && !isExcludedUrl(configuration, entry.name))) { | ||
notifyPageActivity(pendingRequestsCount) | ||
@@ -126,2 +129,5 @@ } | ||
lifeCycle.subscribe(LifeCycleEventType.REQUEST_STARTED, (startEvent) => { | ||
if (isExcludedUrl(configuration, startEvent.url)) { | ||
return | ||
} | ||
if (firstRequestIndex === undefined) { | ||
@@ -134,4 +140,8 @@ firstRequestIndex = startEvent.requestIndex | ||
lifeCycle.subscribe(LifeCycleEventType.REQUEST_COMPLETED, (request) => { | ||
// If the request started before the tracking start, ignore it | ||
if (firstRequestIndex === undefined || request.requestIndex < firstRequestIndex) { | ||
if ( | ||
isExcludedUrl(configuration, request.url) || | ||
firstRequestIndex === undefined || | ||
// If the request started before the tracking start, ignore it | ||
request.requestIndex < firstRequestIndex | ||
) { | ||
return | ||
@@ -152,1 +162,5 @@ } | ||
} | ||
function isExcludedUrl(configuration: RumConfiguration, requestUrl: string): boolean { | ||
return matchList(configuration.excludedActivityUrls, requestUrl) | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1090824
22232
+ Added@datadog/browser-core@4.11.0(transitive)
- Removed@datadog/browser-core@4.10.4(transitive)
Updated@datadog/browser-core@4.11.0