Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@datadog/browser-rum-core

Package Overview
Dependencies
Maintainers
1
Versions
181
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@datadog/browser-rum-core - npm Package Compare versions

Comparing version 2.7.4 to 2.8.0

2

cjs/boot/buildEnv.js

@@ -7,4 +7,4 @@ "use strict";

datacenter: 'us',
sdkVersion: '2.7.4',
sdkVersion: '2.8.0',
};
//# sourceMappingURL=buildEnv.js.map

@@ -8,4 +8,7 @@ import { Configuration } from '@datadog/browser-core';

addAction: (action: import("../domain/rumEventsCollection/action/trackActions").CustomAction, savedCommonContext?: CommonContext | undefined) => void;
addError: ({ error, startTime, context: customerContext, source }: import("../domain/rumEventsCollection/error/errorCollection").ProvidedError, savedCommonContext?: CommonContext | undefined) => void;
addTiming: (name: string, time?: import("@datadog/browser-core").RelativeTime) => void;
addError: ({ error, startClocks, context: customerContext, source }: import("../domain/rumEventsCollection/error/errorCollection").ProvidedError, savedCommonContext?: CommonContext | undefined) => void;
addTiming: (name: string, endClocks?: {
relative: import("@datadog/browser-core").RelativeTime;
timeStamp: import("@datadog/browser-core").TimeStamp;
}) => void;
configuration: Configuration;

@@ -19,6 +22,9 @@ lifeCycle: LifeCycle;

addAction: (action: import("../domain/rumEventsCollection/action/trackActions").CustomAction, savedCommonContext?: CommonContext | undefined) => void;
addError: ({ error, startTime, context: customerContext, source }: import("../domain/rumEventsCollection/error/errorCollection").ProvidedError, savedCommonContext?: CommonContext | undefined) => void;
addError: ({ error, startClocks, context: customerContext, source }: import("../domain/rumEventsCollection/error/errorCollection").ProvidedError, savedCommonContext?: CommonContext | undefined) => void;
parentContexts: import("../domain/parentContexts").ParentContexts;
addTiming: (name: string, time?: import("@datadog/browser-core").RelativeTime) => void;
addTiming: (name: string, endClocks?: {
relative: import("@datadog/browser-core").RelativeTime;
timeStamp: import("@datadog/browser-core").TimeStamp;
}) => void;
stop(): void;
};

@@ -13,3 +13,3 @@ "use strict";

var addTimingStrategy = function (name) {
beforeInitAddTiming.add([name, browser_core_1.relativeNow()]);
beforeInitAddTiming.add([name, browser_core_1.clocksNow()]);
};

@@ -55,4 +55,4 @@ var beforeInitAddAction = new browser_core_1.BoundedBuffer();

beforeInitAddTiming.drain(function (_a) {
var name = _a[0], time = _a[1];
return addTimingStrategy(name, time);
var name = _a[0], endClocks = _a[1];
return addTimingStrategy(name, endClocks);
});

@@ -70,3 +70,3 @@ isAlreadyInitialized = true;

context: browser_core_1.deepClone(context),
startTime: browser_core_1.relativeNow(),
startClocks: browser_core_1.clocksNow(),
type: rawRumEvent_types_1.ActionType.CUSTOM,

@@ -95,3 +95,3 @@ });

source: checkedSource,
startTime: browser_core_1.relativeNow(),
startClocks: browser_core_1.clocksNow(),
});

@@ -98,0 +98,0 @@ }),

@@ -21,3 +21,2 @@ "use strict";

if (browserWindow.Zone) {
// eslint-disable-next-line no-underscore-dangle
var symbol = browserWindow.Zone.__symbol__('MutationObserver');

@@ -24,0 +23,0 @@ constructor = browserWindow[symbol];

@@ -25,3 +25,3 @@ "use strict";

var viewContext = parentContexts.findView(startTime);
if (session.isTracked() && viewContext && viewContext.session.id) {
if (session.isTracked() && viewContext && viewContext.session.id === session.getId()) {
var actionContext = parentContexts.findAction(startTime);

@@ -83,5 +83,4 @@ var commonContext = savedCommonContext || getCommonContext();

function getSessionType() {
// eslint-disable-next-line no-underscore-dangle
return window._DATADOG_SYNTHETICS_BROWSER === undefined ? SessionType.USER : SessionType.SYNTHETICS;
}
//# sourceMappingURL=assembly.js.map

@@ -7,3 +7,3 @@ import { Context, RelativeTime } from '@datadog/browser-core';

import { AutoAction, AutoActionCreatedEvent } from './rumEventsCollection/action/trackActions';
import { ViewEvent, ViewCreatedEvent } from './rumEventsCollection/view/trackViews';
import { ViewEvent, ViewCreatedEvent, ViewEndedEvent } from './rumEventsCollection/view/trackViews';
export declare enum LifeCycleEventType {

@@ -39,3 +39,4 @@ PERFORMANCE_ENTRY_COLLECTED = 0,

notify(eventType: LifeCycleEventType.VIEW_UPDATED, data: ViewEvent): void;
notify(eventType: LifeCycleEventType.SESSION_RENEWED | LifeCycleEventType.DOM_MUTATED | LifeCycleEventType.BEFORE_UNLOAD | LifeCycleEventType.AUTO_ACTION_DISCARDED | LifeCycleEventType.VIEW_ENDED | LifeCycleEventType.RECORD_STARTED | LifeCycleEventType.RECORD_STOPPED): void;
notify(eventType: LifeCycleEventType.VIEW_ENDED, data: ViewEndedEvent): void;
notify(eventType: LifeCycleEventType.SESSION_RENEWED | LifeCycleEventType.DOM_MUTATED | LifeCycleEventType.BEFORE_UNLOAD | LifeCycleEventType.AUTO_ACTION_DISCARDED | LifeCycleEventType.RECORD_STARTED | LifeCycleEventType.RECORD_STOPPED): void;
notify(eventType: LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, data: {

@@ -55,3 +56,4 @@ startTime: RelativeTime;

subscribe(eventType: LifeCycleEventType.VIEW_UPDATED, callback: (data: ViewEvent) => void): Subscription;
subscribe(eventType: LifeCycleEventType.SESSION_RENEWED | LifeCycleEventType.DOM_MUTATED | LifeCycleEventType.BEFORE_UNLOAD | LifeCycleEventType.AUTO_ACTION_DISCARDED | LifeCycleEventType.VIEW_ENDED | LifeCycleEventType.RECORD_STARTED | LifeCycleEventType.RECORD_STOPPED, callback: () => void): Subscription;
subscribe(eventType: LifeCycleEventType.VIEW_ENDED, callback: (data: ViewEndedEvent) => void): Subscription;
subscribe(eventType: LifeCycleEventType.SESSION_RENEWED | LifeCycleEventType.DOM_MUTATED | LifeCycleEventType.BEFORE_UNLOAD | LifeCycleEventType.AUTO_ACTION_DISCARDED | LifeCycleEventType.RECORD_STARTED | LifeCycleEventType.RECORD_STOPPED, callback: () => void): Subscription;
subscribe(eventType: LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, callback: (data: {

@@ -58,0 +60,0 @@ startTime: RelativeTime;

@@ -16,9 +16,2 @@ "use strict";

lifeCycle.subscribe(lifeCycle_1.LifeCycleEventType.VIEW_CREATED, function (currentContext) {
if (currentView) {
previousViews.unshift({
context: buildCurrentViewContext(),
endTime: currentContext.startTime,
startTime: currentView.startTime,
});
}
currentView = currentContext;

@@ -30,6 +23,17 @@ currentSessionId = session.getId();

// most recently created.
if (currentView.id === currentContext.id) {
if (currentView && currentView.id === currentContext.id) {
currentView = currentContext;
}
});
lifeCycle.subscribe(lifeCycle_1.LifeCycleEventType.VIEW_ENDED, function (_a) {
var endClocks = _a.endClocks;
if (currentView) {
previousViews.unshift({
endTime: endClocks.relative,
context: buildCurrentViewContext(),
startTime: currentView.startClocks.relative,
});
currentView = undefined;
}
});
lifeCycle.subscribe(lifeCycle_1.LifeCycleEventType.AUTO_ACTION_CREATED, function (currentContext) {

@@ -43,4 +47,4 @@ currentAction = currentContext;

// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
endTime: (currentAction.startTime + action.duration),
startTime: currentAction.startTime,
endTime: (currentAction.startClocks.relative + action.duration),
startTime: currentAction.startClocks.relative,
});

@@ -64,3 +68,3 @@ }

function clearOldContexts(previousContexts, timeOutDelay) {
var oldTimeThreshold = performance.now() - timeOutDelay;
var oldTimeThreshold = browser_core_1.relativeNow() - timeOutDelay;
while (previousContexts.length > 0 && previousContexts[previousContexts.length - 1].startTime < oldTimeThreshold) {

@@ -90,3 +94,3 @@ previousContexts.pop();

}
if (currentContext && startTime >= currentContext.startTime) {
if (currentContext && startTime >= currentContext.startClocks.relative) {
return buildContext();

@@ -93,0 +97,0 @@ }

@@ -1,2 +0,2 @@

import { Configuration, Duration, FetchCompleteContext, FetchStartContext, RelativeTime, RequestType, XhrCompleteContext, XhrStartContext } from '@datadog/browser-core';
import { Configuration, Duration, FetchCompleteContext, FetchStartContext, RequestType, XhrCompleteContext, XhrStartContext, ClocksState } from '@datadog/browser-core';
import { LifeCycle } from './lifeCycle';

@@ -28,3 +28,3 @@ import { TraceIdentifier, Tracer } from './tracing/tracer';

responseType?: string;
startTime: RelativeTime;
startClocks: ClocksState;
duration: Duration;

@@ -31,0 +31,0 @@ spanId?: TraceIdentifier;

@@ -35,3 +35,3 @@ "use strict";

spanId: context.spanId,
startTime: context.startTime,
startClocks: context.startClocks,
status: context.status,

@@ -68,3 +68,3 @@ traceId: context.traceId,

spanId: context.spanId,
startTime: context.startTime,
startClocks: context.startClocks,
status: context.status,

@@ -71,0 +71,0 @@ traceId: context.traceId,

@@ -49,3 +49,3 @@ "use strict";

},
date: browser_core_1.getTimeStamp(action.startTime),
date: browser_core_1.preferredTimeStamp(action.startClocks),
type: rawRumEvent_types_1.RumEventType.ACTION,

@@ -56,3 +56,3 @@ }, autoActionProperties);

rawRumEvent: actionEvent,
startTime: action.startTime,
startTime: action.startClocks.relative,
};

@@ -59,0 +59,0 @@ }

@@ -1,4 +0,4 @@

import { Context, Duration, RelativeTime } from '@datadog/browser-core';
import { Context, Duration, ClocksState } from '@datadog/browser-core';
import { ActionType } from '../../../rawRumEvent.types';
import { LifeCycle } from '../../lifeCycle';
import { ActionType } from '../../../rawRumEvent.types';
declare type AutoActionType = ActionType.CLICK;

@@ -13,3 +13,3 @@ export interface ActionCounts {

name: string;
startTime: RelativeTime;
startClocks: ClocksState;
context?: Context;

@@ -21,3 +21,3 @@ }

name: string;
startTime: RelativeTime;
startClocks: ClocksState;
duration: Duration;

@@ -28,3 +28,3 @@ counts: ActionCounts;

id: string;
startTime: RelativeTime;
startClocks: ClocksState;
}

@@ -31,0 +31,0 @@ export declare function trackActions(lifeCycle: LifeCycle): {

@@ -5,6 +5,6 @@ "use strict";

var browser_core_1 = require("@datadog/browser-core");
var rawRumEvent_types_1 = require("../../../rawRumEvent.types");
var lifeCycle_1 = require("../../lifeCycle");
var trackEventCounts_1 = require("../../trackEventCounts");
var trackPageActivities_1 = require("../../trackPageActivities");
var rawRumEvent_types_1 = require("../../../rawRumEvent.types");
var getActionNameFromElement_1 = require("./getActionNameFromElement");

@@ -46,5 +46,5 @@ function trackActions(lifeCycle) {

currentAction = pendingAutoAction;
currentIdlePageActivitySubscription = trackPageActivities_1.waitIdlePageActivity(lifeCycle, function (hadActivity, endTime) {
if (hadActivity) {
pendingAutoAction.complete(endTime);
currentIdlePageActivitySubscription = trackPageActivities_1.waitIdlePageActivity(lifeCycle, function (params) {
if (params.hadActivity) {
pendingAutoAction.complete(params.endTime);
}

@@ -72,5 +72,5 @@ else {

this.id = browser_core_1.generateUUID();
this.startTime = browser_core_1.relativeNow();
this.startClocks = browser_core_1.clocksNow();
this.eventCountsSubscription = trackEventCounts_1.trackEventCounts(lifeCycle);
this.lifeCycle.notify(lifeCycle_1.LifeCycleEventType.AUTO_ACTION_CREATED, { id: this.id, startTime: this.startTime });
this.lifeCycle.notify(lifeCycle_1.LifeCycleEventType.AUTO_ACTION_CREATED, { id: this.id, startClocks: this.startClocks });
}

@@ -85,6 +85,6 @@ PendingAutoAction.prototype.complete = function (endTime) {

},
duration: browser_core_1.elapsed(this.startTime, endTime),
duration: browser_core_1.elapsed(browser_core_1.preferredClock(this.startClocks), endTime),
id: this.id,
name: this.name,
startTime: this.startTime,
startClocks: this.startClocks,
type: this.type,

@@ -91,0 +91,0 @@ });

@@ -1,6 +0,6 @@

import { Configuration, Context, Observable, RawError, RelativeTime } from '@datadog/browser-core';
import { Configuration, Context, Observable, RawError, ClocksState } from '@datadog/browser-core';
import { CommonContext } from '../../../rawRumEvent.types';
import { LifeCycle } from '../../lifeCycle';
export interface ProvidedError {
startTime: RelativeTime;
startClocks: ClocksState;
error: unknown;

@@ -12,6 +12,6 @@ context?: Context;

export declare function startErrorCollection(lifeCycle: LifeCycle, configuration: Configuration): {
addError: ({ error, startTime, context: customerContext, source }: ProvidedError, savedCommonContext?: CommonContext | undefined) => void;
addError: ({ error, startClocks, context: customerContext, source }: ProvidedError, savedCommonContext?: CommonContext | undefined) => void;
};
export declare function doStartErrorCollection(lifeCycle: LifeCycle, observable: Observable<RawError>): {
addError: ({ error, startTime, context: customerContext, source }: ProvidedError, savedCommonContext?: CommonContext | undefined) => void;
addError: ({ error, startClocks, context: customerContext, source }: ProvidedError, savedCommonContext?: CommonContext | undefined) => void;
};

@@ -16,4 +16,4 @@ "use strict";

addError: function (_a, savedCommonContext) {
var error = _a.error, startTime = _a.startTime, customerContext = _a.context, source = _a.source;
var rawError = computeRawError(error, startTime, source);
var error = _a.error, startClocks = _a.startClocks, customerContext = _a.context, source = _a.source;
var rawError = computeRawError(error, startClocks, source);
lifeCycle.notify(lifeCycle_1.LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, tslib_1.__assign({ customerContext: customerContext,

@@ -25,9 +25,9 @@ savedCommonContext: savedCommonContext }, processError(rawError)));

exports.doStartErrorCollection = doStartErrorCollection;
function computeRawError(error, startTime, source) {
function computeRawError(error, startClocks, source) {
var stackTrace = error instanceof Error ? browser_core_1.computeStackTrace(error) : undefined;
return tslib_1.__assign({ startTime: startTime, source: source }, browser_core_1.formatUnknownError(stackTrace, error, 'Provided'));
return tslib_1.__assign({ startClocks: startClocks, source: source }, browser_core_1.formatUnknownError(stackTrace, error, 'Provided'));
}
function processError(error) {
var rawRumEvent = {
date: browser_core_1.getTimeStamp(error.startTime),
date: browser_core_1.preferredTimeStamp(error.startClocks),
error: {

@@ -50,5 +50,5 @@ message: error.message,

rawRumEvent: rawRumEvent,
startTime: error.startTime,
startTime: error.startClocks.relative,
};
}
//# sourceMappingURL=errorCollection.js.map

@@ -12,4 +12,5 @@ "use strict";

}
var startClocks = browser_core_1.relativeToClocks(entry.startTime);
var rawRumEvent = {
date: browser_core_1.getTimeStamp(entry.startTime),
date: browser_core_1.preferredTimeStamp(startClocks),
long_task: {

@@ -22,3 +23,3 @@ duration: browser_core_1.toServerDuration(entry.duration),

rawRumEvent: rawRumEvent,
startTime: entry.startTime,
startTime: startClocks.relative,
});

@@ -25,0 +26,0 @@ });

@@ -8,6 +8,7 @@ import { RumPerformanceResourceTiming } from '../../../browser/performanceCollection';

* - Timing (start, end) are nested inside the request (start, end)
* - Some timing can be not exactly nested, being off by < 1 ms
* - Browsers generate a timing entry for OPTIONS request
*
* Strategy:
* - from valid nested entries
* - from valid nested entries (with 1 ms error margin)
* - if a single timing match, return the timing

@@ -14,0 +15,0 @@ * - if two following timings match (OPTIONS request), return the timing for the actual request

@@ -10,6 +10,7 @@ "use strict";

* - Timing (start, end) are nested inside the request (start, end)
* - Some timing can be not exactly nested, being off by < 1 ms
* - Browsers generate a timing entry for OPTIONS request
*
* Strategy:
* - from valid nested entries
* - from valid nested entries (with 1 ms error margin)
* - if a single timing match, return the timing

@@ -30,3 +31,5 @@ * - if two following timings match (OPTIONS request), return the timing for the actual request

.filter(resourceUtils_1.toValidEntry)
.filter(function (entry) { return isBetween(entry, request.startTime, endTime(request)); });
.filter(function (entry) {
return isBetween(entry, request.startClocks.relative, endTime({ startTime: request.startClocks.relative, duration: request.duration }));
});
if (candidates.length === 1) {

@@ -49,4 +52,6 @@ return candidates[0];

function isBetween(timing, start, end) {
return timing.startTime >= start && endTime(timing) <= end;
var errorMargin = 1;
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
return timing.startTime >= start - errorMargin && endTime(timing) <= end + errorMargin;
}
//# sourceMappingURL=matchRequestTiming.js.map

@@ -26,7 +26,7 @@ "use strict";

var matchingTiming = matchRequestTiming_1.matchRequestTiming(request);
var startTime = matchingTiming ? matchingTiming.startTime : request.startTime;
var startClocks = matchingTiming ? browser_core_1.relativeToClocks(matchingTiming.startTime) : request.startClocks;
var correspondingTimingOverrides = matchingTiming ? computePerformanceEntryMetrics(matchingTiming) : undefined;
var tracingInfo = computeRequestTracingInfo(request);
var resourceEvent = browser_core_1.combine({
date: browser_core_1.getTimeStamp(startTime),
date: browser_core_1.preferredTimeStamp(startClocks),
resource: {

@@ -41,3 +41,3 @@ type: type,

}, tracingInfo, correspondingTimingOverrides);
return { startTime: startTime, rawRumEvent: resourceEvent };
return { startTime: startClocks.relative, rawRumEvent: resourceEvent };
}

@@ -48,4 +48,5 @@ function processResourceEntry(entry) {

var tracingInfo = computeEntryTracingInfo(entry);
var startClocks = browser_core_1.relativeToClocks(entry.startTime);
var resourceEvent = browser_core_1.combine({
date: browser_core_1.getTimeStamp(entry.startTime),
date: browser_core_1.preferredTimeStamp(startClocks),
resource: {

@@ -57,3 +58,3 @@ type: type,

}, tracingInfo, entryMetrics);
return { startTime: entry.startTime, rawRumEvent: resourceEvent };
return { startTime: startClocks.relative, rawRumEvent: resourceEvent };
}

@@ -60,0 +61,0 @@ function computePerformanceEntryMetrics(timing) {

import { Duration } from '@datadog/browser-core';
import { EventCounts } from '../../trackEventCounts';
import { ViewLoadingType } from '../../../rawRumEvent.types';
import { LifeCycle } from '../../lifeCycle';
import { EventCounts } from '../../trackEventCounts';
export interface ViewMetrics {

@@ -6,0 +6,0 @@ eventCounts: EventCounts;

@@ -5,7 +5,7 @@ "use strict";

var browser_core_1 = require("@datadog/browser-core");
var performanceCollection_1 = require("../../../browser/performanceCollection");
var rawRumEvent_types_1 = require("../../../rawRumEvent.types");
var lifeCycle_1 = require("../../lifeCycle");
var trackEventCounts_1 = require("../../trackEventCounts");
var rawRumEvent_types_1 = require("../../../rawRumEvent.types");
var trackPageActivities_1 = require("../../trackPageActivities");
var performanceCollection_1 = require("../../../browser/performanceCollection");
var lifeCycle_1 = require("../../lifeCycle");
function trackViewMetrics(lifeCycle, scheduleViewUpdate, loadingType) {

@@ -80,6 +80,6 @@ var viewMetrics = {

function trackActivityLoadingTime(lifeCycle, callback) {
var startTime = browser_core_1.relativeNow();
var stopWaitIdlePageActivity = trackPageActivities_1.waitIdlePageActivity(lifeCycle, function (hadActivity, endTime) {
if (hadActivity) {
callback(browser_core_1.elapsed(startTime, endTime));
var startTime = browser_core_1.preferredNow();
var stopWaitIdlePageActivity = trackPageActivities_1.waitIdlePageActivity(lifeCycle, function (params) {
if (params.hadActivity) {
callback(browser_core_1.elapsed(startTime, params.endTime));
}

@@ -86,0 +86,0 @@ else {

@@ -1,5 +0,5 @@

import { Duration, RelativeTime } from '@datadog/browser-core';
import { Duration, ClocksState } from '@datadog/browser-core';
import { ViewLoadingType, ViewCustomTimings } from '../../../rawRumEvent.types';
import { LifeCycle } from '../../lifeCycle';
import { EventCounts } from '../../trackEventCounts';
import { ViewLoadingType, ViewCustomTimings } from '../../../rawRumEvent.types';
import { Timings } from './trackInitialViewTimings';

@@ -15,3 +15,3 @@ export interface ViewEvent {

documentVersion: number;
startTime: RelativeTime;
startClocks: ClocksState;
duration: Duration;

@@ -29,9 +29,15 @@ isActive: boolean;

referrer: string;
startTime: RelativeTime;
startClocks: ClocksState;
}
export interface ViewEndedEvent {
endClocks: ClocksState;
}
export declare const THROTTLE_VIEW_UPDATE_PERIOD = 3000;
export declare const SESSION_KEEP_ALIVE_INTERVAL: number;
export declare function trackViews(location: Location, lifeCycle: LifeCycle): {
addTiming: (name: string, time?: RelativeTime) => void;
addTiming: (name: string, endClocks?: {
relative: import("@datadog/browser-core").RelativeTime;
timeStamp: import("@datadog/browser-core").TimeStamp;
}) => void;
stop: () => void;
};

@@ -6,7 +6,7 @@ "use strict";

var browser_core_1 = require("@datadog/browser-core");
var rawRumEvent_types_1 = require("../../../rawRumEvent.types");
var lifeCycle_1 = require("../../lifeCycle");
var rawRumEvent_types_1 = require("../../../rawRumEvent.types");
var trackInitialViewTimings_1 = require("./trackInitialViewTimings");
var trackLocationChanges_1 = require("./trackLocationChanges");
var trackViewMetrics_1 = require("./trackViewMetrics");
var trackLocationChanges_1 = require("./trackLocationChanges");
exports.THROTTLE_VIEW_UPDATE_PERIOD = 3000;

@@ -52,4 +52,3 @@ exports.SESSION_KEEP_ALIVE_INTERVAL = 5 * browser_core_1.ONE_MINUTE;

function trackInitialView() {
var startOrigin = 0;
var initialView = newView(lifeCycle, location, isRecording, rawRumEvent_types_1.ViewLoadingType.INITIAL_LOAD, document.referrer, startOrigin);
var initialView = newView(lifeCycle, location, isRecording, rawRumEvent_types_1.ViewLoadingType.INITIAL_LOAD, document.referrer, browser_core_1.clocksOrigin());
var stop = trackInitialViewTimings_1.trackInitialViewTimings(lifeCycle, function (timings) {

@@ -65,5 +64,5 @@ initialView.updateTimings(timings);

return {
addTiming: function (name, time) {
if (time === void 0) { time = browser_core_1.relativeNow(); }
currentView.addTiming(name, time);
addTiming: function (name, endClocks) {
if (endClocks === void 0) { endClocks = browser_core_1.clocksNow(); }
currentView.addTiming(name, endClocks);
currentView.triggerUpdate();

@@ -80,4 +79,4 @@ },

exports.trackViews = trackViews;
function newView(lifeCycle, initialLocation, initialHasReplay, loadingType, referrer, startTime, name) {
if (startTime === void 0) { startTime = browser_core_1.relativeNow(); }
function newView(lifeCycle, initialLocation, initialHasReplay, loadingType, referrer, startClocks, name) {
if (startClocks === void 0) { startClocks = browser_core_1.clocksNow(); }
// Setup initial values

@@ -88,6 +87,6 @@ var id = browser_core_1.generateUUID();

var documentVersion = 0;
var endTime;
var endClocks;
var location = tslib_1.__assign({}, initialLocation);
var hasReplay = initialHasReplay;
lifeCycle.notify(lifeCycle_1.LifeCycleEventType.VIEW_CREATED, { id: id, startTime: startTime, location: location, referrer: referrer });
lifeCycle.notify(lifeCycle_1.LifeCycleEventType.VIEW_CREATED, { id: id, startClocks: startClocks, location: location, referrer: referrer });
// Update the view every time the measures are changing

@@ -110,4 +109,4 @@ var _a = browser_core_1.throttle(browser_core_1.monitor(triggerViewUpdate), exports.THROTTLE_VIEW_UPDATE_PERIOD, {

referrer: referrer,
startTime: startTime,
timings: timings, duration: browser_core_1.elapsed(startTime, endTime === undefined ? browser_core_1.relativeNow() : endTime), isActive: endTime === undefined }));
startClocks: startClocks,
timings: timings, duration: browser_core_1.elapsed(browser_core_1.preferredClock(startClocks), browser_core_1.preferredClock(endClocks === undefined ? browser_core_1.clocksNow() : endClocks)), isActive: endClocks === undefined }));
}

@@ -117,5 +116,5 @@ return {

end: function () {
endTime = browser_core_1.relativeNow();
endClocks = browser_core_1.clocksNow();
stopViewMetricsTracking();
lifeCycle.notify(lifeCycle_1.LifeCycleEventType.VIEW_ENDED);
lifeCycle.notify(lifeCycle_1.LifeCycleEventType.VIEW_ENDED, { endClocks: endClocks });
},

@@ -136,4 +135,4 @@ getLocation: function () {

},
addTiming: function (name, endTime) {
customTimings[sanitizeTiming(name)] = browser_core_1.elapsed(startTime, endTime);
addTiming: function (name, endClocks) {
customTimings[sanitizeTiming(name)] = browser_core_1.elapsed(browser_core_1.preferredClock(startClocks), browser_core_1.preferredClock(endClocks));
},

@@ -140,0 +139,0 @@ updateLocation: function (newLocation) {

import { LifeCycle } from '../../lifeCycle';
export declare function startViewCollection(lifeCycle: LifeCycle, location: Location): {
addTiming: (name: string, time?: import("@datadog/browser-core").RelativeTime) => void;
addTiming: (name: string, endClocks?: {
relative: import("@datadog/browser-core").RelativeTime;
timeStamp: import("@datadog/browser-core").TimeStamp;
}) => void;
stop: () => void;
};

@@ -20,3 +20,3 @@ "use strict";

},
date: browser_core_1.getTimeStamp(view.startTime),
date: browser_core_1.preferredTimeStamp(view.startClocks),
type: rawRumEvent_types_1.RumEventType.VIEW,

@@ -60,5 +60,5 @@ view: {

rawRumEvent: viewEvent,
startTime: view.startTime,
startTime: view.startClocks.relative,
};
}
//# sourceMappingURL=viewCollection.js.map

@@ -1,2 +0,2 @@

import { Observable, RelativeTime } from '@datadog/browser-core';
import { Observable, PreferredTime } from '@datadog/browser-core';
import { LifeCycle } from './lifeCycle';

@@ -9,3 +9,9 @@ export declare const PAGE_ACTIVITY_VALIDATION_DELAY = 100;

}
export declare function waitIdlePageActivity(lifeCycle: LifeCycle, completionCallback: (hadActivity: boolean, endTime: RelativeTime) => void): {
declare type CompletionCallbackParameters = {
hadActivity: true;
endTime: PreferredTime;
} | {
hadActivity: false;
};
export declare function waitIdlePageActivity(lifeCycle: LifeCycle, completionCallback: (params: CompletionCallbackParameters) => void): {
stop: () => void;

@@ -17,4 +23,5 @@ };

};
export declare function waitPageActivitiesCompletion(pageActivitiesObservable: Observable<PageActivityEvent>, stopPageActivitiesTracking: () => void, completionCallback: (hadActivity: boolean, endTime: RelativeTime) => void): {
export declare function waitPageActivitiesCompletion(pageActivitiesObservable: Observable<PageActivityEvent>, stopPageActivitiesTracking: () => void, completionCallback: (params: CompletionCallbackParameters) => void): {
stop: () => void;
};
export {};

@@ -87,4 +87,4 @@ "use strict";

var hasCompleted = false;
var validationTimeoutId = setTimeout(browser_core_1.monitor(function () { return complete(false, 0); }), exports.PAGE_ACTIVITY_VALIDATION_DELAY);
var maxDurationTimeoutId = setTimeout(browser_core_1.monitor(function () { return complete(true, browser_core_1.relativeNow()); }), exports.PAGE_ACTIVITY_MAX_DURATION);
var validationTimeoutId = setTimeout(browser_core_1.monitor(function () { return complete({ hadActivity: false }); }), exports.PAGE_ACTIVITY_VALIDATION_DELAY);
var maxDurationTimeoutId = setTimeout(browser_core_1.monitor(function () { return complete({ hadActivity: true, endTime: browser_core_1.preferredNow() }); }), exports.PAGE_ACTIVITY_MAX_DURATION);
pageActivitiesObservable.subscribe(function (_a) {

@@ -94,5 +94,5 @@ var isBusy = _a.isBusy;

clearTimeout(idleTimeoutId);
var lastChangeTime = browser_core_1.relativeNow();
var lastChangeTime = browser_core_1.preferredNow();
if (!isBusy) {
idleTimeoutId = setTimeout(browser_core_1.monitor(function () { return complete(true, lastChangeTime); }), exports.PAGE_ACTIVITY_END_DELAY);
idleTimeoutId = setTimeout(browser_core_1.monitor(function () { return complete({ hadActivity: true, endTime: lastChangeTime }); }), exports.PAGE_ACTIVITY_END_DELAY);
}

@@ -107,3 +107,3 @@ });

};
function complete(hadActivity, endTime) {
function complete(params) {
if (hasCompleted) {

@@ -113,3 +113,3 @@ return;

stop();
completionCallback(hadActivity, endTime);
completionCallback(params);
}

@@ -116,0 +116,0 @@ return { stop: stop };

export var buildEnv = {
buildMode: 'release',
datacenter: 'us',
sdkVersion: '2.7.4',
sdkVersion: '2.8.0',
};
//# sourceMappingURL=buildEnv.js.map

@@ -8,4 +8,7 @@ import { Configuration } from '@datadog/browser-core';

addAction: (action: import("../domain/rumEventsCollection/action/trackActions").CustomAction, savedCommonContext?: CommonContext | undefined) => void;
addError: ({ error, startTime, context: customerContext, source }: import("../domain/rumEventsCollection/error/errorCollection").ProvidedError, savedCommonContext?: CommonContext | undefined) => void;
addTiming: (name: string, time?: import("@datadog/browser-core").RelativeTime) => void;
addError: ({ error, startClocks, context: customerContext, source }: import("../domain/rumEventsCollection/error/errorCollection").ProvidedError, savedCommonContext?: CommonContext | undefined) => void;
addTiming: (name: string, endClocks?: {
relative: import("@datadog/browser-core").RelativeTime;
timeStamp: import("@datadog/browser-core").TimeStamp;
}) => void;
configuration: Configuration;

@@ -19,6 +22,9 @@ lifeCycle: LifeCycle;

addAction: (action: import("../domain/rumEventsCollection/action/trackActions").CustomAction, savedCommonContext?: CommonContext | undefined) => void;
addError: ({ error, startTime, context: customerContext, source }: import("../domain/rumEventsCollection/error/errorCollection").ProvidedError, savedCommonContext?: CommonContext | undefined) => void;
addError: ({ error, startClocks, context: customerContext, source }: import("../domain/rumEventsCollection/error/errorCollection").ProvidedError, savedCommonContext?: CommonContext | undefined) => void;
parentContexts: import("../domain/parentContexts").ParentContexts;
addTiming: (name: string, time?: import("@datadog/browser-core").RelativeTime) => void;
addTiming: (name: string, endClocks?: {
relative: import("@datadog/browser-core").RelativeTime;
timeStamp: import("@datadog/browser-core").TimeStamp;
}) => void;
stop(): void;
};

@@ -1,2 +0,2 @@

import { BoundedBuffer, buildCookieOptions, checkCookiesAuthorized, checkIsNotLocalFile, createContextManager, deepClone, ErrorSource, isPercentage, makePublicApi, monitor, relativeNow, } from '@datadog/browser-core';
import { BoundedBuffer, buildCookieOptions, checkCookiesAuthorized, checkIsNotLocalFile, createContextManager, deepClone, ErrorSource, isPercentage, makePublicApi, monitor, clocksNow, } from '@datadog/browser-core';
import { ActionType } from '../rawRumEvent.types';

@@ -10,3 +10,3 @@ export function makeRumPublicApi(startRumImpl) {

var addTimingStrategy = function (name) {
beforeInitAddTiming.add([name, relativeNow()]);
beforeInitAddTiming.add([name, clocksNow()]);
};

@@ -52,4 +52,4 @@ var beforeInitAddAction = new BoundedBuffer();

beforeInitAddTiming.drain(function (_a) {
var name = _a[0], time = _a[1];
return addTimingStrategy(name, time);
var name = _a[0], endClocks = _a[1];
return addTimingStrategy(name, endClocks);
});

@@ -67,3 +67,3 @@ isAlreadyInitialized = true;

context: deepClone(context),
startTime: relativeNow(),
startClocks: clocksNow(),
type: ActionType.CUSTOM,

@@ -92,3 +92,3 @@ });

source: checkedSource,
startTime: relativeNow(),
startClocks: clocksNow(),
});

@@ -95,0 +95,0 @@ }),

@@ -18,3 +18,2 @@ import { monitor } from '@datadog/browser-core';

if (browserWindow.Zone) {
// eslint-disable-next-line no-underscore-dangle
var symbol = browserWindow.Zone.__symbol__('MutationObserver');

@@ -21,0 +20,0 @@ constructor = browserWindow[symbol];

@@ -22,3 +22,3 @@ import { combine, isEmptyObject, limitModification, timeStampNow } from '@datadog/browser-core';

var viewContext = parentContexts.findView(startTime);
if (session.isTracked() && viewContext && viewContext.session.id) {
if (session.isTracked() && viewContext && viewContext.session.id === session.getId()) {
var actionContext = parentContexts.findAction(startTime);

@@ -79,5 +79,4 @@ var commonContext = savedCommonContext || getCommonContext();

function getSessionType() {
// eslint-disable-next-line no-underscore-dangle
return window._DATADOG_SYNTHETICS_BROWSER === undefined ? SessionType.USER : SessionType.SYNTHETICS;
}
//# sourceMappingURL=assembly.js.map

@@ -7,3 +7,3 @@ import { Context, RelativeTime } from '@datadog/browser-core';

import { AutoAction, AutoActionCreatedEvent } from './rumEventsCollection/action/trackActions';
import { ViewEvent, ViewCreatedEvent } from './rumEventsCollection/view/trackViews';
import { ViewEvent, ViewCreatedEvent, ViewEndedEvent } from './rumEventsCollection/view/trackViews';
export declare enum LifeCycleEventType {

@@ -39,3 +39,4 @@ PERFORMANCE_ENTRY_COLLECTED = 0,

notify(eventType: LifeCycleEventType.VIEW_UPDATED, data: ViewEvent): void;
notify(eventType: LifeCycleEventType.SESSION_RENEWED | LifeCycleEventType.DOM_MUTATED | LifeCycleEventType.BEFORE_UNLOAD | LifeCycleEventType.AUTO_ACTION_DISCARDED | LifeCycleEventType.VIEW_ENDED | LifeCycleEventType.RECORD_STARTED | LifeCycleEventType.RECORD_STOPPED): void;
notify(eventType: LifeCycleEventType.VIEW_ENDED, data: ViewEndedEvent): void;
notify(eventType: LifeCycleEventType.SESSION_RENEWED | LifeCycleEventType.DOM_MUTATED | LifeCycleEventType.BEFORE_UNLOAD | LifeCycleEventType.AUTO_ACTION_DISCARDED | LifeCycleEventType.RECORD_STARTED | LifeCycleEventType.RECORD_STOPPED): void;
notify(eventType: LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, data: {

@@ -55,3 +56,4 @@ startTime: RelativeTime;

subscribe(eventType: LifeCycleEventType.VIEW_UPDATED, callback: (data: ViewEvent) => void): Subscription;
subscribe(eventType: LifeCycleEventType.SESSION_RENEWED | LifeCycleEventType.DOM_MUTATED | LifeCycleEventType.BEFORE_UNLOAD | LifeCycleEventType.AUTO_ACTION_DISCARDED | LifeCycleEventType.VIEW_ENDED | LifeCycleEventType.RECORD_STARTED | LifeCycleEventType.RECORD_STOPPED, callback: () => void): Subscription;
subscribe(eventType: LifeCycleEventType.VIEW_ENDED, callback: (data: ViewEndedEvent) => void): Subscription;
subscribe(eventType: LifeCycleEventType.SESSION_RENEWED | LifeCycleEventType.DOM_MUTATED | LifeCycleEventType.BEFORE_UNLOAD | LifeCycleEventType.AUTO_ACTION_DISCARDED | LifeCycleEventType.RECORD_STARTED | LifeCycleEventType.RECORD_STOPPED, callback: () => void): Subscription;
subscribe(eventType: LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, callback: (data: {

@@ -58,0 +60,0 @@ startTime: RelativeTime;

@@ -1,2 +0,2 @@

import { monitor, ONE_MINUTE, SESSION_TIME_OUT_DELAY } from '@datadog/browser-core';
import { monitor, ONE_MINUTE, SESSION_TIME_OUT_DELAY, relativeNow, } from '@datadog/browser-core';
import { LifeCycleEventType } from './lifeCycle';

@@ -13,9 +13,2 @@ export var VIEW_CONTEXT_TIME_OUT_DELAY = SESSION_TIME_OUT_DELAY;

lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED, function (currentContext) {
if (currentView) {
previousViews.unshift({
context: buildCurrentViewContext(),
endTime: currentContext.startTime,
startTime: currentView.startTime,
});
}
currentView = currentContext;

@@ -27,6 +20,17 @@ currentSessionId = session.getId();

// most recently created.
if (currentView.id === currentContext.id) {
if (currentView && currentView.id === currentContext.id) {
currentView = currentContext;
}
});
lifeCycle.subscribe(LifeCycleEventType.VIEW_ENDED, function (_a) {
var endClocks = _a.endClocks;
if (currentView) {
previousViews.unshift({
endTime: endClocks.relative,
context: buildCurrentViewContext(),
startTime: currentView.startClocks.relative,
});
currentView = undefined;
}
});
lifeCycle.subscribe(LifeCycleEventType.AUTO_ACTION_CREATED, function (currentContext) {

@@ -40,4 +44,4 @@ currentAction = currentContext;

// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
endTime: (currentAction.startTime + action.duration),
startTime: currentAction.startTime,
endTime: (currentAction.startClocks.relative + action.duration),
startTime: currentAction.startClocks.relative,
});

@@ -61,3 +65,3 @@ }

function clearOldContexts(previousContexts, timeOutDelay) {
var oldTimeThreshold = performance.now() - timeOutDelay;
var oldTimeThreshold = relativeNow() - timeOutDelay;
while (previousContexts.length > 0 && previousContexts[previousContexts.length - 1].startTime < oldTimeThreshold) {

@@ -87,3 +91,3 @@ previousContexts.pop();

}
if (currentContext && startTime >= currentContext.startTime) {
if (currentContext && startTime >= currentContext.startClocks.relative) {
return buildContext();

@@ -90,0 +94,0 @@ }

@@ -1,2 +0,2 @@

import { Configuration, Duration, FetchCompleteContext, FetchStartContext, RelativeTime, RequestType, XhrCompleteContext, XhrStartContext } from '@datadog/browser-core';
import { Configuration, Duration, FetchCompleteContext, FetchStartContext, RequestType, XhrCompleteContext, XhrStartContext, ClocksState } from '@datadog/browser-core';
import { LifeCycle } from './lifeCycle';

@@ -28,3 +28,3 @@ import { TraceIdentifier, Tracer } from './tracing/tracer';

responseType?: string;
startTime: RelativeTime;
startClocks: ClocksState;
duration: Duration;

@@ -31,0 +31,0 @@ spanId?: TraceIdentifier;

@@ -31,3 +31,3 @@ import { RequestType, startFetchProxy, startXhrProxy, } from '@datadog/browser-core';

spanId: context.spanId,
startTime: context.startTime,
startClocks: context.startClocks,
status: context.status,

@@ -63,3 +63,3 @@ traceId: context.traceId,

spanId: context.spanId,
startTime: context.startTime,
startClocks: context.startClocks,
status: context.status,

@@ -66,0 +66,0 @@ traceId: context.traceId,

import { __assign } from "tslib";
import { combine, getTimeStamp, toServerDuration } from '@datadog/browser-core';
import { combine, toServerDuration, preferredTimeStamp } from '@datadog/browser-core';
import { ActionType, RumEventType } from '../../../rawRumEvent.types';

@@ -45,3 +45,3 @@ import { LifeCycleEventType } from '../../lifeCycle';

},
date: getTimeStamp(action.startTime),
date: preferredTimeStamp(action.startClocks),
type: RumEventType.ACTION,

@@ -52,3 +52,3 @@ }, autoActionProperties);

rawRumEvent: actionEvent,
startTime: action.startTime,
startTime: action.startClocks.relative,
};

@@ -55,0 +55,0 @@ }

@@ -1,4 +0,4 @@

import { Context, Duration, RelativeTime } from '@datadog/browser-core';
import { Context, Duration, ClocksState } from '@datadog/browser-core';
import { ActionType } from '../../../rawRumEvent.types';
import { LifeCycle } from '../../lifeCycle';
import { ActionType } from '../../../rawRumEvent.types';
declare type AutoActionType = ActionType.CLICK;

@@ -13,3 +13,3 @@ export interface ActionCounts {

name: string;
startTime: RelativeTime;
startClocks: ClocksState;
context?: Context;

@@ -21,3 +21,3 @@ }

name: string;
startTime: RelativeTime;
startClocks: ClocksState;
duration: Duration;

@@ -28,3 +28,3 @@ counts: ActionCounts;

id: string;
startTime: RelativeTime;
startClocks: ClocksState;
}

@@ -31,0 +31,0 @@ export declare function trackActions(lifeCycle: LifeCycle): {

@@ -1,6 +0,6 @@

import { addEventListener, elapsed, generateUUID, relativeNow, } from '@datadog/browser-core';
import { addEventListener, elapsed, generateUUID, clocksNow, preferredClock, } from '@datadog/browser-core';
import { ActionType } from '../../../rawRumEvent.types';
import { LifeCycleEventType } from '../../lifeCycle';
import { trackEventCounts } from '../../trackEventCounts';
import { waitIdlePageActivity } from '../../trackPageActivities';
import { ActionType } from '../../../rawRumEvent.types';
import { getActionNameFromElement } from './getActionNameFromElement';

@@ -41,5 +41,5 @@ export function trackActions(lifeCycle) {

currentAction = pendingAutoAction;
currentIdlePageActivitySubscription = waitIdlePageActivity(lifeCycle, function (hadActivity, endTime) {
if (hadActivity) {
pendingAutoAction.complete(endTime);
currentIdlePageActivitySubscription = waitIdlePageActivity(lifeCycle, function (params) {
if (params.hadActivity) {
pendingAutoAction.complete(params.endTime);
}

@@ -67,5 +67,5 @@ else {

this.id = generateUUID();
this.startTime = relativeNow();
this.startClocks = clocksNow();
this.eventCountsSubscription = trackEventCounts(lifeCycle);
this.lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, { id: this.id, startTime: this.startTime });
this.lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, { id: this.id, startClocks: this.startClocks });
}

@@ -80,6 +80,6 @@ PendingAutoAction.prototype.complete = function (endTime) {

},
duration: elapsed(this.startTime, endTime),
duration: elapsed(preferredClock(this.startClocks), endTime),
id: this.id,
name: this.name,
startTime: this.startTime,
startClocks: this.startClocks,
type: this.type,

@@ -86,0 +86,0 @@ });

@@ -1,6 +0,6 @@

import { Configuration, Context, Observable, RawError, RelativeTime } from '@datadog/browser-core';
import { Configuration, Context, Observable, RawError, ClocksState } from '@datadog/browser-core';
import { CommonContext } from '../../../rawRumEvent.types';
import { LifeCycle } from '../../lifeCycle';
export interface ProvidedError {
startTime: RelativeTime;
startClocks: ClocksState;
error: unknown;

@@ -12,6 +12,6 @@ context?: Context;

export declare function startErrorCollection(lifeCycle: LifeCycle, configuration: Configuration): {
addError: ({ error, startTime, context: customerContext, source }: ProvidedError, savedCommonContext?: CommonContext | undefined) => void;
addError: ({ error, startClocks, context: customerContext, source }: ProvidedError, savedCommonContext?: CommonContext | undefined) => void;
};
export declare function doStartErrorCollection(lifeCycle: LifeCycle, observable: Observable<RawError>): {
addError: ({ error, startTime, context: customerContext, source }: ProvidedError, savedCommonContext?: CommonContext | undefined) => void;
addError: ({ error, startClocks, context: customerContext, source }: ProvidedError, savedCommonContext?: CommonContext | undefined) => void;
};
import { __assign } from "tslib";
import { computeStackTrace, formatUnknownError, getTimeStamp, startAutomaticErrorCollection, } from '@datadog/browser-core';
import { computeStackTrace, formatUnknownError, startAutomaticErrorCollection, preferredTimeStamp, } from '@datadog/browser-core';
import { RumEventType } from '../../../rawRumEvent.types';

@@ -12,4 +12,4 @@ import { LifeCycleEventType } from '../../lifeCycle';

addError: function (_a, savedCommonContext) {
var error = _a.error, startTime = _a.startTime, customerContext = _a.context, source = _a.source;
var rawError = computeRawError(error, startTime, source);
var error = _a.error, startClocks = _a.startClocks, customerContext = _a.context, source = _a.source;
var rawError = computeRawError(error, startClocks, source);
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, __assign({ customerContext: customerContext,

@@ -20,9 +20,9 @@ savedCommonContext: savedCommonContext }, processError(rawError)));

}
function computeRawError(error, startTime, source) {
function computeRawError(error, startClocks, source) {
var stackTrace = error instanceof Error ? computeStackTrace(error) : undefined;
return __assign({ startTime: startTime, source: source }, formatUnknownError(stackTrace, error, 'Provided'));
return __assign({ startClocks: startClocks, source: source }, formatUnknownError(stackTrace, error, 'Provided'));
}
function processError(error) {
var rawRumEvent = {
date: getTimeStamp(error.startTime),
date: preferredTimeStamp(error.startClocks),
error: {

@@ -45,5 +45,5 @@ message: error.message,

rawRumEvent: rawRumEvent,
startTime: error.startTime,
startTime: error.startClocks.relative,
};
}
//# sourceMappingURL=errorCollection.js.map

@@ -1,2 +0,2 @@

import { getTimeStamp, toServerDuration } from '@datadog/browser-core';
import { toServerDuration, relativeToClocks, preferredTimeStamp } from '@datadog/browser-core';
import { RumEventType } from '../../../rawRumEvent.types';

@@ -9,4 +9,5 @@ import { LifeCycleEventType } from '../../lifeCycle';

}
var startClocks = relativeToClocks(entry.startTime);
var rawRumEvent = {
date: getTimeStamp(entry.startTime),
date: preferredTimeStamp(startClocks),
long_task: {

@@ -19,3 +20,3 @@ duration: toServerDuration(entry.duration),

rawRumEvent: rawRumEvent,
startTime: entry.startTime,
startTime: startClocks.relative,
});

@@ -22,0 +23,0 @@ });

@@ -8,6 +8,7 @@ import { RumPerformanceResourceTiming } from '../../../browser/performanceCollection';

* - Timing (start, end) are nested inside the request (start, end)
* - Some timing can be not exactly nested, being off by < 1 ms
* - Browsers generate a timing entry for OPTIONS request
*
* Strategy:
* - from valid nested entries
* - from valid nested entries (with 1 ms error margin)
* - if a single timing match, return the timing

@@ -14,0 +15,0 @@ * - if two following timings match (OPTIONS request), return the timing for the actual request

@@ -7,6 +7,7 @@ import { toValidEntry } from './resourceUtils';

* - Timing (start, end) are nested inside the request (start, end)
* - Some timing can be not exactly nested, being off by < 1 ms
* - Browsers generate a timing entry for OPTIONS request
*
* Strategy:
* - from valid nested entries
* - from valid nested entries (with 1 ms error margin)
* - if a single timing match, return the timing

@@ -27,3 +28,5 @@ * - if two following timings match (OPTIONS request), return the timing for the actual request

.filter(toValidEntry)
.filter(function (entry) { return isBetween(entry, request.startTime, endTime(request)); });
.filter(function (entry) {
return isBetween(entry, request.startClocks.relative, endTime({ startTime: request.startClocks.relative, duration: request.duration }));
});
if (candidates.length === 1) {

@@ -45,4 +48,6 @@ return candidates[0];

function isBetween(timing, start, end) {
return timing.startTime >= start && endTime(timing) <= end;
var errorMargin = 1;
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
return timing.startTime >= start - errorMargin && endTime(timing) <= end + errorMargin;
}
//# sourceMappingURL=matchRequestTiming.js.map
import { __assign } from "tslib";
import { combine, generateUUID, getTimeStamp, RequestType, ResourceType, toServerDuration } from '@datadog/browser-core';
import { combine, generateUUID, RequestType, ResourceType, toServerDuration, relativeToClocks, preferredTimeStamp, } from '@datadog/browser-core';
import { RumEventType } from '../../../rawRumEvent.types';

@@ -22,7 +22,7 @@ import { LifeCycleEventType } from '../../lifeCycle';

var matchingTiming = matchRequestTiming(request);
var startTime = matchingTiming ? matchingTiming.startTime : request.startTime;
var startClocks = matchingTiming ? relativeToClocks(matchingTiming.startTime) : request.startClocks;
var correspondingTimingOverrides = matchingTiming ? computePerformanceEntryMetrics(matchingTiming) : undefined;
var tracingInfo = computeRequestTracingInfo(request);
var resourceEvent = combine({
date: getTimeStamp(startTime),
date: preferredTimeStamp(startClocks),
resource: {

@@ -37,3 +37,3 @@ type: type,

}, tracingInfo, correspondingTimingOverrides);
return { startTime: startTime, rawRumEvent: resourceEvent };
return { startTime: startClocks.relative, rawRumEvent: resourceEvent };
}

@@ -44,4 +44,5 @@ function processResourceEntry(entry) {

var tracingInfo = computeEntryTracingInfo(entry);
var startClocks = relativeToClocks(entry.startTime);
var resourceEvent = combine({
date: getTimeStamp(entry.startTime),
date: preferredTimeStamp(startClocks),
resource: {

@@ -53,3 +54,3 @@ type: type,

}, tracingInfo, entryMetrics);
return { startTime: entry.startTime, rawRumEvent: resourceEvent };
return { startTime: startClocks.relative, rawRumEvent: resourceEvent };
}

@@ -56,0 +57,0 @@ function computePerformanceEntryMetrics(timing) {

import { Duration } from '@datadog/browser-core';
import { EventCounts } from '../../trackEventCounts';
import { ViewLoadingType } from '../../../rawRumEvent.types';
import { LifeCycle } from '../../lifeCycle';
import { EventCounts } from '../../trackEventCounts';
export interface ViewMetrics {

@@ -6,0 +6,0 @@ eventCounts: EventCounts;

@@ -1,7 +0,7 @@

import { noop, relativeNow, elapsed, round } from '@datadog/browser-core';
import { noop, elapsed, round, preferredNow } from '@datadog/browser-core';
import { supportPerformanceTimingEvent } from '../../../browser/performanceCollection';
import { ViewLoadingType } from '../../../rawRumEvent.types';
import { LifeCycleEventType } from '../../lifeCycle';
import { trackEventCounts } from '../../trackEventCounts';
import { ViewLoadingType } from '../../../rawRumEvent.types';
import { waitIdlePageActivity } from '../../trackPageActivities';
import { supportPerformanceTimingEvent } from '../../../browser/performanceCollection';
import { LifeCycleEventType } from '../../lifeCycle';
export function trackViewMetrics(lifeCycle, scheduleViewUpdate, loadingType) {

@@ -75,6 +75,6 @@ var viewMetrics = {

function trackActivityLoadingTime(lifeCycle, callback) {
var startTime = relativeNow();
var stopWaitIdlePageActivity = waitIdlePageActivity(lifeCycle, function (hadActivity, endTime) {
if (hadActivity) {
callback(elapsed(startTime, endTime));
var startTime = preferredNow();
var stopWaitIdlePageActivity = waitIdlePageActivity(lifeCycle, function (params) {
if (params.hadActivity) {
callback(elapsed(startTime, params.endTime));
}

@@ -81,0 +81,0 @@ else {

@@ -1,5 +0,5 @@

import { Duration, RelativeTime } from '@datadog/browser-core';
import { Duration, ClocksState } from '@datadog/browser-core';
import { ViewLoadingType, ViewCustomTimings } from '../../../rawRumEvent.types';
import { LifeCycle } from '../../lifeCycle';
import { EventCounts } from '../../trackEventCounts';
import { ViewLoadingType, ViewCustomTimings } from '../../../rawRumEvent.types';
import { Timings } from './trackInitialViewTimings';

@@ -15,3 +15,3 @@ export interface ViewEvent {

documentVersion: number;
startTime: RelativeTime;
startClocks: ClocksState;
duration: Duration;

@@ -29,9 +29,15 @@ isActive: boolean;

referrer: string;
startTime: RelativeTime;
startClocks: ClocksState;
}
export interface ViewEndedEvent {
endClocks: ClocksState;
}
export declare const THROTTLE_VIEW_UPDATE_PERIOD = 3000;
export declare const SESSION_KEEP_ALIVE_INTERVAL: number;
export declare function trackViews(location: Location, lifeCycle: LifeCycle): {
addTiming: (name: string, time?: RelativeTime) => void;
addTiming: (name: string, endClocks?: {
relative: import("@datadog/browser-core").RelativeTime;
timeStamp: import("@datadog/browser-core").TimeStamp;
}) => void;
stop: () => void;
};
import { __assign } from "tslib";
import { elapsed, generateUUID, monitor, ONE_MINUTE, relativeNow, throttle, } from '@datadog/browser-core';
import { elapsed, generateUUID, monitor, ONE_MINUTE, throttle, clocksNow, preferredClock, clocksOrigin, } from '@datadog/browser-core';
import { ViewLoadingType } from '../../../rawRumEvent.types';
import { LifeCycleEventType } from '../../lifeCycle';
import { ViewLoadingType } from '../../../rawRumEvent.types';
import { trackInitialViewTimings } from './trackInitialViewTimings';
import { trackLocationChanges, areDifferentLocation } from './trackLocationChanges';
import { trackViewMetrics } from './trackViewMetrics';
import { trackLocationChanges, areDifferentLocation } from './trackLocationChanges';
export var THROTTLE_VIEW_UPDATE_PERIOD = 3000;

@@ -48,4 +48,3 @@ export var SESSION_KEEP_ALIVE_INTERVAL = 5 * ONE_MINUTE;

function trackInitialView() {
var startOrigin = 0;
var initialView = newView(lifeCycle, location, isRecording, ViewLoadingType.INITIAL_LOAD, document.referrer, startOrigin);
var initialView = newView(lifeCycle, location, isRecording, ViewLoadingType.INITIAL_LOAD, document.referrer, clocksOrigin());
var stop = trackInitialViewTimings(lifeCycle, function (timings) {

@@ -61,5 +60,5 @@ initialView.updateTimings(timings);

return {
addTiming: function (name, time) {
if (time === void 0) { time = relativeNow(); }
currentView.addTiming(name, time);
addTiming: function (name, endClocks) {
if (endClocks === void 0) { endClocks = clocksNow(); }
currentView.addTiming(name, endClocks);
currentView.triggerUpdate();

@@ -75,4 +74,4 @@ },

}
function newView(lifeCycle, initialLocation, initialHasReplay, loadingType, referrer, startTime, name) {
if (startTime === void 0) { startTime = relativeNow(); }
function newView(lifeCycle, initialLocation, initialHasReplay, loadingType, referrer, startClocks, name) {
if (startClocks === void 0) { startClocks = clocksNow(); }
// Setup initial values

@@ -83,6 +82,6 @@ var id = generateUUID();

var documentVersion = 0;
var endTime;
var endClocks;
var location = __assign({}, initialLocation);
var hasReplay = initialHasReplay;
lifeCycle.notify(LifeCycleEventType.VIEW_CREATED, { id: id, startTime: startTime, location: location, referrer: referrer });
lifeCycle.notify(LifeCycleEventType.VIEW_CREATED, { id: id, startClocks: startClocks, location: location, referrer: referrer });
// Update the view every time the measures are changing

@@ -105,4 +104,4 @@ var _a = throttle(monitor(triggerViewUpdate), THROTTLE_VIEW_UPDATE_PERIOD, {

referrer: referrer,
startTime: startTime,
timings: timings, duration: elapsed(startTime, endTime === undefined ? relativeNow() : endTime), isActive: endTime === undefined }));
startClocks: startClocks,
timings: timings, duration: elapsed(preferredClock(startClocks), preferredClock(endClocks === undefined ? clocksNow() : endClocks)), isActive: endClocks === undefined }));
}

@@ -112,5 +111,5 @@ return {

end: function () {
endTime = relativeNow();
endClocks = clocksNow();
stopViewMetricsTracking();
lifeCycle.notify(LifeCycleEventType.VIEW_ENDED);
lifeCycle.notify(LifeCycleEventType.VIEW_ENDED, { endClocks: endClocks });
},

@@ -131,4 +130,4 @@ getLocation: function () {

},
addTiming: function (name, endTime) {
customTimings[sanitizeTiming(name)] = elapsed(startTime, endTime);
addTiming: function (name, endClocks) {
customTimings[sanitizeTiming(name)] = elapsed(preferredClock(startClocks), preferredClock(endClocks));
},

@@ -135,0 +134,0 @@ updateLocation: function (newLocation) {

import { LifeCycle } from '../../lifeCycle';
export declare function startViewCollection(lifeCycle: LifeCycle, location: Location): {
addTiming: (name: string, time?: import("@datadog/browser-core").RelativeTime) => void;
addTiming: (name: string, endClocks?: {
relative: import("@datadog/browser-core").RelativeTime;
timeStamp: import("@datadog/browser-core").TimeStamp;
}) => void;
stop: () => void;
};

@@ -1,2 +0,2 @@

import { getTimeStamp, isEmptyObject, mapValues, toServerDuration, } from '@datadog/browser-core';
import { isEmptyObject, mapValues, toServerDuration, preferredTimeStamp, } from '@datadog/browser-core';
import { RumEventType } from '../../../rawRumEvent.types';

@@ -16,3 +16,3 @@ import { LifeCycleEventType } from '../../lifeCycle';

},
date: getTimeStamp(view.startTime),
date: preferredTimeStamp(view.startClocks),
type: RumEventType.VIEW,

@@ -56,5 +56,5 @@ view: {

rawRumEvent: viewEvent,
startTime: view.startTime,
startTime: view.startClocks.relative,
};
}
//# sourceMappingURL=viewCollection.js.map

@@ -1,2 +0,2 @@

import { Observable, RelativeTime } from '@datadog/browser-core';
import { Observable, PreferredTime } from '@datadog/browser-core';
import { LifeCycle } from './lifeCycle';

@@ -9,3 +9,9 @@ export declare const PAGE_ACTIVITY_VALIDATION_DELAY = 100;

}
export declare function waitIdlePageActivity(lifeCycle: LifeCycle, completionCallback: (hadActivity: boolean, endTime: RelativeTime) => void): {
declare type CompletionCallbackParameters = {
hadActivity: true;
endTime: PreferredTime;
} | {
hadActivity: false;
};
export declare function waitIdlePageActivity(lifeCycle: LifeCycle, completionCallback: (params: CompletionCallbackParameters) => void): {
stop: () => void;

@@ -17,4 +23,5 @@ };

};
export declare function waitPageActivitiesCompletion(pageActivitiesObservable: Observable<PageActivityEvent>, stopPageActivitiesTracking: () => void, completionCallback: (hadActivity: boolean, endTime: RelativeTime) => void): {
export declare function waitPageActivitiesCompletion(pageActivitiesObservable: Observable<PageActivityEvent>, stopPageActivitiesTracking: () => void, completionCallback: (params: CompletionCallbackParameters) => void): {
stop: () => void;
};
export {};

@@ -1,2 +0,2 @@

import { monitor, Observable, relativeNow } from '@datadog/browser-core';
import { monitor, Observable, preferredNow } from '@datadog/browser-core';
import { LifeCycleEventType } from './lifeCycle';

@@ -82,4 +82,4 @@ // Delay to wait for a page activity to validate the tracking process

var hasCompleted = false;
var validationTimeoutId = setTimeout(monitor(function () { return complete(false, 0); }), PAGE_ACTIVITY_VALIDATION_DELAY);
var maxDurationTimeoutId = setTimeout(monitor(function () { return complete(true, relativeNow()); }), PAGE_ACTIVITY_MAX_DURATION);
var validationTimeoutId = setTimeout(monitor(function () { return complete({ hadActivity: false }); }), PAGE_ACTIVITY_VALIDATION_DELAY);
var maxDurationTimeoutId = setTimeout(monitor(function () { return complete({ hadActivity: true, endTime: preferredNow() }); }), PAGE_ACTIVITY_MAX_DURATION);
pageActivitiesObservable.subscribe(function (_a) {

@@ -89,5 +89,5 @@ var isBusy = _a.isBusy;

clearTimeout(idleTimeoutId);
var lastChangeTime = relativeNow();
var lastChangeTime = preferredNow();
if (!isBusy) {
idleTimeoutId = setTimeout(monitor(function () { return complete(true, lastChangeTime); }), PAGE_ACTIVITY_END_DELAY);
idleTimeoutId = setTimeout(monitor(function () { return complete({ hadActivity: true, endTime: lastChangeTime }); }), PAGE_ACTIVITY_END_DELAY);
}

@@ -102,3 +102,3 @@ });

};
function complete(hadActivity, endTime) {
function complete(params) {
if (hasCompleted) {

@@ -108,3 +108,3 @@ return;

stop();
completionCallback(hadActivity, endTime);
completionCallback(params);
}

@@ -111,0 +111,0 @@ return { stop: stop };

{
"name": "@datadog/browser-rum-core",
"version": "2.7.4",
"version": "2.8.0",
"license": "Apache-2.0",

@@ -15,3 +15,3 @@ "main": "cjs/index.js",

"dependencies": {
"@datadog/browser-core": "2.7.4",
"@datadog/browser-core": "2.8.0",
"tslib": "^1.10.0"

@@ -27,3 +27,3 @@ },

},
"gitHead": "5127d03aefeb9d9094df3629c5977bd7411363f7"
"gitHead": "7ae5b864b5c54d3f8e76bd1a18e75192b0342a97"
}

@@ -1,2 +0,2 @@

import { ErrorSource, ONE_SECOND, RelativeTime } from '@datadog/browser-core'
import { ErrorSource, ONE_SECOND, RelativeTime, TimeStamp } from '@datadog/browser-core'
import { setup, TestSetupBuilder } from '../../test/specHelper'

@@ -18,3 +18,3 @@ import { ActionType } from '../rawRumEvent.types'

describe('rum entry', () => {
describe('rum public api', () => {
describe('configuration validation', () => {

@@ -173,3 +173,3 @@ let rumPublicApi: RumPublicApi

name: 'foo',
startTime: jasmine.any(Number),
startClocks: jasmine.any(Object),
type: ActionType.CUSTOM,

@@ -191,3 +191,3 @@ },

expect(addActionSpy.calls.argsFor(0)[0].startTime as number).toEqual(ONE_SECOND)
expect(addActionSpy.calls.argsFor(0)[0].startClocks.relative as number).toEqual(ONE_SECOND)
})

@@ -264,3 +264,3 @@

source: ErrorSource.CUSTOM,
startTime: jasmine.any(Number),
startClocks: jasmine.any(Object),
},

@@ -295,3 +295,3 @@ { context: {}, user: {} },

expect(addErrorSpy.calls.argsFor(0)[0].startTime as number).toEqual(ONE_SECOND)
expect(addErrorSpy.calls.argsFor(0)[0].startClocks.relative as number).toEqual(ONE_SECOND)
})

@@ -429,3 +429,6 @@

expect(addTimingSpy.calls.argsFor(0)[0]).toEqual('foo')
expect(addTimingSpy.calls.argsFor(0)[1]).toEqual(10 as RelativeTime)
expect(addTimingSpy.calls.argsFor(0)[1]).toEqual({
relative: 10 as RelativeTime,
timeStamp: (jasmine.any(Number) as unknown) as TimeStamp,
})
})

@@ -432,0 +435,0 @@

@@ -13,5 +13,5 @@ import {

monitor,
relativeNow,
RelativeTime,
UserConfiguration,
clocksNow,
ClocksState,
} from '@datadog/browser-core'

@@ -46,5 +46,5 @@ import { CustomAction } from '../domain/rumEventsCollection/action/trackActions'

const beforeInitAddTiming = new BoundedBuffer<[string, RelativeTime]>()
const beforeInitAddTiming = new BoundedBuffer<[string, ClocksState]>()
let addTimingStrategy: StartRumResult['addTiming'] = (name) => {
beforeInitAddTiming.add([name, relativeNow()])
beforeInitAddTiming.add([name, clocksNow()])
}

@@ -93,3 +93,3 @@

beforeInitAddError.drain(([error, commonContext]) => addErrorStrategy(error, commonContext))
beforeInitAddTiming.drain(([name, time]) => addTimingStrategy(name, time))
beforeInitAddTiming.drain(([name, endClocks]) => addTimingStrategy(name, endClocks))

@@ -112,3 +112,3 @@ isAlreadyInitialized = true

context: deepClone(context as Context),
startTime: relativeNow(),
startClocks: clocksNow(),
type: ActionType.CUSTOM,

@@ -137,3 +137,3 @@ })

source: checkedSource,
startTime: relativeNow(),
startClocks: clocksNow(),
})

@@ -140,0 +140,0 @@ }),

@@ -29,3 +29,2 @@ import { monitor } from '@datadog/browser-core'

if (browserWindow.Zone) {
// eslint-disable-next-line no-underscore-dangle
const symbol = browserWindow.Zone.__symbol__('MutationObserver')

@@ -32,0 +31,0 @@ constructor = browserWindow[symbol as any] as any

@@ -330,3 +330,3 @@ import { DEFAULT_CONFIGURATION, noop, RelativeTime } from '@datadog/browser-core'

it('when view context has session id, it should generate event', () => {
it('when view context has current session id, it should generate event', () => {
viewSessionId = '1234'

@@ -341,2 +341,12 @@

it('when view context has not the current session id, it should not generate event', () => {
viewSessionId = '6789'
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
startTime: 0 as RelativeTime,
})
expect(serverRumEvents.length).toBe(0)
})
it('when view context has no session id, it should not generate event', () => {

@@ -343,0 +353,0 @@ viewSessionId = undefined

@@ -48,3 +48,3 @@ import { combine, Configuration, Context, isEmptyObject, limitModification, timeStampNow } from '@datadog/browser-core'

const viewContext = parentContexts.findView(startTime)
if (session.isTracked() && viewContext && viewContext.session.id) {
if (session.isTracked() && viewContext && viewContext.session.id === session.getId()) {
const actionContext = parentContexts.findAction(startTime)

@@ -112,4 +112,3 @@ const commonContext = savedCommonContext || getCommonContext()

function getSessionType() {
// eslint-disable-next-line no-underscore-dangle
return (window as BrowserWindow)._DATADOG_SYNTHETICS_BROWSER === undefined ? SessionType.USER : SessionType.SYNTHETICS
}

@@ -7,3 +7,3 @@ import { Context, RelativeTime } from '@datadog/browser-core'

import { AutoAction, AutoActionCreatedEvent } from './rumEventsCollection/action/trackActions'
import { ViewEvent, ViewCreatedEvent } from './rumEventsCollection/view/trackViews'
import { ViewEvent, ViewCreatedEvent, ViewEndedEvent } from './rumEventsCollection/view/trackViews'

@@ -43,2 +43,3 @@ export enum LifeCycleEventType {

notify(eventType: LifeCycleEventType.VIEW_UPDATED, data: ViewEvent): void
notify(eventType: LifeCycleEventType.VIEW_ENDED, data: ViewEndedEvent): void
notify(

@@ -50,3 +51,2 @@ eventType:

| LifeCycleEventType.AUTO_ACTION_DISCARDED
| LifeCycleEventType.VIEW_ENDED
| LifeCycleEventType.RECORD_STARTED

@@ -88,2 +88,3 @@ | LifeCycleEventType.RECORD_STOPPED

subscribe(eventType: LifeCycleEventType.VIEW_UPDATED, callback: (data: ViewEvent) => void): Subscription
subscribe(eventType: LifeCycleEventType.VIEW_ENDED, callback: (data: ViewEndedEvent) => void): Subscription
subscribe(

@@ -95,3 +96,2 @@ eventType:

| LifeCycleEventType.AUTO_ACTION_DISCARDED
| LifeCycleEventType.VIEW_ENDED
| LifeCycleEventType.RECORD_STARTED

@@ -98,0 +98,0 @@ | LifeCycleEventType.RECORD_STOPPED,

@@ -1,2 +0,2 @@

import { Duration, RelativeTime } from '@datadog/browser-core'
import { Duration, RelativeTime, relativeToClocks } from '@datadog/browser-core'
import { setup, TestSetupBuilder } from '../../test/specHelper'

@@ -21,6 +21,12 @@ import { LifeCycleEventType } from './lifeCycle'

const FAKE_ID = 'fake'
const startTime = 10 as RelativeTime
const startClocks = relativeToClocks(10 as RelativeTime)
function buildViewCreatedEvent(partialViewCreatedEvent: Partial<ViewCreatedEvent> = {}): ViewCreatedEvent {
return { location, startTime, id: FAKE_ID, referrer: 'http://foo.com', ...partialViewCreatedEvent }
return {
location,
startClocks,
id: FAKE_ID,
referrer: 'http://foo.com',
...partialViewCreatedEvent,
}
}

@@ -72,11 +78,15 @@

LifeCycleEventType.VIEW_CREATED,
buildViewCreatedEvent({ startTime: 10 as RelativeTime, id: 'view 1' })
buildViewCreatedEvent({ startClocks: relativeToClocks(10 as RelativeTime), id: 'view 1' })
)
lifeCycle.notify(LifeCycleEventType.VIEW_ENDED, { endClocks: relativeToClocks(20 as RelativeTime) })
lifeCycle.notify(
LifeCycleEventType.VIEW_CREATED,
buildViewCreatedEvent({ startTime: 20 as RelativeTime, id: 'view 2' })
buildViewCreatedEvent({ startClocks: relativeToClocks(20 as RelativeTime), id: 'view 2' })
)
lifeCycle.notify(LifeCycleEventType.VIEW_ENDED, { endClocks: relativeToClocks(30 as RelativeTime) })
lifeCycle.notify(
LifeCycleEventType.VIEW_CREATED,
buildViewCreatedEvent({ startTime: 30 as RelativeTime, id: 'view 3' })
buildViewCreatedEvent({ startClocks: relativeToClocks(30 as RelativeTime), id: 'view 3' })
)

@@ -94,8 +104,10 @@

LifeCycleEventType.VIEW_CREATED,
buildViewCreatedEvent({ startTime: 10 as RelativeTime, id: 'view 1' })
buildViewCreatedEvent({ startClocks: relativeToClocks(10 as RelativeTime), id: 'view 1' })
)
lifeCycle.notify(LifeCycleEventType.VIEW_ENDED, { endClocks: relativeToClocks(20 as RelativeTime) })
lifeCycle.notify(
LifeCycleEventType.VIEW_CREATED,
buildViewCreatedEvent({ startTime: 20 as RelativeTime, id: 'view 2' })
buildViewCreatedEvent({ startClocks: relativeToClocks(20 as RelativeTime), id: 'view 2' })
)
lifeCycle.notify(LifeCycleEventType.VIEW_ENDED, { endClocks: relativeToClocks(20 as RelativeTime) })

@@ -105,3 +117,3 @@ expect(parentContexts.findView(5 as RelativeTime)).not.toBeDefined()

it('should replace the current view context on VIEW_CREATED', () => {
it('should set the current view context on VIEW_CREATED', () => {
const { lifeCycle } = setupBuilder.build()

@@ -158,3 +170,3 @@

lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, { startTime, id: FAKE_ID })
lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, { startClocks, id: FAKE_ID })

@@ -168,9 +180,18 @@ expect(parentContexts.findAction()).toBeDefined()

lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, { startTime: 10 as RelativeTime, id: 'action 1' })
lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, {
startClocks: relativeToClocks(10 as RelativeTime),
id: 'action 1',
})
lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_COMPLETED, stubActionWithDuration(10))
lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, { startTime: 30 as RelativeTime, id: 'action 2' })
lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, {
startClocks: relativeToClocks(30 as RelativeTime),
id: 'action 2',
})
lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_COMPLETED, stubActionWithDuration(10))
lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, { startTime: 50 as RelativeTime, id: 'action 3' })
lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, {
startClocks: relativeToClocks(50 as RelativeTime),
id: 'action 3',
})

@@ -186,6 +207,12 @@ expect(parentContexts.findAction(15 as RelativeTime)!.action.id).toBe('action 1')

lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, { startTime: 10 as RelativeTime, id: 'action 1' })
lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, {
startClocks: relativeToClocks(10 as RelativeTime),
id: 'action 1',
})
lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_DISCARDED)
lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, { startTime: 20 as RelativeTime, id: 'action 2' })
lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, {
startClocks: relativeToClocks(20 as RelativeTime),
id: 'action 2',
})

@@ -198,3 +225,3 @@ expect(parentContexts.findAction(10 as RelativeTime)).toBeUndefined()

lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, { startTime, id: FAKE_ID })
lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, { startClocks, id: FAKE_ID })
lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_DISCARDED)

@@ -208,3 +235,3 @@

lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, { startTime, id: FAKE_ID })
lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, { startClocks, id: FAKE_ID })
lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_COMPLETED, stubActionWithDuration(10))

@@ -224,5 +251,6 @@

id: 'view 1',
startTime: 10 as RelativeTime,
startClocks: relativeToClocks(10 as RelativeTime),
})
)
lifeCycle.notify(LifeCycleEventType.VIEW_ENDED, { endClocks: relativeToClocks(20 as RelativeTime) })
lifeCycle.notify(

@@ -232,8 +260,14 @@ LifeCycleEventType.VIEW_CREATED,

id: 'view 2',
startTime: 20 as RelativeTime,
startClocks: relativeToClocks(20 as RelativeTime),
})
)
lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, { startTime: 10 as RelativeTime, id: 'action 1' })
lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, {
startClocks: relativeToClocks(10 as RelativeTime),
id: 'action 1',
})
lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_COMPLETED, stubActionWithDuration(10))
lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, { startTime: 20 as RelativeTime, id: 'action 2' })
lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, {
startClocks: relativeToClocks(20 as RelativeTime),
id: 'action 2',
})

@@ -257,2 +291,3 @@ expect(parentContexts.findView(15 as RelativeTime)).toBeDefined()

const originalTime = performance.now()
const originalClocks = relativeToClocks(originalTime as RelativeTime)
const targetTime = (originalTime + 5) as RelativeTime

@@ -264,7 +299,10 @@

id: 'view 1',
startTime: originalTime as RelativeTime,
startClocks: originalClocks,
})
)
lifeCycle.notify(LifeCycleEventType.VIEW_ENDED, {
endClocks: relativeToClocks((originalTime + 10) as RelativeTime),
})
lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, {
startTime: originalTime as RelativeTime,
startClocks: originalClocks,
id: 'action 1',

@@ -275,3 +313,3 @@ })

LifeCycleEventType.VIEW_CREATED,
buildViewCreatedEvent({ startTime: (originalTime + 10) as RelativeTime, id: 'view 2' })
buildViewCreatedEvent({ startClocks: relativeToClocks((originalTime + 10) as RelativeTime), id: 'view 2' })
)

@@ -278,0 +316,0 @@

@@ -1,2 +0,9 @@

import { monitor, ONE_MINUTE, RelativeTime, SESSION_TIME_OUT_DELAY } from '@datadog/browser-core'
import {
monitor,
ONE_MINUTE,
RelativeTime,
SESSION_TIME_OUT_DELAY,
relativeNow,
ClocksState,
} from '@datadog/browser-core'
import { ActionContext, ViewContext } from '../rawRumEvent.types'

@@ -33,9 +40,2 @@ import { LifeCycle, LifeCycleEventType } from './lifeCycle'

lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED, (currentContext) => {
if (currentView) {
previousViews.unshift({
context: buildCurrentViewContext(),
endTime: currentContext.startTime,
startTime: currentView.startTime,
})
}
currentView = currentContext

@@ -48,3 +48,3 @@ currentSessionId = session.getId()

// most recently created.
if (currentView!.id === currentContext.id) {
if (currentView && currentView.id === currentContext.id) {
currentView = currentContext

@@ -54,2 +54,13 @@ }

lifeCycle.subscribe(LifeCycleEventType.VIEW_ENDED, ({ endClocks }) => {
if (currentView) {
previousViews.unshift({
endTime: endClocks.relative,
context: buildCurrentViewContext(),
startTime: currentView.startClocks.relative,
})
currentView = undefined
}
})
lifeCycle.subscribe(LifeCycleEventType.AUTO_ACTION_CREATED, (currentContext) => {

@@ -64,4 +75,4 @@ currentAction = currentContext

// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
endTime: (currentAction.startTime + action.duration) as RelativeTime,
startTime: currentAction.startTime,
endTime: (currentAction.startClocks.relative + action.duration) as RelativeTime,
startTime: currentAction.startClocks.relative,
})

@@ -92,3 +103,3 @@ }

function clearOldContexts(previousContexts: Array<PreviousContext<unknown>>, timeOutDelay: number) {
const oldTimeThreshold = performance.now() - timeOutDelay
const oldTimeThreshold = relativeNow() - timeOutDelay
while (previousContexts.length > 0 && previousContexts[previousContexts.length - 1].startTime < oldTimeThreshold) {

@@ -120,3 +131,3 @@ previousContexts.pop()

previousContexts: Array<PreviousContext<T>>,
currentContext?: { startTime: RelativeTime },
currentContext?: { startClocks: ClocksState },
startTime?: RelativeTime

@@ -127,3 +138,3 @@ ) {

}
if (currentContext && startTime >= currentContext.startTime) {
if (currentContext && startTime >= currentContext.startClocks.relative) {
return buildContext()

@@ -130,0 +141,0 @@ }

@@ -6,3 +6,2 @@ import {

FetchStartContext,
RelativeTime,
RequestType,

@@ -13,2 +12,3 @@ startFetchProxy,

XhrStartContext,
ClocksState,
} from '@datadog/browser-core'

@@ -41,3 +41,3 @@ import { LifeCycle, LifeCycleEventType } from './lifeCycle'

responseType?: string
startTime: RelativeTime
startClocks: ClocksState
duration: Duration

@@ -77,3 +77,3 @@ spanId?: TraceIdentifier

spanId: context.spanId,
startTime: context.startTime,
startClocks: context.startClocks,
status: context.status,

@@ -111,3 +111,3 @@ traceId: context.traceId,

spanId: context.spanId,
startTime: context.startTime,
startClocks: context.startClocks,
status: context.status,

@@ -114,0 +114,0 @@ traceId: context.traceId,

@@ -1,2 +0,2 @@

import { Duration, RelativeTime, ServerDuration } from '@datadog/browser-core'
import { Duration, RelativeTime, ServerDuration, TimeStamp } from '@datadog/browser-core'
import { setup, TestSetupBuilder } from '../../../../test/specHelper'

@@ -35,3 +35,3 @@ import { RumEventType, ActionType } from '../../../rawRumEvent.types'

name: 'foo',
startTime: 1234 as RelativeTime,
startClocks: { relative: 1234 as RelativeTime, timeStamp: 123456789 as TimeStamp },
type: ActionType.CLICK,

@@ -68,3 +68,3 @@ })

name: 'foo',
startTime: 1234 as RelativeTime,
startClocks: { relative: 1234 as RelativeTime, timeStamp: 123456789 as TimeStamp },
type: ActionType.CUSTOM,

@@ -71,0 +71,0 @@ })

@@ -1,2 +0,2 @@

import { combine, Configuration, getTimeStamp, toServerDuration } from '@datadog/browser-core'
import { combine, Configuration, toServerDuration, preferredTimeStamp } from '@datadog/browser-core'
import { ActionType, CommonContext, RumEventType } from '../../../rawRumEvent.types'

@@ -52,3 +52,3 @@ import { LifeCycle, LifeCycleEventType } from '../../lifeCycle'

},
date: getTimeStamp(action.startTime),
date: preferredTimeStamp(action.startClocks),
type: RumEventType.ACTION as const,

@@ -61,3 +61,3 @@ },

rawRumEvent: actionEvent,
startTime: action.startTime,
startTime: action.startClocks.relative,
}

@@ -64,0 +64,0 @@ }

@@ -1,2 +0,2 @@

import { Context, DOM_EVENT, RelativeTime } from '@datadog/browser-core'
import { Context, DOM_EVENT, ClocksState } from '@datadog/browser-core'
import { RumEvent } from '../../../../../rum/src'

@@ -85,3 +85,3 @@ import { setup, TestSetupBuilder } from '../../../../test/specHelper'

referrer: 'http://foo.com',
startTime: 0 as RelativeTime,
startClocks: (jasmine.any(Object) as unknown) as ClocksState,
})

@@ -109,3 +109,3 @@ clock.tick(EXPIRE_DELAY)

name: 'Click me',
startTime: jasmine.any(Number),
startClocks: jasmine.any(Object),
type: ActionType.CLICK,

@@ -112,0 +112,0 @@ },

@@ -8,9 +8,11 @@ import {

generateUUID,
relativeNow,
RelativeTime,
ClocksState,
clocksNow,
PreferredTime,
preferredClock,
} from '@datadog/browser-core'
import { ActionType } from '../../../rawRumEvent.types'
import { LifeCycle, LifeCycleEventType } from '../../lifeCycle'
import { EventCounts, trackEventCounts } from '../../trackEventCounts'
import { waitIdlePageActivity } from '../../trackPageActivities'
import { ActionType } from '../../../rawRumEvent.types'
import { getActionNameFromElement } from './getActionNameFromElement'

@@ -29,3 +31,3 @@

name: string
startTime: RelativeTime
startClocks: ClocksState
context?: Context

@@ -38,3 +40,3 @@ }

name: string
startTime: RelativeTime
startClocks: ClocksState
duration: Duration

@@ -46,3 +48,3 @@ counts: ActionCounts

id: string
startTime: RelativeTime
startClocks: ClocksState
}

@@ -96,5 +98,5 @@

currentAction = pendingAutoAction
currentIdlePageActivitySubscription = waitIdlePageActivity(lifeCycle, (hadActivity, endTime) => {
if (hadActivity) {
pendingAutoAction.complete(endTime)
currentIdlePageActivitySubscription = waitIdlePageActivity(lifeCycle, (params) => {
if (params.hadActivity) {
pendingAutoAction.complete(params.endTime)
} else {

@@ -118,3 +120,3 @@ pendingAutoAction.discard()

private id: string
private startTime: RelativeTime
private startClocks: ClocksState
private eventCountsSubscription: { eventCounts: EventCounts; stop(): void }

@@ -124,8 +126,8 @@

this.id = generateUUID()
this.startTime = relativeNow()
this.startClocks = clocksNow()
this.eventCountsSubscription = trackEventCounts(lifeCycle)
this.lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, { id: this.id, startTime: this.startTime })
this.lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_CREATED, { id: this.id, startClocks: this.startClocks })
}
complete(endTime: RelativeTime) {
complete(endTime: PreferredTime) {
const eventCounts = this.eventCountsSubscription.eventCounts

@@ -138,6 +140,6 @@ this.lifeCycle.notify(LifeCycleEventType.AUTO_ACTION_COMPLETED, {

},
duration: elapsed(this.startTime, endTime),
duration: elapsed(preferredClock(this.startClocks), endTime),
id: this.id,
name: this.name,
startTime: this.startTime,
startClocks: this.startClocks,
type: this.type,

@@ -144,0 +146,0 @@ })

@@ -1,2 +0,2 @@

import { ErrorSource, Observable, RawError, RelativeTime } from '@datadog/browser-core'
import { ErrorSource, Observable, RawError, RelativeTime, TimeStamp } from '@datadog/browser-core'
import { setup, TestSetupBuilder } from '../../../../test/specHelper'

@@ -31,3 +31,3 @@ import { RumEventType } from '../../../rawRumEvent.types'

source: ErrorSource.CUSTOM,
startTime: 12 as RelativeTime,
startClocks: { relative: 1234 as RelativeTime, timeStamp: 123456789 as TimeStamp },
})

@@ -50,3 +50,3 @@

savedCommonContext: undefined,
startTime: 12,
startTime: 1234,
})

@@ -61,3 +61,3 @@ })

source: ErrorSource.CUSTOM,
startTime: 12 as RelativeTime,
startClocks: { relative: 1234 as RelativeTime, timeStamp: 123456789 as TimeStamp },
})

@@ -75,3 +75,3 @@ expect(rawRumEvents[0].customerContext).toEqual({

source: ErrorSource.CUSTOM,
startTime: 12 as RelativeTime,
startClocks: { relative: 1234 as RelativeTime, timeStamp: 123456789 as TimeStamp },
},

@@ -91,3 +91,3 @@ { context: { foo: 'bar' }, user: {} }

source: ErrorSource.CUSTOM,
startTime: 12 as RelativeTime,
startClocks: { relative: 1234 as RelativeTime, timeStamp: 123456789 as TimeStamp },
},

@@ -114,3 +114,3 @@ { context: {}, user: { id: 'foo' } }

stack: 'bar',
startTime: 1234 as RelativeTime,
startClocks: { relative: 1234 as RelativeTime, timeStamp: 123456789 as TimeStamp },
type: 'foo',

@@ -117,0 +117,0 @@ })

@@ -6,7 +6,7 @@ import {

formatUnknownError,
getTimeStamp,
Observable,
RawError,
RelativeTime,
startAutomaticErrorCollection,
ClocksState,
preferredTimeStamp,
} from '@datadog/browser-core'

