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

@datadog/browser-core

Package Overview
Dependencies
Maintainers
1
Versions
258
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@datadog/browser-core - npm Package Compare versions

Comparing version 4.10.0 to 4.10.1

2

cjs/boot/init.js

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

var publicApi = (0, utils_1.assign)({
version: "4.10.0",
version: "4.10.1",
// This API method is intentionally not monitored, since the only thing executed is the

@@ -12,0 +12,0 @@ // user-provided 'callback'. All SDK usages executed in the callback should be monitored, and

@@ -44,4 +44,4 @@ import type { CookieOptions } from '../../browser/cookie';

flushTimeout: number;
maxBatchSize: number;
maxMessageSize: number;
batchMessagesLimit: number;
messageBytesLimit: number;
}

@@ -48,0 +48,0 @@ export declare function validateAndBuildConfiguration(initConfiguration: InitConfiguration): Configuration | undefined;

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

*/
maxBatchSize: 50,
maxMessageSize: 256 * utils_1.ONE_KILO_BYTE,
batchMessagesLimit: 50,
messageBytesLimit: 256 * utils_1.ONE_KILO_BYTE,
}, (0, transportConfiguration_1.computeTransportConfiguration)(initConfiguration));

@@ -57,0 +57,0 @@ }

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

var parameters = "ddsource=".concat(source || 'browser') +
"&ddtags=".concat(encodeURIComponent(["sdk_version:".concat("4.10.0")].concat(tags).join(','))) +
"&ddtags=".concat(encodeURIComponent(["sdk_version:".concat("4.10.1")].concat(tags).join(','))) +
"&dd-api-key=".concat(clientToken) +
"&dd-evp-origin-version=".concat(encodeURIComponent("4.10.0")) +
"&dd-evp-origin-version=".concat(encodeURIComponent("4.10.1")) +
'&dd-evp-origin=browser' +

@@ -37,0 +37,0 @@ "&dd-request-id=".concat((0, utils_1.generateUUID)());

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

var TELEMETRY_ALLOWED_SITES = [
// INTAKE_SITE_US5,
// INTAKE_SITE_US3,
// INTAKE_SITE_EU,
// INTAKE_SITE_US,
configuration_1.INTAKE_SITE_US5,
// INTAKE_SITE_US3,
// INTAKE_SITE_EU,
// INTAKE_SITE_US,
];

@@ -45,3 +45,3 @@ var monitoringConfiguration = { maxMessagesPerPage: 0, sentMessageCount: 0, telemetryEnabled: false };

service: 'browser-sdk',
version: "4.10.0",
version: "4.10.1",
source: 'browser',

