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

@datadog/browser-rum-core

Package Overview
Dependencies
Maintainers
1
Versions
181
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 2.8.0 to 2.8.1

2

cjs/boot/buildEnv.js

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

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

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

function startRumAssembly(applicationId, configuration, lifeCycle, session, parentContexts, getCommonContext) {
var errorFilter = browser_core_1.createErrorFilter(configuration, function (error) {
lifeCycle.notify(lifeCycle_1.LifeCycleEventType.RAW_ERROR_COLLECTED, { error: error });
});
lifeCycle.subscribe(lifeCycle_1.LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, function (_a) {

@@ -60,3 +63,3 @@ var startTime = _a.startTime, rawRumEvent = _a.rawRumEvent, savedCommonContext = _a.savedCommonContext, customerContext = _a.customerContext;

}
if (shouldSend(serverRumEvent, configuration.beforeSend)) {
if (shouldSend(serverRumEvent, configuration.beforeSend, errorFilter)) {
lifeCycle.notify(lifeCycle_1.LifeCycleEventType.RUM_EVENT_COLLECTED, serverRumEvent);

@@ -68,3 +71,3 @@ }

exports.startRumAssembly = startRumAssembly;
function shouldSend(event, beforeSend) {
function shouldSend(event, beforeSend, errorFilter) {
if (beforeSend) {

@@ -79,2 +82,5 @@ var result = browser_core_1.limitModification(event, FIELDS_WITH_SENSITIVE_DATA, beforeSend);

}
if (event.type === rawRumEvent_types_1.RumEventType.ERROR) {
return !errorFilter.isLimitReached();
}
return true;

@@ -81,0 +87,0 @@ }

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

import { Context, RelativeTime } from '@datadog/browser-core';
import { Context, RawError, RelativeTime } from '@datadog/browser-core';
import { RumPerformanceEntry } from '../browser/performanceCollection';

@@ -24,3 +24,4 @@ import { CommonContext, RawRumEvent } from '../rawRumEvent.types';

RECORD_STARTED = 14,
RECORD_STOPPED = 15
RECORD_STOPPED = 15,
RAW_ERROR_COLLECTED = 16
}

@@ -40,2 +41,7 @@ export interface Subscription {

notify(eventType: LifeCycleEventType.VIEW_ENDED, data: ViewEndedEvent): void;
notify(eventType: LifeCycleEventType.RAW_ERROR_COLLECTED, data: {
error: RawError;
savedCommonContext?: CommonContext;
customerContext?: Context;
}): void;
notify(eventType: LifeCycleEventType.SESSION_RENEWED | LifeCycleEventType.DOM_MUTATED | LifeCycleEventType.BEFORE_UNLOAD | LifeCycleEventType.AUTO_ACTION_DISCARDED | LifeCycleEventType.RECORD_STARTED | LifeCycleEventType.RECORD_STOPPED): void;

@@ -57,2 +63,7 @@ notify(eventType: LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, data: {

subscribe(eventType: LifeCycleEventType.VIEW_ENDED, callback: (data: ViewEndedEvent) => void): Subscription;
subscribe(eventType: LifeCycleEventType.RAW_ERROR_COLLECTED, callback: (data: {
error: RawError;
savedCommonContext?: CommonContext;
customerContext?: Context;
}) => void): Subscription;
subscribe(eventType: LifeCycleEventType.SESSION_RENEWED | LifeCycleEventType.DOM_MUTATED | LifeCycleEventType.BEFORE_UNLOAD | LifeCycleEventType.AUTO_ACTION_DISCARDED | LifeCycleEventType.RECORD_STARTED | LifeCycleEventType.RECORD_STOPPED, callback: () => void): Subscription;

@@ -59,0 +70,0 @@ subscribe(eventType: LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, callback: (data: {

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

LifeCycleEventType[LifeCycleEventType["RECORD_STOPPED"] = 15] = "RECORD_STOPPED";
LifeCycleEventType[LifeCycleEventType["RAW_ERROR_COLLECTED"] = 16] = "RAW_ERROR_COLLECTED";
})(LifeCycleEventType = exports.LifeCycleEventType || (exports.LifeCycleEventType = {}));

@@ -24,0 +25,0 @@ var LifeCycle = /** @class */ (function () {

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

import { Configuration, Context, Observable, RawError, ClocksState } from '@datadog/browser-core';
import { Configuration, Context, ClocksState } from '@datadog/browser-core';
import { CommonContext } from '../../../rawRumEvent.types';

@@ -14,4 +14,4 @@ import { LifeCycle } from '../../lifeCycle';

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

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

function startErrorCollection(lifeCycle, configuration) {
return doStartErrorCollection(lifeCycle, browser_core_1.startAutomaticErrorCollection(configuration));
browser_core_1.startAutomaticErrorCollection(configuration).subscribe(function (error) {
return lifeCycle.notify(lifeCycle_1.LifeCycleEventType.RAW_ERROR_COLLECTED, { error: error });
});
return doStartErrorCollection(lifeCycle);
}
exports.startErrorCollection = startErrorCollection;
function doStartErrorCollection(lifeCycle, observable) {
observable.subscribe(function (error) { return lifeCycle.notify(lifeCycle_1.LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, processError(error)); });
function doStartErrorCollection(lifeCycle) {
lifeCycle.subscribe(lifeCycle_1.LifeCycleEventType.RAW_ERROR_COLLECTED, function (_a) {
var error = _a.error, customerContext = _a.customerContext, savedCommonContext = _a.savedCommonContext;
lifeCycle.notify(lifeCycle_1.LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, tslib_1.__assign({ customerContext: customerContext,
savedCommonContext: savedCommonContext }, processError(error)));
});
return {

@@ -19,4 +26,7 @@ addError: function (_a, savedCommonContext) {

var rawError = computeRawError(error, startClocks, source);
lifeCycle.notify(lifeCycle_1.LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, tslib_1.__assign({ customerContext: customerContext,
savedCommonContext: savedCommonContext }, processError(rawError)));
lifeCycle.notify(lifeCycle_1.LifeCycleEventType.RAW_ERROR_COLLECTED, {
customerContext: customerContext,
savedCommonContext: savedCommonContext,
error: rawError,
});
},

@@ -23,0 +33,0 @@ };

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

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

import { combine, isEmptyObject, limitModification, timeStampNow } from '@datadog/browser-core';
import { combine, createErrorFilter, isEmptyObject, limitModification, timeStampNow, } from '@datadog/browser-core';
import { RumEventType, } from '../rawRumEvent.types';

@@ -19,2 +19,5 @@ import { LifeCycleEventType } from './lifeCycle';

export function startRumAssembly(applicationId, configuration, lifeCycle, session, parentContexts, getCommonContext) {
var errorFilter = createErrorFilter(configuration, function (error) {
lifeCycle.notify(LifeCycleEventType.RAW_ERROR_COLLECTED, { error: error });
});
lifeCycle.subscribe(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, function (_a) {

@@ -57,3 +60,3 @@ var startTime = _a.startTime, rawRumEvent = _a.rawRumEvent, savedCommonContext = _a.savedCommonContext, customerContext = _a.customerContext;

}
if (shouldSend(serverRumEvent, configuration.beforeSend)) {
if (shouldSend(serverRumEvent, configuration.beforeSend, errorFilter)) {
lifeCycle.notify(LifeCycleEventType.RUM_EVENT_COLLECTED, serverRumEvent);

@@ -64,3 +67,3 @@ }

}
function shouldSend(event, beforeSend) {
function shouldSend(event, beforeSend, errorFilter) {
if (beforeSend) {

@@ -75,2 +78,5 @@ var result = limitModification(event, FIELDS_WITH_SENSITIVE_DATA, beforeSend);

}
if (event.type === RumEventType.ERROR) {
return !errorFilter.isLimitReached();
}
return true;

@@ -77,0 +83,0 @@ }

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

import { Context, RelativeTime } from '@datadog/browser-core';
import { Context, RawError, RelativeTime } from '@datadog/browser-core';
import { RumPerformanceEntry } from '../browser/performanceCollection';

@@ -24,3 +24,4 @@ import { CommonContext, RawRumEvent } from '../rawRumEvent.types';

RECORD_STARTED = 14,
RECORD_STOPPED = 15
RECORD_STOPPED = 15,
RAW_ERROR_COLLECTED = 16
}

@@ -40,2 +41,7 @@ export interface Subscription {

notify(eventType: LifeCycleEventType.VIEW_ENDED, data: ViewEndedEvent): void;
notify(eventType: LifeCycleEventType.RAW_ERROR_COLLECTED, data: {
error: RawError;
savedCommonContext?: CommonContext;
customerContext?: Context;
}): void;
notify(eventType: LifeCycleEventType.SESSION_RENEWED | LifeCycleEventType.DOM_MUTATED | LifeCycleEventType.BEFORE_UNLOAD | LifeCycleEventType.AUTO_ACTION_DISCARDED | LifeCycleEventType.RECORD_STARTED | LifeCycleEventType.RECORD_STOPPED): void;

@@ -57,2 +63,7 @@ notify(eventType: LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, data: {

subscribe(eventType: LifeCycleEventType.VIEW_ENDED, callback: (data: ViewEndedEvent) => void): Subscription;
subscribe(eventType: LifeCycleEventType.RAW_ERROR_COLLECTED, callback: (data: {
error: RawError;
savedCommonContext?: CommonContext;
customerContext?: Context;
}) => void): Subscription;
subscribe(eventType: LifeCycleEventType.SESSION_RENEWED | LifeCycleEventType.DOM_MUTATED | LifeCycleEventType.BEFORE_UNLOAD | LifeCycleEventType.AUTO_ACTION_DISCARDED | LifeCycleEventType.RECORD_STARTED | LifeCycleEventType.RECORD_STOPPED, callback: () => void): Subscription;

@@ -59,0 +70,0 @@ subscribe(eventType: LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, callback: (data: {

@@ -19,2 +19,3 @@ export var LifeCycleEventType;

LifeCycleEventType[LifeCycleEventType["RECORD_STOPPED"] = 15] = "RECORD_STOPPED";
LifeCycleEventType[LifeCycleEventType["RAW_ERROR_COLLECTED"] = 16] = "RAW_ERROR_COLLECTED";
})(LifeCycleEventType || (LifeCycleEventType = {}));

@@ -21,0 +22,0 @@ var LifeCycle = /** @class */ (function () {

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

import { Configuration, Context, Observable, RawError, ClocksState } from '@datadog/browser-core';
import { Configuration, Context, ClocksState } from '@datadog/browser-core';
import { CommonContext } from '../../../rawRumEvent.types';

@@ -14,4 +14,4 @@ import { LifeCycle } from '../../lifeCycle';

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

@@ -6,6 +6,13 @@ import { __assign } from "tslib";

export function startErrorCollection(lifeCycle, configuration) {
return doStartErrorCollection(lifeCycle, startAutomaticErrorCollection(configuration));
startAutomaticErrorCollection(configuration).subscribe(function (error) {
return lifeCycle.notify(LifeCycleEventType.RAW_ERROR_COLLECTED, { error: error });
});
return doStartErrorCollection(lifeCycle);
}
export function doStartErrorCollection(lifeCycle, observable) {
observable.subscribe(function (error) { return lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, processError(error)); });
export function doStartErrorCollection(lifeCycle) {
lifeCycle.subscribe(LifeCycleEventType.RAW_ERROR_COLLECTED, function (_a) {
var error = _a.error, customerContext = _a.customerContext, savedCommonContext = _a.savedCommonContext;
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, __assign({ customerContext: customerContext,
savedCommonContext: savedCommonContext }, processError(error)));
});
return {

@@ -15,4 +22,7 @@ addError: function (_a, savedCommonContext) {

var rawError = computeRawError(error, startClocks, source);
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, __assign({ customerContext: customerContext,
savedCommonContext: savedCommonContext }, processError(rawError)));
lifeCycle.notify(LifeCycleEventType.RAW_ERROR_COLLECTED, {
customerContext: customerContext,
savedCommonContext: savedCommonContext,
error: rawError,
});
},

@@ -19,0 +29,0 @@ };

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

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

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

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

},
"gitHead": "7ae5b864b5c54d3f8e76bd1a18e75192b0342a97"
"gitHead": "58466bcf571900220819af5f4cfe7ae2adf5e5ec"
}

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

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

@@ -3,0 +4,0 @@ import { RumPerformanceNavigationTiming } from '../browser/performanceCollection'

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

import { isIE } from '@datadog/browser-core'
import { isIE } from '../../../core/test/specHelper'
import { LifeCycle, LifeCycleEventType } from '../domain/lifeCycle'

@@ -3,0 +3,0 @@ import { startDOMMutationCollection } from './domMutationCollection'

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

import { DEFAULT_CONFIGURATION, noop, RelativeTime } from '@datadog/browser-core'
import { ErrorSource, ONE_MINUTE, RawError, RelativeTime } from '@datadog/browser-core'
import { createRawRumEvent } from '../../test/fixtures'
import { setup, TestSetupBuilder } from '../../test/specHelper'
import { CommonContext, RumEventType } from '../rawRumEvent.types'
import { RumActionEvent, RumEvent } from '../rumEvent.types'
import { CommonContext, RawRumErrorEvent, RumEventType } from '../rawRumEvent.types'
import { RumActionEvent, RumErrorEvent, RumEvent } from '../rumEvent.types'
import { startRumAssembly } from './assembly'

@@ -11,11 +11,7 @@ import { LifeCycle, LifeCycleEventType } from './lifeCycle'

let setupBuilder: TestSetupBuilder
let lifeCycle: LifeCycle
let commonContext: CommonContext
let serverRumEvents: RumEvent[]
let isTracked: boolean
let viewSessionId: string | undefined
let beforeSend: (event: RumEvent) => void
beforeEach(() => {
isTracked = true
viewSessionId = '1234'

@@ -26,13 +22,3 @@ commonContext = {

}
beforeSend = noop
setupBuilder = setup()
.withSession({
getId: () => '1234',
isTracked: () => isTracked,
isTrackedWithResource: () => true,
})
.withConfiguration({
...DEFAULT_CONFIGURATION,
beforeSend: (x: RumEvent) => beforeSend(x),
})
.withParentContexts({

@@ -55,11 +41,9 @@ findAction: () => ({

})
.beforeBuild(({ applicationId, configuration, lifeCycle: localLifeCycle, session, parentContexts }) => {
startRumAssembly(applicationId, configuration, localLifeCycle, session, parentContexts, () => commonContext)
.beforeBuild(({ applicationId, configuration, lifeCycle, session, parentContexts }) => {
serverRumEvents = []
lifeCycle.subscribe(LifeCycleEventType.RUM_EVENT_COLLECTED, (serverRumEvent) =>
serverRumEvents.push(serverRumEvent)
)
startRumAssembly(applicationId, configuration, lifeCycle, session, parentContexts, () => commonContext)
})
;({ lifeCycle } = setupBuilder.build())
serverRumEvents = []
lifeCycle.subscribe(LifeCycleEventType.RUM_EVENT_COLLECTED, (serverRumEvent) =>
serverRumEvents.push(serverRumEvent)
)
})

@@ -73,3 +57,7 @@

it('should allow modification on sensitive field', () => {
beforeSend = (event: RumEvent) => (event.view.url = 'modified')
const { lifeCycle } = setupBuilder
.withConfiguration({
beforeSend: (event) => (event.view.url = 'modified'),
})
.build()

@@ -85,3 +73,7 @@ lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {

it('should reject modification on non sensitive field', () => {
beforeSend = (event: RumEvent) => ((event.view as any).id = 'modified')
const { lifeCycle } = setupBuilder
.withConfiguration({
beforeSend: (event: RumEvent) => ((event.view as any).id = 'modified'),
})
.build()

@@ -99,3 +91,7 @@ lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {

it('should allow dismissing events other than views', () => {
beforeSend = () => false
const { lifeCycle } = setupBuilder
.withConfiguration({
beforeSend: () => false,
})
.build()

@@ -134,3 +130,8 @@ lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {

it('should not allow dismissing view events', () => {
beforeSend = () => false
const { lifeCycle } = setupBuilder
.withConfiguration({
beforeSend: () => false,
})
.build()
const consoleWarnSpy = spyOn(console, 'warn')

@@ -151,2 +152,3 @@ lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {

it('should be merged with event attributes', () => {
const { lifeCycle } = setupBuilder.build()
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {

@@ -162,2 +164,3 @@ rawRumEvent: createRawRumEvent(RumEventType.VIEW, undefined),

it('should be overwritten by event attributes', () => {
const { lifeCycle } = setupBuilder.build()
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {

@@ -174,2 +177,3 @@ rawRumEvent: createRawRumEvent(RumEventType.VIEW, { date: 10 }),

it('should be merged with event attributes', () => {
const { lifeCycle } = setupBuilder.build()
commonContext.context = { bar: 'foo' }

@@ -185,2 +189,3 @@ lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {

it('should not be included if empty', () => {
const { lifeCycle } = setupBuilder.build()
commonContext.context = {}

@@ -196,2 +201,3 @@ lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {

it('should ignore subsequent context mutation', () => {
const { lifeCycle } = setupBuilder.build()
commonContext.context = { bar: 'foo', baz: 'foz' }

@@ -213,2 +219,3 @@ lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {

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

@@ -232,2 +239,3 @@

it('should be included in event attributes', () => {
const { lifeCycle } = setupBuilder.build()
commonContext.user = { id: 'foo' }

@@ -243,2 +251,3 @@ lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {

it('should not be included if empty', () => {
const { lifeCycle } = setupBuilder.build()
commonContext.user = {}

@@ -254,2 +263,3 @@ lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {

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

@@ -273,2 +283,3 @@

it('should be merged with event attributes', () => {
const { lifeCycle } = setupBuilder.build()
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {

@@ -286,2 +297,3 @@ customerContext: { foo: 'bar' },

it('should be added on some event categories', () => {
const { lifeCycle } = setupBuilder.build()
;[RumEventType.RESOURCE, RumEventType.LONG_TASK, RumEventType.ERROR].forEach((category) => {

@@ -314,2 +326,3 @@ lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {

it('should be merged with event attributes', () => {
const { lifeCycle } = setupBuilder.build()
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {

@@ -330,4 +343,3 @@ rawRumEvent: createRawRumEvent(RumEventType.ACTION),

it('when tracked, it should generate event', () => {
isTracked = true
const { lifeCycle } = setupBuilder.build()
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {

@@ -341,4 +353,9 @@ rawRumEvent: createRawRumEvent(RumEventType.VIEW),

it('when not tracked, it should not generate event', () => {
isTracked = false
const { lifeCycle } = setupBuilder
.withSession({
getId: () => '1234',
isTracked: () => false,
isTrackedWithResource: () => false,
})
.build()
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {

@@ -352,2 +369,3 @@ rawRumEvent: createRawRumEvent(RumEventType.VIEW),

it('when view context has current session id, it should generate event', () => {
const { lifeCycle } = setupBuilder.build()
viewSessionId = '1234'

@@ -363,2 +381,3 @@

it('when view context has not the current session id, it should not generate event', () => {
const { lifeCycle } = setupBuilder.build()
viewSessionId = '6789'

@@ -374,2 +393,3 @@

it('when view context has no session id, it should not generate event', () => {
const { lifeCycle } = setupBuilder.build()
viewSessionId = undefined

@@ -387,2 +407,3 @@

it('should include the session type and id', () => {
const { lifeCycle } = setupBuilder.build()
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {

@@ -400,2 +421,3 @@ rawRumEvent: createRawRumEvent(RumEventType.VIEW),

it('should set the session.has_replay attribute if it is defined in the common context', () => {
const { lifeCycle } = setupBuilder.build()
commonContext.hasReplay = true

@@ -411,2 +433,3 @@

it('should not use commonContext.hasReplay on view events', () => {
const { lifeCycle } = setupBuilder.build()
commonContext.hasReplay = true

@@ -421,2 +444,70 @@

})
describe('error events limitation', () => {
const notifiedRawErrors: RawError[] = []
beforeEach(() => {
notifiedRawErrors.length = 0
setupBuilder.beforeBuild(({ lifeCycle }) => {
lifeCycle.subscribe(LifeCycleEventType.RAW_ERROR_COLLECTED, ({ error }) => notifiedRawErrors.push(error))
})
})
it('stops sending error events when reaching the limit', () => {
const { lifeCycle } = setupBuilder.withConfiguration({ maxErrorsByMinute: 1 }).build()
notifyRawRumErrorEvent(lifeCycle, 'foo')
notifyRawRumErrorEvent(lifeCycle, 'bar')
expect(serverRumEvents.length).toBe(1)
expect((serverRumEvents[0] as RumErrorEvent).error.message).toBe('foo')
expect(notifiedRawErrors.length).toBe(1)
expect(notifiedRawErrors[0]).toEqual(
jasmine.objectContaining({
message: 'Reached max number of errors by minute: 1',
source: ErrorSource.AGENT,
})
)
})
it('does not take discarded errors into account', () => {
const { lifeCycle } = setupBuilder
.withConfiguration({
maxErrorsByMinute: 1,
beforeSend: (event) => {
if (event.type === RumEventType.ERROR && (event as RumErrorEvent).error.message === 'discard me') {
return false
}
},
})
.build()
notifyRawRumErrorEvent(lifeCycle, 'discard me')
notifyRawRumErrorEvent(lifeCycle, 'discard me')
notifyRawRumErrorEvent(lifeCycle, 'discard me')
notifyRawRumErrorEvent(lifeCycle, 'foo')
expect(serverRumEvents.length).toBe(1)
expect((serverRumEvents[0] as RumErrorEvent).error.message).toBe('foo')
expect(notifiedRawErrors.length).toBe(0)
})
it('allows to send new errors after a minute', () => {
const { lifeCycle, clock } = setupBuilder.withFakeClock().withConfiguration({ maxErrorsByMinute: 1 }).build()
notifyRawRumErrorEvent(lifeCycle, 'foo')
notifyRawRumErrorEvent(lifeCycle, 'bar')
clock.tick(ONE_MINUTE)
notifyRawRumErrorEvent(lifeCycle, 'baz')
expect(serverRumEvents.length).toBe(2)
expect((serverRumEvents[0] as RumErrorEvent).error.message).toBe('foo')
expect((serverRumEvents[1] as RumErrorEvent).error.message).toBe('baz')
})
function notifyRawRumErrorEvent(lifeCycle: LifeCycle, message = 'oh snap') {
const rawRumEvent = createRawRumEvent(RumEventType.ERROR) as RawRumErrorEvent
rawRumEvent.error.message = message
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent,
startTime: 0 as RelativeTime,
})
}
})
})

@@ -1,3 +0,12 @@

import { combine, Configuration, Context, isEmptyObject, limitModification, timeStampNow } from '@datadog/browser-core'
import {
combine,
Configuration,
Context,
createErrorFilter,
ErrorFilter,
isEmptyObject,
limitModification,
timeStampNow,
} from '@datadog/browser-core'
import {
CommonContext,

@@ -44,2 +53,6 @@ RawRumErrorEvent,

) {
const errorFilter = createErrorFilter(configuration, (error) => {
lifeCycle.notify(LifeCycleEventType.RAW_ERROR_COLLECTED, { error })
})
lifeCycle.subscribe(

@@ -84,3 +97,3 @@ LifeCycleEventType.RAW_RUM_EVENT_COLLECTED,

}
if (shouldSend(serverRumEvent, configuration.beforeSend)) {
if (shouldSend(serverRumEvent, configuration.beforeSend, errorFilter)) {
lifeCycle.notify(LifeCycleEventType.RUM_EVENT_COLLECTED, serverRumEvent)

@@ -93,3 +106,7 @@ }

function shouldSend(event: RumEvent & Context, beforeSend?: (event: any) => unknown) {
function shouldSend(
event: RumEvent & Context,
beforeSend: ((event: any) => unknown) | undefined,
errorFilter: ErrorFilter
) {
if (beforeSend) {

@@ -104,2 +121,5 @@ const result = limitModification(event, FIELDS_WITH_SENSITIVE_DATA, beforeSend)

}
if (event.type === RumEventType.ERROR) {
return !errorFilter.isLimitReached()
}
return true

@@ -106,0 +126,0 @@ }

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

import { Context, RelativeTime } from '@datadog/browser-core'
import { Context, RawError, RelativeTime } from '@datadog/browser-core'
import { RumPerformanceEntry } from '../browser/performanceCollection'

@@ -26,2 +26,3 @@ import { CommonContext, RawRumEvent } from '../rawRumEvent.types'

RECORD_STOPPED,
RAW_ERROR_COLLECTED,
}

@@ -45,2 +46,6 @@

notify(
eventType: LifeCycleEventType.RAW_ERROR_COLLECTED,
data: { error: RawError; savedCommonContext?: CommonContext; customerContext?: Context }
): void
notify(
eventType:

@@ -89,2 +94,6 @@ | LifeCycleEventType.SESSION_RENEWED

subscribe(
eventType: LifeCycleEventType.RAW_ERROR_COLLECTED,
callback: (data: { error: RawError; savedCommonContext?: CommonContext; customerContext?: Context }) => void
): Subscription
subscribe(
eventType:

@@ -91,0 +100,0 @@ | LifeCycleEventType.SESSION_RENEWED

import {
Configuration,
DEFAULT_CONFIGURATION,
RequestType,
resetFetchProxy,
resetXhrProxy,
} from '@datadog/browser-core'
import {
FetchStub,
FetchStubManager,
isIE,
RequestType,
resetFetchProxy,
resetXhrProxy,
SPEC_ENDPOINTS,

@@ -14,3 +16,3 @@ stubFetch,

withXhr,
} from '@datadog/browser-core'
} from '../../../core/test/specHelper'
import { LifeCycle, LifeCycleEventType } from './lifeCycle'

@@ -17,0 +19,0 @@ import { RequestCompleteEvent, RequestStartEvent, trackFetch, trackXhr } from './requestCollection'

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

import { ErrorSource, Observable, RawError, RelativeTime, TimeStamp } from '@datadog/browser-core'
import { ErrorSource, RelativeTime, TimeStamp } from '@datadog/browser-core'
import { setup, TestSetupBuilder } from '../../../../test/specHelper'
import { RumEventType } from '../../../rawRumEvent.types'
import { LifeCycleEventType } from '../../lifeCycle'
import { doStartErrorCollection } from './errorCollection'

@@ -8,3 +9,2 @@

let setupBuilder: TestSetupBuilder
const errorObservable = new Observable<RawError>()
let addError: ReturnType<typeof doStartErrorCollection>['addError']

@@ -18,3 +18,3 @@

.beforeBuild(({ lifeCycle }) => {
;({ addError } = doStartErrorCollection(lifeCycle, errorObservable))
;({ addError } = doStartErrorCollection(lifeCycle))
})

@@ -99,16 +99,18 @@ })

describe('auto', () => {
describe('RAW_ERROR_COLLECTED LifeCycle event', () => {
it('should create error event from collected error', () => {
const { rawRumEvents } = setupBuilder.build()
errorObservable.notify({
message: 'hello',
resource: {
method: 'GET',
statusCode: 500,
url: 'url',
const { rawRumEvents, lifeCycle } = setupBuilder.build()
lifeCycle.notify(LifeCycleEventType.RAW_ERROR_COLLECTED, {
error: {
message: 'hello',
resource: {
method: 'GET',
statusCode: 500,
url: 'url',
},
source: ErrorSource.NETWORK,
stack: 'bar',
startClocks: { relative: 1234 as RelativeTime, timeStamp: 123456789 as TimeStamp },
type: 'foo',
},
source: ErrorSource.NETWORK,
stack: 'bar',
startClocks: { relative: 1234 as RelativeTime, timeStamp: 123456789 as TimeStamp },
type: 'foo',
})

@@ -115,0 +117,0 @@

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

formatUnknownError,
Observable,
RawError,

@@ -26,7 +25,17 @@ startAutomaticErrorCollection,

export function startErrorCollection(lifeCycle: LifeCycle, configuration: Configuration) {
return doStartErrorCollection(lifeCycle, startAutomaticErrorCollection(configuration))
startAutomaticErrorCollection(configuration).subscribe((error) =>
lifeCycle.notify(LifeCycleEventType.RAW_ERROR_COLLECTED, { error })
)
return doStartErrorCollection(lifeCycle)
}
export function doStartErrorCollection(lifeCycle: LifeCycle, observable: Observable<RawError>) {
observable.subscribe((error) => lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, processError(error)))
export function doStartErrorCollection(lifeCycle: LifeCycle) {
lifeCycle.subscribe(LifeCycleEventType.RAW_ERROR_COLLECTED, ({ error, customerContext, savedCommonContext }) => {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
customerContext,
savedCommonContext,
...processError(error),
})
})

@@ -39,6 +48,6 @@ return {

const rawError = computeRawError(error, startClocks, source)
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
lifeCycle.notify(LifeCycleEventType.RAW_ERROR_COLLECTED, {
customerContext,
savedCommonContext,
...processError(rawError),
error: rawError,
})

@@ -45,0 +54,0 @@ },

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

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

@@ -4,0 +5,0 @@ import { RequestCompleteEvent } from '../../requestCollection'

@@ -1,9 +0,3 @@

import {
Configuration,
DEFAULT_CONFIGURATION,
Duration,
RelativeTime,
ServerDuration,
SPEC_ENDPOINTS,
} from '@datadog/browser-core'
import { Configuration, DEFAULT_CONFIGURATION, Duration, RelativeTime, ServerDuration } from '@datadog/browser-core'
import { SPEC_ENDPOINTS } from '../../../../../core/test/specHelper'
import { RumPerformanceResourceTiming } from '../../../browser/performanceCollection'

@@ -10,0 +4,0 @@ import {

@@ -1,8 +0,3 @@

import {
createNewEvent,
DOM_EVENT,
RelativeTime,
restorePageVisibility,
setPageVisibility,
} from '@datadog/browser-core'
import { DOM_EVENT, RelativeTime } from '@datadog/browser-core'
import { createNewEvent, restorePageVisibility, setPageVisibility } from '../../../../../core/test/specHelper'
import { resetFirstHidden, trackFirstHidden } from './trackFirstHidden'

@@ -9,0 +4,0 @@

@@ -1,9 +0,3 @@

import {
createNewEvent,
DOM_EVENT,
Duration,
RelativeTime,
restorePageVisibility,
setPageVisibility,
} from '@datadog/browser-core'
import { DOM_EVENT, Duration, RelativeTime } from '@datadog/browser-core'
import { createNewEvent, restorePageVisibility, setPageVisibility } from '../../../../../core/test/specHelper'
import { setup, TestSetupBuilder } from '../../../../test/specHelper'

@@ -10,0 +4,0 @@ import {

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

getCookie,
isIE,
SESSION_COOKIE_NAME,

@@ -12,2 +11,3 @@ setCookie,

} from '@datadog/browser-core'
import { isIE } from '../../../core/test/specHelper'

@@ -14,0 +14,0 @@ import { LifeCycle, LifeCycleEventType } from './lifeCycle'

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

import { Configuration, DEFAULT_CONFIGURATION, isIE, objectEntries } from '@datadog/browser-core'
import { Configuration, DEFAULT_CONFIGURATION, objectEntries } from '@datadog/browser-core'
import { isIE } from '../../../../core/test/specHelper'
import { setup, TestSetupBuilder } from '../../../test/specHelper'

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

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