Socket
Socket
Sign inDemoInstall

@datadog/browser-rum-core

Package Overview
Dependencies
Maintainers
1
Versions
179
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 5.9.0 to 5.10.0

cjs/domain/vital/vitalCollection.d.ts

4

cjs/boot/preStartRum.d.ts

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

import { type DeflateWorker } from '@datadog/browser-core';
import type { TrackingConsentState, DeflateWorker } from '@datadog/browser-core';
import { type RumConfiguration, type RumInitConfiguration } from '../domain/configuration';

@@ -7,2 +7,2 @@ import type { CommonContext } from '../domain/contexts/commonContext';

import type { StartRumResult } from './startRum';
export declare function createPreStartStrategy({ ignoreInitIfSyntheticsWillInjectRum, startDeflateWorker }: RumPublicApiOptions, getCommonContext: () => CommonContext, doStartRum: (initConfiguration: RumInitConfiguration, configuration: RumConfiguration, deflateWorker: DeflateWorker | undefined, initialViewOptions?: ViewOptions) => StartRumResult): Strategy;
export declare function createPreStartStrategy({ ignoreInitIfSyntheticsWillInjectRum, startDeflateWorker }: RumPublicApiOptions, getCommonContext: () => CommonContext, trackingConsentState: TrackingConsentState, doStartRum: (initConfiguration: RumInitConfiguration, configuration: RumConfiguration, deflateWorker: DeflateWorker | undefined, initialViewOptions?: ViewOptions) => StartRumResult): Strategy;

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

var configuration_1 = require("../domain/configuration");
function createPreStartStrategy(_a, getCommonContext, doStartRum) {
function createPreStartStrategy(_a, getCommonContext, trackingConsentState, doStartRum) {
var ignoreInitIfSyntheticsWillInjectRum = _a.ignoreInitIfSyntheticsWillInjectRum, startDeflateWorker = _a.startDeflateWorker;

@@ -14,6 +14,8 @@ var bufferApiCalls = new browser_core_1.BoundedBuffer();

var cachedConfiguration;
var trackingConsentStateSubscription = trackingConsentState.observable.subscribe(tryStartRum);
function tryStartRum() {
if (!cachedInitConfiguration || !cachedConfiguration) {
if (!cachedInitConfiguration || !cachedConfiguration || !trackingConsentState.isGranted()) {
return;
}
trackingConsentStateSubscription.unsubscribe();
var initialViewOptions;

@@ -79,2 +81,3 @@ if (cachedConfiguration.trackViewsManually) {

cachedConfiguration = configuration;
trackingConsentState.tryToInit(configuration.trackingConsent);
tryStartRum();

@@ -113,2 +116,8 @@ },

},
startDurationVital: function (vitalStart) {
bufferApiCalls.add(function (startRumResult) { return startRumResult.startDurationVital(vitalStart); });
},
stopDurationVital: function (vitalStart) {
bufferApiCalls.add(function (startRumResult) { return startRumResult.stopDurationVital(vitalStart); });
},
};

@@ -115,0 +124,0 @@ }

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

import type { Context, User, DeflateWorker, DeflateEncoderStreamId, DeflateEncoder } from '@datadog/browser-core';
import type { Context, User, DeflateWorker, DeflateEncoderStreamId, DeflateEncoder, TrackingConsent } from '@datadog/browser-core';
import type { LifeCycle } from '../domain/lifeCycle';

@@ -33,5 +33,20 @@ import type { ViewContexts } from '../domain/contexts/viewContexts';

addFeatureFlagEvaluation: StartRumResult['addFeatureFlagEvaluation'];
startDurationVital: StartRumResult['startDurationVital'];
stopDurationVital: StartRumResult['stopDurationVital'];
}
export declare function makeRumPublicApi(startRumImpl: StartRum, recorderApi: RecorderApi, options?: RumPublicApiOptions): {
init: (initConfiguration: RumInitConfiguration) => void;
/**
* Set the tracking consent of the current user.
*
* @param {"granted" | "not-granted"} trackingConsent The user tracking consent
*
* Data will be sent only if it is set to "granted". This value won't be stored by the library
* across page loads: you will need to call this method or set the appropriate `trackingConsent`
* field in the init() method at each page load.
*
* If this method is called before the init() method, the provided value will take precedence
* over the one provided as initialization parameter.
*/
setTrackingConsent: (trackingConsent: TrackingConsent) => void;
setGlobalContextProperty: (key: any, value: any) => void;

@@ -38,0 +53,0 @@ removeGlobalContextProperty: (key: any) => void;

@@ -13,6 +13,32 @@ "use strict";

var userContextManager = (0, browser_core_1.createContextManager)(customerDataTrackerManager.getOrCreateTracker(1 /* CustomerDataType.User */));
var trackingConsentState = (0, browser_core_1.createTrackingConsentState)();
function getCommonContext() {
return (0, commonContext_1.buildCommonContext)(globalContextManager, userContextManager, recorderApi);
}
var strategy = (0, preStartRum_1.createPreStartStrategy)(options, getCommonContext, function (initConfiguration, configuration, deflateWorker, initialViewOptions) {
var strategy = (0, preStartRum_1.createPreStartStrategy)(options, getCommonContext, trackingConsentState, function (initConfiguration, configuration, deflateWorker, initialViewOptions) {
if ((0, browser_core_1.isExperimentalFeatureEnabled)(browser_core_1.ExperimentalFeature.CUSTOM_VITALS)) {
/**
* Start a custom duration vital
* stored in @vital.custom.<name>
*
* @param name name of the custom vital
* @param options.context custom context attached to the vital
* @param options.startTime epoch timestamp of the start of the custom vital (if not set, will use current time)
*/
;
rumPublicApi.startDurationVital = (0, browser_core_1.monitor)(function (name, options) {
strategy.startDurationVital({
name: (0, browser_core_1.sanitize)(name),
startClocks: (options === null || options === void 0 ? void 0 : options.startTime) ? (0, browser_core_1.timeStampToClocks)(options.startTime) : (0, browser_core_1.clocksNow)(),
context: (0, browser_core_1.sanitize)(options === null || options === void 0 ? void 0 : options.context),
});
});
rumPublicApi.stopDurationVital = (0, browser_core_1.monitor)(function (name, options) {
strategy.stopDurationVital({
name: (0, browser_core_1.sanitize)(name),
stopClocks: (options === null || options === void 0 ? void 0 : options.stopTime) ? (0, browser_core_1.timeStampToClocks)(options.stopTime) : (0, browser_core_1.clocksNow)(),
context: (0, browser_core_1.sanitize)(options === null || options === void 0 ? void 0 : options.context),
});
});
}
if (initConfiguration.storeContextsAcrossPages) {

@@ -25,3 +51,3 @@ (0, browser_core_1.storeContextManager)(configuration, globalContextManager, RUM_STORAGE_KEY, 2 /* CustomerDataType.GlobalContext */);

? function (streamId) { return options.createDeflateEncoder(configuration, deflateWorker, streamId); }
: browser_core_1.createIdentityEncoder);
: browser_core_1.createIdentityEncoder, trackingConsentState);
recorderApi.onRumStart(startRumResult.lifeCycle, configuration, startRumResult.session, startRumResult.viewContexts, deflateWorker);

@@ -37,2 +63,15 @@ strategy = createPostStartStrategy(initConfiguration, startRumResult);

init: (0, browser_core_1.monitor)(function (initConfiguration) { return strategy.init(initConfiguration); }),
/**
* Set the tracking consent of the current user.
*
* @param {"granted" | "not-granted"} trackingConsent The user tracking consent
*
* Data will be sent only if it is set to "granted". This value won't be stored by the library
* across page loads: you will need to call this method or set the appropriate `trackingConsent`
* field in the init() method at each page load.
*
* If this method is called before the init() method, the provided value will take precedence
* over the one provided as initialization parameter.
*/
setTrackingConsent: (0, browser_core_1.monitor)(function (trackingConsent) { return trackingConsentState.update(trackingConsent); }),
setGlobalContextProperty: (0, browser_core_1.monitor)(function (key, value) { return globalContextManager.setContextProperty(key, value); }),

@@ -39,0 +78,0 @@ removeGlobalContextProperty: (0, browser_core_1.monitor)(function (key) { return globalContextManager.removeContextProperty(key); }),

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

import type { Observable, RawError, DeflateEncoderStreamId, Encoder, CustomerDataTrackerManager } from '@datadog/browser-core';
import type { Observable, RawError, DeflateEncoderStreamId, Encoder, CustomerDataTrackerManager, TrackingConsentState } from '@datadog/browser-core';
import { LifeCycle } from '../domain/lifeCycle';

@@ -11,3 +11,3 @@ import type { RumSessionManager } from '../domain/rumSessionManager';

export type StartRumResult = ReturnType<StartRum>;
export declare function startRum(initConfiguration: RumInitConfiguration, configuration: RumConfiguration, recorderApi: RecorderApi, customerDataTrackerManager: CustomerDataTrackerManager, getCommonContext: () => CommonContext, initialViewOptions: ViewOptions | undefined, createEncoder: (streamId: DeflateEncoderStreamId) => Encoder): {
export declare function startRum(initConfiguration: RumInitConfiguration, configuration: RumConfiguration, recorderApi: RecorderApi, customerDataTrackerManager: CustomerDataTrackerManager, getCommonContext: () => CommonContext, initialViewOptions: ViewOptions | undefined, createEncoder: (streamId: DeflateEncoderStreamId) => Encoder, trackingConsentState: TrackingConsentState): {
addAction: (action: import("../domain/action/actionCollection").CustomAction, savedCommonContext?: CommonContext | undefined) => void;

@@ -23,2 +23,4 @@ addError: ({ error, handlingStack, startClocks, context: customerContext }: import("../domain/error/errorCollection").ProvidedError, savedCommonContext?: CommonContext | undefined) => void;

getInternalContext: (startTime?: number | undefined) => import("../domain/contexts/internalContext").InternalContext | undefined;
startDurationVital: (vitalStart: import("../domain/vital/vitalCollection").DurationVitalStart) => void;
stopDurationVital: (vitalStop: import("../domain/vital/vitalCollection").DurationVitalStop) => void;
stop: () => void;

@@ -25,0 +27,0 @@ };

@@ -27,6 +27,11 @@ "use strict";

var displayContext_1 = require("../domain/contexts/displayContext");
function startRum(initConfiguration, configuration, recorderApi, customerDataTrackerManager, getCommonContext, initialViewOptions, createEncoder) {
var vitalCollection_1 = require("../domain/vital/vitalCollection");
function startRum(initConfiguration, configuration, recorderApi, customerDataTrackerManager, getCommonContext, initialViewOptions, createEncoder,
// `startRum` and its subcomponents assume tracking consent is granted initially and starts
// collecting logs unconditionally. As such, `startRum` should be called with a
// `trackingConsentState` set to "granted".
trackingConsentState) {
var cleanupTasks = [];
var lifeCycle = new lifeCycle_1.LifeCycle();
lifeCycle.subscribe(11 /* LifeCycleEventType.RUM_EVENT_COLLECTED */, function (event) { return (0, browser_core_1.sendToExtension)('rum', event); });
lifeCycle.subscribe(13 /* LifeCycleEventType.RUM_EVENT_COLLECTED */, function (event) { return (0, browser_core_1.sendToExtension)('rum', event); });
var telemetry = startRumTelemetry(configuration);

@@ -51,3 +56,3 @@ telemetry.setContextProvider(function () {

var reportError = function (error) {
lifeCycle.notify(12 /* LifeCycleEventType.RAW_ERROR_COLLECTED */, { error: error });
lifeCycle.notify(14 /* LifeCycleEventType.RAW_ERROR_COLLECTED */, { error: error });
(0, browser_core_1.addTelemetryDebug)('Error reported to customer', { 'error.message': error.message });

@@ -58,6 +63,8 @@ };

var pageExitSubscription = pageExitObservable.subscribe(function (event) {
lifeCycle.notify(9 /* LifeCycleEventType.PAGE_EXITED */, event);
lifeCycle.notify(11 /* LifeCycleEventType.PAGE_EXITED */, event);
});
cleanupTasks.push(function () { return pageExitSubscription.unsubscribe(); });
var session = !(0, browser_core_1.canUseEventBridge)() ? (0, rumSessionManager_1.startRumSessionManager)(configuration, lifeCycle) : (0, rumSessionManager_1.startRumSessionManagerStub)();
var session = !(0, browser_core_1.canUseEventBridge)()
? (0, rumSessionManager_1.startRumSessionManager)(configuration, lifeCycle, trackingConsentState)
: (0, rumSessionManager_1.startRumSessionManagerStub)();
if (!(0, browser_core_1.canUseEventBridge)()) {

@@ -84,2 +91,3 @@ var batch_1 = (0, startRumBatch_1.startRumBatch)(configuration, lifeCycle, telemetry.observable, reportError, pageExitObservable, session.expireObservable, createEncoder);

cleanupTasks.push(stopPerformanceCollection);
var vitalCollection = (0, vitalCollection_1.startVitalCollection)(lifeCycle);
var internalContext = (0, internalContext_1.startInternalContext)(configuration.applicationId, session, viewContexts, actionContexts, urlContexts);

@@ -97,2 +105,4 @@ return {

getInternalContext: internalContext.get,
startDurationVital: vitalCollection.startDurationVital,
stopDurationVital: vitalCollection.stopDurationVital,
stop: function () {

@@ -99,0 +109,0 @@ cleanupTasks.forEach(function (task) { return task(); });

@@ -29,2 +29,3 @@ import type { Duration, RelativeTime } from '@datadog/browser-core';

initiatorType: string;
responseStatus?: number;
name: string;

@@ -31,0 +32,0 @@ startTime: RelativeTime;

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

lifeCycle.subscribe(1 /* LifeCycleEventType.AUTO_ACTION_COMPLETED */, function (action) {
return lifeCycle.notify(10 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, processAction(action, pageStateHistory));
return lifeCycle.notify(12 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, processAction(action, pageStateHistory));
});

@@ -17,3 +17,3 @@ var actionContexts = { findActionId: browser_core_1.noop };

addAction: function (action, savedCommonContext) {
lifeCycle.notify(10 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, (0, browser_core_1.assign)({
lifeCycle.notify(12 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, (0, browser_core_1.assign)({
savedCommonContext: savedCommonContext,

@@ -20,0 +20,0 @@ }, processAction(action, pageStateHistory)));

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

var currentClickChain;
lifeCycle.subscribe(8 /* LifeCycleEventType.SESSION_RENEWED */, function () {
lifeCycle.subscribe(10 /* LifeCycleEventType.SESSION_RENEWED */, function () {
history.reset();
});
lifeCycle.subscribe(4 /* LifeCycleEventType.VIEW_ENDED */, stopClickChain);
lifeCycle.subscribe(5 /* LifeCycleEventType.VIEW_ENDED */, stopClickChain);
var stopActionEventsListener = (0, listenActionEvents_1.listenActionEvents)(configuration, {

@@ -93,3 +93,3 @@ onPointerDown: function (pointerDownEvent) {

}, exports.CLICK_ACTION_MAX_DURATION).stop;
var viewEndedSubscription = lifeCycle.subscribe(4 /* LifeCycleEventType.VIEW_ENDED */, function (_a) {
var viewEndedSubscription = lifeCycle.subscribe(5 /* LifeCycleEventType.VIEW_ENDED */, function (_a) {
var endClocks = _a.endClocks;

@@ -96,0 +96,0 @@ click.stop(endClocks.timeStamp);

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

_a["long_task" /* RumEventType.LONG_TASK */] = (0, browser_core_1.assign)({}, USER_CUSTOMIZABLE_FIELD_PATHS, VIEW_MODIFIABLE_FIELD_PATHS),
_a["vital" /* RumEventType.VITAL */] = (0, browser_core_1.assign)({}, USER_CUSTOMIZABLE_FIELD_PATHS, VIEW_MODIFIABLE_FIELD_PATHS),
_a);

@@ -41,6 +42,7 @@ var eventRateLimiters = (_b = {},

_b["action" /* RumEventType.ACTION */] = (0, browser_core_1.createEventRateLimiter)("action" /* RumEventType.ACTION */, configuration.eventRateLimiterThreshold, reportError),
_b["vital" /* RumEventType.VITAL */] = (0, browser_core_1.createEventRateLimiter)("vital" /* RumEventType.VITAL */, configuration.eventRateLimiterThreshold, reportError),
_b);
var syntheticsContext = (0, syntheticsContext_1.getSyntheticsContext)();
var ciTestContext = (0, ciTestContext_1.getCiTestContext)();
lifeCycle.subscribe(10 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, function (_a) {
lifeCycle.subscribe(12 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, function (_a) {
var startTime = _a.startTime, rawRumEvent = _a.rawRumEvent, domainContext = _a.domainContext, savedCommonContext = _a.savedCommonContext, customerContext = _a.customerContext;

@@ -61,3 +63,3 @@ var viewContext = viewContexts.findView(startTime);

},
browser_sdk_version: (0, browser_core_1.canUseEventBridge)() ? "5.9.0" : undefined,
browser_sdk_version: (0, browser_core_1.canUseEventBridge)() ? "5.10.0" : undefined,
},

@@ -105,3 +107,3 @@ application: {

}
lifeCycle.notify(11 /* LifeCycleEventType.RUM_EVENT_COLLECTED */, serverRumEvent);
lifeCycle.notify(13 /* LifeCycleEventType.RUM_EVENT_COLLECTED */, serverRumEvent);
}

@@ -108,0 +110,0 @@ }

@@ -24,7 +24,3 @@ "use strict";

var featureFlagContexts = new browser_core_1.ValueHistory(exports.FEATURE_FLAG_CONTEXT_TIME_OUT_DELAY);
lifeCycle.subscribe(4 /* LifeCycleEventType.VIEW_ENDED */, function (_a) {
var endClocks = _a.endClocks;
featureFlagContexts.closeActive(endClocks.relative);
});
lifeCycle.subscribe(2 /* LifeCycleEventType.VIEW_CREATED */, function (_a) {
lifeCycle.subscribe(2 /* LifeCycleEventType.BEFORE_VIEW_CREATED */, function (_a) {
var startClocks = _a.startClocks;

@@ -34,2 +30,6 @@ featureFlagContexts.add({}, startClocks.relative);

});
lifeCycle.subscribe(6 /* LifeCycleEventType.AFTER_VIEW_ENDED */, function (_a) {
var endClocks = _a.endClocks;
featureFlagContexts.closeActive(endClocks.relative);
});
return {

@@ -36,0 +36,0 @@ findFeatureFlagEvaluations: function (startTime) { return featureFlagContexts.find(startTime); },

@@ -14,7 +14,3 @@ "use strict";

var previousViewUrl;
lifeCycle.subscribe(4 /* LifeCycleEventType.VIEW_ENDED */, function (_a) {
var endClocks = _a.endClocks;
urlContextHistory.closeActive(endClocks.relative);
});
lifeCycle.subscribe(2 /* LifeCycleEventType.VIEW_CREATED */, function (_a) {
lifeCycle.subscribe(2 /* LifeCycleEventType.BEFORE_VIEW_CREATED */, function (_a) {
var startClocks = _a.startClocks;

@@ -28,2 +24,6 @@ var viewUrl = location.href;

});
lifeCycle.subscribe(6 /* LifeCycleEventType.AFTER_VIEW_ENDED */, function (_a) {
var endClocks = _a.endClocks;
urlContextHistory.closeActive(endClocks.relative);
});
var locationChangeSubscription = locationChangeObservable.subscribe(function (_a) {

@@ -30,0 +30,0 @@ var newLocation = _a.newLocation;

@@ -8,10 +8,10 @@ "use strict";

var viewContextHistory = new browser_core_1.ValueHistory(exports.VIEW_CONTEXT_TIME_OUT_DELAY);
lifeCycle.subscribe(2 /* LifeCycleEventType.VIEW_CREATED */, function (view) {
lifeCycle.subscribe(2 /* LifeCycleEventType.BEFORE_VIEW_CREATED */, function (view) {
viewContextHistory.add(buildViewContext(view), view.startClocks.relative);
});
lifeCycle.subscribe(4 /* LifeCycleEventType.VIEW_ENDED */, function (_a) {
lifeCycle.subscribe(6 /* LifeCycleEventType.AFTER_VIEW_ENDED */, function (_a) {
var endClocks = _a.endClocks;
viewContextHistory.closeActive(endClocks.relative);
});
lifeCycle.subscribe(8 /* LifeCycleEventType.SESSION_RENEWED */, function () {
lifeCycle.subscribe(10 /* LifeCycleEventType.SESSION_RENEWED */, function () {
viewContextHistory.reset();

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

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

(0, trackReportError_1.trackReportError)(configuration, errorObservable);
errorObservable.subscribe(function (error) { return lifeCycle.notify(12 /* LifeCycleEventType.RAW_ERROR_COLLECTED */, { error: error }); });
errorObservable.subscribe(function (error) { return lifeCycle.notify(14 /* LifeCycleEventType.RAW_ERROR_COLLECTED */, { error: error }); });
return doStartErrorCollection(lifeCycle, pageStateHistory, featureFlagContexts);

@@ -18,5 +18,5 @@ }

function doStartErrorCollection(lifeCycle, pageStateHistory, featureFlagContexts) {
lifeCycle.subscribe(12 /* LifeCycleEventType.RAW_ERROR_COLLECTED */, function (_a) {
lifeCycle.subscribe(14 /* LifeCycleEventType.RAW_ERROR_COLLECTED */, function (_a) {
var error = _a.error, customerContext = _a.customerContext, savedCommonContext = _a.savedCommonContext;
lifeCycle.notify(10 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, (0, browser_core_1.assign)({
lifeCycle.notify(12 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, (0, browser_core_1.assign)({
customerContext: customerContext,

@@ -39,3 +39,3 @@ savedCommonContext: savedCommonContext,

});
lifeCycle.notify(12 /* LifeCycleEventType.RAW_ERROR_COLLECTED */, {
lifeCycle.notify(14 /* LifeCycleEventType.RAW_ERROR_COLLECTED */, {
customerContext: customerContext,

@@ -42,0 +42,0 @@ savedCommonContext: savedCommonContext,

@@ -14,13 +14,15 @@ import type { Context, PageExitEvent, RawError, RelativeTime } from '@datadog/browser-core';

AUTO_ACTION_COMPLETED = 1,
VIEW_CREATED = 2,
VIEW_UPDATED = 3,
VIEW_ENDED = 4,
REQUEST_STARTED = 5,
REQUEST_COMPLETED = 6,
SESSION_EXPIRED = 7,
SESSION_RENEWED = 8,
PAGE_EXITED = 9,
RAW_RUM_EVENT_COLLECTED = 10,
RUM_EVENT_COLLECTED = 11,
RAW_ERROR_COLLECTED = 12
BEFORE_VIEW_CREATED = 2,
VIEW_CREATED = 3,
VIEW_UPDATED = 4,
VIEW_ENDED = 5,
AFTER_VIEW_ENDED = 6,
REQUEST_STARTED = 7,
REQUEST_COMPLETED = 8,
SESSION_EXPIRED = 9,
SESSION_RENEWED = 10,
PAGE_EXITED = 11,
RAW_RUM_EVENT_COLLECTED = 12,
RUM_EVENT_COLLECTED = 13,
RAW_ERROR_COLLECTED = 14
}

@@ -30,5 +32,7 @@ declare const LifeCycleEventTypeAsConst: {

AUTO_ACTION_COMPLETED: LifeCycleEventType.AUTO_ACTION_COMPLETED;
BEFORE_VIEW_CREATED: LifeCycleEventType.BEFORE_VIEW_CREATED;
VIEW_CREATED: LifeCycleEventType.VIEW_CREATED;
VIEW_UPDATED: LifeCycleEventType.VIEW_UPDATED;
VIEW_ENDED: LifeCycleEventType.VIEW_ENDED;
AFTER_VIEW_ENDED: LifeCycleEventType.AFTER_VIEW_ENDED;
REQUEST_STARTED: LifeCycleEventType.REQUEST_STARTED;

@@ -46,5 +50,7 @@ REQUEST_COMPLETED: LifeCycleEventType.REQUEST_COMPLETED;

[LifeCycleEventTypeAsConst.AUTO_ACTION_COMPLETED]: AutoAction;
[LifeCycleEventTypeAsConst.BEFORE_VIEW_CREATED]: ViewCreatedEvent;
[LifeCycleEventTypeAsConst.VIEW_CREATED]: ViewCreatedEvent;
[LifeCycleEventTypeAsConst.VIEW_UPDATED]: ViewEvent;
[LifeCycleEventTypeAsConst.VIEW_ENDED]: ViewEndedEvent;
[LifeCycleEventTypeAsConst.AFTER_VIEW_ENDED]: ViewEndedEvent;
[LifeCycleEventTypeAsConst.REQUEST_STARTED]: RequestStartEvent;

@@ -51,0 +57,0 @@ [LifeCycleEventTypeAsConst.REQUEST_COMPLETED]: RequestCompleteEvent;

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

};
lifeCycle.notify(10 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, {
lifeCycle.notify(12 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, {
rawRumEvent: rawRumEvent,

@@ -32,0 +32,0 @@ startTime: startClocks.relative,

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

context.requestIndex = getNextRequestIndex();
lifeCycle.notify(5 /* LifeCycleEventType.REQUEST_STARTED */, {
lifeCycle.notify(7 /* LifeCycleEventType.REQUEST_STARTED */, {
requestIndex: context.requestIndex,

@@ -32,3 +32,3 @@ url: context.url,

tracer.clearTracingIfNeeded(context);
lifeCycle.notify(6 /* LifeCycleEventType.REQUEST_COMPLETED */, {
lifeCycle.notify(8 /* LifeCycleEventType.REQUEST_COMPLETED */, {
duration: context.duration,

@@ -62,3 +62,3 @@ method: context.method,

context.requestIndex = getNextRequestIndex();
lifeCycle.notify(5 /* LifeCycleEventType.REQUEST_STARTED */, {
lifeCycle.notify(7 /* LifeCycleEventType.REQUEST_STARTED */, {
requestIndex: context.requestIndex,

@@ -71,3 +71,3 @@ url: context.url,

tracer.clearTracingIfNeeded(context);
lifeCycle.notify(6 /* LifeCycleEventType.REQUEST_COMPLETED */, {
lifeCycle.notify(8 /* LifeCycleEventType.REQUEST_COMPLETED */, {
duration: duration,

@@ -74,0 +74,0 @@ method: context.method,

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

function startResourceCollection(lifeCycle, configuration, sessionManager, pageStateHistory) {
lifeCycle.subscribe(6 /* LifeCycleEventType.REQUEST_COMPLETED */, function (request) {
lifeCycle.subscribe(8 /* LifeCycleEventType.REQUEST_COMPLETED */, function (request) {
var rawEvent = processRequest(request, configuration, sessionManager, pageStateHistory);
if (rawEvent) {
lifeCycle.notify(10 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, rawEvent);
lifeCycle.notify(12 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, rawEvent);
}

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

if (rawEvent) {
lifeCycle.notify(10 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, rawEvent);
lifeCycle.notify(12 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, rawEvent);
}

@@ -87,2 +87,3 @@ }

url: entry.name,
status_code: discardZeroStatus(entry.responseStatus),
},

@@ -161,2 +162,9 @@ type: "resource" /* RumEventType.RESOURCE */,

}
/**
* The status is 0 for cross origin resources without CORS headers, so the status is meaningless and we shouldn't report it
* https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/responseStatus#cross-origin_response_status_codes
*/
function discardZeroStatus(statusCode) {
return statusCode === 0 ? undefined : statusCode;
}
//# sourceMappingURL=resourceCollection.js.map

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

import type { RelativeTime } from '@datadog/browser-core';
import type { RelativeTime, TrackingConsentState } from '@datadog/browser-core';
import { Observable } from '@datadog/browser-core';

@@ -20,3 +20,3 @@ import type { RumConfiguration } from './configuration';

}
export declare function startRumSessionManager(configuration: RumConfiguration, lifeCycle: LifeCycle): RumSessionManager;
export declare function startRumSessionManager(configuration: RumConfiguration, lifeCycle: LifeCycle, trackingConsentState: TrackingConsentState): RumSessionManager;
/**

@@ -23,0 +23,0 @@ * Start a tracked replay session stub

@@ -6,11 +6,9 @@ "use strict";

exports.RUM_SESSION_KEY = 'rum';
function startRumSessionManager(configuration, lifeCycle) {
var sessionManager = (0, browser_core_1.startSessionManager)(configuration, exports.RUM_SESSION_KEY, function (rawTrackingType) {
return computeSessionState(configuration, rawTrackingType);
});
function startRumSessionManager(configuration, lifeCycle, trackingConsentState) {
var sessionManager = (0, browser_core_1.startSessionManager)(configuration, exports.RUM_SESSION_KEY, function (rawTrackingType) { return computeSessionState(configuration, rawTrackingType); }, trackingConsentState);
sessionManager.expireObservable.subscribe(function () {
lifeCycle.notify(7 /* LifeCycleEventType.SESSION_EXPIRED */);
lifeCycle.notify(9 /* LifeCycleEventType.SESSION_EXPIRED */);
});
sessionManager.renewObservable.subscribe(function () {
lifeCycle.notify(8 /* LifeCycleEventType.SESSION_RENEWED */);
lifeCycle.notify(10 /* LifeCycleEventType.SESSION_RENEWED */);
});

@@ -17,0 +15,0 @@ return {

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

// It means that contexts bytes count sums can be higher than it really is
lifeCycle.subscribe(11 /* LifeCycleEventType.RUM_EVENT_COLLECTED */, function (event) {
lifeCycle.subscribe(13 /* LifeCycleEventType.RUM_EVENT_COLLECTED */, function (event) {
batchHasRumEvent = true;

@@ -21,0 +21,0 @@ updateMeasure(currentBatchMeasures.globalContextBytes, customerDataTrackerManager.getOrCreateTracker(2 /* CustomerDataType.GlobalContext */).getBytesCount());

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

};
var subscription = lifeCycle.subscribe(11 /* LifeCycleEventType.RUM_EVENT_COLLECTED */, function (event) {
var subscription = lifeCycle.subscribe(13 /* LifeCycleEventType.RUM_EVENT_COLLECTED */, function (event) {
var _a;
if (event.type === 'view' || !isChildEvent(event)) {
if (event.type === 'view' || event.type === 'vital' || !isChildEvent(event)) {
return;

@@ -19,0 +19,0 @@ }

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

function startViewLifeCycle() {
lifeCycle.subscribe(8 /* LifeCycleEventType.SESSION_RENEWED */, function () {
lifeCycle.subscribe(10 /* LifeCycleEventType.SESSION_RENEWED */, function () {
// Renew view on session renewal

@@ -43,7 +43,7 @@ currentView = startNewView("route_change" /* ViewLoadingType.ROUTE_CHANGE */, undefined, {

});
lifeCycle.subscribe(7 /* LifeCycleEventType.SESSION_EXPIRED */, function () {
lifeCycle.subscribe(9 /* LifeCycleEventType.SESSION_EXPIRED */, function () {
currentView.end({ sessionIsActive: false });
});
// End the current view on page unload
lifeCycle.subscribe(9 /* LifeCycleEventType.PAGE_EXITED */, function (pageExitEvent) {
lifeCycle.subscribe(11 /* LifeCycleEventType.PAGE_EXITED */, function (pageExitEvent) {
if (pageExitEvent.reason === browser_core_1.PageExitReason.UNLOADING || pageExitEvent.reason === browser_core_1.PageExitReason.PAGEHIDE) {

@@ -98,3 +98,3 @@ currentView.end();

}
lifeCycle.notify(2 /* LifeCycleEventType.VIEW_CREATED */, {
var viewCreatedEvent = {
id: id,

@@ -105,3 +105,5 @@ name: name,

version: version,
});
};
lifeCycle.notify(2 /* LifeCycleEventType.BEFORE_VIEW_CREATED */, viewCreatedEvent);
lifeCycle.notify(3 /* LifeCycleEventType.VIEW_CREATED */, viewCreatedEvent);
// Update the view every time the measures are changing

@@ -124,3 +126,3 @@ var _a = (0, browser_core_1.throttle)(triggerViewUpdate, exports.THROTTLE_VIEW_UPDATE_PERIOD, {

var currentEnd = endClocks === undefined ? (0, browser_core_1.timeStampNow)() : endClocks.timeStamp;
lifeCycle.notify(3 /* LifeCycleEventType.VIEW_UPDATED */, {
lifeCycle.notify(4 /* LifeCycleEventType.VIEW_UPDATED */, {
customTimings: customTimings,

@@ -158,3 +160,4 @@ documentVersion: documentVersion,

sessionIsActive = (_b = options.sessionIsActive) !== null && _b !== void 0 ? _b : true;
lifeCycle.notify(4 /* LifeCycleEventType.VIEW_ENDED */, { endClocks: endClocks });
lifeCycle.notify(5 /* LifeCycleEventType.VIEW_ENDED */, { endClocks: endClocks });
lifeCycle.notify(6 /* LifeCycleEventType.AFTER_VIEW_ENDED */, { endClocks: endClocks });
(0, browser_core_1.clearInterval)(keepAliveIntervalId);

@@ -161,0 +164,0 @@ setViewEnd(endClocks.relative);

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

function startViewCollection(lifeCycle, configuration, location, domMutationObservable, locationChangeObservable, featureFlagContexts, pageStateHistory, recorderApi, initialViewOptions) {
lifeCycle.subscribe(3 /* LifeCycleEventType.VIEW_UPDATED */, function (view) {
return lifeCycle.notify(10 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, processViewUpdate(view, configuration, featureFlagContexts, recorderApi, pageStateHistory));
lifeCycle.subscribe(4 /* LifeCycleEventType.VIEW_UPDATED */, function (view) {
return lifeCycle.notify(12 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, processViewUpdate(view, configuration, featureFlagContexts, recorderApi, pageStateHistory));
});

@@ -11,0 +11,0 @@ return (0, trackViews_1.trackViews)(location, lifeCycle, domMutationObservable, configuration, locationChangeObservable, !configuration.trackViewsManually, initialViewOptions);

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

}
}), lifeCycle.subscribe(5 /* LifeCycleEventType.REQUEST_STARTED */, function (startEvent) {
}), lifeCycle.subscribe(7 /* LifeCycleEventType.REQUEST_STARTED */, function (startEvent) {
if (isExcludedUrl(configuration, startEvent.url)) {

@@ -97,3 +97,3 @@ return;

notifyPageActivity();
}), lifeCycle.subscribe(6 /* LifeCycleEventType.REQUEST_COMPLETED */, function (request) {
}), lifeCycle.subscribe(8 /* LifeCycleEventType.REQUEST_COMPLETED */, function (request) {
if (isExcludedUrl(configuration, request.url) ||

@@ -100,0 +100,0 @@ firstRequestIndex === undefined ||

@@ -5,3 +5,3 @@ /**

import type { RumEventType } from './rawRumEvent.types';
export type RumEventDomainContext<T extends RumEventType = any> = T extends RumEventType.VIEW ? RumViewEventDomainContext : T extends RumEventType.ACTION ? RumActionEventDomainContext : T extends RumEventType.RESOURCE ? RumFetchResourceEventDomainContext | RumXhrResourceEventDomainContext | RumOtherResourceEventDomainContext : T extends RumEventType.ERROR ? RumErrorEventDomainContext : T extends RumEventType.LONG_TASK ? RumLongTaskEventDomainContext : never;
export type RumEventDomainContext<T extends RumEventType = any> = T extends RumEventType.VIEW ? RumViewEventDomainContext : T extends RumEventType.ACTION ? RumActionEventDomainContext : T extends RumEventType.RESOURCE ? RumFetchResourceEventDomainContext | RumXhrResourceEventDomainContext | RumOtherResourceEventDomainContext : T extends RumEventType.ERROR ? RumErrorEventDomainContext : T extends RumEventType.LONG_TASK ? RumLongTaskEventDomainContext : T extends RumEventType.VITAL ? RumVitalEventDomainContext : never;
export interface RumViewEventDomainContext {

@@ -33,1 +33,3 @@ location: Readonly<Location>;

}
export interface RumVitalEventDomainContext {
}
export { RumPublicApi, makeRumPublicApi, RecorderApi } from './boot/rumPublicApi';
export { StartRum } from './boot/startRum';
export { RumEvent, RumActionEvent, CommonProperties, RumErrorEvent, RumViewEvent, RumResourceEvent, RumLongTaskEvent, } from './rumEvent.types';
export { RumEvent, RumActionEvent, CommonProperties, RumErrorEvent, RumViewEvent, RumResourceEvent, RumLongTaskEvent, RumVitalEvent, } from './rumEvent.types';
export { RumLongTaskEventDomainContext, RumErrorEventDomainContext, RumOtherResourceEventDomainContext, RumXhrResourceEventDomainContext, RumFetchResourceEventDomainContext, RumActionEventDomainContext, RumViewEventDomainContext, RumEventDomainContext, } from './domainContext.types';

@@ -9,3 +9,3 @@ export { ReplayStats, ActionType, RumEventType, FrustrationType, RawRumActionEvent } from './rawRumEvent.types';

export { ViewCreatedEvent } from './domain/view/trackViews';
export { ViewContexts, ViewContext } from './domain/contexts/viewContexts';
export { ViewContexts, ViewContext, startViewContexts } from './domain/contexts/viewContexts';
export { RumSessionManager, RumSession } from './domain/rumSessionManager';

@@ -12,0 +12,0 @@ export { getMutationObserverConstructor } from './browser/domMutationObservable';

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.getSessionReplayUrl = exports.STABLE_ATTRIBUTES = exports.DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE = exports.getScrollY = exports.getScrollX = exports.getViewportDimension = exports.initViewportObservable = exports.getMutationObserverConstructor = exports.LifeCycle = exports.startRum = exports.makeRumPublicApi = void 0;
exports.getSessionReplayUrl = exports.STABLE_ATTRIBUTES = exports.DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE = exports.getScrollY = exports.getScrollX = exports.getViewportDimension = exports.initViewportObservable = exports.getMutationObserverConstructor = exports.startViewContexts = exports.LifeCycle = exports.startRum = exports.makeRumPublicApi = void 0;
var rumPublicApi_1 = require("./boot/rumPublicApi");

@@ -25,2 +25,4 @@ Object.defineProperty(exports, "makeRumPublicApi", { enumerable: true, get: function () { return rumPublicApi_1.makeRumPublicApi; } });

Object.defineProperty(exports, "LifeCycle", { enumerable: true, get: function () { return lifeCycle_1.LifeCycle; } });
var viewContexts_1 = require("./domain/contexts/viewContexts");
Object.defineProperty(exports, "startViewContexts", { enumerable: true, get: function () { return viewContexts_1.startViewContexts; } });
var domMutationObservable_1 = require("./browser/domMutationObservable");

@@ -27,0 +29,0 @@ Object.defineProperty(exports, "getMutationObserverConstructor", { enumerable: true, get: function () { return domMutationObservable_1.getMutationObserverConstructor; } });

@@ -8,3 +8,4 @@ import type { Context, Duration, ErrorSource, ErrorHandling, ResourceType, ServerDuration, TimeStamp, RawErrorCause, DefaultPrivacyLevel, Connectivity } from '@datadog/browser-core';

VIEW = "view",
RESOURCE = "resource"
RESOURCE = "resource",
VITAL = "vital"
}

@@ -194,3 +195,18 @@ export interface RawRumResourceEvent {

}
export type RawRumEvent = RawRumErrorEvent | RawRumResourceEvent | RawRumViewEvent | RawRumLongTaskEvent | RawRumActionEvent;
export interface RawRumVitalEvent {
date: TimeStamp;
type: RumEventType.VITAL;
vital: {
id: string;
name: string;
type: VitalType;
custom: {
[key: string]: number;
};
};
}
export declare const enum VitalType {
DURATION = "duration"
}
export type RawRumEvent = RawRumErrorEvent | RawRumResourceEvent | RawRumViewEvent | RawRumLongTaskEvent | RawRumActionEvent | RawRumVitalEvent;
export interface RumContext {

@@ -197,0 +213,0 @@ date: TimeStamp;

@@ -7,3 +7,3 @@ /**

*/
export type RumEvent = RumActionEvent | RumErrorEvent | RumLongTaskEvent | RumResourceEvent | RumViewEvent;
export type RumEvent = RumActionEvent | RumErrorEvent | RumLongTaskEvent | RumResourceEvent | RumViewEvent | RumVitalEvent;
/**

@@ -224,3 +224,3 @@ * Schema of all properties of an Action event

*/
readonly source_type?: 'android' | 'browser' | 'ios' | 'react-native' | 'flutter' | 'roku';
readonly source_type?: 'android' | 'browser' | 'ios' | 'react-native' | 'flutter' | 'roku' | 'ndk' | 'ios+il2cpp' | 'ndk+il2cpp';
/**

@@ -233,3 +233,3 @@ * Resource properties of the error

*/
readonly method: 'POST' | 'GET' | 'HEAD' | 'PUT' | 'DELETE' | 'PATCH';
readonly method: 'POST' | 'GET' | 'HEAD' | 'PUT' | 'DELETE' | 'PATCH' | 'TRACE' | 'OPTIONS' | 'CONNECT';
/**

@@ -263,2 +263,92 @@ * HTTP Status code of the resource

};
/**
* Description of each thread in the process when error happened.
*/
threads?: {
/**
* Name of the thread (e.g. 'Thread 0').
*/
readonly name: string;
/**
* Tells if the thread crashed.
*/
readonly crashed: boolean;
/**
* Unsymbolicated stack trace of the given thread.
*/
readonly stack: string;
/**
* Platform-specific state of the thread when its state was captured (CPU registers dump for iOS, thread state enum for Android, etc.).
*/
readonly state?: string;
[k: string]: unknown;
}[];
/**
* Description of each binary image (native libraries; for Android: .so files) loaded or referenced by the process/application.
*/
readonly binary_images?: {
/**
* Build UUID that uniquely identifies the binary image.
*/
readonly uuid: string;
/**
* Name of the library.
*/
readonly name: string;
/**
* Determines if it's a system or user library.
*/
readonly is_system: boolean;
/**
* Library's load address (hexadecimal).
*/
readonly load_address?: string;
/**
* Max value from the library address range (hexadecimal).
*/
readonly max_address?: string;
/**
* CPU architecture from the library.
*/
readonly arch?: string;
[k: string]: unknown;
}[];
/**
* A boolean value saying if any of the stack traces was truncated due to minification.
*/
readonly was_truncated?: boolean;
/**
* Platform-specific metadata of the error event.
*/
readonly meta?: {
/**
* The CPU architecture of the process that crashed.
*/
readonly code_type?: string;
/**
* Parent process information.
*/
readonly parent_process?: string;
/**
* A client-generated 16-byte UUID of the incident.
*/
readonly incident_identifier?: string;
/**
* The name of the crashed process.
*/
readonly process?: string;
/**
* The name of the corresponding BSD termination signal. (in case of iOS crash)
*/
readonly exception_type?: string;
/**
* CPU specific information about the exception encoded into 64-bit hexadecimal number preceded by the signal code.
*/
readonly exception_codes?: string;
/**
* The location of the executable.
*/
readonly path?: string;
[k: string]: unknown;
};
[k: string]: unknown;

@@ -345,3 +435,3 @@ };

*/
readonly method?: 'POST' | 'GET' | 'HEAD' | 'PUT' | 'DELETE' | 'PATCH';
readonly method?: 'POST' | 'GET' | 'HEAD' | 'PUT' | 'DELETE' | 'PATCH' | 'TRACE' | 'OPTIONS' | 'CONNECT';
/**

@@ -846,2 +936,36 @@ * URL of the resource

/**
* Schema of all properties of a Vital event
*/
export type RumVitalEvent = CommonProperties & ViewContainerSchema & {
/**
* RUM event type
*/
readonly type: 'vital';
/**
* Vital properties
*/
readonly vital: {
/**
* Type of the vital
*/
readonly type: 'duration';
/**
* UUID of the vital
*/
readonly id: string;
/**
* Name of the vital, as it is also used as facet path for its value, it must contain only letters, digits, or the characters - _ . @ $
*/
readonly name?: string;
/**
* User custom vital.
*/
readonly custom?: {
[k: string]: number;
};
[k: string]: unknown;
};
[k: string]: unknown;
};
/**
* Schema of common properties of RUM events

@@ -848,0 +972,0 @@ */

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

}, reportError, pageExitObservable, sessionExpireObservable);
lifeCycle.subscribe(11 /* LifeCycleEventType.RUM_EVENT_COLLECTED */, function (serverRumEvent) {
lifeCycle.subscribe(13 /* LifeCycleEventType.RUM_EVENT_COLLECTED */, function (serverRumEvent) {
if (serverRumEvent.type === "view" /* RumEventType.VIEW */) {

@@ -18,0 +18,0 @@ batch.upsert(serverRumEvent, serverRumEvent.view.id);

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

var bridge = (0, browser_core_1.getEventBridge)();
lifeCycle.subscribe(11 /* LifeCycleEventType.RUM_EVENT_COLLECTED */, function (serverRumEvent) {
lifeCycle.subscribe(13 /* LifeCycleEventType.RUM_EVENT_COLLECTED */, function (serverRumEvent) {
bridge.send('rum', serverRumEvent);

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

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

import { type DeflateWorker } from '@datadog/browser-core';
import type { TrackingConsentState, DeflateWorker } from '@datadog/browser-core';
import { type RumConfiguration, type RumInitConfiguration } from '../domain/configuration';

@@ -7,2 +7,2 @@ import type { CommonContext } from '../domain/contexts/commonContext';

import type { StartRumResult } from './startRum';
export declare function createPreStartStrategy({ ignoreInitIfSyntheticsWillInjectRum, startDeflateWorker }: RumPublicApiOptions, getCommonContext: () => CommonContext, doStartRum: (initConfiguration: RumInitConfiguration, configuration: RumConfiguration, deflateWorker: DeflateWorker | undefined, initialViewOptions?: ViewOptions) => StartRumResult): Strategy;
export declare function createPreStartStrategy({ ignoreInitIfSyntheticsWillInjectRum, startDeflateWorker }: RumPublicApiOptions, getCommonContext: () => CommonContext, trackingConsentState: TrackingConsentState, doStartRum: (initConfiguration: RumInitConfiguration, configuration: RumConfiguration, deflateWorker: DeflateWorker | undefined, initialViewOptions?: ViewOptions) => StartRumResult): Strategy;
import { BoundedBuffer, display, canUseEventBridge, displayAlreadyInitializedError, willSyntheticsInjectRum, noop, timeStampNow, clocksNow, assign, } from '@datadog/browser-core';
import { validateAndBuildRumConfiguration, } from '../domain/configuration';
export function createPreStartStrategy(_a, getCommonContext, doStartRum) {
export function createPreStartStrategy(_a, getCommonContext, trackingConsentState, doStartRum) {
var ignoreInitIfSyntheticsWillInjectRum = _a.ignoreInitIfSyntheticsWillInjectRum, startDeflateWorker = _a.startDeflateWorker;

@@ -10,6 +10,8 @@ var bufferApiCalls = new BoundedBuffer();

var cachedConfiguration;
var trackingConsentStateSubscription = trackingConsentState.observable.subscribe(tryStartRum);
function tryStartRum() {
if (!cachedInitConfiguration || !cachedConfiguration) {
if (!cachedInitConfiguration || !cachedConfiguration || !trackingConsentState.isGranted()) {
return;
}
trackingConsentStateSubscription.unsubscribe();
var initialViewOptions;

@@ -75,2 +77,3 @@ if (cachedConfiguration.trackViewsManually) {

cachedConfiguration = configuration;
trackingConsentState.tryToInit(configuration.trackingConsent);
tryStartRum();

@@ -109,2 +112,8 @@ },

},
startDurationVital: function (vitalStart) {
bufferApiCalls.add(function (startRumResult) { return startRumResult.startDurationVital(vitalStart); });
},
stopDurationVital: function (vitalStart) {
bufferApiCalls.add(function (startRumResult) { return startRumResult.stopDurationVital(vitalStart); });
},
};

@@ -111,0 +120,0 @@ }

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

import type { Context, User, DeflateWorker, DeflateEncoderStreamId, DeflateEncoder } from '@datadog/browser-core';
import type { Context, User, DeflateWorker, DeflateEncoderStreamId, DeflateEncoder, TrackingConsent } from '@datadog/browser-core';
import type { LifeCycle } from '../domain/lifeCycle';

@@ -33,5 +33,20 @@ import type { ViewContexts } from '../domain/contexts/viewContexts';

addFeatureFlagEvaluation: StartRumResult['addFeatureFlagEvaluation'];
startDurationVital: StartRumResult['startDurationVital'];
stopDurationVital: StartRumResult['stopDurationVital'];
}
export declare function makeRumPublicApi(startRumImpl: StartRum, recorderApi: RecorderApi, options?: RumPublicApiOptions): {
init: (initConfiguration: RumInitConfiguration) => void;
/**
* Set the tracking consent of the current user.
*
* @param {"granted" | "not-granted"} trackingConsent The user tracking consent
*
* Data will be sent only if it is set to "granted". This value won't be stored by the library
* across page loads: you will need to call this method or set the appropriate `trackingConsent`
* field in the init() method at each page load.
*
* If this method is called before the init() method, the provided value will take precedence
* over the one provided as initialization parameter.
*/
setTrackingConsent: (trackingConsent: TrackingConsent) => void;
setGlobalContextProperty: (key: any, value: any) => void;

@@ -38,0 +53,0 @@ removeGlobalContextProperty: (key: any) => void;

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

import { assign, createContextManager, deepClone, makePublicApi, monitor, clocksNow, callMonitored, createHandlingStack, checkUser, sanitizeUser, sanitize, createIdentityEncoder, createCustomerDataTrackerManager, storeContextManager, displayAlreadyInitializedError, } from '@datadog/browser-core';
import { timeStampToClocks, isExperimentalFeatureEnabled, ExperimentalFeature, assign, createContextManager, deepClone, makePublicApi, monitor, clocksNow, callMonitored, createHandlingStack, checkUser, sanitizeUser, sanitize, createIdentityEncoder, createCustomerDataTrackerManager, storeContextManager, displayAlreadyInitializedError, createTrackingConsentState, } from '@datadog/browser-core';
import { buildCommonContext } from '../domain/contexts/commonContext';

@@ -10,6 +10,32 @@ import { createPreStartStrategy } from './preStartRum';

var userContextManager = createContextManager(customerDataTrackerManager.getOrCreateTracker(1 /* CustomerDataType.User */));
var trackingConsentState = createTrackingConsentState();
function getCommonContext() {
return buildCommonContext(globalContextManager, userContextManager, recorderApi);
}
var strategy = createPreStartStrategy(options, getCommonContext, function (initConfiguration, configuration, deflateWorker, initialViewOptions) {
var strategy = createPreStartStrategy(options, getCommonContext, trackingConsentState, function (initConfiguration, configuration, deflateWorker, initialViewOptions) {
if (isExperimentalFeatureEnabled(ExperimentalFeature.CUSTOM_VITALS)) {
/**
* Start a custom duration vital
* stored in @vital.custom.<name>
*
* @param name name of the custom vital
* @param options.context custom context attached to the vital
* @param options.startTime epoch timestamp of the start of the custom vital (if not set, will use current time)
*/
;
rumPublicApi.startDurationVital = monitor(function (name, options) {
strategy.startDurationVital({
name: sanitize(name),
startClocks: (options === null || options === void 0 ? void 0 : options.startTime) ? timeStampToClocks(options.startTime) : clocksNow(),
context: sanitize(options === null || options === void 0 ? void 0 : options.context),
});
});
rumPublicApi.stopDurationVital = monitor(function (name, options) {
strategy.stopDurationVital({
name: sanitize(name),
stopClocks: (options === null || options === void 0 ? void 0 : options.stopTime) ? timeStampToClocks(options.stopTime) : clocksNow(),
context: sanitize(options === null || options === void 0 ? void 0 : options.context),
});
});
}
if (initConfiguration.storeContextsAcrossPages) {

@@ -22,3 +48,3 @@ storeContextManager(configuration, globalContextManager, RUM_STORAGE_KEY, 2 /* CustomerDataType.GlobalContext */);

? function (streamId) { return options.createDeflateEncoder(configuration, deflateWorker, streamId); }
: createIdentityEncoder);
: createIdentityEncoder, trackingConsentState);
recorderApi.onRumStart(startRumResult.lifeCycle, configuration, startRumResult.session, startRumResult.viewContexts, deflateWorker);

@@ -34,2 +60,15 @@ strategy = createPostStartStrategy(initConfiguration, startRumResult);

init: monitor(function (initConfiguration) { return strategy.init(initConfiguration); }),
/**
* Set the tracking consent of the current user.
*
* @param {"granted" | "not-granted"} trackingConsent The user tracking consent
*
* Data will be sent only if it is set to "granted". This value won't be stored by the library
* across page loads: you will need to call this method or set the appropriate `trackingConsent`
* field in the init() method at each page load.
*
* If this method is called before the init() method, the provided value will take precedence
* over the one provided as initialization parameter.
*/
setTrackingConsent: monitor(function (trackingConsent) { return trackingConsentState.update(trackingConsent); }),
setGlobalContextProperty: monitor(function (key, value) { return globalContextManager.setContextProperty(key, value); }),

@@ -36,0 +75,0 @@ removeGlobalContextProperty: monitor(function (key) { return globalContextManager.removeContextProperty(key); }),

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

import type { Observable, RawError, DeflateEncoderStreamId, Encoder, CustomerDataTrackerManager } from '@datadog/browser-core';
import type { Observable, RawError, DeflateEncoderStreamId, Encoder, CustomerDataTrackerManager, TrackingConsentState } from '@datadog/browser-core';
import { LifeCycle } from '../domain/lifeCycle';

@@ -11,3 +11,3 @@ import type { RumSessionManager } from '../domain/rumSessionManager';

export type StartRumResult = ReturnType<StartRum>;
export declare function startRum(initConfiguration: RumInitConfiguration, configuration: RumConfiguration, recorderApi: RecorderApi, customerDataTrackerManager: CustomerDataTrackerManager, getCommonContext: () => CommonContext, initialViewOptions: ViewOptions | undefined, createEncoder: (streamId: DeflateEncoderStreamId) => Encoder): {
export declare function startRum(initConfiguration: RumInitConfiguration, configuration: RumConfiguration, recorderApi: RecorderApi, customerDataTrackerManager: CustomerDataTrackerManager, getCommonContext: () => CommonContext, initialViewOptions: ViewOptions | undefined, createEncoder: (streamId: DeflateEncoderStreamId) => Encoder, trackingConsentState: TrackingConsentState): {
addAction: (action: import("../domain/action/actionCollection").CustomAction, savedCommonContext?: CommonContext | undefined) => void;

@@ -23,2 +23,4 @@ addError: ({ error, handlingStack, startClocks, context: customerContext }: import("../domain/error/errorCollection").ProvidedError, savedCommonContext?: CommonContext | undefined) => void;

getInternalContext: (startTime?: number | undefined) => import("../domain/contexts/internalContext").InternalContext | undefined;
startDurationVital: (vitalStart: import("../domain/vital/vitalCollection").DurationVitalStart) => void;
stopDurationVital: (vitalStop: import("../domain/vital/vitalCollection").DurationVitalStop) => void;
stop: () => void;

@@ -25,0 +27,0 @@ };

@@ -24,6 +24,11 @@ import { sendToExtension, createPageExitObservable, addTelemetryConfiguration, startTelemetry, canUseEventBridge, getEventBridge, addTelemetryDebug, } from '@datadog/browser-core';

import { startDisplayContext } from '../domain/contexts/displayContext';
export function startRum(initConfiguration, configuration, recorderApi, customerDataTrackerManager, getCommonContext, initialViewOptions, createEncoder) {
import { startVitalCollection } from '../domain/vital/vitalCollection';
export function startRum(initConfiguration, configuration, recorderApi, customerDataTrackerManager, getCommonContext, initialViewOptions, createEncoder,
// `startRum` and its subcomponents assume tracking consent is granted initially and starts
// collecting logs unconditionally. As such, `startRum` should be called with a
// `trackingConsentState` set to "granted".
trackingConsentState) {
var cleanupTasks = [];
var lifeCycle = new LifeCycle();
lifeCycle.subscribe(11 /* LifeCycleEventType.RUM_EVENT_COLLECTED */, function (event) { return sendToExtension('rum', event); });
lifeCycle.subscribe(13 /* LifeCycleEventType.RUM_EVENT_COLLECTED */, function (event) { return sendToExtension('rum', event); });
var telemetry = startRumTelemetry(configuration);

@@ -48,3 +53,3 @@ telemetry.setContextProvider(function () {

var reportError = function (error) {
lifeCycle.notify(12 /* LifeCycleEventType.RAW_ERROR_COLLECTED */, { error: error });
lifeCycle.notify(14 /* LifeCycleEventType.RAW_ERROR_COLLECTED */, { error: error });
addTelemetryDebug('Error reported to customer', { 'error.message': error.message });

@@ -55,6 +60,8 @@ };

var pageExitSubscription = pageExitObservable.subscribe(function (event) {
lifeCycle.notify(9 /* LifeCycleEventType.PAGE_EXITED */, event);
lifeCycle.notify(11 /* LifeCycleEventType.PAGE_EXITED */, event);
});
cleanupTasks.push(function () { return pageExitSubscription.unsubscribe(); });
var session = !canUseEventBridge() ? startRumSessionManager(configuration, lifeCycle) : startRumSessionManagerStub();
var session = !canUseEventBridge()
? startRumSessionManager(configuration, lifeCycle, trackingConsentState)
: startRumSessionManagerStub();
if (!canUseEventBridge()) {

@@ -81,2 +88,3 @@ var batch_1 = startRumBatch(configuration, lifeCycle, telemetry.observable, reportError, pageExitObservable, session.expireObservable, createEncoder);

cleanupTasks.push(stopPerformanceCollection);
var vitalCollection = startVitalCollection(lifeCycle);
var internalContext = startInternalContext(configuration.applicationId, session, viewContexts, actionContexts, urlContexts);

@@ -94,2 +102,4 @@ return {

getInternalContext: internalContext.get,
startDurationVital: vitalCollection.startDurationVital,
stopDurationVital: vitalCollection.stopDurationVital,
stop: function () {

@@ -96,0 +106,0 @@ cleanupTasks.forEach(function (task) { return task(); });

@@ -29,2 +29,3 @@ import type { Duration, RelativeTime } from '@datadog/browser-core';

initiatorType: string;
responseStatus?: number;
name: string;

@@ -31,0 +32,0 @@ startTime: RelativeTime;

@@ -5,3 +5,3 @@ import { noop, assign, combine, toServerDuration, generateUUID } from '@datadog/browser-core';

lifeCycle.subscribe(1 /* LifeCycleEventType.AUTO_ACTION_COMPLETED */, function (action) {
return lifeCycle.notify(10 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, processAction(action, pageStateHistory));
return lifeCycle.notify(12 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, processAction(action, pageStateHistory));
});

@@ -14,3 +14,3 @@ var actionContexts = { findActionId: noop };

addAction: function (action, savedCommonContext) {
lifeCycle.notify(10 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, assign({
lifeCycle.notify(12 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, assign({
savedCommonContext: savedCommonContext,

@@ -17,0 +17,0 @@ }, processAction(action, pageStateHistory)));

@@ -16,6 +16,6 @@ import { includes, timeStampNow, Observable, assign, getRelativeTime, ONE_MINUTE, ValueHistory, generateUUID, clocksNow, ONE_SECOND, elapsed, } from '@datadog/browser-core';

var currentClickChain;
lifeCycle.subscribe(8 /* LifeCycleEventType.SESSION_RENEWED */, function () {
lifeCycle.subscribe(10 /* LifeCycleEventType.SESSION_RENEWED */, function () {
history.reset();
});
lifeCycle.subscribe(4 /* LifeCycleEventType.VIEW_ENDED */, stopClickChain);
lifeCycle.subscribe(5 /* LifeCycleEventType.VIEW_ENDED */, stopClickChain);
var stopActionEventsListener = listenActionEvents(configuration, {

@@ -89,3 +89,3 @@ onPointerDown: function (pointerDownEvent) {

}, CLICK_ACTION_MAX_DURATION).stop;
var viewEndedSubscription = lifeCycle.subscribe(4 /* LifeCycleEventType.VIEW_ENDED */, function (_a) {
var viewEndedSubscription = lifeCycle.subscribe(5 /* LifeCycleEventType.VIEW_ENDED */, function (_a) {
var endClocks = _a.endClocks;

@@ -92,0 +92,0 @@ click.stop(endClocks.timeStamp);

@@ -33,2 +33,3 @@ import { combine, isEmptyObject, timeStampNow, currentDrift, display, createEventRateLimiter, canUseEventBridge, assign, round, isExperimentalFeatureEnabled, ExperimentalFeature, getConnectivity, } from '@datadog/browser-core';

_a["long_task" /* RumEventType.LONG_TASK */] = assign({}, USER_CUSTOMIZABLE_FIELD_PATHS, VIEW_MODIFIABLE_FIELD_PATHS),
_a["vital" /* RumEventType.VITAL */] = assign({}, USER_CUSTOMIZABLE_FIELD_PATHS, VIEW_MODIFIABLE_FIELD_PATHS),
_a);

@@ -38,6 +39,7 @@ var eventRateLimiters = (_b = {},

_b["action" /* RumEventType.ACTION */] = createEventRateLimiter("action" /* RumEventType.ACTION */, configuration.eventRateLimiterThreshold, reportError),
_b["vital" /* RumEventType.VITAL */] = createEventRateLimiter("vital" /* RumEventType.VITAL */, configuration.eventRateLimiterThreshold, reportError),
_b);
var syntheticsContext = getSyntheticsContext();
var ciTestContext = getCiTestContext();
lifeCycle.subscribe(10 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, function (_a) {
lifeCycle.subscribe(12 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, function (_a) {
var startTime = _a.startTime, rawRumEvent = _a.rawRumEvent, domainContext = _a.domainContext, savedCommonContext = _a.savedCommonContext, customerContext = _a.customerContext;

@@ -58,3 +60,3 @@ var viewContext = viewContexts.findView(startTime);

},
browser_sdk_version: canUseEventBridge() ? "5.9.0" : undefined,
browser_sdk_version: canUseEventBridge() ? "5.10.0" : undefined,
},

@@ -102,3 +104,3 @@ application: {

}
lifeCycle.notify(11 /* LifeCycleEventType.RUM_EVENT_COLLECTED */, serverRumEvent);
lifeCycle.notify(13 /* LifeCycleEventType.RUM_EVENT_COLLECTED */, serverRumEvent);
}

@@ -105,0 +107,0 @@ }

@@ -21,7 +21,3 @@ import { noop, isExperimentalFeatureEnabled, SESSION_TIME_OUT_DELAY, ValueHistory, ExperimentalFeature, } from '@datadog/browser-core';

var featureFlagContexts = new ValueHistory(FEATURE_FLAG_CONTEXT_TIME_OUT_DELAY);
lifeCycle.subscribe(4 /* LifeCycleEventType.VIEW_ENDED */, function (_a) {
var endClocks = _a.endClocks;
featureFlagContexts.closeActive(endClocks.relative);
});
lifeCycle.subscribe(2 /* LifeCycleEventType.VIEW_CREATED */, function (_a) {
lifeCycle.subscribe(2 /* LifeCycleEventType.BEFORE_VIEW_CREATED */, function (_a) {
var startClocks = _a.startClocks;

@@ -31,2 +27,6 @@ featureFlagContexts.add({}, startClocks.relative);

});
lifeCycle.subscribe(6 /* LifeCycleEventType.AFTER_VIEW_ENDED */, function (_a) {
var endClocks = _a.endClocks;
featureFlagContexts.closeActive(endClocks.relative);
});
return {

@@ -33,0 +33,0 @@ findFeatureFlagEvaluations: function (startTime) { return featureFlagContexts.find(startTime); },

@@ -11,7 +11,3 @@ import { SESSION_TIME_OUT_DELAY, relativeNow, ValueHistory } from '@datadog/browser-core';

var previousViewUrl;
lifeCycle.subscribe(4 /* LifeCycleEventType.VIEW_ENDED */, function (_a) {
var endClocks = _a.endClocks;
urlContextHistory.closeActive(endClocks.relative);
});
lifeCycle.subscribe(2 /* LifeCycleEventType.VIEW_CREATED */, function (_a) {
lifeCycle.subscribe(2 /* LifeCycleEventType.BEFORE_VIEW_CREATED */, function (_a) {
var startClocks = _a.startClocks;

@@ -25,2 +21,6 @@ var viewUrl = location.href;

});
lifeCycle.subscribe(6 /* LifeCycleEventType.AFTER_VIEW_ENDED */, function (_a) {
var endClocks = _a.endClocks;
urlContextHistory.closeActive(endClocks.relative);
});
var locationChangeSubscription = locationChangeObservable.subscribe(function (_a) {

@@ -27,0 +27,0 @@ var newLocation = _a.newLocation;

@@ -5,10 +5,10 @@ import { SESSION_TIME_OUT_DELAY, ValueHistory } from '@datadog/browser-core';

var viewContextHistory = new ValueHistory(VIEW_CONTEXT_TIME_OUT_DELAY);
lifeCycle.subscribe(2 /* LifeCycleEventType.VIEW_CREATED */, function (view) {
lifeCycle.subscribe(2 /* LifeCycleEventType.BEFORE_VIEW_CREATED */, function (view) {
viewContextHistory.add(buildViewContext(view), view.startClocks.relative);
});
lifeCycle.subscribe(4 /* LifeCycleEventType.VIEW_ENDED */, function (_a) {
lifeCycle.subscribe(6 /* LifeCycleEventType.AFTER_VIEW_ENDED */, function (_a) {
var endClocks = _a.endClocks;
viewContextHistory.closeActive(endClocks.relative);
});
lifeCycle.subscribe(8 /* LifeCycleEventType.SESSION_RENEWED */, function () {
lifeCycle.subscribe(10 /* LifeCycleEventType.SESSION_RENEWED */, function () {
viewContextHistory.reset();

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

@@ -9,9 +9,9 @@ import { isEmptyObject, assign, ErrorSource, generateUUID, computeRawError, computeStackTrace, Observable, trackRuntimeError, } from '@datadog/browser-core';

trackReportError(configuration, errorObservable);
errorObservable.subscribe(function (error) { return lifeCycle.notify(12 /* LifeCycleEventType.RAW_ERROR_COLLECTED */, { error: error }); });
errorObservable.subscribe(function (error) { return lifeCycle.notify(14 /* LifeCycleEventType.RAW_ERROR_COLLECTED */, { error: error }); });
return doStartErrorCollection(lifeCycle, pageStateHistory, featureFlagContexts);
}
export function doStartErrorCollection(lifeCycle, pageStateHistory, featureFlagContexts) {
lifeCycle.subscribe(12 /* LifeCycleEventType.RAW_ERROR_COLLECTED */, function (_a) {
lifeCycle.subscribe(14 /* LifeCycleEventType.RAW_ERROR_COLLECTED */, function (_a) {
var error = _a.error, customerContext = _a.customerContext, savedCommonContext = _a.savedCommonContext;
lifeCycle.notify(10 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, assign({
lifeCycle.notify(12 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, assign({
customerContext: customerContext,

@@ -34,3 +34,3 @@ savedCommonContext: savedCommonContext,

});
lifeCycle.notify(12 /* LifeCycleEventType.RAW_ERROR_COLLECTED */, {
lifeCycle.notify(14 /* LifeCycleEventType.RAW_ERROR_COLLECTED */, {
customerContext: customerContext,

@@ -37,0 +37,0 @@ savedCommonContext: savedCommonContext,

@@ -14,13 +14,15 @@ import type { Context, PageExitEvent, RawError, RelativeTime } from '@datadog/browser-core';

AUTO_ACTION_COMPLETED = 1,
VIEW_CREATED = 2,
VIEW_UPDATED = 3,
VIEW_ENDED = 4,
REQUEST_STARTED = 5,
REQUEST_COMPLETED = 6,
SESSION_EXPIRED = 7,
SESSION_RENEWED = 8,
PAGE_EXITED = 9,
RAW_RUM_EVENT_COLLECTED = 10,
RUM_EVENT_COLLECTED = 11,
RAW_ERROR_COLLECTED = 12
BEFORE_VIEW_CREATED = 2,
VIEW_CREATED = 3,
VIEW_UPDATED = 4,
VIEW_ENDED = 5,
AFTER_VIEW_ENDED = 6,
REQUEST_STARTED = 7,
REQUEST_COMPLETED = 8,
SESSION_EXPIRED = 9,
SESSION_RENEWED = 10,
PAGE_EXITED = 11,
RAW_RUM_EVENT_COLLECTED = 12,
RUM_EVENT_COLLECTED = 13,
RAW_ERROR_COLLECTED = 14
}

@@ -30,5 +32,7 @@ declare const LifeCycleEventTypeAsConst: {

AUTO_ACTION_COMPLETED: LifeCycleEventType.AUTO_ACTION_COMPLETED;
BEFORE_VIEW_CREATED: LifeCycleEventType.BEFORE_VIEW_CREATED;
VIEW_CREATED: LifeCycleEventType.VIEW_CREATED;
VIEW_UPDATED: LifeCycleEventType.VIEW_UPDATED;
VIEW_ENDED: LifeCycleEventType.VIEW_ENDED;
AFTER_VIEW_ENDED: LifeCycleEventType.AFTER_VIEW_ENDED;
REQUEST_STARTED: LifeCycleEventType.REQUEST_STARTED;

@@ -46,5 +50,7 @@ REQUEST_COMPLETED: LifeCycleEventType.REQUEST_COMPLETED;

[LifeCycleEventTypeAsConst.AUTO_ACTION_COMPLETED]: AutoAction;
[LifeCycleEventTypeAsConst.BEFORE_VIEW_CREATED]: ViewCreatedEvent;
[LifeCycleEventTypeAsConst.VIEW_CREATED]: ViewCreatedEvent;
[LifeCycleEventTypeAsConst.VIEW_UPDATED]: ViewEvent;
[LifeCycleEventTypeAsConst.VIEW_ENDED]: ViewEndedEvent;
[LifeCycleEventTypeAsConst.AFTER_VIEW_ENDED]: ViewEndedEvent;
[LifeCycleEventTypeAsConst.REQUEST_STARTED]: RequestStartEvent;

@@ -51,0 +57,0 @@ [LifeCycleEventTypeAsConst.REQUEST_COMPLETED]: RequestCompleteEvent;

@@ -26,3 +26,3 @@ import { toServerDuration, relativeToClocks, generateUUID } from '@datadog/browser-core';

};
lifeCycle.notify(10 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, {
lifeCycle.notify(12 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, {
rawRumEvent: rawRumEvent,

@@ -29,0 +29,0 @@ startTime: startClocks.relative,

@@ -20,3 +20,3 @@ import { initFetchObservable, initXhrObservable, readBytesFromStream, elapsed, timeStampNow, tryToClone, } from '@datadog/browser-core';

context.requestIndex = getNextRequestIndex();
lifeCycle.notify(5 /* LifeCycleEventType.REQUEST_STARTED */, {
lifeCycle.notify(7 /* LifeCycleEventType.REQUEST_STARTED */, {
requestIndex: context.requestIndex,

@@ -28,3 +28,3 @@ url: context.url,

tracer.clearTracingIfNeeded(context);
lifeCycle.notify(6 /* LifeCycleEventType.REQUEST_COMPLETED */, {
lifeCycle.notify(8 /* LifeCycleEventType.REQUEST_COMPLETED */, {
duration: context.duration,

@@ -57,3 +57,3 @@ method: context.method,

context.requestIndex = getNextRequestIndex();
lifeCycle.notify(5 /* LifeCycleEventType.REQUEST_STARTED */, {
lifeCycle.notify(7 /* LifeCycleEventType.REQUEST_STARTED */, {
requestIndex: context.requestIndex,

@@ -66,3 +66,3 @@ url: context.url,

tracer.clearTracingIfNeeded(context);
lifeCycle.notify(6 /* LifeCycleEventType.REQUEST_COMPLETED */, {
lifeCycle.notify(8 /* LifeCycleEventType.REQUEST_COMPLETED */, {
duration: duration,

@@ -69,0 +69,0 @@ method: context.method,

@@ -6,6 +6,6 @@ import { combine, generateUUID, toServerDuration, relativeToClocks, assign, isNumber, isExperimentalFeatureEnabled, ExperimentalFeature, } from '@datadog/browser-core';

export function startResourceCollection(lifeCycle, configuration, sessionManager, pageStateHistory) {
lifeCycle.subscribe(6 /* LifeCycleEventType.REQUEST_COMPLETED */, function (request) {
lifeCycle.subscribe(8 /* LifeCycleEventType.REQUEST_COMPLETED */, function (request) {
var rawEvent = processRequest(request, configuration, sessionManager, pageStateHistory);
if (rawEvent) {
lifeCycle.notify(10 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, rawEvent);
lifeCycle.notify(12 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, rawEvent);
}

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

if (rawEvent) {
lifeCycle.notify(10 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, rawEvent);
lifeCycle.notify(12 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, rawEvent);
}

@@ -83,2 +83,3 @@ }

url: entry.name,
status_code: discardZeroStatus(entry.responseStatus),
},

@@ -157,2 +158,9 @@ type: "resource" /* RumEventType.RESOURCE */,

}
/**
* The status is 0 for cross origin resources without CORS headers, so the status is meaningless and we shouldn't report it
* https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/responseStatus#cross-origin_response_status_codes
*/
function discardZeroStatus(statusCode) {
return statusCode === 0 ? undefined : statusCode;
}
//# sourceMappingURL=resourceCollection.js.map

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

import type { RelativeTime } from '@datadog/browser-core';
import type { RelativeTime, TrackingConsentState } from '@datadog/browser-core';
import { Observable } from '@datadog/browser-core';

@@ -20,3 +20,3 @@ import type { RumConfiguration } from './configuration';

}
export declare function startRumSessionManager(configuration: RumConfiguration, lifeCycle: LifeCycle): RumSessionManager;
export declare function startRumSessionManager(configuration: RumConfiguration, lifeCycle: LifeCycle, trackingConsentState: TrackingConsentState): RumSessionManager;
/**

@@ -23,0 +23,0 @@ * Start a tracked replay session stub

import { Observable, noop, performDraw, startSessionManager } from '@datadog/browser-core';
export var RUM_SESSION_KEY = 'rum';
export function startRumSessionManager(configuration, lifeCycle) {
var sessionManager = startSessionManager(configuration, RUM_SESSION_KEY, function (rawTrackingType) {
return computeSessionState(configuration, rawTrackingType);
});
export function startRumSessionManager(configuration, lifeCycle, trackingConsentState) {
var sessionManager = startSessionManager(configuration, RUM_SESSION_KEY, function (rawTrackingType) { return computeSessionState(configuration, rawTrackingType); }, trackingConsentState);
sessionManager.expireObservable.subscribe(function () {
lifeCycle.notify(7 /* LifeCycleEventType.SESSION_EXPIRED */);
lifeCycle.notify(9 /* LifeCycleEventType.SESSION_EXPIRED */);
});
sessionManager.renewObservable.subscribe(function () {
lifeCycle.notify(8 /* LifeCycleEventType.SESSION_RENEWED */);
lifeCycle.notify(10 /* LifeCycleEventType.SESSION_RENEWED */);
});

@@ -13,0 +11,0 @@ return {

@@ -15,3 +15,3 @@ import { includes, performDraw, ONE_SECOND, addTelemetryDebug, setInterval, } from '@datadog/browser-core';

// It means that contexts bytes count sums can be higher than it really is
lifeCycle.subscribe(11 /* LifeCycleEventType.RUM_EVENT_COLLECTED */, function (event) {
lifeCycle.subscribe(13 /* LifeCycleEventType.RUM_EVENT_COLLECTED */, function (event) {
batchHasRumEvent = true;

@@ -18,0 +18,0 @@ updateMeasure(currentBatchMeasures.globalContextBytes, customerDataTrackerManager.getOrCreateTracker(2 /* CustomerDataType.GlobalContext */).getBytesCount());

@@ -11,5 +11,5 @@ import { noop } from '@datadog/browser-core';

};
var subscription = lifeCycle.subscribe(11 /* LifeCycleEventType.RUM_EVENT_COLLECTED */, function (event) {
var subscription = lifeCycle.subscribe(13 /* LifeCycleEventType.RUM_EVENT_COLLECTED */, function (event) {
var _a;
if (event.type === 'view' || !isChildEvent(event)) {
if (event.type === 'view' || event.type === 'vital' || !isChildEvent(event)) {
return;

@@ -16,0 +16,0 @@ }

@@ -31,3 +31,3 @@ import { noop, PageExitReason, shallowClone, elapsed, generateUUID, ONE_MINUTE, throttle, clocksNow, clocksOrigin, timeStampNow, display, looksLikeRelativeTime, setInterval, clearInterval, setTimeout, Observable, } from '@datadog/browser-core';

function startViewLifeCycle() {
lifeCycle.subscribe(8 /* LifeCycleEventType.SESSION_RENEWED */, function () {
lifeCycle.subscribe(10 /* LifeCycleEventType.SESSION_RENEWED */, function () {
// Renew view on session renewal

@@ -40,7 +40,7 @@ currentView = startNewView("route_change" /* ViewLoadingType.ROUTE_CHANGE */, undefined, {

});
lifeCycle.subscribe(7 /* LifeCycleEventType.SESSION_EXPIRED */, function () {
lifeCycle.subscribe(9 /* LifeCycleEventType.SESSION_EXPIRED */, function () {
currentView.end({ sessionIsActive: false });
});
// End the current view on page unload
lifeCycle.subscribe(9 /* LifeCycleEventType.PAGE_EXITED */, function (pageExitEvent) {
lifeCycle.subscribe(11 /* LifeCycleEventType.PAGE_EXITED */, function (pageExitEvent) {
if (pageExitEvent.reason === PageExitReason.UNLOADING || pageExitEvent.reason === PageExitReason.PAGEHIDE) {

@@ -94,3 +94,3 @@ currentView.end();

}
lifeCycle.notify(2 /* LifeCycleEventType.VIEW_CREATED */, {
var viewCreatedEvent = {
id: id,

@@ -101,3 +101,5 @@ name: name,

version: version,
});
};
lifeCycle.notify(2 /* LifeCycleEventType.BEFORE_VIEW_CREATED */, viewCreatedEvent);
lifeCycle.notify(3 /* LifeCycleEventType.VIEW_CREATED */, viewCreatedEvent);
// Update the view every time the measures are changing

@@ -120,3 +122,3 @@ var _a = throttle(triggerViewUpdate, THROTTLE_VIEW_UPDATE_PERIOD, {

var currentEnd = endClocks === undefined ? timeStampNow() : endClocks.timeStamp;
lifeCycle.notify(3 /* LifeCycleEventType.VIEW_UPDATED */, {
lifeCycle.notify(4 /* LifeCycleEventType.VIEW_UPDATED */, {
customTimings: customTimings,

@@ -154,3 +156,4 @@ documentVersion: documentVersion,

sessionIsActive = (_b = options.sessionIsActive) !== null && _b !== void 0 ? _b : true;
lifeCycle.notify(4 /* LifeCycleEventType.VIEW_ENDED */, { endClocks: endClocks });
lifeCycle.notify(5 /* LifeCycleEventType.VIEW_ENDED */, { endClocks: endClocks });
lifeCycle.notify(6 /* LifeCycleEventType.AFTER_VIEW_ENDED */, { endClocks: endClocks });
clearInterval(keepAliveIntervalId);

@@ -157,0 +160,0 @@ setViewEnd(endClocks.relative);

import { isEmptyObject, mapValues, toServerDuration, isNumber } from '@datadog/browser-core';
import { trackViews } from './trackViews';
export function startViewCollection(lifeCycle, configuration, location, domMutationObservable, locationChangeObservable, featureFlagContexts, pageStateHistory, recorderApi, initialViewOptions) {
lifeCycle.subscribe(3 /* LifeCycleEventType.VIEW_UPDATED */, function (view) {
return lifeCycle.notify(10 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, processViewUpdate(view, configuration, featureFlagContexts, recorderApi, pageStateHistory));
lifeCycle.subscribe(4 /* LifeCycleEventType.VIEW_UPDATED */, function (view) {
return lifeCycle.notify(12 /* LifeCycleEventType.RAW_RUM_EVENT_COLLECTED */, processViewUpdate(view, configuration, featureFlagContexts, recorderApi, pageStateHistory));
});

@@ -7,0 +7,0 @@ return trackViews(location, lifeCycle, domMutationObservable, configuration, locationChangeObservable, !configuration.trackViewsManually, initialViewOptions);

@@ -82,3 +82,3 @@ import { instrumentMethod, matchList, monitor, Observable, timeStampNow, setTimeout, clearTimeout, } from '@datadog/browser-core';

}
}), lifeCycle.subscribe(5 /* LifeCycleEventType.REQUEST_STARTED */, function (startEvent) {
}), lifeCycle.subscribe(7 /* LifeCycleEventType.REQUEST_STARTED */, function (startEvent) {
if (isExcludedUrl(configuration, startEvent.url)) {

@@ -92,3 +92,3 @@ return;

notifyPageActivity();
}), lifeCycle.subscribe(6 /* LifeCycleEventType.REQUEST_COMPLETED */, function (request) {
}), lifeCycle.subscribe(8 /* LifeCycleEventType.REQUEST_COMPLETED */, function (request) {
if (isExcludedUrl(configuration, request.url) ||

@@ -95,0 +95,0 @@ firstRequestIndex === undefined ||

@@ -5,3 +5,3 @@ /**

import type { RumEventType } from './rawRumEvent.types';
export type RumEventDomainContext<T extends RumEventType = any> = T extends RumEventType.VIEW ? RumViewEventDomainContext : T extends RumEventType.ACTION ? RumActionEventDomainContext : T extends RumEventType.RESOURCE ? RumFetchResourceEventDomainContext | RumXhrResourceEventDomainContext | RumOtherResourceEventDomainContext : T extends RumEventType.ERROR ? RumErrorEventDomainContext : T extends RumEventType.LONG_TASK ? RumLongTaskEventDomainContext : never;
export type RumEventDomainContext<T extends RumEventType = any> = T extends RumEventType.VIEW ? RumViewEventDomainContext : T extends RumEventType.ACTION ? RumActionEventDomainContext : T extends RumEventType.RESOURCE ? RumFetchResourceEventDomainContext | RumXhrResourceEventDomainContext | RumOtherResourceEventDomainContext : T extends RumEventType.ERROR ? RumErrorEventDomainContext : T extends RumEventType.LONG_TASK ? RumLongTaskEventDomainContext : T extends RumEventType.VITAL ? RumVitalEventDomainContext : never;
export interface RumViewEventDomainContext {

@@ -33,1 +33,3 @@ location: Readonly<Location>;

}
export interface RumVitalEventDomainContext {
}
export { RumPublicApi, makeRumPublicApi, RecorderApi } from './boot/rumPublicApi';
export { StartRum } from './boot/startRum';
export { RumEvent, RumActionEvent, CommonProperties, RumErrorEvent, RumViewEvent, RumResourceEvent, RumLongTaskEvent, } from './rumEvent.types';
export { RumEvent, RumActionEvent, CommonProperties, RumErrorEvent, RumViewEvent, RumResourceEvent, RumLongTaskEvent, RumVitalEvent, } from './rumEvent.types';
export { RumLongTaskEventDomainContext, RumErrorEventDomainContext, RumOtherResourceEventDomainContext, RumXhrResourceEventDomainContext, RumFetchResourceEventDomainContext, RumActionEventDomainContext, RumViewEventDomainContext, RumEventDomainContext, } from './domainContext.types';

@@ -9,3 +9,3 @@ export { ReplayStats, ActionType, RumEventType, FrustrationType, RawRumActionEvent } from './rawRumEvent.types';

export { ViewCreatedEvent } from './domain/view/trackViews';
export { ViewContexts, ViewContext } from './domain/contexts/viewContexts';
export { ViewContexts, ViewContext, startViewContexts } from './domain/contexts/viewContexts';
export { RumSessionManager, RumSession } from './domain/rumSessionManager';

@@ -12,0 +12,0 @@ export { getMutationObserverConstructor } from './browser/domMutationObservable';

export { makeRumPublicApi } from './boot/rumPublicApi';
export { startRum } from './boot/startRum';
export { LifeCycle } from './domain/lifeCycle';
export { startViewContexts } from './domain/contexts/viewContexts';
export { getMutationObserverConstructor } from './browser/domMutationObservable';

@@ -5,0 +6,0 @@ export { initViewportObservable, getViewportDimension } from './browser/viewportObservable';

@@ -8,3 +8,4 @@ import type { Context, Duration, ErrorSource, ErrorHandling, ResourceType, ServerDuration, TimeStamp, RawErrorCause, DefaultPrivacyLevel, Connectivity } from '@datadog/browser-core';

VIEW = "view",
RESOURCE = "resource"
RESOURCE = "resource",
VITAL = "vital"
}

@@ -194,3 +195,18 @@ export interface RawRumResourceEvent {

}
export type RawRumEvent = RawRumErrorEvent | RawRumResourceEvent | RawRumViewEvent | RawRumLongTaskEvent | RawRumActionEvent;
export interface RawRumVitalEvent {
date: TimeStamp;
type: RumEventType.VITAL;
vital: {
id: string;
name: string;
type: VitalType;
custom: {
[key: string]: number;
};
};
}
export declare const enum VitalType {
DURATION = "duration"
}
export type RawRumEvent = RawRumErrorEvent | RawRumResourceEvent | RawRumViewEvent | RawRumLongTaskEvent | RawRumActionEvent | RawRumVitalEvent;
export interface RumContext {

@@ -197,0 +213,0 @@ date: TimeStamp;

@@ -7,3 +7,3 @@ /**

*/
export type RumEvent = RumActionEvent | RumErrorEvent | RumLongTaskEvent | RumResourceEvent | RumViewEvent;
export type RumEvent = RumActionEvent | RumErrorEvent | RumLongTaskEvent | RumResourceEvent | RumViewEvent | RumVitalEvent;
/**

@@ -224,3 +224,3 @@ * Schema of all properties of an Action event

*/
readonly source_type?: 'android' | 'browser' | 'ios' | 'react-native' | 'flutter' | 'roku';
readonly source_type?: 'android' | 'browser' | 'ios' | 'react-native' | 'flutter' | 'roku' | 'ndk' | 'ios+il2cpp' | 'ndk+il2cpp';
/**

@@ -233,3 +233,3 @@ * Resource properties of the error

*/
readonly method: 'POST' | 'GET' | 'HEAD' | 'PUT' | 'DELETE' | 'PATCH';
readonly method: 'POST' | 'GET' | 'HEAD' | 'PUT' | 'DELETE' | 'PATCH' | 'TRACE' | 'OPTIONS' | 'CONNECT';
/**

@@ -263,2 +263,92 @@ * HTTP Status code of the resource

};
/**
* Description of each thread in the process when error happened.
*/
threads?: {
/**
* Name of the thread (e.g. 'Thread 0').
*/
readonly name: string;
/**
* Tells if the thread crashed.
*/
readonly crashed: boolean;
/**
* Unsymbolicated stack trace of the given thread.
*/
readonly stack: string;
/**
* Platform-specific state of the thread when its state was captured (CPU registers dump for iOS, thread state enum for Android, etc.).
*/
readonly state?: string;
[k: string]: unknown;
}[];
/**
* Description of each binary image (native libraries; for Android: .so files) loaded or referenced by the process/application.
*/
readonly binary_images?: {
/**
* Build UUID that uniquely identifies the binary image.
*/
readonly uuid: string;
/**
* Name of the library.
*/
readonly name: string;
/**
* Determines if it's a system or user library.
*/
readonly is_system: boolean;
/**
* Library's load address (hexadecimal).
*/
readonly load_address?: string;
/**
* Max value from the library address range (hexadecimal).
*/
readonly max_address?: string;
/**
* CPU architecture from the library.
*/
readonly arch?: string;
[k: string]: unknown;
}[];
/**
* A boolean value saying if any of the stack traces was truncated due to minification.
*/
readonly was_truncated?: boolean;
/**
* Platform-specific metadata of the error event.
*/
readonly meta?: {
/**
* The CPU architecture of the process that crashed.
*/
readonly code_type?: string;
/**
* Parent process information.
*/
readonly parent_process?: string;
/**
* A client-generated 16-byte UUID of the incident.
*/
readonly incident_identifier?: string;
/**
* The name of the crashed process.
*/
readonly process?: string;
/**
* The name of the corresponding BSD termination signal. (in case of iOS crash)
*/
readonly exception_type?: string;
/**
* CPU specific information about the exception encoded into 64-bit hexadecimal number preceded by the signal code.
*/
readonly exception_codes?: string;
/**
* The location of the executable.
*/
readonly path?: string;
[k: string]: unknown;
};
[k: string]: unknown;

@@ -345,3 +435,3 @@ };

*/
readonly method?: 'POST' | 'GET' | 'HEAD' | 'PUT' | 'DELETE' | 'PATCH';
readonly method?: 'POST' | 'GET' | 'HEAD' | 'PUT' | 'DELETE' | 'PATCH' | 'TRACE' | 'OPTIONS' | 'CONNECT';
/**

@@ -846,2 +936,36 @@ * URL of the resource

/**
* Schema of all properties of a Vital event
*/
export type RumVitalEvent = CommonProperties & ViewContainerSchema & {
/**
* RUM event type
*/
readonly type: 'vital';
/**
* Vital properties
*/
readonly vital: {
/**
* Type of the vital
*/
readonly type: 'duration';
/**
* UUID of the vital
*/
readonly id: string;
/**
* Name of the vital, as it is also used as facet path for its value, it must contain only letters, digits, or the characters - _ . @ $
*/
readonly name?: string;
/**
* User custom vital.
*/
readonly custom?: {
[k: string]: number;
};
[k: string]: unknown;
};
[k: string]: unknown;
};
/**
* Schema of common properties of RUM events

@@ -848,0 +972,0 @@ */

@@ -12,3 +12,3 @@ import { combine, isTelemetryReplicationAllowed, startBatchWithReplica, } from '@datadog/browser-core';

}, reportError, pageExitObservable, sessionExpireObservable);
lifeCycle.subscribe(11 /* LifeCycleEventType.RUM_EVENT_COLLECTED */, function (serverRumEvent) {
lifeCycle.subscribe(13 /* LifeCycleEventType.RUM_EVENT_COLLECTED */, function (serverRumEvent) {
if (serverRumEvent.type === "view" /* RumEventType.VIEW */) {

@@ -15,0 +15,0 @@ batch.upsert(serverRumEvent, serverRumEvent.view.id);

import { getEventBridge } from '@datadog/browser-core';
export function startRumEventBridge(lifeCycle) {
var bridge = getEventBridge();
lifeCycle.subscribe(11 /* LifeCycleEventType.RUM_EVENT_COLLECTED */, function (serverRumEvent) {
lifeCycle.subscribe(13 /* LifeCycleEventType.RUM_EVENT_COLLECTED */, function (serverRumEvent) {
bridge.send('rum', serverRumEvent);

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

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

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

"dependencies": {
"@datadog/browser-core": "5.9.0"
"@datadog/browser-core": "5.10.0"
},

@@ -32,3 +32,3 @@ "devDependencies": {

},
"gitHead": "465eecbc937d9ee15e2f0c03c5c574fe3e909aed"
"gitHead": "406566926cdbe6d4534be5a9774b973cb210d5e9"
}
import {
BoundedBuffer,
display,
type DeflateWorker,
canUseEventBridge,

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

} from '@datadog/browser-core'
import type { TrackingConsentState, DeflateWorker } from '@datadog/browser-core'
import {

@@ -27,2 +27,3 @@ validateAndBuildRumConfiguration,

getCommonContext: () => CommonContext,
trackingConsentState: TrackingConsentState,
doStartRum: (

@@ -44,7 +45,11 @@ initConfiguration: RumInitConfiguration,

const trackingConsentStateSubscription = trackingConsentState.observable.subscribe(tryStartRum)
function tryStartRum() {
if (!cachedInitConfiguration || !cachedConfiguration) {
if (!cachedInitConfiguration || !cachedConfiguration || !trackingConsentState.isGranted()) {
return
}
trackingConsentStateSubscription.unsubscribe()
let initialViewOptions: ViewOptions | undefined

@@ -125,2 +130,3 @@

cachedConfiguration = configuration
trackingConsentState.tryToInit(configuration.trackingConsent)
tryStartRum()

@@ -164,2 +170,10 @@ },

},
startDurationVital(vitalStart) {
bufferApiCalls.add((startRumResult) => startRumResult.startDurationVital(vitalStart))
},
stopDurationVital(vitalStart) {
bufferApiCalls.add((startRumResult) => startRumResult.stopDurationVital(vitalStart))
},
}

@@ -166,0 +180,0 @@ }

@@ -9,4 +9,8 @@ import type {

DeflateEncoder,
TrackingConsent,
} from '@datadog/browser-core'
import {
timeStampToClocks,
isExperimentalFeatureEnabled,
ExperimentalFeature,
CustomerDataType,

@@ -29,2 +33,3 @@ assign,

displayAlreadyInitializedError,
createTrackingConsentState,
} from '@datadog/browser-core'

@@ -85,2 +90,4 @@ import type { LifeCycle } from '../domain/lifeCycle'

addFeatureFlagEvaluation: StartRumResult['addFeatureFlagEvaluation']
startDurationVital: StartRumResult['startDurationVital']
stopDurationVital: StartRumResult['stopDurationVital']
}

@@ -94,2 +101,3 @@

const userContextManager = createContextManager(customerDataTrackerManager.getOrCreateTracker(CustomerDataType.User))
const trackingConsentState = createTrackingConsentState()

@@ -103,4 +111,43 @@ function getCommonContext() {

getCommonContext,
trackingConsentState,
(initConfiguration, configuration, deflateWorker, initialViewOptions) => {
if (isExperimentalFeatureEnabled(ExperimentalFeature.CUSTOM_VITALS)) {
/**
* Start a custom duration vital
* stored in @vital.custom.<name>
*
* @param name name of the custom vital
* @param options.context custom context attached to the vital
* @param options.startTime epoch timestamp of the start of the custom vital (if not set, will use current time)
*/
;(rumPublicApi as any).startDurationVital = monitor(
(name: string, options?: { context?: object; startTime?: number }) => {
strategy.startDurationVital({
name: sanitize(name)!,
startClocks: options?.startTime ? timeStampToClocks(options.startTime as TimeStamp) : clocksNow(),
context: sanitize(options?.context) as Context,
})
}
)
/**
* Stop a custom duration vital
* stored in @vital.custom.<name>
*
* @param name name of the custom vital
* @param options.context custom context attached to the vital
* @param options.stopTime epoch timestamp of the stop of the custom vital (if not set, will use current time)
*/
;(rumPublicApi as any).stopDurationVital = monitor(
(name: string, options?: { context?: object; stopTime?: number }) => {
strategy.stopDurationVital({
name: sanitize(name)!,
stopClocks: options?.stopTime ? timeStampToClocks(options.stopTime as TimeStamp) : clocksNow(),
context: sanitize(options?.context) as Context,
})
}
)
}
if (initConfiguration.storeContextsAcrossPages) {

@@ -124,3 +171,4 @@ storeContextManager(configuration, globalContextManager, RUM_STORAGE_KEY, CustomerDataType.GlobalContext)

? (streamId) => options.createDeflateEncoder!(configuration, deflateWorker, streamId)
: createIdentityEncoder
: createIdentityEncoder,
trackingConsentState
)

@@ -153,2 +201,16 @@

/**
* Set the tracking consent of the current user.
*
* @param {"granted" | "not-granted"} trackingConsent The user tracking consent
*
* Data will be sent only if it is set to "granted". This value won't be stored by the library
* across page loads: you will need to call this method or set the appropriate `trackingConsent`
* field in the init() method at each page load.
*
* If this method is called before the init() method, the provided value will take precedence
* over the one provided as initialization parameter.
*/
setTrackingConsent: monitor((trackingConsent: TrackingConsent) => trackingConsentState.update(trackingConsent)),
setGlobalContextProperty: monitor((key, value) => globalContextManager.setContextProperty(key, value)),

@@ -155,0 +217,0 @@

@@ -8,2 +8,3 @@ import type {

CustomerDataTrackerManager,
TrackingConsentState,
} from '@datadog/browser-core'

@@ -48,2 +49,3 @@ import {

import { startDisplayContext } from '../domain/contexts/displayContext'
import { startVitalCollection } from '../domain/vital/vitalCollection'
import type { RecorderApi } from './rumPublicApi'

@@ -61,3 +63,8 @@

initialViewOptions: ViewOptions | undefined,
createEncoder: (streamId: DeflateEncoderStreamId) => Encoder
createEncoder: (streamId: DeflateEncoderStreamId) => Encoder,
// `startRum` and its subcomponents assume tracking consent is granted initially and starts
// collecting logs unconditionally. As such, `startRum` should be called with a
// `trackingConsentState` set to "granted".
trackingConsentState: TrackingConsentState
) {

@@ -100,3 +107,5 @@ const cleanupTasks: Array<() => void> = []

const session = !canUseEventBridge() ? startRumSessionManager(configuration, lifeCycle) : startRumSessionManagerStub()
const session = !canUseEventBridge()
? startRumSessionManager(configuration, lifeCycle, trackingConsentState)
: startRumSessionManagerStub()
if (!canUseEventBridge()) {

@@ -168,2 +177,3 @@ const batch = startRumBatch(

const vitalCollection = startVitalCollection(lifeCycle)
const internalContext = startInternalContext(

@@ -188,2 +198,4 @@ configuration.applicationId,

getInternalContext: internalContext.get,
startDurationVital: vitalCollection.startDurationVital,
stopDurationVital: vitalCollection.stopDurationVital,
stop: () => {

@@ -190,0 +202,0 @@ cleanupTasks.forEach((task) => task())

@@ -52,2 +52,3 @@ import type { Duration, RelativeTime, TimeStamp } from '@datadog/browser-core'

initiatorType: string
responseStatus?: number
name: string

@@ -54,0 +55,0 @@ startTime: RelativeTime

@@ -104,2 +104,3 @@ import type { Context, RawError, EventRateLimiter, User } from '@datadog/browser-core'

[RumEventType.LONG_TASK]: assign({}, USER_CUSTOMIZABLE_FIELD_PATHS, VIEW_MODIFIABLE_FIELD_PATHS),
[RumEventType.VITAL]: assign({}, USER_CUSTOMIZABLE_FIELD_PATHS, VIEW_MODIFIABLE_FIELD_PATHS),
}

@@ -117,2 +118,7 @@ const eventRateLimiters = {

),
[RumEventType.VITAL]: createEventRateLimiter(
RumEventType.VITAL,
configuration.eventRateLimiterThreshold,
reportError
),
}

@@ -119,0 +125,0 @@

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

lifeCycle.subscribe(LifeCycleEventType.VIEW_ENDED, ({ endClocks }) => {
featureFlagContexts.closeActive(endClocks.relative)
})
lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED, ({ startClocks }) => {
lifeCycle.subscribe(LifeCycleEventType.BEFORE_VIEW_CREATED, ({ startClocks }) => {
featureFlagContexts.add({}, startClocks.relative)

@@ -55,2 +51,6 @@ customerDataTracker.resetCustomerData()

lifeCycle.subscribe(LifeCycleEventType.AFTER_VIEW_ENDED, ({ endClocks }) => {
featureFlagContexts.closeActive(endClocks.relative)
})
return {

@@ -57,0 +57,0 @@ findFeatureFlagEvaluations: (startTime?: RelativeTime) => featureFlagContexts.find(startTime),

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

lifeCycle.subscribe(LifeCycleEventType.VIEW_ENDED, ({ endClocks }) => {
urlContextHistory.closeActive(endClocks.relative)
})
lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED, ({ startClocks }) => {
lifeCycle.subscribe(LifeCycleEventType.BEFORE_VIEW_CREATED, ({ startClocks }) => {
const viewUrl = location.href

@@ -51,2 +47,6 @@ urlContextHistory.add(

lifeCycle.subscribe(LifeCycleEventType.AFTER_VIEW_ENDED, ({ endClocks }) => {
urlContextHistory.closeActive(endClocks.relative)
})
const locationChangeSubscription = locationChangeObservable.subscribe(({ newLocation }) => {

@@ -53,0 +53,0 @@ const current = urlContextHistory.find()

@@ -25,7 +25,7 @@ import type { RelativeTime, ClocksState } from '@datadog/browser-core'

lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED, (view) => {
lifeCycle.subscribe(LifeCycleEventType.BEFORE_VIEW_CREATED, (view) => {
viewContextHistory.add(buildViewContext(view), view.startClocks.relative)
})
lifeCycle.subscribe(LifeCycleEventType.VIEW_ENDED, ({ endClocks }) => {
lifeCycle.subscribe(LifeCycleEventType.AFTER_VIEW_ENDED, ({ endClocks }) => {
viewContextHistory.closeActive(endClocks.relative)

@@ -32,0 +32,0 @@ })

@@ -13,10 +13,13 @@ import type { Context, PageExitEvent, RawError, RelativeTime } from '@datadog/browser-core'

export const enum LifeCycleEventType {
// Contexts (like viewContexts) should be opened using prefixed BEFORE_XXX events and closed using prefixed AFTER_XXX events
// It ensures the context is available during the non prefixed event callbacks
PERFORMANCE_ENTRIES_COLLECTED,
AUTO_ACTION_COMPLETED,
BEFORE_VIEW_CREATED,
VIEW_CREATED,
VIEW_UPDATED,
VIEW_ENDED,
AFTER_VIEW_ENDED,
REQUEST_STARTED,
REQUEST_COMPLETED,
// The SESSION_EXPIRED lifecycle event has been introduced to represent when a session has expired

@@ -33,3 +36,2 @@ // and trigger cleanup tasks related to this, prior to renewing the session. Its implementation is

SESSION_EXPIRED,
SESSION_RENEWED,

@@ -58,5 +60,7 @@ PAGE_EXITED,

AUTO_ACTION_COMPLETED: LifeCycleEventType.AUTO_ACTION_COMPLETED
BEFORE_VIEW_CREATED: LifeCycleEventType.BEFORE_VIEW_CREATED
VIEW_CREATED: LifeCycleEventType.VIEW_CREATED
VIEW_UPDATED: LifeCycleEventType.VIEW_UPDATED
VIEW_ENDED: LifeCycleEventType.VIEW_ENDED
AFTER_VIEW_ENDED: LifeCycleEventType.AFTER_VIEW_ENDED
REQUEST_STARTED: LifeCycleEventType.REQUEST_STARTED

@@ -77,5 +81,7 @@ REQUEST_COMPLETED: LifeCycleEventType.REQUEST_COMPLETED

[LifeCycleEventTypeAsConst.AUTO_ACTION_COMPLETED]: AutoAction
[LifeCycleEventTypeAsConst.BEFORE_VIEW_CREATED]: ViewCreatedEvent
[LifeCycleEventTypeAsConst.VIEW_CREATED]: ViewCreatedEvent
[LifeCycleEventTypeAsConst.VIEW_UPDATED]: ViewEvent
[LifeCycleEventTypeAsConst.VIEW_ENDED]: ViewEndedEvent
[LifeCycleEventTypeAsConst.AFTER_VIEW_ENDED]: ViewEndedEvent
[LifeCycleEventTypeAsConst.REQUEST_STARTED]: RequestStartEvent

@@ -82,0 +88,0 @@ [LifeCycleEventTypeAsConst.REQUEST_COMPLETED]: RequestCompleteEvent

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

)
return {

@@ -146,2 +145,3 @@ startTime: startClocks.relative,

url: entry.name,
status_code: discardZeroStatus(entry.responseStatus),
},

@@ -240,1 +240,9 @@ type: RumEventType.RESOURCE as const,

}
/**
* The status is 0 for cross origin resources without CORS headers, so the status is meaningless and we shouldn't report it
* https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/responseStatus#cross-origin_response_status_codes
*/
function discardZeroStatus(statusCode: number | undefined): number | undefined {
return statusCode === 0 ? undefined : statusCode
}

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

import type { RelativeTime } from '@datadog/browser-core'
import type { RelativeTime, TrackingConsentState } from '@datadog/browser-core'
import { Observable, noop, performDraw, startSessionManager } from '@datadog/browser-core'

@@ -26,5 +26,12 @@ import type { RumConfiguration } from './configuration'

export function startRumSessionManager(configuration: RumConfiguration, lifeCycle: LifeCycle): RumSessionManager {
const sessionManager = startSessionManager(configuration, RUM_SESSION_KEY, (rawTrackingType) =>
computeSessionState(configuration, rawTrackingType)
export function startRumSessionManager(
configuration: RumConfiguration,
lifeCycle: LifeCycle,
trackingConsentState: TrackingConsentState
): RumSessionManager {
const sessionManager = startSessionManager(
configuration,
RUM_SESSION_KEY,
(rawTrackingType) => computeSessionState(configuration, rawTrackingType),
trackingConsentState
)

@@ -31,0 +38,0 @@

@@ -33,3 +33,3 @@ import { noop } from '@datadog/browser-core'

const subscription = lifeCycle.subscribe(LifeCycleEventType.RUM_EVENT_COLLECTED, (event): void => {
if (event.type === 'view' || !isChildEvent(event)) {
if (event.type === 'view' || event.type === 'vital' || !isChildEvent(event)) {
return

@@ -36,0 +36,0 @@ }

@@ -192,3 +192,3 @@ import type { Duration, ClocksState, TimeStamp, Subscription, RelativeTime } from '@datadog/browser-core'

lifeCycle.notify(LifeCycleEventType.VIEW_CREATED, {
const viewCreatedEvent = {
id,

@@ -199,3 +199,5 @@ name,

version,
})
}
lifeCycle.notify(LifeCycleEventType.BEFORE_VIEW_CREATED, viewCreatedEvent)
lifeCycle.notify(LifeCycleEventType.VIEW_CREATED, viewCreatedEvent)

@@ -277,2 +279,3 @@ // Update the view every time the measures are changing

lifeCycle.notify(LifeCycleEventType.VIEW_ENDED, { endClocks })
lifeCycle.notify(LifeCycleEventType.AFTER_VIEW_ENDED, { endClocks })
clearInterval(keepAliveIntervalId)

@@ -279,0 +282,0 @@ setViewEnd(endClocks.relative)

@@ -17,3 +17,5 @@ /**

? RumLongTaskEventDomainContext
: never
: T extends RumEventType.VITAL
? RumVitalEventDomainContext
: never

@@ -52,1 +54,3 @@ export interface RumViewEventDomainContext {

}
export interface RumVitalEventDomainContext {}

@@ -11,2 +11,3 @@ export { RumPublicApi, makeRumPublicApi, RecorderApi } from './boot/rumPublicApi'

RumLongTaskEvent,
RumVitalEvent,
} from './rumEvent.types'

@@ -27,3 +28,3 @@ export {

export { ViewCreatedEvent } from './domain/view/trackViews'
export { ViewContexts, ViewContext } from './domain/contexts/viewContexts'
export { ViewContexts, ViewContext, startViewContexts } from './domain/contexts/viewContexts'
export { RumSessionManager, RumSession } from './domain/rumSessionManager'

@@ -30,0 +31,0 @@ export { getMutationObserverConstructor } from './browser/domMutationObservable'

@@ -21,2 +21,3 @@ import type {

RESOURCE = 'resource',
VITAL = 'vital',
}

@@ -219,2 +220,19 @@

export interface RawRumVitalEvent {
date: TimeStamp
type: RumEventType.VITAL
vital: {
id: string
name: string
type: VitalType
custom: {
[key: string]: number
}
}
}
export const enum VitalType {
DURATION = 'duration',
}
export type RawRumEvent =

@@ -226,2 +244,3 @@ | RawRumErrorEvent

| RawRumActionEvent
| RawRumVitalEvent

@@ -228,0 +247,0 @@ export interface RumContext {

@@ -9,3 +9,9 @@ /* eslint-disable */

*/
export type RumEvent = RumActionEvent | RumErrorEvent | RumLongTaskEvent | RumResourceEvent | RumViewEvent
export type RumEvent =
| RumActionEvent
| RumErrorEvent
| RumLongTaskEvent
| RumResourceEvent
| RumViewEvent
| RumVitalEvent
/**

@@ -229,3 +235,12 @@ * Schema of all properties of an Action event

*/
readonly source_type?: 'android' | 'browser' | 'ios' | 'react-native' | 'flutter' | 'roku'
readonly source_type?:
| 'android'
| 'browser'
| 'ios'
| 'react-native'
| 'flutter'
| 'roku'
| 'ndk'
| 'ios+il2cpp'
| 'ndk+il2cpp'
/**

@@ -238,3 +253,3 @@ * Resource properties of the error

*/
readonly method: 'POST' | 'GET' | 'HEAD' | 'PUT' | 'DELETE' | 'PATCH'
readonly method: 'POST' | 'GET' | 'HEAD' | 'PUT' | 'DELETE' | 'PATCH' | 'TRACE' | 'OPTIONS' | 'CONNECT'
/**

@@ -282,2 +297,92 @@ * HTTP Status code of the resource

}
/**
* Description of each thread in the process when error happened.
*/
threads?: {
/**
* Name of the thread (e.g. 'Thread 0').
*/
readonly name: string
/**
* Tells if the thread crashed.
*/
readonly crashed: boolean
/**
* Unsymbolicated stack trace of the given thread.
*/
readonly stack: string
/**
* Platform-specific state of the thread when its state was captured (CPU registers dump for iOS, thread state enum for Android, etc.).
*/
readonly state?: string
[k: string]: unknown
}[]
/**
* Description of each binary image (native libraries; for Android: .so files) loaded or referenced by the process/application.
*/
readonly binary_images?: {
/**
* Build UUID that uniquely identifies the binary image.
*/
readonly uuid: string
/**
* Name of the library.
*/
readonly name: string
/**
* Determines if it's a system or user library.
*/
readonly is_system: boolean
/**
* Library's load address (hexadecimal).
*/
readonly load_address?: string
/**
* Max value from the library address range (hexadecimal).
*/
readonly max_address?: string
/**
* CPU architecture from the library.
*/
readonly arch?: string
[k: string]: unknown
}[]
/**
* A boolean value saying if any of the stack traces was truncated due to minification.
*/
readonly was_truncated?: boolean
/**
* Platform-specific metadata of the error event.
*/
readonly meta?: {
/**
* The CPU architecture of the process that crashed.
*/
readonly code_type?: string
/**
* Parent process information.
*/
readonly parent_process?: string
/**
* A client-generated 16-byte UUID of the incident.
*/
readonly incident_identifier?: string
/**
* The name of the crashed process.
*/
readonly process?: string
/**
* The name of the corresponding BSD termination signal. (in case of iOS crash)
*/
readonly exception_type?: string
/**
* CPU specific information about the exception encoded into 64-bit hexadecimal number preceded by the signal code.
*/
readonly exception_codes?: string
/**
* The location of the executable.
*/
readonly path?: string
[k: string]: unknown
}
[k: string]: unknown

@@ -379,3 +484,3 @@ }

*/
readonly method?: 'POST' | 'GET' | 'HEAD' | 'PUT' | 'DELETE' | 'PATCH'
readonly method?: 'POST' | 'GET' | 'HEAD' | 'PUT' | 'DELETE' | 'PATCH' | 'TRACE' | 'OPTIONS' | 'CONNECT'
/**

@@ -902,2 +1007,37 @@ * URL of the resource

}
/**
* Schema of all properties of a Vital event
*/
export type RumVitalEvent = CommonProperties &
ViewContainerSchema & {
/**
* RUM event type
*/
readonly type: 'vital'
/**
* Vital properties
*/
readonly vital: {
/**
* Type of the vital
*/
readonly type: 'duration'
/**
* UUID of the vital
*/
readonly id: string
/**
* Name of the vital, as it is also used as facet path for its value, it must contain only letters, digits, or the characters - _ . @ $
*/
readonly name?: string
/**
* User custom vital.
*/
readonly custom?: {
[k: string]: number
}
[k: string]: unknown
}
[k: string]: unknown
}

@@ -904,0 +1044,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