@@ -17,3 +17,3 @@ import { CommonContext, RawRumErrorEvent, RumEventType } from '../../../rawRumEvent.types'

export interface ProvidedError {
startTime: RelativeTime
startClocks: ClocksState
error: unknown

@@ -35,6 +35,6 @@ context?: Context

addError: (
{ error, startTime, context: customerContext, source }: ProvidedError,
{ error, startClocks, context: customerContext, source }: ProvidedError,
savedCommonContext?: CommonContext
) => {
const rawError = computeRawError(error, startTime, source)
const rawError = computeRawError(error, startClocks, source)
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {

@@ -49,5 +49,5 @@ customerContext,

function computeRawError(error: unknown, startTime: RelativeTime, source: ProvidedSource): RawError {
function computeRawError(error: unknown, startClocks: ClocksState, source: ProvidedSource): RawError {
const stackTrace = error instanceof Error ? computeStackTrace(error) : undefined
return { startTime, source, ...formatUnknownError(stackTrace, error, 'Provided') }
return { startClocks, source, ...formatUnknownError(stackTrace, error, 'Provided') }
}

@@ -57,3 +57,3 @@

const rawRumEvent: RawRumErrorEvent = {
date: getTimeStamp(error.startTime),
date: preferredTimeStamp(error.startClocks),
error: {

@@ -77,4 +77,4 @@ message: error.message,

rawRumEvent,
startTime: error.startTime,
startTime: error.startClocks.relative,
}
}

@@ -1,2 +0,2 @@

import { getTimeStamp, toServerDuration } from '@datadog/browser-core'
import { toServerDuration, relativeToClocks, preferredTimeStamp } from '@datadog/browser-core'
import { RawRumLongTaskEvent, RumEventType } from '../../../rawRumEvent.types'

@@ -10,4 +10,5 @@ import { LifeCycle, LifeCycleEventType } from '../../lifeCycle'

}
const startClocks = relativeToClocks(entry.startTime)
const rawRumEvent: RawRumLongTaskEvent = {
date: getTimeStamp(entry.startTime),
date: preferredTimeStamp(startClocks),
long_task: {

@@ -20,5 +21,5 @@ duration: toServerDuration(entry.duration),

rawRumEvent,
startTime: entry.startTime,
startTime: startClocks.relative,
})
})
}

