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

@datadog/browser-rum-core

Package Overview
Dependencies
Maintainers
1
Versions
182
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 2.16.0 to 2.17.0

2

cjs/boot/buildEnv.js

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

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

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

import { Context, UserConfiguration, Configuration, InternalMonitoring } from '@datadog/browser-core';
import { Context, InitConfiguration, Configuration, InternalMonitoring } from '@datadog/browser-core';
import { ProvidedSource } from '../domain/rumEventsCollection/error/errorCollection';

@@ -7,11 +7,16 @@ import { RumEventDomainContext } from '../domainContext.types';

import { startRum } from './startRum';
export interface RumUserConfiguration extends UserConfiguration {
export interface RumInitConfiguration extends InitConfiguration {
applicationId: string;
beforeSend?: (event: RumEvent, context: RumEventDomainContext) => void | boolean;
}
/**
* TODO: remove this type in the next major release
* @deprecated Use RumInitConfiguration instead
*/
export declare type RumUserConfiguration = RumInitConfiguration;
export declare type RumPublicApi = ReturnType<typeof makeRumPublicApi>;
export declare type StartRum<C extends RumUserConfiguration = RumUserConfiguration> = (userConfiguration: C, configuration: Configuration, internalMonitoring: InternalMonitoring, getCommonContext: () => CommonContext, initialViewName?: string) => StartRumResult;
export declare type StartRum<C extends RumInitConfiguration = RumInitConfiguration> = (initConfiguration: C, configuration: Configuration, internalMonitoring: InternalMonitoring, getCommonContext: () => CommonContext, initialViewName?: string) => StartRumResult;
declare type StartRumResult = ReturnType<typeof startRum>;
export declare function makeRumPublicApi<C extends RumUserConfiguration>(startRumImpl: StartRum<C>): {
init: (userConfiguration: C) => void;
export declare function makeRumPublicApi<C extends RumInitConfiguration>(startRumImpl: StartRum<C>): {
init: (initConfiguration: C) => void;
addRumGlobalContext: (key: string, value: any) => void;

@@ -22,2 +27,3 @@ removeRumGlobalContext: (key: string) => void;

getInternalContext: (startTime?: number | undefined) => import("../rawRumEvent.types").InternalContext | undefined;
getInitConfiguration: () => InitConfiguration | undefined;
addAction: (name: string, context?: object | undefined) => void;

@@ -32,2 +38,3 @@ /**

removeUser: () => void;
startView: (name?: string | undefined) => void;
} & {

@@ -34,0 +41,0 @@ onReady(callback: () => void): void;

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

var getInternalContextStrategy = function () { return undefined; };
var getInitConfigurationStrategy = function () { return undefined; };
var bufferApiCalls = new browser_core_1.BoundedBuffer();

@@ -36,13 +37,13 @@ var addTimingStrategy = function (name, time) {

}
function initRum(userConfiguration) {
if (!browser_core_1.checkCookiesAuthorized(browser_core_1.buildCookieOptions(userConfiguration)) ||
function initRum(initConfiguration) {
if (!browser_core_1.checkCookiesAuthorized(browser_core_1.buildCookieOptions(initConfiguration)) ||
!browser_core_1.checkIsNotLocalFile() ||
!canInitRum(userConfiguration)) {
!canInitRum(initConfiguration)) {
return;
}
if (userConfiguration.publicApiKey) {
userConfiguration.clientToken = userConfiguration.publicApiKey;
if (initConfiguration.publicApiKey) {
initConfiguration.clientToken = initConfiguration.publicApiKey;
}
var _a = browser_core_1.commonInit(userConfiguration, buildEnv_1.buildEnv), configuration = _a.configuration, internalMonitoring = _a.internalMonitoring;
if (!configuration.isEnabled('view-renaming') || !configuration.trackViewsManually) {
var _a = browser_core_1.commonInit(initConfiguration, buildEnv_1.buildEnv), configuration = _a.configuration, internalMonitoring = _a.internalMonitoring;
if (!configuration.trackViewsManually) {
doStartRum();

@@ -61,13 +62,11 @@ }

}
getInitConfigurationStrategy = function () { return browser_core_1.deepClone(initConfiguration); };
isAlreadyInitialized = true;
function doStartRum(initialViewName) {
var _a;
var startView;
(_a = startRumImpl(userConfiguration, configuration, internalMonitoring, function () { return ({
;
(_a = startRumImpl(initConfiguration, configuration, internalMonitoring, function () { return ({
user: user,
context: globalContextManager.get(),
}); }, initialViewName), startView = _a.startView, addActionStrategy = _a.addAction, addErrorStrategy = _a.addError, addTimingStrategy = _a.addTiming, getInternalContextStrategy = _a.getInternalContext);
if (configuration.isEnabled('view-renaming')) {
startViewStrategy = startView;
}
}); }, initialViewName), startViewStrategy = _a.startView, addActionStrategy = _a.addAction, addErrorStrategy = _a.addError, addTimingStrategy = _a.addTiming, getInternalContextStrategy = _a.getInternalContext);
bufferApiCalls.drain();

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

getInternalContext: browser_core_1.monitor(function (startTime) { return getInternalContextStrategy(startTime); }),
getInitConfiguration: browser_core_1.monitor(function () { return getInitConfigurationStrategy(); }),
addAction: browser_core_1.monitor(function (name, context) {

@@ -134,6 +134,6 @@ addActionStrategy({

}),
startView: browser_core_1.monitor(function (name) {
startViewStrategy(name);
}),
});
rumPublicApi['startView'] = browser_core_1.monitor(function (name) {
startViewStrategy(name);
});
return rumPublicApi;

@@ -156,5 +156,5 @@ function sanitizeUser(newUser) {

}
function canInitRum(userConfiguration) {
function canInitRum(initConfiguration) {
if (isAlreadyInitialized) {
if (!userConfiguration.silentMultipleInit) {
if (!initConfiguration.silentMultipleInit) {
browser_core_1.display.error('DD_RUM is already initialized.');

@@ -164,21 +164,21 @@ }

}
if (!userConfiguration || (!userConfiguration.clientToken && !userConfiguration.publicApiKey)) {
if (!initConfiguration || (!initConfiguration.clientToken && !initConfiguration.publicApiKey)) {
browser_core_1.display.error('Client Token is not configured, we will not send any data.');
return false;
}
if (!userConfiguration.applicationId) {
if (!initConfiguration.applicationId) {
browser_core_1.display.error('Application ID is not configured, no RUM data will be collected.');
return false;
}
if (userConfiguration.sampleRate !== undefined && !browser_core_1.isPercentage(userConfiguration.sampleRate)) {
if (initConfiguration.sampleRate !== undefined && !browser_core_1.isPercentage(initConfiguration.sampleRate)) {
browser_core_1.display.error('Sample Rate should be a number between 0 and 100');
return false;
}
if (userConfiguration.resourceSampleRate !== undefined && !browser_core_1.isPercentage(userConfiguration.resourceSampleRate)) {
if (initConfiguration.resourceSampleRate !== undefined && !browser_core_1.isPercentage(initConfiguration.resourceSampleRate)) {
browser_core_1.display.error('Resource Sample Rate should be a number between 0 and 100');
return false;
}
if (Array.isArray(userConfiguration.allowedTracingOrigins) &&
userConfiguration.allowedTracingOrigins.length !== 0 &&
userConfiguration.service === undefined) {
if (Array.isArray(initConfiguration.allowedTracingOrigins) &&
initConfiguration.allowedTracingOrigins.length !== 0 &&
initConfiguration.service === undefined) {
browser_core_1.display.error('Service need to be configured when tracing is enabled');

@@ -185,0 +185,0 @@ return false;

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

import { CommonContext } from '../rawRumEvent.types';
import { RumUserConfiguration } from './rumPublicApi';
export declare function startRum(userConfiguration: RumUserConfiguration, configuration: Configuration, internalMonitoring: InternalMonitoring, getCommonContext: () => CommonContext, initialViewName?: string): {
import { RumInitConfiguration } from './rumPublicApi';
export declare function startRum(initConfiguration: RumInitConfiguration, configuration: Configuration, internalMonitoring: InternalMonitoring, getCommonContext: () => CommonContext, initialViewName?: string): {
addAction: (action: import("../domain/rumEventsCollection/action/trackActions").CustomAction, savedCommonContext?: CommonContext | undefined) => void;

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

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

var batch_1 = require("../transport/batch");
function startRum(userConfiguration, configuration, internalMonitoring, getCommonContext, initialViewName) {
function startRum(initConfiguration, configuration, internalMonitoring, getCommonContext, initialViewName) {
var lifeCycle = new lifeCycle_1.LifeCycle();

@@ -27,6 +27,6 @@ var session = rumSession_1.startRumSession(configuration, lifeCycle);

return browser_core_1.combine({
application_id: userConfiguration.applicationId,
application_id: initConfiguration.applicationId,
}, parentContexts.findView(), getCommonContext().context);
});
var _a = startRumEventCollection(userConfiguration.applicationId, lifeCycle, configuration, session, getCommonContext), parentContexts = _a.parentContexts, foregroundContexts = _a.foregroundContexts;
var _a = startRumEventCollection(initConfiguration.applicationId, lifeCycle, configuration, session, getCommonContext), parentContexts = _a.parentContexts, foregroundContexts = _a.foregroundContexts;
longTaskCollection_1.startLongTaskCollection(lifeCycle);

@@ -39,3 +39,3 @@ resourceCollection_1.startResourceCollection(lifeCycle, session);

performanceCollection_1.startPerformanceCollection(lifeCycle, configuration);
var internalContext = internalContext_1.startInternalContext(userConfiguration.applicationId, session, parentContexts);
var internalContext = internalContext_1.startInternalContext(initConfiguration.applicationId, session, parentContexts);
return {

@@ -42,0 +42,0 @@ addAction: addAction,

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

});
var shouldTrackViewsAutomatically = !configuration.isEnabled('view-renaming') || !configuration.trackViewsManually;
return trackViews_1.trackViews(location, lifeCycle, domMutationObservable, shouldTrackViewsAutomatically, initialViewName);
return trackViews_1.trackViews(location, lifeCycle, domMutationObservable, !configuration.trackViewsManually, initialViewName);
}

@@ -16,0 +15,0 @@ exports.startViewCollection = startViewCollection;

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

export { RumUserConfiguration, RumPublicApi, makeRumPublicApi, StartRum } from './boot/rumPublicApi';
export { RumInitConfiguration, RumUserConfiguration, RumPublicApi, makeRumPublicApi, StartRum, } from './boot/rumPublicApi';
export { ProvidedSource } from './domain/rumEventsCollection/error/errorCollection';

@@ -3,0 +3,0 @@ export { RumEvent, RumActionEvent, CommonProperties, RumErrorEvent, RumViewEvent, RumResourceEvent, RumLongTaskEvent, } from './rumEvent.types';

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

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

import { Context, UserConfiguration, Configuration, InternalMonitoring } from '@datadog/browser-core';
import { Context, InitConfiguration, Configuration, InternalMonitoring } from '@datadog/browser-core';
import { ProvidedSource } from '../domain/rumEventsCollection/error/errorCollection';

@@ -7,11 +7,16 @@ import { RumEventDomainContext } from '../domainContext.types';

import { startRum } from './startRum';
export interface RumUserConfiguration extends UserConfiguration {
export interface RumInitConfiguration extends InitConfiguration {
applicationId: string;
beforeSend?: (event: RumEvent, context: RumEventDomainContext) => void | boolean;
}
/**
* TODO: remove this type in the next major release
* @deprecated Use RumInitConfiguration instead
*/
export declare type RumUserConfiguration = RumInitConfiguration;
export declare type RumPublicApi = ReturnType<typeof makeRumPublicApi>;
export declare type StartRum<C extends RumUserConfiguration = RumUserConfiguration> = (userConfiguration: C, configuration: Configuration, internalMonitoring: InternalMonitoring, getCommonContext: () => CommonContext, initialViewName?: string) => StartRumResult;
export declare type StartRum<C extends RumInitConfiguration = RumInitConfiguration> = (initConfiguration: C, configuration: Configuration, internalMonitoring: InternalMonitoring, getCommonContext: () => CommonContext, initialViewName?: string) => StartRumResult;
declare type StartRumResult = ReturnType<typeof startRum>;
export declare function makeRumPublicApi<C extends RumUserConfiguration>(startRumImpl: StartRum<C>): {
init: (userConfiguration: C) => void;
export declare function makeRumPublicApi<C extends RumInitConfiguration>(startRumImpl: StartRum<C>): {
init: (initConfiguration: C) => void;
addRumGlobalContext: (key: string, value: any) => void;

@@ -22,2 +27,3 @@ removeRumGlobalContext: (key: string) => void;

getInternalContext: (startTime?: number | undefined) => import("../rawRumEvent.types").InternalContext | undefined;
getInitConfiguration: () => InitConfiguration | undefined;
addAction: (name: string, context?: object | undefined) => void;

@@ -32,2 +38,3 @@ /**

removeUser: () => void;
startView: (name?: string | undefined) => void;
} & {

@@ -34,0 +41,0 @@ onReady(callback: () => void): void;

@@ -9,2 +9,3 @@ import { BoundedBuffer, buildCookieOptions, checkCookiesAuthorized, checkIsNotLocalFile, createContextManager, deepClone, ErrorSource, isPercentage, makePublicApi, monitor, clocksNow, timeStampNow, display, commonInit, callMonitored, createHandlingStack, } from '@datadog/browser-core';

var getInternalContextStrategy = function () { return undefined; };
var getInitConfigurationStrategy = function () { return undefined; };
var bufferApiCalls = new BoundedBuffer();

@@ -33,13 +34,13 @@ var addTimingStrategy = function (name, time) {

}
function initRum(userConfiguration) {
if (!checkCookiesAuthorized(buildCookieOptions(userConfiguration)) ||
function initRum(initConfiguration) {
if (!checkCookiesAuthorized(buildCookieOptions(initConfiguration)) ||
!checkIsNotLocalFile() ||
!canInitRum(userConfiguration)) {
!canInitRum(initConfiguration)) {
return;
}
if (userConfiguration.publicApiKey) {
userConfiguration.clientToken = userConfiguration.publicApiKey;
if (initConfiguration.publicApiKey) {
initConfiguration.clientToken = initConfiguration.publicApiKey;
}
var _a = commonInit(userConfiguration, buildEnv), configuration = _a.configuration, internalMonitoring = _a.internalMonitoring;
if (!configuration.isEnabled('view-renaming') || !configuration.trackViewsManually) {
var _a = commonInit(initConfiguration, buildEnv), configuration = _a.configuration, internalMonitoring = _a.internalMonitoring;
if (!configuration.trackViewsManually) {
doStartRum();

@@ -58,13 +59,11 @@ }

}
getInitConfigurationStrategy = function () { return deepClone(initConfiguration); };
isAlreadyInitialized = true;
function doStartRum(initialViewName) {
var _a;
var startView;
(_a = startRumImpl(userConfiguration, configuration, internalMonitoring, function () { return ({
;
(_a = startRumImpl(initConfiguration, configuration, internalMonitoring, function () { return ({
user: user,
context: globalContextManager.get(),
}); }, initialViewName), startView = _a.startView, addActionStrategy = _a.addAction, addErrorStrategy = _a.addError, addTimingStrategy = _a.addTiming, getInternalContextStrategy = _a.getInternalContext);
if (configuration.isEnabled('view-renaming')) {
startViewStrategy = startView;
}
}); }, initialViewName), startViewStrategy = _a.startView, addActionStrategy = _a.addAction, addErrorStrategy = _a.addError, addTimingStrategy = _a.addTiming, getInternalContextStrategy = _a.getInternalContext);
bufferApiCalls.drain();

@@ -80,2 +79,3 @@ }

getInternalContext: monitor(function (startTime) { return getInternalContextStrategy(startTime); }),
getInitConfiguration: monitor(function () { return getInitConfigurationStrategy(); }),
addAction: monitor(function (name, context) {

@@ -131,6 +131,6 @@ addActionStrategy({

}),
startView: monitor(function (name) {
startViewStrategy(name);
}),
});
rumPublicApi['startView'] = monitor(function (name) {
startViewStrategy(name);
});
return rumPublicApi;

@@ -153,5 +153,5 @@ function sanitizeUser(newUser) {

}
function canInitRum(userConfiguration) {
function canInitRum(initConfiguration) {
if (isAlreadyInitialized) {
if (!userConfiguration.silentMultipleInit) {
if (!initConfiguration.silentMultipleInit) {
display.error('DD_RUM is already initialized.');

@@ -161,21 +161,21 @@ }

}
if (!userConfiguration || (!userConfiguration.clientToken && !userConfiguration.publicApiKey)) {
if (!initConfiguration || (!initConfiguration.clientToken && !initConfiguration.publicApiKey)) {
display.error('Client Token is not configured, we will not send any data.');
return false;
}
if (!userConfiguration.applicationId) {
if (!initConfiguration.applicationId) {
display.error('Application ID is not configured, no RUM data will be collected.');
return false;
}
if (userConfiguration.sampleRate !== undefined && !isPercentage(userConfiguration.sampleRate)) {
if (initConfiguration.sampleRate !== undefined && !isPercentage(initConfiguration.sampleRate)) {
display.error('Sample Rate should be a number between 0 and 100');
return false;
}
if (userConfiguration.resourceSampleRate !== undefined && !isPercentage(userConfiguration.resourceSampleRate)) {
if (initConfiguration.resourceSampleRate !== undefined && !isPercentage(initConfiguration.resourceSampleRate)) {
display.error('Resource Sample Rate should be a number between 0 and 100');
return false;
}
if (Array.isArray(userConfiguration.allowedTracingOrigins) &&
userConfiguration.allowedTracingOrigins.length !== 0 &&
userConfiguration.service === undefined) {
if (Array.isArray(initConfiguration.allowedTracingOrigins) &&
initConfiguration.allowedTracingOrigins.length !== 0 &&
initConfiguration.service === undefined) {
display.error('Service need to be configured when tracing is enabled');

@@ -182,0 +182,0 @@ return false;

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

import { CommonContext } from '../rawRumEvent.types';
import { RumUserConfiguration } from './rumPublicApi';
export declare function startRum(userConfiguration: RumUserConfiguration, configuration: Configuration, internalMonitoring: InternalMonitoring, getCommonContext: () => CommonContext, initialViewName?: string): {
import { RumInitConfiguration } from './rumPublicApi';
export declare function startRum(initConfiguration: RumInitConfiguration, configuration: Configuration, internalMonitoring: InternalMonitoring, getCommonContext: () => CommonContext, initialViewName?: string): {
addAction: (action: import("../domain/rumEventsCollection/action/trackActions").CustomAction, savedCommonContext?: CommonContext | undefined) => void;

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

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

import { startRumBatch } from '../transport/batch';
export function startRum(userConfiguration, configuration, internalMonitoring, getCommonContext, initialViewName) {
export function startRum(initConfiguration, configuration, internalMonitoring, getCommonContext, initialViewName) {
var lifeCycle = new LifeCycle();

@@ -24,6 +24,6 @@ var session = startRumSession(configuration, lifeCycle);

return combine({
application_id: userConfiguration.applicationId,
application_id: initConfiguration.applicationId,
}, parentContexts.findView(), getCommonContext().context);
});
var _a = startRumEventCollection(userConfiguration.applicationId, lifeCycle, configuration, session, getCommonContext), parentContexts = _a.parentContexts, foregroundContexts = _a.foregroundContexts;
var _a = startRumEventCollection(initConfiguration.applicationId, lifeCycle, configuration, session, getCommonContext), parentContexts = _a.parentContexts, foregroundContexts = _a.foregroundContexts;
startLongTaskCollection(lifeCycle);

@@ -36,3 +36,3 @@ startResourceCollection(lifeCycle, session);

startPerformanceCollection(lifeCycle, configuration);
var internalContext = startInternalContext(userConfiguration.applicationId, session, parentContexts);
var internalContext = startInternalContext(initConfiguration.applicationId, session, parentContexts);
return {

@@ -39,0 +39,0 @@ addAction: addAction,

@@ -9,4 +9,3 @@ import { isEmptyObject, mapValues, toServerDuration, } from '@datadog/browser-core';

});
var shouldTrackViewsAutomatically = !configuration.isEnabled('view-renaming') || !configuration.trackViewsManually;
return trackViews(location, lifeCycle, domMutationObservable, shouldTrackViewsAutomatically, initialViewName);
return trackViews(location, lifeCycle, domMutationObservable, !configuration.trackViewsManually, initialViewName);
}

@@ -13,0 +12,0 @@ function processViewUpdate(view, foregroundContexts) {

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

export { RumUserConfiguration, RumPublicApi, makeRumPublicApi, StartRum } from './boot/rumPublicApi';
export { RumInitConfiguration, RumUserConfiguration, RumPublicApi, makeRumPublicApi, StartRum, } from './boot/rumPublicApi';
export { ProvidedSource } from './domain/rumEventsCollection/error/errorCollection';

@@ -3,0 +3,0 @@ export { RumEvent, RumActionEvent, CommonProperties, RumErrorEvent, RumViewEvent, RumResourceEvent, RumLongTaskEvent, } from './rumEvent.types';

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

export { makeRumPublicApi } from './boot/rumPublicApi';
export { makeRumPublicApi, } from './boot/rumPublicApi';
export { startRum } from './boot/startRum';

@@ -3,0 +3,0 @@ export { LifeCycle, LifeCycleEventType } from './domain/lifeCycle';

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

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

"dependencies": {
"@datadog/browser-core": "2.16.0",
"@datadog/browser-core": "2.17.0",
"tslib": "^1.10.0"

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

},
"gitHead": "948fb85289b73a32adbe21798a4a27839fc948f2"
"gitHead": "062e559cfe16288cf412ec73d365ee4e9d4c96ec"
}
import { ErrorSource, ONE_SECOND, RelativeTime, getTimeStamp, display, TimeStamp } from '@datadog/browser-core'
import { setup, TestSetupBuilder } from '../../test/specHelper'
import { ActionType } from '../rawRumEvent.types'
import { makeRumPublicApi, RumPublicApi, RumUserConfiguration, StartRum } from './rumPublicApi'
import { makeRumPublicApi, RumPublicApi, RumInitConfiguration, StartRum } from './rumPublicApi'

@@ -30,3 +30,3 @@ const noopStartRum = (): ReturnType<StartRum> => ({

const invalidConfiguration = { clientToken: 'yes' }
rumPublicApi.init(invalidConfiguration as RumUserConfiguration)
rumPublicApi.init(invalidConfiguration as RumInitConfiguration)
expect(display.error).toHaveBeenCalledTimes(1)

@@ -144,2 +144,24 @@

describe('getInitConfiguration', () => {
let rumPublicApi: RumPublicApi
beforeEach(() => {
rumPublicApi = makeRumPublicApi(() => ({
...noopStartRum(),
}))
})
it('returns undefined before init', () => {
expect(rumPublicApi.getInitConfiguration()).toBe(undefined)
})
it('returns the user configuration after init', () => {
const initConfiguration = { ...DEFAULT_INIT_CONFIGURATION, service: 'my-service', version: '1.4.2', env: 'dev' }
rumPublicApi.init(initConfiguration)
expect(rumPublicApi.getInitConfiguration()).toEqual(initConfiguration)
expect(rumPublicApi.getInitConfiguration()).not.toBe(initConfiguration)
})
})
describe('addAction', () => {

@@ -465,3 +487,3 @@ let addActionSpy: jasmine.Spy<ReturnType<StartRum>['addAction']>

describe('trackViews mode', () => {
const AUTO_CONFIGURATION = { ...DEFAULT_INIT_CONFIGURATION, enableExperimentalFeatures: ['view-renaming'] }
const AUTO_CONFIGURATION = { ...DEFAULT_INIT_CONFIGURATION }
const MANUAL_CONFIGURATION = { ...AUTO_CONFIGURATION, trackViewsManually: true }

@@ -504,4 +526,3 @@

clock.tick(10)
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
;(rumPublicApi as any).startView('foo')
rumPublicApi.startView('foo')

@@ -524,4 +545,3 @@ expect(startViewSpy).not.toHaveBeenCalled()

// eslint-disable-next-line @typescript-eslint/no-unsafe-call
;(rumPublicApi as any).startView('foo')
rumPublicApi.startView('foo')

@@ -543,4 +563,3 @@ expect(startViewSpy).toHaveBeenCalled()

it('before init startView should start rum', () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
;(rumPublicApi as any).startView('foo')
rumPublicApi.startView('foo')
expect(startRumSpy).not.toHaveBeenCalled()

@@ -560,4 +579,3 @@ expect(startViewSpy).not.toHaveBeenCalled()

// eslint-disable-next-line @typescript-eslint/no-unsafe-call
;(rumPublicApi as any).startView('foo')
rumPublicApi.startView('foo')
expect(startRumSpy).toHaveBeenCalled()

@@ -570,6 +588,4 @@ expect(startRumSpy.calls.argsFor(0)[4]).toEqual('foo')

rumPublicApi.init(MANUAL_CONFIGURATION)
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
;(rumPublicApi as any).startView('foo')
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
;(rumPublicApi as any).startView('bar')
rumPublicApi.startView('foo')
rumPublicApi.startView('bar')

@@ -590,4 +606,3 @@ expect(startRumSpy).toHaveBeenCalled()

clock.tick(10)
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
;(rumPublicApi as any).startView('foo')
rumPublicApi.startView('foo')

@@ -594,0 +609,0 @@ clock.tick(10)

@@ -13,3 +13,3 @@ import {

monitor,
UserConfiguration,
InitConfiguration,
clocksNow,

@@ -31,3 +31,3 @@ timeStampNow,

export interface RumUserConfiguration extends UserConfiguration {
export interface RumInitConfiguration extends InitConfiguration {
applicationId: string

@@ -37,6 +37,12 @@ beforeSend?: (event: RumEvent, context: RumEventDomainContext) => void | boolean

/**
* TODO: remove this type in the next major release
* @deprecated Use RumInitConfiguration instead
*/
export type RumUserConfiguration = RumInitConfiguration
export type RumPublicApi = ReturnType<typeof makeRumPublicApi>
export type StartRum<C extends RumUserConfiguration = RumUserConfiguration> = (
userConfiguration: C,
export type StartRum<C extends RumInitConfiguration = RumInitConfiguration> = (
initConfiguration: C,
configuration: Configuration,

@@ -50,3 +56,3 @@ internalMonitoring: InternalMonitoring,

export function makeRumPublicApi<C extends RumUserConfiguration>(startRumImpl: StartRum<C>) {
export function makeRumPublicApi<C extends RumInitConfiguration>(startRumImpl: StartRum<C>) {
let isAlreadyInitialized = false

@@ -58,2 +64,3 @@

let getInternalContextStrategy: StartRumResult['getInternalContext'] = () => undefined
let getInitConfigurationStrategy = (): InitConfiguration | undefined => undefined

@@ -81,16 +88,16 @@ let bufferApiCalls = new BoundedBuffer()

function initRum(userConfiguration: C) {
function initRum(initConfiguration: C) {
if (
!checkCookiesAuthorized(buildCookieOptions(userConfiguration)) ||
!checkCookiesAuthorized(buildCookieOptions(initConfiguration)) ||
!checkIsNotLocalFile() ||
!canInitRum(userConfiguration)
!canInitRum(initConfiguration)
) {
return
}
if (userConfiguration.publicApiKey) {
userConfiguration.clientToken = userConfiguration.publicApiKey
if (initConfiguration.publicApiKey) {
initConfiguration.clientToken = initConfiguration.publicApiKey
}
const { configuration, internalMonitoring } = commonInit(userConfiguration, buildEnv)
if (!configuration.isEnabled('view-renaming') || !configuration.trackViewsManually) {
const { configuration, internalMonitoring } = commonInit(initConfiguration, buildEnv)
if (!configuration.trackViewsManually) {
doStartRum()

@@ -109,8 +116,9 @@ } else {

}
getInitConfigurationStrategy = () => deepClone<InitConfiguration>(initConfiguration)
isAlreadyInitialized = true
function doStartRum(initialViewName?: string) {
let startView
;({
startView,
startView: startViewStrategy,
addAction: addActionStrategy,

@@ -121,3 +129,3 @@ addError: addErrorStrategy,

} = startRumImpl(
userConfiguration,
initConfiguration,
configuration,

@@ -131,5 +139,2 @@ internalMonitoring,

))
if (configuration.isEnabled('view-renaming')) {
startViewStrategy = startView
}
bufferApiCalls.drain()

@@ -150,2 +155,3 @@ }

getInternalContext: monitor((startTime?: number) => getInternalContextStrategy(startTime)),
getInitConfiguration: monitor(() => getInitConfigurationStrategy()),

@@ -204,6 +210,7 @@ addAction: monitor((name: string, context?: object) => {

}),
startView: monitor((name?: string) => {
startViewStrategy(name)
}),
})
;(rumPublicApi as any)['startView'] = monitor((name?: string) => {
startViewStrategy(name)
})
return rumPublicApi

@@ -228,5 +235,5 @@

function canInitRum(userConfiguration: RumUserConfiguration) {
function canInitRum(initConfiguration: RumInitConfiguration) {
if (isAlreadyInitialized) {
if (!userConfiguration.silentMultipleInit) {
if (!initConfiguration.silentMultipleInit) {
display.error('DD_RUM is already initialized.')

@@ -236,15 +243,15 @@ }

}
if (!userConfiguration || (!userConfiguration.clientToken && !userConfiguration.publicApiKey)) {
if (!initConfiguration || (!initConfiguration.clientToken && !initConfiguration.publicApiKey)) {
display.error('Client Token is not configured, we will not send any data.')
return false
}
if (!userConfiguration.applicationId) {
if (!initConfiguration.applicationId) {
display.error('Application ID is not configured, no RUM data will be collected.')
return false
}
if (userConfiguration.sampleRate !== undefined && !isPercentage(userConfiguration.sampleRate)) {
if (initConfiguration.sampleRate !== undefined && !isPercentage(initConfiguration.sampleRate)) {
display.error('Sample Rate should be a number between 0 and 100')
return false
}
if (userConfiguration.resourceSampleRate !== undefined && !isPercentage(userConfiguration.resourceSampleRate)) {
if (initConfiguration.resourceSampleRate !== undefined && !isPercentage(initConfiguration.resourceSampleRate)) {
display.error('Resource Sample Rate should be a number between 0 and 100')

@@ -254,5 +261,5 @@ return false

if (
Array.isArray(userConfiguration.allowedTracingOrigins) &&
userConfiguration.allowedTracingOrigins.length !== 0 &&
userConfiguration.service === undefined
Array.isArray(initConfiguration.allowedTracingOrigins) &&
initConfiguration.allowedTracingOrigins.length !== 0 &&
initConfiguration.service === undefined
) {

@@ -259,0 +266,0 @@ display.error('Service need to be configured when tracing is enabled')

@@ -18,6 +18,6 @@ import { combine, Configuration, InternalMonitoring } from '@datadog/browser-core'

import { startRumBatch } from '../transport/batch'
import { RumUserConfiguration } from './rumPublicApi'
import { RumInitConfiguration } from './rumPublicApi'
export function startRum(
userConfiguration: RumUserConfiguration,
initConfiguration: RumInitConfiguration,
configuration: Configuration,

@@ -35,3 +35,3 @@ internalMonitoring: InternalMonitoring,

{
application_id: userConfiguration.applicationId,
application_id: initConfiguration.applicationId,
},

@@ -44,3 +44,3 @@ parentContexts.findView(),

const { parentContexts, foregroundContexts } = startRumEventCollection(
userConfiguration.applicationId,
initConfiguration.applicationId,
lifeCycle,

@@ -68,3 +68,3 @@ configuration,

const internalContext = startInternalContext(userConfiguration.applicationId, session, parentContexts)
const internalContext = startInternalContext(initConfiguration.applicationId, session, parentContexts)

@@ -71,0 +71,0 @@ return {

@@ -27,4 +27,3 @@ import {

const shouldTrackViewsAutomatically = !configuration.isEnabled('view-renaming') || !configuration.trackViewsManually
return trackViews(location, lifeCycle, domMutationObservable, shouldTrackViewsAutomatically, initialViewName)
return trackViews(location, lifeCycle, domMutationObservable, !configuration.trackViewsManually, initialViewName)
}

@@ -31,0 +30,0 @@

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

export { RumUserConfiguration, RumPublicApi, makeRumPublicApi, StartRum } from './boot/rumPublicApi'
export {
RumInitConfiguration,
RumUserConfiguration,
RumPublicApi,
makeRumPublicApi,
StartRum,
} from './boot/rumPublicApi'
export { ProvidedSource } from './domain/rumEventsCollection/error/errorCollection'

@@ -3,0 +9,0 @@ export {

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