@@ -48,0 +48,0 @@ _dd: {

@@ -5,5 +5,5 @@ import type { Context } from '../tools/context';

private request;
private maxSize;
private bytesLimit;
private maxMessageSize;
private batchMessagesLimit;
private batchBytesLimit;
private messageBytesLimit;
private flushTimeout;

@@ -13,9 +13,9 @@ private beforeUnloadCallback;

private upsertBuffer;
private bufferBytesSize;
private bufferMessageCount;
constructor(request: HttpRequest, maxSize: number, bytesLimit: number, maxMessageSize: number, flushTimeout: number, beforeUnloadCallback?: () => void);
private bufferBytesCount;
private bufferMessagesCount;
constructor(request: HttpRequest, batchMessagesLimit: number, batchBytesLimit: number, messageBytesLimit: number, flushTimeout: number, beforeUnloadCallback?: () => void);
add(message: Context): void;
upsert(message: Context, key: string): void;
flush(reason?: string): void;
sizeInBytes(candidate: string): number;
computeBytesCount(candidate: string): number;
private addOrUpdate;

@@ -22,0 +22,0 @@ private process;

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

var Batch = /** @class */ (function () {
function Batch(request, maxSize, bytesLimit, maxMessageSize, flushTimeout, beforeUnloadCallback) {
function Batch(request, batchMessagesLimit, batchBytesLimit, messageBytesLimit, flushTimeout, beforeUnloadCallback) {
if (beforeUnloadCallback === void 0) { beforeUnloadCallback = utils_1.noop; }
this.request = request;
this.maxSize = maxSize;
this.bytesLimit = bytesLimit;
this.maxMessageSize = maxMessageSize;
this.batchMessagesLimit = batchMessagesLimit;
this.batchBytesLimit = batchBytesLimit;
this.messageBytesLimit = messageBytesLimit;
this.flushTimeout = flushTimeout;

@@ -22,4 +22,4 @@ this.beforeUnloadCallback = beforeUnloadCallback;

this.upsertBuffer = {};
this.bufferBytesSize = 0;
this.bufferMessageCount = 0;
this.bufferBytesCount = 0;
this.bufferMessagesCount = 0;
this.flushOnVisibilityHidden();

@@ -35,13 +35,13 @@ this.flushPeriodically();

Batch.prototype.flush = function (reason) {
if (this.bufferMessageCount !== 0) {
if (this.bufferMessagesCount !== 0) {
var messages = this.pushOnlyBuffer.concat((0, utils_1.objectValues)(this.upsertBuffer));
this.request.send(messages.join('\n'), this.bufferBytesSize, reason);
this.request.send(messages.join('\n'), this.bufferBytesCount, reason);
this.pushOnlyBuffer = [];
this.upsertBuffer = {};
this.bufferBytesSize = 0;
this.bufferMessageCount = 0;
this.bufferBytesCount = 0;
this.bufferMessagesCount = 0;
}
};
Batch.prototype.sizeInBytes = function (candidate) {
// Accurate byte size computations can degrade performances when there is a lot of events to process
Batch.prototype.computeBytesCount = function (candidate) {
// Accurate bytes count computations can degrade performances when there is a lot of events to process
if (!HAS_MULTI_BYTES_CHARACTERS.test(candidate)) {

@@ -56,5 +56,5 @@ return candidate.length;

Batch.prototype.addOrUpdate = function (message, key) {
var _a = this.process(message), processedMessage = _a.processedMessage, messageBytesSize = _a.messageBytesSize;
if (messageBytesSize >= this.maxMessageSize) {
display_1.display.warn("Discarded a message whose size was bigger than the maximum allowed size ".concat(this.maxMessageSize, "KB."));
var _a = this.process(message), processedMessage = _a.processedMessage, messageBytesCount = _a.messageBytesCount;
if (messageBytesCount >= this.messageBytesLimit) {
display_1.display.warn("Discarded a message whose size was bigger than the maximum allowed size ".concat(this.messageBytesLimit, "KB."));
return;

@@ -65,8 +65,8 @@ }

}
if (this.willReachedBytesLimitWith(messageBytesSize)) {
this.flush('max_size');
if (this.willReachedBytesLimitWith(messageBytesCount)) {
this.flush('batch_bytes_limit');
}
this.push(processedMessage, messageBytesSize, key);
this.push(processedMessage, messageBytesCount, key);
if (this.isFull()) {
this.flush('max_messages_count');
this.flush('batch_messages_limit');
}

@@ -76,9 +76,9 @@ };

var processedMessage = (0, utils_1.jsonStringify)(message);
var messageBytesSize = this.sizeInBytes(processedMessage);
return { processedMessage: processedMessage, messageBytesSize: messageBytesSize };
var messageBytesCount = this.computeBytesCount(processedMessage);
return { processedMessage: processedMessage, messageBytesCount: messageBytesCount };
};
Batch.prototype.push = function (processedMessage, messageBytesSize, key) {
if (this.bufferMessageCount > 0) {
Batch.prototype.push = function (processedMessage, messageBytesCount, key) {
if (this.bufferMessagesCount > 0) {
// \n separator at serialization
this.bufferBytesSize += 1;
this.bufferBytesCount += 1;
}

@@ -91,4 +91,4 @@ if (key !== undefined) {

}
this.bufferBytesSize += messageBytesSize;
this.bufferMessageCount += 1;
this.bufferBytesCount += messageBytesCount;
this.bufferMessagesCount += 1;
};

@@ -98,7 +98,7 @@ Batch.prototype.remove = function (key) {

delete this.upsertBuffer[key];
var messageBytesSize = this.sizeInBytes(removedMessage);
this.bufferBytesSize -= messageBytesSize;
this.bufferMessageCount -= 1;
if (this.bufferMessageCount > 0) {
this.bufferBytesSize -= 1;
var messageBytesCount = this.computeBytesCount(removedMessage);
this.bufferBytesCount -= messageBytesCount;
this.bufferMessagesCount -= 1;
if (this.bufferMessagesCount > 0) {
this.bufferBytesCount -= 1;
}

@@ -109,8 +109,8 @@ };

};
Batch.prototype.willReachedBytesLimitWith = function (messageBytesSize) {
Batch.prototype.willReachedBytesLimitWith = function (messageBytesCount) {
// byte of the separator at the end of the message
return this.bufferBytesSize + messageBytesSize + 1 >= this.bytesLimit;
return this.bufferBytesCount + messageBytesCount + 1 >= this.batchBytesLimit;
};
Batch.prototype.isFull = function () {
return this.bufferMessageCount === this.maxSize || this.bufferBytesSize >= this.bytesLimit;
return this.bufferMessagesCount === this.batchMessagesLimit || this.bufferBytesCount >= this.batchBytesLimit;
};

@@ -120,3 +120,3 @@ Batch.prototype.flushPeriodically = function () {

setTimeout((0, internalMonitoring_1.monitor)(function () {
_this.flush('max_duration');
_this.flush('batch_flush_timeout');
_this.flushPeriodically();

@@ -123,0 +123,0 @@ }), this.flushTimeout);

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

endpointType: endpointType,
version: "4.10.0",
version: "4.10.1",
connection: navigator.connection ? navigator.connection.effectiveType : undefined,

@@ -24,0 +24,0 @@ onLine: navigator.onLine,

@@ -14,3 +14,3 @@ import type { EndpointBuilder } from '../domain/configuration';

constructor(endpointBuilder: EndpointBuilder, bytesLimit: number);
send(data: string | FormData, size: number, reason?: string): void;
send(data: string | FormData, bytesCount: number, reason?: string): void;
}

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

}
HttpRequest.prototype.send = function (data, size, reason) {
HttpRequest.prototype.send = function (data, bytesCount, reason) {
var url = this.endpointBuilder.build();
var canUseBeacon = !!navigator.sendBeacon && size < this.bytesLimit;
var canUseBeacon = !!navigator.sendBeacon && bytesCount < this.bytesLimit;
if (canUseBeacon) {

@@ -29,3 +29,3 @@ try {

}
(0, failedSendBeacon_1.addFailedSendBeacon)(this.endpointBuilder.endpointType, size, reason);
(0, failedSendBeacon_1.addFailedSendBeacon)(this.endpointBuilder.endpointType, bytesCount, reason);
}

@@ -32,0 +32,0 @@ catch (e) {

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

function createBatch(endpointBuilder) {
return new index_1.Batch(new index_1.HttpRequest(endpointBuilder, configuration.batchBytesLimit), configuration.maxBatchSize, configuration.batchBytesLimit, configuration.maxMessageSize, configuration.flushTimeout);
return new index_1.Batch(new index_1.HttpRequest(endpointBuilder, configuration.batchBytesLimit), configuration.batchMessagesLimit, configuration.batchBytesLimit, configuration.messageBytesLimit, configuration.flushTimeout);
}

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

@@ -6,3 +6,3 @@ import { setDebugMode } from '../domain/internalMonitoring';

var publicApi = assign({
version: "4.10.0",
version: "4.10.1",
// This API method is intentionally not monitored, since the only thing executed is the

@@ -9,0 +9,0 @@ // user-provided 'callback'. All SDK usages executed in the callback should be monitored, and

@@ -44,4 +44,4 @@ import type { CookieOptions } from '../../browser/cookie';

flushTimeout: number;
maxBatchSize: number;
maxMessageSize: number;
batchMessagesLimit: number;
messageBytesLimit: number;
}

@@ -48,0 +48,0 @@ export declare function validateAndBuildConfiguration(initConfiguration: InitConfiguration): Configuration | undefined;

@@ -50,4 +50,4 @@ import { getCurrentSite } from '../../browser/cookie';

*/
maxBatchSize: 50,
maxMessageSize: 256 * ONE_KILO_BYTE,
batchMessagesLimit: 50,
messageBytesLimit: 256 * ONE_KILO_BYTE,
}, computeTransportConfiguration(initConfiguration));

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

@@ -29,5 +29,5 @@ import { timeStampNow } from '../../tools/timeUtils';

var parameters = "ddsource=".concat(source || 'browser') +
"&ddtags=".concat(encodeURIComponent(["sdk_version:".concat("4.10.0")].concat(tags).join(','))) +
"&ddtags=".concat(encodeURIComponent(["sdk_version:".concat("4.10.1")].concat(tags).join(','))) +
"&dd-api-key=".concat(clientToken) +
"&dd-evp-origin-version=".concat(encodeURIComponent("4.10.0")) +
"&dd-evp-origin-version=".concat(encodeURIComponent("4.10.1")) +
'&dd-evp-origin=browser' +

@@ -34,0 +34,0 @@ "&dd-request-id=".concat(generateUUID());

@@ -7,8 +7,8 @@ import { display } from '../../tools/display';

import { timeStampNow } from '../../tools/timeUtils';
import { isExperimentalFeatureEnabled, INTAKE_SITE_STAGING } from '../configuration';
import { isExperimentalFeatureEnabled, INTAKE_SITE_STAGING, INTAKE_SITE_US5 } from '../configuration';
var TELEMETRY_ALLOWED_SITES = [
// INTAKE_SITE_US5,
// INTAKE_SITE_US3,
// INTAKE_SITE_EU,
// INTAKE_SITE_US,
INTAKE_SITE_US5,
// INTAKE_SITE_US3,
// INTAKE_SITE_EU,
// INTAKE_SITE_US,
];

@@ -42,3 +42,3 @@ var monitoringConfiguration = { maxMessagesPerPage: 0, sentMessageCount: 0, telemetryEnabled: false };

service: 'browser-sdk',
version: "4.10.0",
version: "4.10.1",
source: 'browser',

@@ -45,0 +45,0 @@ _dd: {

@@ -5,5 +5,5 @@ import type { Context } from '../tools/context';

private request;
private maxSize;
private bytesLimit;
private maxMessageSize;
private batchMessagesLimit;
private batchBytesLimit;
private messageBytesLimit;
private flushTimeout;

@@ -13,9 +13,9 @@ private beforeUnloadCallback;

private upsertBuffer;
private bufferBytesSize;
private bufferMessageCount;
constructor(request: HttpRequest, maxSize: number, bytesLimit: number, maxMessageSize: number, flushTimeout: number, beforeUnloadCallback?: () => void);
private bufferBytesCount;
private bufferMessagesCount;
constructor(request: HttpRequest, batchMessagesLimit: number, batchBytesLimit: number, messageBytesLimit: number, flushTimeout: number, beforeUnloadCallback?: () => void);
add(message: Context): void;
upsert(message: Context, key: string): void;
flush(reason?: string): void;
sizeInBytes(candidate: string): number;
computeBytesCount(candidate: string): number;
private addOrUpdate;

@@ -22,0 +22,0 @@ private process;

@@ -8,8 +8,8 @@ import { display } from '../tools/display';

var Batch = /** @class */ (function () {
function Batch(request, maxSize, bytesLimit, maxMessageSize, flushTimeout, beforeUnloadCallback) {
function Batch(request, batchMessagesLimit, batchBytesLimit, messageBytesLimit, flushTimeout, beforeUnloadCallback) {
if (beforeUnloadCallback === void 0) { beforeUnloadCallback = noop; }
this.request = request;
this.maxSize = maxSize;
this.bytesLimit = bytesLimit;
this.maxMessageSize = maxMessageSize;
this.batchMessagesLimit = batchMessagesLimit;
this.batchBytesLimit = batchBytesLimit;
this.messageBytesLimit = messageBytesLimit;
this.flushTimeout = flushTimeout;

@@ -19,4 +19,4 @@ this.beforeUnloadCallback = beforeUnloadCallback;

this.upsertBuffer = {};
this.bufferBytesSize = 0;
this.bufferMessageCount = 0;
this.bufferBytesCount = 0;
this.bufferMessagesCount = 0;
this.flushOnVisibilityHidden();

@@ -32,13 +32,13 @@ this.flushPeriodically();

Batch.prototype.flush = function (reason) {
if (this.bufferMessageCount !== 0) {
if (this.bufferMessagesCount !== 0) {
var messages = this.pushOnlyBuffer.concat(objectValues(this.upsertBuffer));
this.request.send(messages.join('\n'), this.bufferBytesSize, reason);
this.request.send(messages.join('\n'), this.bufferBytesCount, reason);
this.pushOnlyBuffer = [];
this.upsertBuffer = {};
this.bufferBytesSize = 0;
this.bufferMessageCount = 0;
this.bufferBytesCount = 0;
this.bufferMessagesCount = 0;
}
};
Batch.prototype.sizeInBytes = function (candidate) {
// Accurate byte size computations can degrade performances when there is a lot of events to process
Batch.prototype.computeBytesCount = function (candidate) {
// Accurate bytes count computations can degrade performances when there is a lot of events to process
if (!HAS_MULTI_BYTES_CHARACTERS.test(candidate)) {

@@ -53,5 +53,5 @@ return candidate.length;

Batch.prototype.addOrUpdate = function (message, key) {
var _a = this.process(message), processedMessage = _a.processedMessage, messageBytesSize = _a.messageBytesSize;
if (messageBytesSize >= this.maxMessageSize) {
display.warn("Discarded a message whose size was bigger than the maximum allowed size ".concat(this.maxMessageSize, "KB."));
var _a = this.process(message), processedMessage = _a.processedMessage, messageBytesCount = _a.messageBytesCount;
if (messageBytesCount >= this.messageBytesLimit) {
display.warn("Discarded a message whose size was bigger than the maximum allowed size ".concat(this.messageBytesLimit, "KB."));
return;

@@ -62,8 +62,8 @@ }

}
if (this.willReachedBytesLimitWith(messageBytesSize)) {
this.flush('max_size');
if (this.willReachedBytesLimitWith(messageBytesCount)) {
this.flush('batch_bytes_limit');
}
this.push(processedMessage, messageBytesSize, key);
this.push(processedMessage, messageBytesCount, key);
if (this.isFull()) {
this.flush('max_messages_count');
this.flush('batch_messages_limit');
}

@@ -73,9 +73,9 @@ };

var processedMessage = jsonStringify(message);
var messageBytesSize = this.sizeInBytes(processedMessage);
return { processedMessage: processedMessage, messageBytesSize: messageBytesSize };
var messageBytesCount = this.computeBytesCount(processedMessage);
return { processedMessage: processedMessage, messageBytesCount: messageBytesCount };
};
Batch.prototype.push = function (processedMessage, messageBytesSize, key) {
if (this.bufferMessageCount > 0) {
Batch.prototype.push = function (processedMessage, messageBytesCount, key) {
if (this.bufferMessagesCount > 0) {
// \n separator at serialization
this.bufferBytesSize += 1;
this.bufferBytesCount += 1;
}

@@ -88,4 +88,4 @@ if (key !== undefined) {

}
this.bufferBytesSize += messageBytesSize;
this.bufferMessageCount += 1;
this.bufferBytesCount += messageBytesCount;
this.bufferMessagesCount += 1;
};

@@ -95,7 +95,7 @@ Batch.prototype.remove = function (key) {

delete this.upsertBuffer[key];
var messageBytesSize = this.sizeInBytes(removedMessage);
this.bufferBytesSize -= messageBytesSize;
this.bufferMessageCount -= 1;
if (this.bufferMessageCount > 0) {
this.bufferBytesSize -= 1;
var messageBytesCount = this.computeBytesCount(removedMessage);
this.bufferBytesCount -= messageBytesCount;
this.bufferMessagesCount -= 1;
if (this.bufferMessagesCount > 0) {
this.bufferBytesCount -= 1;
}

@@ -106,8 +106,8 @@ };

};
Batch.prototype.willReachedBytesLimitWith = function (messageBytesSize) {
Batch.prototype.willReachedBytesLimitWith = function (messageBytesCount) {
// byte of the separator at the end of the message
return this.bufferBytesSize + messageBytesSize + 1 >= this.bytesLimit;
return this.bufferBytesCount + messageBytesCount + 1 >= this.batchBytesLimit;
};
Batch.prototype.isFull = function () {
return this.bufferMessageCount === this.maxSize || this.bufferBytesSize >= this.bytesLimit;
return this.bufferMessagesCount === this.batchMessagesLimit || this.bufferBytesCount >= this.batchBytesLimit;
};

@@ -117,3 +117,3 @@ Batch.prototype.flushPeriodically = function () {

setTimeout(monitor(function () {
_this.flush('max_duration');
_this.flush('batch_flush_timeout');
_this.flushPeriodically();

@@ -120,0 +120,0 @@ }), this.flushTimeout);

@@ -17,3 +17,3 @@ import { isExperimentalFeatureEnabled } from '../domain/configuration';

endpointType: endpointType,
version: "4.10.0",
version: "4.10.1",
connection: navigator.connection ? navigator.connection.effectiveType : undefined,

@@ -20,0 +20,0 @@ onLine: navigator.onLine,

@@ -14,3 +14,3 @@ import type { EndpointBuilder } from '../domain/configuration';

constructor(endpointBuilder: EndpointBuilder, bytesLimit: number);
send(data: string | FormData, size: number, reason?: string): void;
send(data: string | FormData, bytesCount: number, reason?: string): void;
}

@@ -16,5 +16,5 @@ import { addMonitoringError } from '../domain/internalMonitoring';

}
HttpRequest.prototype.send = function (data, size, reason) {
HttpRequest.prototype.send = function (data, bytesCount, reason) {
var url = this.endpointBuilder.build();
var canUseBeacon = !!navigator.sendBeacon && size < this.bytesLimit;
var canUseBeacon = !!navigator.sendBeacon && bytesCount < this.bytesLimit;
if (canUseBeacon) {

@@ -26,3 +26,3 @@ try {

}
addFailedSendBeacon(this.endpointBuilder.endpointType, size, reason);
addFailedSendBeacon(this.endpointBuilder.endpointType, bytesCount, reason);
}

@@ -29,0 +29,0 @@ catch (e) {

@@ -9,3 +9,3 @@ import { Batch, HttpRequest } from './index';

function createBatch(endpointBuilder) {
return new Batch(new HttpRequest(endpointBuilder, configuration.batchBytesLimit), configuration.maxBatchSize, configuration.batchBytesLimit, configuration.maxMessageSize, configuration.flushTimeout);
return new Batch(new HttpRequest(endpointBuilder, configuration.batchBytesLimit), configuration.batchMessagesLimit, configuration.batchBytesLimit, configuration.messageBytesLimit, configuration.flushTimeout);
}

@@ -12,0 +12,0 @@ return {

{
"name": "@datadog/browser-core",
"version": "4.10.0",
"version": "4.10.1",
"license": "Apache-2.0",

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

},
"gitHead": "0d9e40c8625d33d9b725f3a5bf81a711b318796c"
"gitHead": "e5626dc79ba7f597662015c528de80fc611d076b"
}

@@ -71,4 +71,4 @@ import type { CookieOptions } from '../../browser/cookie'

flushTimeout: number
maxBatchSize: number
maxMessageSize: number
batchMessagesLimit: number
messageBytesLimit: number
}

@@ -123,4 +123,4 @@

*/
maxBatchSize: 50,
maxMessageSize: 256 * ONE_KILO_BYTE,
batchMessagesLimit: 50,
messageBytesLimit: 256 * ONE_KILO_BYTE,
},

@@ -127,0 +127,0 @@ computeTransportConfiguration(initConfiguration)

@@ -29,2 +29,6 @@ import type { Context } from '../../tools/context'

describe('internal monitoring', () => {
afterEach(() => {
resetInternalMonitoring()
})
describe('decorator', () => {

@@ -81,6 +85,2 @@ class Candidate {

afterEach(() => {
resetInternalMonitoring()
})
it('should preserve original behavior', () => {

@@ -134,6 +134,2 @@ expect(candidate.monitoredNotThrowing()).toEqual(1)

afterEach(() => {
resetInternalMonitoring()
})
describe('direct call', () => {

@@ -184,6 +180,2 @@ it('should preserve original behavior', () => {

afterEach(() => {
resetInternalMonitoring()
})
it('should be added to error messages', () => {

@@ -214,3 +206,2 @@ internalMonitoring.setExternalContextProvider(() => ({

afterEach(() => {
resetInternalMonitoring()
resetExperimentalFeatures()

@@ -259,3 +250,3 @@ })

;[
{ site: INTAKE_SITE_US5, enabled: false },
{ site: INTAKE_SITE_US5, enabled: true },
{ site: INTAKE_SITE_US3, enabled: false },

@@ -293,3 +284,2 @@ { site: INTAKE_SITE_EU, enabled: false },

resetExperimentalFeatures()
resetInternalMonitoring()
})

@@ -370,6 +360,2 @@

afterEach(() => {
resetInternalMonitoring()
})
it('should not notify observable', () => {

@@ -376,0 +362,0 @@ callMonitored(() => {

@@ -9,3 +9,3 @@ import type { Context } from '../../tools/context'

import { timeStampNow } from '../../tools/timeUtils'
import { isExperimentalFeatureEnabled, INTAKE_SITE_STAGING } from '../configuration'
import { isExperimentalFeatureEnabled, INTAKE_SITE_STAGING, INTAKE_SITE_US5 } from '../configuration'
import type { TelemetryEvent } from './telemetryEvent.types'

@@ -39,3 +39,3 @@

const TELEMETRY_ALLOWED_SITES: string[] = [
// INTAKE_SITE_US5,
INTAKE_SITE_US5,
// INTAKE_SITE_US3,

@@ -42,0 +42,0 @@ // INTAKE_SITE_EU,

@@ -8,3 +8,3 @@ /* eslint-disable @typescript-eslint/unbound-method */

describe('batch', () => {
const MAX_SIZE = 3
const BATCH_MESSAGES_LIMIT = 3
const BATCH_BYTES_LIMIT = 100

@@ -19,3 +19,3 @@ const MESSAGE_BYTES_LIMIT = 50 * 1024

spyOn(transport, 'send')
batch = new Batch(transport, MAX_SIZE, BATCH_BYTES_LIMIT, MESSAGE_BYTES_LIMIT, FLUSH_TIMEOUT)
batch = new Batch(transport, BATCH_MESSAGES_LIMIT, BATCH_BYTES_LIMIT, MESSAGE_BYTES_LIMIT, FLUSH_TIMEOUT)
})

@@ -41,11 +41,11 @@

it('should calculate the byte size of message composed of 1 byte characters ', () => {
expect(batch.sizeInBytes('1234')).toEqual(4)
it('should count the bytes of a message composed of 1 byte characters', () => {
expect(batch.computeBytesCount('1234')).toEqual(4)
})
it('should calculate the byte size of message composed of multiple bytes characters ', () => {
expect(batch.sizeInBytes('🪐')).toEqual(4)
it('should count the bytes of a message composed of multiple bytes characters', () => {
expect(batch.computeBytesCount('🪐')).toEqual(4)
})
it('should flush when max size is reached', () => {
it('should flush when the message count limit is reached', () => {
batch.add({ message: '1' })

@@ -57,7 +57,7 @@ batch.add({ message: '2' })

jasmine.any(Number),
'max_messages_count'
'batch_messages_limit'
)
})
it('should flush when new message will overflow bytes limit', () => {
it('should flush when a new message will overflow the bytes limit', () => {
batch.add({ message: '50 bytes - xxxxxxxxxxxxxxxxxxxxxxxxx' })

@@ -67,3 +67,7 @@ expect(transport.send).not.toHaveBeenCalled()

batch.add({ message: '60 bytes - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' })
expect(transport.send).toHaveBeenCalledWith('{"message":"50 bytes - xxxxxxxxxxxxxxxxxxxxxxxxx"}', 50, 'max_size')
expect(transport.send).toHaveBeenCalledWith(
'{"message":"50 bytes - xxxxxxxxxxxxxxxxxxxxxxxxx"}',
50,
'batch_bytes_limit'
)

@@ -78,3 +82,3 @@ batch.flush()

it('should consider separator size when computing the size', () => {
it('should consider separators when computing the byte count', () => {
batch.add({ message: '30 bytes - xxxxx' }) // batch: 30 sep: 0

@@ -91,3 +95,3 @@ batch.add({ message: '30 bytes - xxxxx' }) // batch: 60 sep: 1

it('should call send one time when the size is too high and the batch is empty', () => {
it('should call send one time when the byte count is too high and the batch is empty', () => {
const message = '101 bytes - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

@@ -108,3 +112,3 @@ batch.add({ message })

const clock = sinon.useFakeTimers()
batch = new Batch(transport, MAX_SIZE, BATCH_BYTES_LIMIT, MESSAGE_BYTES_LIMIT, 10)
batch = new Batch(transport, BATCH_MESSAGES_LIMIT, BATCH_BYTES_LIMIT, MESSAGE_BYTES_LIMIT, 10)
batch.add({ message: '50 bytes - xxxxxxxxxxxxxxxxxxxxxxxxx' })

@@ -118,5 +122,5 @@ clock.tick(100)

it('should not send a message with a size above the limit', () => {
it('should not send a message with a bytes size above the limit', () => {
const warnStub = sinon.stub(console, 'warn')
batch = new Batch(transport, MAX_SIZE, BATCH_BYTES_LIMIT, 50, FLUSH_TIMEOUT)
batch = new Batch(transport, BATCH_MESSAGES_LIMIT, BATCH_BYTES_LIMIT, 50, FLUSH_TIMEOUT)
batch.add({ message: '50 bytes - xxxxxxxxxxxxx' })

@@ -123,0 +127,0 @@

@@ -14,10 +14,10 @@ import { display } from '../tools/display'

private upsertBuffer: { [key: string]: string } = {}
private bufferBytesSize = 0
private bufferMessageCount = 0
private bufferBytesCount = 0
private bufferMessagesCount = 0
constructor(
private request: HttpRequest,
private maxSize: number,
private bytesLimit: number,
private maxMessageSize: number,
private batchMessagesLimit: number,
private batchBytesLimit: number,
private messageBytesLimit: number,
private flushTimeout: number,

@@ -39,14 +39,14 @@ private beforeUnloadCallback: () => void = noop

flush(reason?: string) {
if (this.bufferMessageCount !== 0) {
if (this.bufferMessagesCount !== 0) {
const messages = this.pushOnlyBuffer.concat(objectValues(this.upsertBuffer))
this.request.send(messages.join('\n'), this.bufferBytesSize, reason)
this.request.send(messages.join('\n'), this.bufferBytesCount, reason)
this.pushOnlyBuffer = []
this.upsertBuffer = {}
this.bufferBytesSize = 0
this.bufferMessageCount = 0
this.bufferBytesCount = 0
this.bufferMessagesCount = 0
}
}
sizeInBytes(candidate: string) {
// Accurate byte size computations can degrade performances when there is a lot of events to process
computeBytesCount(candidate: string) {
// Accurate bytes count computations can degrade performances when there is a lot of events to process
if (!HAS_MULTI_BYTES_CHARACTERS.test(candidate)) {

@@ -64,5 +64,7 @@ return candidate.length

private addOrUpdate(message: Context, key?: string) {
const { processedMessage, messageBytesSize } = this.process(message)
if (messageBytesSize >= this.maxMessageSize) {
display.warn(`Discarded a message whose size was bigger than the maximum allowed size ${this.maxMessageSize}KB.`)
const { processedMessage, messageBytesCount } = this.process(message)
if (messageBytesCount >= this.messageBytesLimit) {
display.warn(
`Discarded a message whose size was bigger than the maximum allowed size ${this.messageBytesLimit}KB.`
)
return

@@ -73,8 +75,9 @@ }

}
if (this.willReachedBytesLimitWith(messageBytesSize)) {
this.flush('max_size')
if (this.willReachedBytesLimitWith(messageBytesCount)) {
this.flush('batch_bytes_limit')
}
this.push(processedMessage, messageBytesSize, key)
this.push(processedMessage, messageBytesCount, key)
if (this.isFull()) {
this.flush('max_messages_count')
this.flush('batch_messages_limit')
}

@@ -85,10 +88,10 @@ }

const processedMessage = jsonStringify(message)!
const messageBytesSize = this.sizeInBytes(processedMessage)
return { processedMessage, messageBytesSize }
const messageBytesCount = this.computeBytesCount(processedMessage)
return { processedMessage, messageBytesCount }
}
private push(processedMessage: string, messageBytesSize: number, key?: string) {
if (this.bufferMessageCount > 0) {
private push(processedMessage: string, messageBytesCount: number, key?: string) {
if (this.bufferMessagesCount > 0) {
// \n separator at serialization
this.bufferBytesSize += 1
this.bufferBytesCount += 1
}

@@ -100,4 +103,4 @@ if (key !== undefined) {

}
this.bufferBytesSize += messageBytesSize
this.bufferMessageCount += 1
this.bufferBytesCount += messageBytesCount
this.bufferMessagesCount += 1
}

@@ -108,7 +111,7 @@

delete this.upsertBuffer[key]
const messageBytesSize = this.sizeInBytes(removedMessage)
this.bufferBytesSize -= messageBytesSize
this.bufferMessageCount -= 1
if (this.bufferMessageCount > 0) {
this.bufferBytesSize -= 1
const messageBytesCount = this.computeBytesCount(removedMessage)
this.bufferBytesCount -= messageBytesCount
this.bufferMessagesCount -= 1
if (this.bufferMessagesCount > 0) {
this.bufferBytesCount -= 1
}

@@ -121,9 +124,9 @@ }

private willReachedBytesLimitWith(messageBytesSize: number) {
private willReachedBytesLimitWith(messageBytesCount: number) {
// byte of the separator at the end of the message
return this.bufferBytesSize + messageBytesSize + 1 >= this.bytesLimit
return this.bufferBytesCount + messageBytesCount + 1 >= this.batchBytesLimit
}
private isFull() {
return this.bufferMessageCount === this.maxSize || this.bufferBytesSize >= this.bytesLimit
return this.bufferMessagesCount === this.batchMessagesLimit || this.bufferBytesCount >= this.batchBytesLimit
}

@@ -134,3 +137,3 @@

monitor(() => {
this.flush('max_duration')
this.flush('batch_flush_timeout')
this.flushPeriodically()

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

@@ -33,3 +33,3 @@ /* eslint-disable @typescript-eslint/unbound-method */

it('should use sendBeacon when the size is correct', () => {
it('should use sendBeacon when the bytes count is correct', () => {
spyOn(navigator, 'sendBeacon').and.callFake(() => true)

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

it('should use xhr over sendBeacon when the size too high', () => {
it('should use xhr over sendBeacon when the bytes count is too high', () => {
spyOn(navigator, 'sendBeacon').and.callFake(() => true)

@@ -45,0 +45,0 @@

@@ -16,5 +16,5 @@ import type { EndpointBuilder } from '../domain/configuration'

send(data: string | FormData, size: number, reason?: string) {
send(data: string | FormData, bytesCount: number, reason?: string) {
const url = this.endpointBuilder.build()
const canUseBeacon = !!navigator.sendBeacon && size < this.bytesLimit
const canUseBeacon = !!navigator.sendBeacon && bytesCount < this.bytesLimit
if (canUseBeacon) {

@@ -27,3 +27,3 @@ try {

addFailedSendBeacon(this.endpointBuilder.endpointType, size, reason)
addFailedSendBeacon(this.endpointBuilder.endpointType, bytesCount, reason)
} catch (e) {

@@ -30,0 +30,0 @@ reportBeaconError(e)

@@ -19,5 +19,5 @@ import type { Configuration, EndpointBuilder } from '../domain/configuration'

new HttpRequest(endpointBuilder, configuration.batchBytesLimit),
configuration.maxBatchSize,
configuration.batchMessagesLimit,
configuration.batchBytesLimit,
configuration.maxMessageSize,
configuration.messageBytesLimit,
configuration.flushTimeout

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

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