@@ -1,2 +0,2 @@

import { Duration, isIE, RelativeTime } from '@datadog/browser-core'
import { Duration, isIE, RelativeTime, relativeToClocks } from '@datadog/browser-core'
import { createResourceEntry } from '../../../../test/fixtures'

@@ -9,3 +9,6 @@ import { RumPerformanceResourceTiming } from '../../../browser/performanceCollection'

describe('matchRequestTiming', () => {
const FAKE_REQUEST: Partial<RequestCompleteEvent> = { startTime: 100 as RelativeTime, duration: 500 as Duration }
const FAKE_REQUEST: Partial<RequestCompleteEvent> = {
startClocks: relativeToClocks(100 as RelativeTime),
duration: 500 as Duration,
}
let entries: RumPerformanceResourceTiming[]

@@ -30,2 +33,11 @@

it('should match single timing nested in the request with error margin', () => {
const match = createResourceEntry({ startTime: 99 as RelativeTime, duration: 502 as Duration })
entries.push(match)
const timing = matchRequestTiming(FAKE_REQUEST as RequestCompleteEvent)
expect(timing).toEqual(match)
})
it('should not match single timing outside the request ', () => {

@@ -71,3 +83,3 @@ const match = createResourceEntry({ startTime: 0 as RelativeTime, duration: 300 as Duration })

it('should match invalid timing nested in the request ', () => {
it('should not match invalid timing nested in the request ', () => {
const match = createResourceEntry({

@@ -74,0 +86,0 @@ duration: 100 as Duration,

@@ -16,6 +16,7 @@ import { Duration, RelativeTime } from '@datadog/browser-core'

* - Timing (start, end) are nested inside the request (start, end)
* - Some timing can be not exactly nested, being off by < 1 ms
* - Browsers generate a timing entry for OPTIONS request
*
* Strategy:
* - from valid nested entries
* - from valid nested entries (with 1 ms error margin)
* - if a single timing match, return the timing

@@ -38,3 +39,9 @@ * - if two following timings match (OPTIONS request), return the timing for the actual request

.filter(toValidEntry)
.filter((entry) => isBetween(entry, request.startTime, endTime(request)))
.filter((entry) =>
isBetween(
entry,
request.startClocks.relative,
endTime({ startTime: request.startClocks.relative, duration: request.duration })
)
)

@@ -62,3 +69,5 @@ if (candidates.length === 1) {

function isBetween(timing: Timing, start: RelativeTime, end: RelativeTime) {
return timing.startTime >= start && endTime(timing) <= end
const errorMargin = 1
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
return timing.startTime >= start - errorMargin && endTime(timing) <= end + errorMargin
}

@@ -64,3 +64,3 @@ import { Duration, RelativeTime, RequestType, ResourceType, ServerDuration, TimeStamp } from '@datadog/browser-core'

method: 'GET',
startTime: 1234 as RelativeTime,
startClocks: { relative: 1234 as RelativeTime, timeStamp: 123456789 as TimeStamp },
status: 200,

@@ -74,3 +74,3 @@ type: RequestType.XHR,

expect(rawRumEvents[0].rawRumEvent).toEqual({
date: (jasmine.any(Number) as unknown) as TimeStamp,
date: jasmine.any(Number),
resource: {

@@ -199,3 +199,2 @@ duration: (100 * 1e6) as ServerDuration,

)
// eslint-disable-next-line no-underscore-dangle
const traceInfo = (rawRumEvents[0].rawRumEvent as RawRumResourceEvent)._dd!

@@ -215,3 +214,2 @@ expect(traceInfo).toBeDefined()

)
// eslint-disable-next-line no-underscore-dangle
const traceInfo = (rawRumEvents[0].rawRumEvent as RawRumResourceEvent)._dd!

@@ -229,3 +227,3 @@ expect(traceInfo).toBeDefined()

method: 'GET',
startTime: 1234 as RelativeTime,
startClocks: { relative: 1234 as RelativeTime, timeStamp: 123456789 as TimeStamp },
status: 200,

@@ -232,0 +230,0 @@ type: RequestType.XHR,

@@ -1,2 +0,10 @@

import { combine, generateUUID, getTimeStamp, RequestType, ResourceType, toServerDuration } from '@datadog/browser-core'
import {
combine,
generateUUID,
RequestType,
ResourceType,
toServerDuration,
relativeToClocks,
preferredTimeStamp,
} from '@datadog/browser-core'
import { RumPerformanceResourceTiming } from '../../../browser/performanceCollection'

@@ -34,3 +42,3 @@ import { RawRumResourceEvent, RumEventType } from '../../../rawRumEvent.types'

const matchingTiming = matchRequestTiming(request)
const startTime = matchingTiming ? matchingTiming.startTime : request.startTime
const startClocks = matchingTiming ? relativeToClocks(matchingTiming.startTime) : request.startClocks
const correspondingTimingOverrides = matchingTiming ? computePerformanceEntryMetrics(matchingTiming) : undefined

@@ -42,3 +50,3 @@

{
date: getTimeStamp(startTime),
date: preferredTimeStamp(startClocks),
resource: {

@@ -56,3 +64,3 @@ type,

)
return { startTime, rawRumEvent: resourceEvent as RawRumResourceEvent }
return { startTime: startClocks.relative, rawRumEvent: resourceEvent as RawRumResourceEvent }
}

@@ -65,5 +73,6 @@

const startClocks = relativeToClocks(entry.startTime)
const resourceEvent = combine(
{
date: getTimeStamp(entry.startTime),
date: preferredTimeStamp(startClocks),
resource: {

@@ -78,3 +87,3 @@ type,

)
return { startTime: entry.startTime, rawRumEvent: resourceEvent as RawRumResourceEvent }
return { startTime: startClocks.relative, rawRumEvent: resourceEvent as RawRumResourceEvent }
}

@@ -81,0 +90,0 @@

@@ -1,7 +0,7 @@

import { Duration, noop, relativeNow, elapsed, round } from '@datadog/browser-core'
import { Duration, noop, elapsed, round, preferredNow } from '@datadog/browser-core'
import { supportPerformanceTimingEvent } from '../../../browser/performanceCollection'
import { ViewLoadingType } from '../../../rawRumEvent.types'
import { LifeCycle, LifeCycleEventType } from '../../lifeCycle'
import { EventCounts, trackEventCounts } from '../../trackEventCounts'
import { ViewLoadingType } from '../../../rawRumEvent.types'
import { waitIdlePageActivity } from '../../trackPageActivities'
import { supportPerformanceTimingEvent } from '../../../browser/performanceCollection'
import { LifeCycle, LifeCycleEventType } from '../../lifeCycle'

@@ -88,6 +88,6 @@ export interface ViewMetrics {

function trackActivityLoadingTime(lifeCycle: LifeCycle, callback: (loadingTimeValue: Duration | undefined) => void) {
const startTime = relativeNow()
const { stop: stopWaitIdlePageActivity } = waitIdlePageActivity(lifeCycle, (hadActivity, endTime) => {
if (hadActivity) {
callback(elapsed(startTime, endTime))
const startTime = preferredNow()
const { stop: stopWaitIdlePageActivity } = waitIdlePageActivity(lifeCycle, (params) => {
if (params.hadActivity) {
callback(elapsed(startTime, params.endTime))
} else {

@@ -94,0 +94,0 @@ callback(undefined)

@@ -1,2 +0,2 @@

import { Duration, RelativeTime } from '../../../../../core/src'
import { Duration, RelativeTime, ClocksState, clocksNow } from '@datadog/browser-core'
import { setup, TestSetupBuilder } from '../../../../test/specHelper'

@@ -360,3 +360,3 @@ import {

let getViewEvent: (index: number) => ViewEvent
let addTiming: (name: string, time?: RelativeTime) => void
let addTiming: (name: string, endClocks?: ClocksState) => void

@@ -431,5 +431,6 @@ beforeEach(() => {

it('should add custom timing with a specific time', () => {
setupBuilder.build()
const { clock } = setupBuilder.build()
addTiming('foo', 1234 as RelativeTime)
clock.tick(1234)
addTiming('foo', clocksNow())

@@ -442,6 +443,7 @@ expect(getViewEvent(1).customTimings).toEqual({

it('should sanitized timing name', () => {
setupBuilder.build()
const { clock } = setupBuilder.build()
const warnSpy = spyOn(console, 'warn')
addTiming('foo bar-qux.@zip_21%$*€👋', 1234 as RelativeTime)
clock.tick(1234)
addTiming('foo bar-qux.@zip_21%$*€👋', clocksNow())

@@ -448,0 +450,0 @@ expect(getViewEvent(1).customTimings).toEqual({

@@ -7,13 +7,15 @@ import {

ONE_MINUTE,
relativeNow,
RelativeTime,
throttle,
ClocksState,
clocksNow,
preferredClock,
clocksOrigin,
} from '@datadog/browser-core'
import { ViewLoadingType, ViewCustomTimings } from '../../../rawRumEvent.types'
import { LifeCycle, LifeCycleEventType } from '../../lifeCycle'
import { EventCounts } from '../../trackEventCounts'
import { ViewLoadingType, ViewCustomTimings } from '../../../rawRumEvent.types'
import { Timings, trackInitialViewTimings } from './trackInitialViewTimings'
import { trackLocationChanges, areDifferentLocation } from './trackLocationChanges'
import { trackViewMetrics } from './trackViewMetrics'
import { trackLocationChanges, areDifferentLocation } from './trackLocationChanges'

@@ -29,3 +31,3 @@ export interface ViewEvent {

documentVersion: number
startTime: RelativeTime
startClocks: ClocksState
duration: Duration

@@ -44,5 +46,9 @@ isActive: boolean

referrer: string
startTime: RelativeTime
startClocks: ClocksState
}
export interface ViewEndedEvent {
endClocks: ClocksState
}
export const THROTTLE_VIEW_UPDATE_PERIOD = 3000

@@ -99,3 +105,2 @@ export const SESSION_KEEP_ALIVE_INTERVAL = 5 * ONE_MINUTE

function trackInitialView() {
const startOrigin = 0 as RelativeTime
const initialView = newView(

@@ -107,3 +112,3 @@ lifeCycle,

document.referrer,
startOrigin
clocksOrigin()
)

@@ -122,4 +127,4 @@ const { stop } = trackInitialViewTimings(lifeCycle, (timings) => {

return {
addTiming: (name: string, time = relativeNow()) => {
currentView.addTiming(name, time)
addTiming: (name: string, endClocks = clocksNow()) => {
currentView.addTiming(name, endClocks)
currentView.triggerUpdate()

@@ -142,3 +147,3 @@ },

referrer: string,
startTime = relativeNow(),
startClocks: ClocksState = clocksNow(),
name?: string

@@ -151,7 +156,7 @@ ) {

let documentVersion = 0
let endTime: RelativeTime | undefined
let endClocks: ClocksState | undefined
let location: Location = { ...initialLocation }
let hasReplay = initialHasReplay
lifeCycle.notify(LifeCycleEventType.VIEW_CREATED, { id, startTime, location, referrer })
lifeCycle.notify(LifeCycleEventType.VIEW_CREATED, { id, startClocks, location, referrer })

@@ -188,6 +193,6 @@ // Update the view every time the measures are changing

referrer,
startTime,
startClocks,
timings,
duration: elapsed(startTime, endTime === undefined ? relativeNow() : endTime),
isActive: endTime === undefined,
duration: elapsed(preferredClock(startClocks), preferredClock(endClocks === undefined ? clocksNow() : endClocks)),
isActive: endClocks === undefined,
})

@@ -199,5 +204,5 @@ }

end() {
endTime = relativeNow()
endClocks = clocksNow()
stopViewMetricsTracking()
lifeCycle.notify(LifeCycleEventType.VIEW_ENDED)
lifeCycle.notify(LifeCycleEventType.VIEW_ENDED, { endClocks })
},

@@ -218,4 +223,4 @@ getLocation() {

},
addTiming(name: string, endTime: RelativeTime) {
customTimings[sanitizeTiming(name)] = elapsed(startTime, endTime)
addTiming(name: string, endClocks: ClocksState) {
customTimings[sanitizeTiming(name)] = elapsed(preferredClock(startClocks), preferredClock(endClocks))
},

@@ -222,0 +227,0 @@ updateLocation(newLocation: Location) {

@@ -1,2 +0,2 @@

import { Duration, RelativeTime, ServerDuration } from '@datadog/browser-core'
import { Duration, RelativeTime, ServerDuration, TimeStamp } from '@datadog/browser-core'
import { setup, TestSetupBuilder } from '../../../../test/specHelper'

@@ -50,3 +50,3 @@ import { RumEventType, ViewLoadingType } from '../../../rawRumEvent.types'

referrer: '',
startTime: 1234 as RelativeTime,
startClocks: { relative: 1234 as RelativeTime, timeStamp: 123456789 as TimeStamp },
timings: {

@@ -53,0 +53,0 @@ domComplete: 10 as Duration,

import {
Duration,
getTimeStamp,
isEmptyObject,

@@ -8,2 +7,3 @@ mapValues,

toServerDuration,
preferredTimeStamp,
} from '@datadog/browser-core'

@@ -27,3 +27,3 @@ import { RawRumViewEvent, RumEventType } from '../../../rawRumEvent.types'

},
date: getTimeStamp(view.startTime),
date: preferredTimeStamp(view.startClocks),
type: RumEventType.VIEW,

@@ -70,4 +70,4 @@ view: {

rawRumEvent: viewEvent,
startTime: view.startTime,
startTime: view.startClocks.relative,
}
}

@@ -1,2 +0,2 @@

import { noop, Observable, RelativeTime } from '@datadog/browser-core'
import { noop, Observable, PreferredTime } from '@datadog/browser-core'
import { RumPerformanceNavigationTiming, RumPerformanceResourceTiming } from '../browser/performanceCollection'

@@ -88,3 +88,3 @@ import { LifeCycle, LifeCycleEventType } from './lifeCycle'

it('stops emiting activities after calling stop()', () => {
it('stops emitting activities after calling stop()', () => {
const lifeCycle = new LifeCycle()

@@ -135,3 +135,3 @@ const { stop, observable } = trackPageActivities(lifeCycle)

it('keeps emiting busy events while all requests are not completed', () => {
it('keeps emitting busy events while all requests are not completed', () => {
const lifeCycle = new LifeCycle()

@@ -157,5 +157,5 @@ trackPageActivities(lifeCycle).observable.subscribe(pushEvent)

it('should not collect an event that is not followed by page activity', (done) => {
waitPageActivitiesCompletion(new Observable(), noop, (hadActivity, endTime) => {
expect(hadActivity).toBeFalse()
expect(endTime).toBeFalsy()
waitPageActivitiesCompletion(new Observable(), noop, (params) => {
expect(params.hadActivity).toBeFalse()
expect((params as any).endTime).toBeUndefined()
done()

@@ -171,5 +171,7 @@ })

const startTime = performance.now()
waitPageActivitiesCompletion(activityObservable, noop, (hadActivity, endTime) => {
expect(hadActivity).toBeTrue()
expect(endTime).toEqual((startTime + BEFORE_PAGE_ACTIVITY_VALIDATION_DELAY) as RelativeTime)
waitPageActivitiesCompletion(activityObservable, noop, (params) => {
expect(params.hadActivity).toBeTrue()
expect((params as { hadActivity: true; endTime: PreferredTime }).endTime).toEqual(
(startTime + BEFORE_PAGE_ACTIVITY_VALIDATION_DELAY) as PreferredTime
)
done()

@@ -192,5 +194,7 @@ })

waitPageActivitiesCompletion(activityObservable, noop, (hadActivity, endTime) => {
expect(hadActivity).toBeTrue()
expect(endTime).toBe((startTime + (extendCount + 1) * BEFORE_PAGE_ACTIVITY_END_DELAY) as RelativeTime)
waitPageActivitiesCompletion(activityObservable, noop, (params) => {
expect(params.hadActivity).toBeTrue()
expect((params as { hadActivity: true; endTime: PreferredTime }).endTime).toBe(
(startTime + (extendCount + 1) * BEFORE_PAGE_ACTIVITY_END_DELAY) as PreferredTime
)
done()

@@ -215,5 +219,7 @@ })

waitPageActivitiesCompletion(activityObservable, noop, (hadActivity, endTime) => {
expect(hadActivity).toBeTrue()
expect(endTime).toBe((startTime + PAGE_ACTIVITY_MAX_DURATION) as RelativeTime)
waitPageActivitiesCompletion(activityObservable, noop, (params) => {
expect(params.hadActivity).toBeTrue()
expect((params as { hadActivity: true; endTime: PreferredTime }).endTime).toBe(
(startTime + PAGE_ACTIVITY_MAX_DURATION) as PreferredTime
)
stop = true

@@ -236,6 +242,6 @@ done()

const startTime = performance.now()
waitPageActivitiesCompletion(activityObservable, noop, (hadActivity, endTime) => {
expect(hadActivity).toBeTrue()
expect(endTime).toBe(
(startTime + BEFORE_PAGE_ACTIVITY_VALIDATION_DELAY + PAGE_ACTIVITY_END_DELAY * 2) as RelativeTime
waitPageActivitiesCompletion(activityObservable, noop, (params) => {
expect(params.hadActivity).toBeTrue()
expect((params as { hadActivity: true; endTime: PreferredTime }).endTime).toBe(
(startTime + BEFORE_PAGE_ACTIVITY_VALIDATION_DELAY + PAGE_ACTIVITY_END_DELAY * 2) as PreferredTime
)

@@ -257,5 +263,7 @@ done()

const startTime = performance.now()
waitPageActivitiesCompletion(activityObservable, noop, (hadActivity, endTime) => {
expect(hadActivity).toBeTrue()
expect(endTime).toBe((startTime + PAGE_ACTIVITY_MAX_DURATION) as RelativeTime)
waitPageActivitiesCompletion(activityObservable, noop, (params) => {
expect(params.hadActivity).toBeTrue()
expect((params as { hadActivity: true; endTime: PreferredTime }).endTime).toBe(
(startTime + PAGE_ACTIVITY_MAX_DURATION) as PreferredTime
)
done()

@@ -262,0 +270,0 @@ })

@@ -1,2 +0,2 @@

import { monitor, Observable, relativeNow, RelativeTime } from '@datadog/browser-core'
import { monitor, Observable, PreferredTime, preferredNow } from '@datadog/browser-core'
import { LifeCycle, LifeCycleEventType, Subscription } from './lifeCycle'

@@ -15,5 +15,7 @@

type CompletionCallbackParameters = { hadActivity: true; endTime: PreferredTime } | { hadActivity: false }
export function waitIdlePageActivity(
lifeCycle: LifeCycle,
completionCallback: (hadActivity: boolean, endTime: RelativeTime) => void
completionCallback: (params: CompletionCallbackParameters) => void
) {

@@ -117,3 +119,3 @@ const { observable: pageActivitiesObservable, stop: stopPageActivitiesTracking } = trackPageActivities(lifeCycle)

stopPageActivitiesTracking: () => void,
completionCallback: (hadActivity: boolean, endTime: RelativeTime) => void
completionCallback: (params: CompletionCallbackParameters) => void
): { stop: () => void } {

@@ -124,7 +126,7 @@ let idleTimeoutId: number

const validationTimeoutId = setTimeout(
monitor(() => complete(false, 0 as RelativeTime)),
monitor(() => complete({ hadActivity: false })),
PAGE_ACTIVITY_VALIDATION_DELAY
)
const maxDurationTimeoutId = setTimeout(
monitor(() => complete(true, relativeNow())),
monitor(() => complete({ hadActivity: true, endTime: preferredNow() })),
PAGE_ACTIVITY_MAX_DURATION

@@ -136,6 +138,6 @@ )

clearTimeout(idleTimeoutId)
const lastChangeTime = relativeNow()
const lastChangeTime = preferredNow()
if (!isBusy) {
idleTimeoutId = setTimeout(
monitor(() => complete(true, lastChangeTime)),
monitor(() => complete({ hadActivity: true, endTime: lastChangeTime })),
PAGE_ACTIVITY_END_DELAY

@@ -154,3 +156,3 @@ )

function complete(hadActivity: boolean, endTime: RelativeTime) {
function complete(params: CompletionCallbackParameters) {
if (hasCompleted) {

@@ -160,3 +162,3 @@ return

stop()
completionCallback(hadActivity, endTime)
completionCallback(params)
}

@@ -163,0 +165,0 @@

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc