Socket
Socket
Sign inDemoInstall

@datadog/browser-rum-core

Package Overview
Dependencies
2
Maintainers
1
Versions
170
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.2.1 to 2.3.0

2

cjs/boot/buildEnv.js

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

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

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

configuration: Configuration;
lifeCycle: LifeCycle;
parentContexts: import("../domain/parentContexts").ParentContexts;
session: RumSession;
getInternalContext: (startTime?: number | undefined) => import("../rawRumEvent.types").InternalContext | undefined;

@@ -13,0 +16,0 @@ };

@@ -38,2 +38,5 @@ "use strict";

configuration: configuration,
lifeCycle: lifeCycle,
parentContexts: parentContexts,
session: session,
getInternalContext: internalContext.get,

@@ -40,0 +43,0 @@ };

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

var actionContext = parentContexts.findAction(startTime);
var commonContext = savedCommonContext || getCommonContext();
var rumContext = {

@@ -37,2 +38,3 @@ _dd: {

session: {
has_replay: commonContext.hasReplay,
// must be computed on each event because synthetics instrumentation can be done after sdk execution

@@ -47,3 +49,2 @@ // cf https://github.com/puppeteer/puppeteer/issues/3667

var serverRumEvent = browser_core_1.withSnakeCaseKeys(assembledRumEvent);
var commonContext = savedCommonContext || getCommonContext();
var context = browser_core_1.combine(commonContext.context, customerContext);

@@ -50,0 +51,0 @@ if (!browser_core_1.isEmptyObject(context)) {

@@ -17,20 +17,30 @@ "use strict";

return injectHeadersIfTracingAllowed(configuration, context, function (tracingHeaders) {
context.init = tslib_1.__assign({}, context.init);
var headers = [];
if (context.init.headers instanceof Headers) {
context.init.headers.forEach(function (value, key) {
headers.push([key, value]);
var _a;
if (context.input instanceof Request && !((_a = context.init) === null || _a === void 0 ? void 0 : _a.headers)) {
context.input = new Request(context.input);
Object.keys(tracingHeaders).forEach(function (key) {
;
context.input.headers.append(key, tracingHeaders[key]);
});
}
else if (Array.isArray(context.init.headers)) {
context.init.headers.forEach(function (header) {
headers.push(header);
});
else {
context.init = tslib_1.__assign({}, context.init);
var headers_1 = [];
if (context.init.headers instanceof Headers) {
context.init.headers.forEach(function (value, key) {
headers_1.push([key, value]);
});
}
else if (Array.isArray(context.init.headers)) {
context.init.headers.forEach(function (header) {
headers_1.push(header);
});
}
else if (context.init.headers) {
Object.keys(context.init.headers).forEach(function (key) {
headers_1.push([key, context.init.headers[key]]);
});
}
context.init.headers = headers_1.concat(browser_core_1.objectEntries(tracingHeaders));
}
else if (context.init.headers) {
Object.keys(context.init.headers).forEach(function (key) {
headers.push([key, context.init.headers[key]]);
});
}
context.init.headers = headers.concat(browser_core_1.objectEntries(tracingHeaders));
});

@@ -37,0 +47,0 @@ },

export { RumUserConfiguration, RumPublicApi, makeRumPublicApi } from './boot/rumPublicApi';
export { ProvidedSource } from './domain/rumEventsCollection/error/errorCollection';
export { RumEvent, RumActionEvent, CommonProperties, RumErrorEvent, RumViewEvent, RumResourceEvent, RumLongTaskEvent, } from './rumEvent.types';
export { ViewContext, CommonContext } from './rawRumEvent.types';
export { startRum } from './boot/rum';
export { LifeCycle, LifeCycleEventType } from './domain/lifeCycle';
export { ParentContexts } from './domain/parentContexts';
export { RumSession } from './domain/rumSession';

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

exports.startRum = rum_1.startRum;
var lifeCycle_1 = require("./domain/lifeCycle");
exports.LifeCycle = lifeCycle_1.LifeCycle;
exports.LifeCycleEventType = lifeCycle_1.LifeCycleEventType;
//# sourceMappingURL=index.js.map

@@ -111,2 +111,3 @@ import { Context, ErrorSource, ResourceType } from '@datadog/browser-core';

type: string;
has_replay?: boolean;
};

@@ -154,3 +155,4 @@ _dd: {

context: Context;
hasReplay?: boolean;
}
export {};

@@ -532,2 +532,6 @@ /**

readonly type: 'user' | 'synthetics';
/**
* Whether this session has a replay
*/
readonly has_replay?: boolean;
[k: string]: unknown;

@@ -534,0 +538,0 @@ };

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

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

configuration: Configuration;
lifeCycle: LifeCycle;
parentContexts: import("../domain/parentContexts").ParentContexts;
session: RumSession;
getInternalContext: (startTime?: number | undefined) => import("../rawRumEvent.types").InternalContext | undefined;

@@ -13,0 +16,0 @@ };

@@ -36,2 +36,5 @@ import { combine, commonInit } from '@datadog/browser-core';

configuration: configuration,
lifeCycle: lifeCycle,
parentContexts: parentContexts,
session: session,
getInternalContext: internalContext.get,

@@ -38,0 +41,0 @@ };

@@ -24,2 +24,3 @@ import { combine, isEmptyObject, limitModification, withSnakeCaseKeys, } from '@datadog/browser-core';

var actionContext = parentContexts.findAction(startTime);
var commonContext = savedCommonContext || getCommonContext();
var rumContext = {

@@ -35,2 +36,3 @@ _dd: {

session: {
has_replay: commonContext.hasReplay,
// must be computed on each event because synthetics instrumentation can be done after sdk execution

@@ -45,3 +47,2 @@ // cf https://github.com/puppeteer/puppeteer/issues/3667

var serverRumEvent = withSnakeCaseKeys(assembledRumEvent);
var commonContext = savedCommonContext || getCommonContext();
var context = combine(commonContext.context, customerContext);

@@ -48,0 +49,0 @@ if (!isEmptyObject(context)) {

@@ -14,20 +14,30 @@ import { __assign } from "tslib";

return injectHeadersIfTracingAllowed(configuration, context, function (tracingHeaders) {
context.init = __assign({}, context.init);
var headers = [];
if (context.init.headers instanceof Headers) {
context.init.headers.forEach(function (value, key) {
headers.push([key, value]);
var _a;
if (context.input instanceof Request && !((_a = context.init) === null || _a === void 0 ? void 0 : _a.headers)) {
context.input = new Request(context.input);
Object.keys(tracingHeaders).forEach(function (key) {
;
context.input.headers.append(key, tracingHeaders[key]);
});
}
else if (Array.isArray(context.init.headers)) {
context.init.headers.forEach(function (header) {
headers.push(header);
});
else {
context.init = __assign({}, context.init);
var headers_1 = [];
if (context.init.headers instanceof Headers) {
context.init.headers.forEach(function (value, key) {
headers_1.push([key, value]);
});
}
else if (Array.isArray(context.init.headers)) {
context.init.headers.forEach(function (header) {
headers_1.push(header);
});
}
else if (context.init.headers) {
Object.keys(context.init.headers).forEach(function (key) {
headers_1.push([key, context.init.headers[key]]);
});
}
context.init.headers = headers_1.concat(objectEntries(tracingHeaders));
}
else if (context.init.headers) {
Object.keys(context.init.headers).forEach(function (key) {
headers.push([key, context.init.headers[key]]);
});
}
context.init.headers = headers.concat(objectEntries(tracingHeaders));
});

@@ -34,0 +44,0 @@ },

export { RumUserConfiguration, RumPublicApi, makeRumPublicApi } from './boot/rumPublicApi';
export { ProvidedSource } from './domain/rumEventsCollection/error/errorCollection';
export { RumEvent, RumActionEvent, CommonProperties, RumErrorEvent, RumViewEvent, RumResourceEvent, RumLongTaskEvent, } from './rumEvent.types';
export { ViewContext, CommonContext } from './rawRumEvent.types';
export { startRum } from './boot/rum';
export { LifeCycle, LifeCycleEventType } from './domain/lifeCycle';
export { ParentContexts } from './domain/parentContexts';
export { RumSession } from './domain/rumSession';
export { makeRumPublicApi } from './boot/rumPublicApi';
export { startRum } from './boot/rum';
export { LifeCycle, LifeCycleEventType } from './domain/lifeCycle';
//# sourceMappingURL=index.js.map

@@ -111,2 +111,3 @@ import { Context, ErrorSource, ResourceType } from '@datadog/browser-core';

type: string;
has_replay?: boolean;
};

@@ -154,3 +155,4 @@ _dd: {

context: Context;
hasReplay?: boolean;
}
export {};

@@ -532,2 +532,6 @@ /**

readonly type: 'user' | 'synthetics';
/**
* Whether this session has a replay
*/
readonly has_replay?: boolean;
[k: string]: unknown;

@@ -534,0 +538,0 @@ };

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

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

"dependencies": {
"@datadog/browser-core": "2.2.1",
"@datadog/browser-core": "2.3.0",
"tslib": "^1.10.0"

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

},
"gitHead": "129bd33e18a2e07fefb995b090254fcc32e601f6"
"gitHead": "f92ef270e80cbe49abf97e08622228ae46681518"
}

@@ -57,2 +57,5 @@ import { combine, commonInit, Configuration, Context } from '@datadog/browser-core'

configuration,
lifeCycle,
parentContexts,
session,
getInternalContext: internalContext.get,

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

@@ -9,3 +9,3 @@ import { Configuration, ErrorSource, ONE_SECOND } from '@datadog/browser-core'

}
const noopStartRum = () => ({
const noopStartRum = (): ReturnType<StartRum> => ({
addAction: () => undefined,

@@ -16,2 +16,5 @@ addError: () => undefined,

getInternalContext: () => undefined,
lifeCycle: {} as any,
parentContexts: {} as any,
session: {} as any,
})

@@ -18,0 +21,0 @@ const DEFAULT_INIT_CONFIGURATION = { applicationId: 'xxx', clientToken: 'xxx' }

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

import { Context, DEFAULT_CONFIGURATION, noop } from '@datadog/browser-core'
import { DEFAULT_CONFIGURATION, noop } from '@datadog/browser-core'
import { createRawRumEvent } from '../../test/fixtures'
import { setup, TestSetupBuilder } from '../../test/specHelper'
import { RumEventType, User } from '../rawRumEvent.types'
import { CommonContext, RumEventType } from '../rawRumEvent.types'
import { RumActionEvent, RumEvent, RumLongTaskEvent } from '../rumEvent.types'

@@ -12,4 +12,3 @@ import { startRumAssembly } from './assembly'

let lifeCycle: LifeCycle
let globalContext: Context
let user: User
let commonContext: CommonContext
let serverRumEvents: RumEvent[]

@@ -23,4 +22,6 @@ let isTracked: boolean

viewSessionId = '1234'
globalContext = {}
user = {}
commonContext = {
context: {},
user: {},
}
beforeSend = noop

@@ -55,6 +56,3 @@ setupBuilder = setup()

.beforeBuild(({ applicationId, configuration, lifeCycle: localLifeCycle, session, parentContexts }) => {
startRumAssembly(applicationId, configuration, localLifeCycle, session, parentContexts, () => ({
user,
context: globalContext,
}))
startRumAssembly(applicationId, configuration, localLifeCycle, session, parentContexts, () => commonContext)
})

@@ -140,3 +138,3 @@ ;({ lifeCycle } = setupBuilder.build())

it('should be merged with event attributes', () => {
globalContext = { bar: 'foo' }
commonContext.context = { bar: 'foo' }
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {

@@ -151,3 +149,3 @@ rawRumEvent: createRawRumEvent(RumEventType.VIEW),

it('should not be included if empty', () => {
globalContext = {}
commonContext.context = {}
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {

@@ -162,3 +160,3 @@ rawRumEvent: createRawRumEvent(RumEventType.VIEW),

it('should ignore subsequent context mutation', () => {
globalContext = { bar: 'foo', baz: 'foz' }
commonContext.context = { bar: 'foo', baz: 'foz' }
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {

@@ -168,3 +166,3 @@ rawRumEvent: createRawRumEvent(RumEventType.VIEW),

})
delete globalContext.bar
delete commonContext.context.bar
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {

@@ -180,3 +178,3 @@ rawRumEvent: createRawRumEvent(RumEventType.VIEW),

it('should not be automatically snake cased', () => {
globalContext = { fooBar: 'foo' }
commonContext.context = { fooBar: 'foo' }
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {

@@ -191,3 +189,3 @@ rawRumEvent: createRawRumEvent(RumEventType.VIEW),

it('should ignore the current global context when a saved global context is provided', () => {
globalContext = { replacedContext: 'b', addedContext: 'x' }
commonContext.context = { replacedContext: 'b', addedContext: 'x' }

@@ -210,3 +208,3 @@ lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {

it('should be included in event attributes', () => {
user = { id: 'foo' }
commonContext.user = { id: 'foo' }
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {

@@ -221,3 +219,3 @@ rawRumEvent: createRawRumEvent(RumEventType.VIEW),

it('should not be included if empty', () => {
user = {}
commonContext.user = {}
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {

@@ -232,3 +230,3 @@ rawRumEvent: createRawRumEvent(RumEventType.VIEW),

it('should not be automatically snake cased', () => {
user = { fooBar: 'foo' }
commonContext.user = { fooBar: 'foo' }
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {

@@ -243,3 +241,3 @@ rawRumEvent: createRawRumEvent(RumEventType.VIEW),

it('should ignore the current user when a saved common context user is provided', () => {
user = { replacedAttribute: 'b', addedAttribute: 'x' }
commonContext.user = { replacedAttribute: 'b', addedAttribute: 'x' }

@@ -324,3 +322,3 @@ lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {

describe('session', () => {
describe('event generation condition', () => {
it('when tracked, it should generate event', () => {

@@ -366,2 +364,26 @@ isTracked = true

})
describe('session context', () => {
it('should include the session type and id', () => {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
startTime: 0,
})
expect(serverRumEvents[0].session).toEqual({
has_replay: undefined,
id: '1234',
type: 'user',
})
})
it('should set the session.has_replay attribute if it is defined in the common context', () => {
commonContext.hasReplay = true
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
startTime: 0,
})
expect(serverRumEvents[0].session.has_replay).toBe(true)
})
})
})

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

const actionContext = parentContexts.findAction(startTime)
const commonContext = savedCommonContext || getCommonContext()
const rumContext: RumContext = {

@@ -68,2 +69,3 @@ _dd: {

session: {
has_replay: commonContext.hasReplay,
// must be computed on each event because synthetics instrumentation can be done after sdk execution

@@ -78,3 +80,2 @@ // cf https://github.com/puppeteer/puppeteer/issues/3667

const serverRumEvent = withSnakeCaseKeys(assembledRumEvent) as RumEvent & Context
const commonContext = savedCommonContext || getCommonContext()

@@ -81,0 +82,0 @@ const context = combine(commonContext.context, customerContext)

@@ -192,2 +192,44 @@ import { Configuration, DEFAULT_CONFIGURATION, isIE, objectEntries } from '@datadog/browser-core'

it('should preserve original headers contained in a Request instance', () => {
const request = new Request(document.location.origin, {
headers: {
foo: 'bar',
},
})
const context: Partial<RumFetchCompleteContext> = {
...ALLOWED_DOMAIN_CONTEXT,
input: request,
}
const tracer = startTracer(configuration as Configuration)
tracer.traceFetch(context)
expect(context.init).toBe(undefined)
expect(context.input).not.toBe(request)
expect(headersAsArray((context.input as Request).headers)).toEqual([
['foo', 'bar'],
...tracingHeadersAsArrayFor(context.traceId!, context.spanId!),
])
expect(headersAsArray(request.headers)).toEqual([['foo', 'bar']])
})
it('should ignore headers from a Request instance if other headers are set', () => {
const context: Partial<RumFetchCompleteContext> = {
...ALLOWED_DOMAIN_CONTEXT,
init: { headers: { 'x-init-header': 'baz' } },
input: new Request(document.location.origin, {
headers: { 'x-request-header': 'bar' },
}),
}
const tracer = startTracer(configuration as Configuration)
tracer.traceFetch(context)
expect(context.init!.headers).toEqual([
['x-init-header', 'baz'],
...tracingHeadersAsArrayFor(context.traceId!, context.spanId!),
])
})
it('should not trace request on disallowed domain', () => {

@@ -281,3 +323,11 @@ const context: Partial<RumFetchCompleteContext> = { ...DISALLOWED_DOMAIN_CONTEXT }

function tracingHeadersAsArrayFor(traceId: TraceIdentifier, spanId: TraceIdentifier) {
return objectEntries(tracingHeadersFor(traceId, spanId)) as string[][]
return objectEntries(tracingHeadersFor(traceId, spanId)) as Array<[string, string]>
}
function headersAsArray(headers: Headers) {
const result: Array<[string, string]> = []
headers.forEach((value, key) => {
result.push([key, value])
})
return result
}

@@ -31,18 +31,25 @@ import { Configuration, getOrigin, objectEntries } from '@datadog/browser-core'

injectHeadersIfTracingAllowed(configuration, context, (tracingHeaders: TracingHeaders) => {
context.init = { ...context.init }
const headers: string[][] = []
if (context.init.headers instanceof Headers) {
context.init.headers.forEach((value, key) => {
headers.push([key, value])
if (context.input instanceof Request && !context.init?.headers) {
context.input = new Request(context.input)
Object.keys(tracingHeaders).forEach((key) => {
;(context.input as Request).headers.append(key, tracingHeaders[key])
})
} else if (Array.isArray(context.init.headers)) {
context.init.headers.forEach((header) => {
headers.push(header)
})
} else if (context.init.headers) {
Object.keys(context.init.headers).forEach((key) => {
headers.push([key, (context.init!.headers as Record<string, string>)[key]])
})
} else {
context.init = { ...context.init }
const headers: string[][] = []
if (context.init.headers instanceof Headers) {
context.init.headers.forEach((value, key) => {
headers.push([key, value])
})
} else if (Array.isArray(context.init.headers)) {
context.init.headers.forEach((header) => {
headers.push(header)
})
} else if (context.init.headers) {
Object.keys(context.init.headers).forEach((key) => {
headers.push([key, (context.init!.headers as Record<string, string>)[key]])
})
}
context.init.headers = headers.concat(objectEntries(tracingHeaders) as string[][])
}
context.init.headers = headers.concat(objectEntries(tracingHeaders) as string[][])
}),

@@ -49,0 +56,0 @@ traceXhr: (context, xhr) =>

@@ -12,2 +12,6 @@ export { RumUserConfiguration, RumPublicApi, makeRumPublicApi } from './boot/rumPublicApi'

} from './rumEvent.types'
export { ViewContext, CommonContext } from './rawRumEvent.types'
export { startRum } from './boot/rum'
export { LifeCycle, LifeCycleEventType } from './domain/lifeCycle'
export { ParentContexts } from './domain/parentContexts'
export { RumSession } from './domain/rumSession'

@@ -125,2 +125,3 @@ import { Context, ErrorSource, ResourceType } from '@datadog/browser-core'

type: string
has_replay?: boolean
}

@@ -179,2 +180,3 @@ _dd: {

context: Context
hasReplay?: boolean
}

@@ -571,2 +571,6 @@ /* tslint:disable */

readonly type: 'user' | 'synthetics'
/**
* Whether this session has a replay
*/
readonly has_replay?: boolean
[k: string]: unknown

@@ -573,0 +577,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

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc