Socket
Socket
Sign inDemoInstall

@datadog/browser-core

Package Overview
Dependencies
0
Maintainers
1
Versions
248
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.39.0 to 4.40.0

cjs/domain/error/error.types.d.ts

2

cjs/boot/init.js

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

var publicApi = (0, polyfills_1.assign)({
version: "4.39.0",
version: "4.40.0",
// 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

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

var clientToken = _a.clientToken, internalAnalyticsSubdomain = _a.internalAnalyticsSubdomain;
var tags = ["sdk_version:".concat("4.39.0"), "api:".concat(api)].concat(configurationTags);
var tags = ["sdk_version:".concat("4.40.0"), "api:".concat(api)].concat(configurationTags);
if (flushReason && (0, experimentalFeatures_1.isExperimentalFeatureEnabled)(experimentalFeatures_1.ExperimentalFeature.COLLECT_FLUSH_REASON)) {

@@ -81,3 +81,3 @@ tags.push("flush_reason:".concat(flushReason));

"dd-api-key=".concat(clientToken),
"dd-evp-origin-version=".concat(encodeURIComponent("4.39.0")),
"dd-evp-origin-version=".concat(encodeURIComponent("4.40.0")),
'dd-evp-origin=browser',

@@ -84,0 +84,0 @@ "dd-request-id=".concat((0, stringUtils_1.generateUUID)()),

import type { StackTrace } from '../tracekit';
import type { ClocksState } from '../../tools/utils/timeUtils';
import type { ErrorSource, ErrorHandling, RawError, RawErrorCause, ErrorWithCause, NonErrorPrefix } from './error.types';
export declare const NO_ERROR_STACK_PRESENT_MESSAGE = "No stack, consider using an instance of Error";
export declare const PROVIDED_ERROR_MESSAGE_PREFIX = "Provided";
export interface ErrorWithCause extends Error {
cause?: Error;
}
export type RawErrorCause = {
message: string;
source: string;
type?: string;
stack?: string;
};
export interface RawError {
startClocks: ClocksState;
message: string;
type?: string;
stack?: string;
source: ErrorSource;
originalError?: unknown;
handling?: ErrorHandling;
handlingStack?: string;
causes?: RawErrorCause[];
}
export declare const ErrorSource: {
readonly AGENT: "agent";
readonly CONSOLE: "console";
readonly CUSTOM: "custom";
readonly LOGGER: "logger";
readonly NETWORK: "network";
readonly SOURCE: "source";
readonly REPORT: "report";
};
export declare const enum ErrorHandling {
HANDLED = "handled",
UNHANDLED = "unhandled"
}
export type ErrorSource = (typeof ErrorSource)[keyof typeof ErrorSource];
type RawErrorParams = {

@@ -44,3 +10,3 @@ stackTrace?: StackTrace;

startClocks: ClocksState;
nonErrorPrefix: string;
nonErrorPrefix: NonErrorPrefix;
source: ErrorSource;

@@ -47,0 +13,0 @@ handling: ErrorHandling;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.flattenErrorCauses = exports.createHandlingStack = exports.formatErrorMessage = exports.getFileFromStackTraceString = exports.toStackTraceString = exports.computeRawError = exports.ErrorSource = exports.PROVIDED_ERROR_MESSAGE_PREFIX = exports.NO_ERROR_STACK_PRESENT_MESSAGE = void 0;
exports.flattenErrorCauses = exports.createHandlingStack = exports.formatErrorMessage = exports.getFileFromStackTraceString = exports.toStackTraceString = exports.computeRawError = exports.NO_ERROR_STACK_PRESENT_MESSAGE = void 0;
var tracekit_1 = require("../tracekit");

@@ -11,12 +11,2 @@ var experimentalFeatures_1 = require("../../tools/experimentalFeatures");

exports.NO_ERROR_STACK_PRESENT_MESSAGE = 'No stack, consider using an instance of Error';
exports.PROVIDED_ERROR_MESSAGE_PREFIX = 'Provided';
exports.ErrorSource = {
AGENT: 'agent',
CONSOLE: 'console',
CUSTOM: 'custom',
LOGGER: 'logger',
NETWORK: 'network',
SOURCE: 'source',
REPORT: 'report',
};
function computeRawError(_a) {

@@ -34,3 +24,3 @@ var stackTrace = _a.stackTrace, originalError = _a.originalError, handlingStack = _a.handlingStack, startClocks = _a.startClocks, nonErrorPrefix = _a.nonErrorPrefix, source = _a.source, handling = _a.handling;

message: "".concat(nonErrorPrefix, " ").concat((0, jsonStringify_1.jsonStringify)(sanitizedError)),
stack: 'No stack, consider using an instance of Error',
stack: exports.NO_ERROR_STACK_PRESENT_MESSAGE,
handlingStack: handlingStack,

@@ -37,0 +27,0 @@ type: stackTrace && stackTrace.name,

import type { Observable } from '../../tools/observable';
import type { RawError } from './error';
import type { RawError } from './error.types';
export declare function trackRuntimeError(errorObservable: Observable<RawError>): {
stop: () => void;
};

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

var error_1 = require("./error");
var error_types_1 = require("./error.types");
function trackRuntimeError(errorObservable) {

@@ -14,4 +15,4 @@ return (0, tracekit_1.startUnhandledErrorCollection)(function (stackTrace, originalError) {

startClocks: (0, timeUtils_1.clocksNow)(),
nonErrorPrefix: 'Uncaught',
source: error_1.ErrorSource.SOURCE,
nonErrorPrefix: "Uncaught" /* NonErrorPrefix.UNCAUGHT */,
source: error_types_1.ErrorSource.SOURCE,
handling: "unhandled" /* ErrorHandling.UNHANDLED */,

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

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

import type { RawError } from '../error/error';
import type { RawError } from '../error/error.types';
export type EventRateLimiter = ReturnType<typeof createEventRateLimiter>;

@@ -3,0 +3,0 @@ export declare function createEventRateLimiter(eventType: string, limit: number, onLimitReached: (limitError: RawError) => void): {

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

var timer_1 = require("../../tools/timer");
var error_1 = require("../error/error");
var timeUtils_1 = require("../../tools/utils/timeUtils");
var error_types_1 = require("../error/error.types");
function createEventRateLimiter(eventType, limit, onLimitReached) {

@@ -28,3 +28,3 @@ var eventCount = 0;

message: "Reached max number of ".concat(eventType, "s by minute: ").concat(limit),
source: error_1.ErrorSource.AGENT,
source: error_types_1.ErrorSource.AGENT,
startClocks: (0, timeUtils_1.clocksNow)(),

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

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

batch_upload_frequency?: number | undefined;
react_version?: string | undefined;
react_native_version?: string | undefined;
dart_version?: string | undefined;
};

@@ -83,0 +86,0 @@ })[];

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

service: telemetryService,
version: "4.39.0",
version: "4.40.0",
source: 'browser',

@@ -138,5 +138,5 @@ _dd: {

error: {
stack: 'Not an instance of error',
stack: error_1.NO_ERROR_STACK_PRESENT_MESSAGE,
},
message: "Uncaught ".concat((0, jsonStringify_1.jsonStringify)(e)),
message: "".concat("Uncaught" /* NonErrorPrefix.UNCAUGHT */, " ").concat((0, jsonStringify_1.jsonStringify)(e)),
};

@@ -143,0 +143,0 @@ }

@@ -262,2 +262,14 @@ /**

batch_upload_frequency?: number;
/**
* The version of React used in a ReactNative application
*/
react_version?: string;
/**
* The version of ReactNative used in a ReactNative application
*/
react_native_version?: string;
/**
* The version of Dart used in a Flutter application
*/
dart_version?: string;
[k: string]: unknown;

@@ -264,0 +276,0 @@ };

@@ -19,2 +19,3 @@ export { Configuration, InitConfiguration, buildCookieOptions, validateAndBuildConfiguration, DefaultPrivacyLevel, EndpointBuilder, serializeConfiguration, INTAKE_SITE_AP1, INTAKE_SITE_STAGING, INTAKE_SITE_US1, INTAKE_SITE_US1_FED, INTAKE_SITE_EU1, } from './domain/configuration';

export * from './tools/getGlobalObject';
export { AbstractLifeCycle } from './tools/abstractLifeCycle';
export * from './domain/eventRateLimiter/createEventRateLimiter';

@@ -26,3 +27,4 @@ export * from './tools/utils/browserDetection';

export { instrumentMethod, instrumentMethodAndCallOriginal, instrumentSetter } from './tools/instrumentMethod';
export { ErrorSource, ErrorHandling, computeRawError, createHandlingStack, RawError, RawErrorCause, ErrorWithCause, toStackTraceString, getFileFromStackTraceString, NO_ERROR_STACK_PRESENT_MESSAGE, PROVIDED_ERROR_MESSAGE_PREFIX, } from './domain/error/error';
export { computeRawError, createHandlingStack, toStackTraceString, getFileFromStackTraceString, NO_ERROR_STACK_PRESENT_MESSAGE, } from './domain/error/error';
export { NonErrorPrefix } from './domain/error/error.types';
export { Context, ContextArray, ContextValue } from './tools/serialisation/context';

@@ -57,1 +59,6 @@ export { areCookiesAuthorized, getCookie, setCookie, deleteCookie, COOKIE_ACCESS_DELAY } from './browser/cookie';

export * from './tools/utils/typeUtils';
export { ErrorHandling } from './domain/error/error.types';
export { ErrorSource } from './domain/error/error.types';
export { RawError } from './domain/error/error.types';
export { RawErrorCause } from './domain/error/error.types';
export { ErrorWithCause } from './domain/error/error.types';

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.createHandlingStack = exports.computeRawError = exports.ErrorSource = exports.instrumentSetter = exports.instrumentMethodAndCallOriginal = exports.instrumentMethod = exports.getZoneJsOriginalValue = exports.runOnReadyState = exports.sendToExtension = exports.createFlushController = exports.startBatchWithReplica = exports.getEventBridge = exports.canUseEventBridge = exports.Batch = exports.createHttpRequest = exports.SESSION_TIME_OUT_DELAY = exports.stopSessionManager = exports.startSessionManager = exports.Observable = exports.setDebugMode = exports.callMonitored = exports.monitor = exports.monitored = exports.addTelemetryConfiguration = exports.isTelemetryReplicationAllowed = exports.resetTelemetry = exports.startFakeTelemetry = exports.addTelemetryError = exports.addTelemetryDebug = exports.startTelemetry = exports.RawReportType = exports.initReportObservable = exports.makePublicApi = exports.defineGlobal = exports.computeStackTrace = exports.trackRuntimeError = exports.ExperimentalFeature = exports.getExperimentalFeatures = exports.resetExperimentalFeatures = exports.addExperimentalFeatures = exports.isExperimentalFeatureEnabled = exports.INTAKE_SITE_EU1 = exports.INTAKE_SITE_US1_FED = exports.INTAKE_SITE_US1 = exports.INTAKE_SITE_STAGING = exports.INTAKE_SITE_AP1 = exports.serializeConfiguration = exports.DefaultPrivacyLevel = exports.validateAndBuildConfiguration = exports.buildCookieOptions = void 0;
exports.sanitizeUser = exports.checkUser = exports.getSyntheticsResultId = exports.getSyntheticsTestId = exports.willSyntheticsInjectRum = exports.SESSION_COOKIE_NAME = exports.readBytesFromStream = exports.CLEAR_OLD_VALUES_INTERVAL = exports.ValueHistory = exports.CUSTOMER_DATA_BYTES_LIMIT = exports.warnIfCustomerDataLimitReached = exports.createContextManager = exports.catchUserErrors = exports.BoundedBuffer = exports.initConsoleObservable = exports.isPageExitReason = exports.PageExitReason = exports.createPageExitObservable = exports.initFetchObservable = exports.initXhrObservable = exports.COOKIE_ACCESS_DELAY = exports.deleteCookie = exports.setCookie = exports.getCookie = exports.areCookiesAuthorized = exports.PROVIDED_ERROR_MESSAGE_PREFIX = exports.NO_ERROR_STACK_PRESENT_MESSAGE = exports.getFileFromStackTraceString = exports.toStackTraceString = void 0;
exports.createHandlingStack = exports.computeRawError = exports.instrumentSetter = exports.instrumentMethodAndCallOriginal = exports.instrumentMethod = exports.getZoneJsOriginalValue = exports.runOnReadyState = exports.sendToExtension = exports.AbstractLifeCycle = exports.createFlushController = exports.startBatchWithReplica = exports.getEventBridge = exports.canUseEventBridge = exports.Batch = exports.createHttpRequest = exports.SESSION_TIME_OUT_DELAY = exports.stopSessionManager = exports.startSessionManager = exports.Observable = exports.setDebugMode = exports.callMonitored = exports.monitor = exports.monitored = exports.addTelemetryConfiguration = exports.isTelemetryReplicationAllowed = exports.resetTelemetry = exports.startFakeTelemetry = exports.addTelemetryError = exports.addTelemetryDebug = exports.startTelemetry = exports.RawReportType = exports.initReportObservable = exports.makePublicApi = exports.defineGlobal = exports.computeStackTrace = exports.trackRuntimeError = exports.ExperimentalFeature = exports.getExperimentalFeatures = exports.resetExperimentalFeatures = exports.addExperimentalFeatures = exports.isExperimentalFeatureEnabled = exports.INTAKE_SITE_EU1 = exports.INTAKE_SITE_US1_FED = exports.INTAKE_SITE_US1 = exports.INTAKE_SITE_STAGING = exports.INTAKE_SITE_AP1 = exports.serializeConfiguration = exports.DefaultPrivacyLevel = exports.validateAndBuildConfiguration = exports.buildCookieOptions = void 0;
exports.ErrorSource = exports.sanitizeUser = exports.checkUser = exports.getSyntheticsResultId = exports.getSyntheticsTestId = exports.willSyntheticsInjectRum = exports.SESSION_COOKIE_NAME = exports.readBytesFromStream = exports.CLEAR_OLD_VALUES_INTERVAL = exports.ValueHistory = exports.CUSTOMER_DATA_BYTES_LIMIT = exports.warnIfCustomerDataLimitReached = exports.createContextManager = exports.catchUserErrors = exports.BoundedBuffer = exports.initConsoleObservable = exports.isPageExitReason = exports.PageExitReason = exports.createPageExitObservable = exports.initFetchObservable = exports.initXhrObservable = exports.COOKIE_ACCESS_DELAY = exports.deleteCookie = exports.setCookie = exports.getCookie = exports.areCookiesAuthorized = exports.NO_ERROR_STACK_PRESENT_MESSAGE = exports.getFileFromStackTraceString = exports.toStackTraceString = void 0;
var configuration_1 = require("./domain/configuration");

@@ -80,2 +80,4 @@ Object.defineProperty(exports, "buildCookieOptions", { enumerable: true, get: function () { return configuration_1.buildCookieOptions; } });

__exportStar(require("./tools/getGlobalObject"), exports);
var abstractLifeCycle_1 = require("./tools/abstractLifeCycle");
Object.defineProperty(exports, "AbstractLifeCycle", { enumerable: true, get: function () { return abstractLifeCycle_1.AbstractLifeCycle; } });
__exportStar(require("./domain/eventRateLimiter/createEventRateLimiter"), exports);

@@ -94,3 +96,2 @@ __exportStar(require("./tools/utils/browserDetection"), exports);

var error_1 = require("./domain/error/error");
Object.defineProperty(exports, "ErrorSource", { enumerable: true, get: function () { return error_1.ErrorSource; } });
Object.defineProperty(exports, "computeRawError", { enumerable: true, get: function () { return error_1.computeRawError; } });

@@ -101,3 +102,2 @@ Object.defineProperty(exports, "createHandlingStack", { enumerable: true, get: function () { return error_1.createHandlingStack; } });

Object.defineProperty(exports, "NO_ERROR_STACK_PRESENT_MESSAGE", { enumerable: true, get: function () { return error_1.NO_ERROR_STACK_PRESENT_MESSAGE; } });
Object.defineProperty(exports, "PROVIDED_ERROR_MESSAGE_PREFIX", { enumerable: true, get: function () { return error_1.PROVIDED_ERROR_MESSAGE_PREFIX; } });
var cookie_1 = require("./browser/cookie");

@@ -156,2 +156,4 @@ Object.defineProperty(exports, "areCookiesAuthorized", { enumerable: true, get: function () { return cookie_1.areCookiesAuthorized; } });

__exportStar(require("./tools/utils/typeUtils"), exports);
var error_types_1 = require("./domain/error/error.types");
Object.defineProperty(exports, "ErrorSource", { enumerable: true, get: function () { return error_types_1.ErrorSource; } });
//# sourceMappingURL=index.js.map

@@ -14,3 +14,2 @@ /**

RESOURCE_PAGE_STATES = "resource_page_states",
CLICKMAP = "clickmap",
COLLECT_FLUSH_REASON = "collect_flush_reason",

@@ -17,0 +16,0 @@ SANITIZE_INPUTS = "sanitize_inputs"

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

ExperimentalFeature["RESOURCE_PAGE_STATES"] = "resource_page_states";
ExperimentalFeature["CLICKMAP"] = "clickmap";
ExperimentalFeature["COLLECT_FLUSH_REASON"] = "collect_flush_reason";

@@ -24,0 +23,0 @@ ExperimentalFeature["SANITIZE_INPUTS"] = "sanitize_inputs";

import type { PageExitEvent, PageExitReason } from '../browser/pageExitObservable';
import { Observable } from '../tools/observable';
import type { Duration } from '../tools/utils/timeUtils';
export type FlushReason = PageExitReason | 'duration_limit' | 'bytes_limit' | 'messages_limit';
export type FlushReason = PageExitReason | 'duration_limit' | 'bytes_limit' | 'messages_limit' | 'session_expire';
export type FlushController = ReturnType<typeof createFlushController>;

@@ -16,10 +16,34 @@ export interface FlushEvent {

pageExitObservable: Observable<PageExitEvent>;
sessionExpireObservable: Observable<void>;
}
export declare function createFlushController({ messagesLimit, bytesLimit, durationLimit, pageExitObservable, }: FlushControllerOptions): {
/**
* Returns a "flush controller", responsible of notifying when flushing a pool of pending data needs
* to happen. The implementation is designed to support both synchronous and asynchronous usages,
* but relies on invariants described in each method documentation to keep a coherent state.
*/
export declare function createFlushController({ messagesLimit, bytesLimit, durationLimit, pageExitObservable, sessionExpireObservable, }: FlushControllerOptions): {
flushObservable: Observable<FlushEvent>;
readonly messagesCount: number;
/**
* Notifies that a message will be added to a pool of pending messages waiting to be flushed.
*
* This function needs to be called synchronously, right before adding the message, so no flush
* event can happen after `notifyBeforeAddMessage` and before adding the message.
*/
notifyBeforeAddMessage(messageBytesCount: number): void;
/**
* Notifies that a message *was* added to a pool of pending messages waiting to be flushed.
*
* This function can be called asynchronously after the message was added, but in this case it
* should not be called if a flush event occurred in between.
*/
notifyAfterAddMessage(): void;
/**
* Notifies that a message was removed from a pool of pending messages waiting to be flushed.
*
* This function needs to be called synchronously, right after removing the message, so no flush
* event can happen after removing the message and before `notifyAfterRemoveMessage`.
*/
notifyAfterRemoveMessage(messageBytesCount: number): void;
};
export {};

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

var timer_1 = require("../tools/timer");
/**
* Returns a "flush controller", responsible of notifying when flushing a pool of pending data needs
* to happen. The implementation is designed to support both synchronous and asynchronous usages,
* but relies on invariants described in each method documentation to keep a coherent state.
*/
function createFlushController(_a) {
var messagesLimit = _a.messagesLimit, bytesLimit = _a.bytesLimit, durationLimit = _a.durationLimit, pageExitObservable = _a.pageExitObservable;
var messagesLimit = _a.messagesLimit, bytesLimit = _a.bytesLimit, durationLimit = _a.durationLimit, pageExitObservable = _a.pageExitObservable, sessionExpireObservable = _a.sessionExpireObservable;
var flushObservable = new observable_1.Observable();
pageExitObservable.subscribe(function (event) { return flush(event.reason); });
sessionExpireObservable.subscribe(function () { return flush('session_expire'); });
var currentBytesCount = 0;

@@ -45,2 +51,8 @@ var currentMessagesCount = 0;

},
/**
* Notifies that a message will be added to a pool of pending messages waiting to be flushed.
*
* This function needs to be called synchronously, right before adding the message, so no flush
* event can happen after `notifyBeforeAddMessage` and before adding the message.
*/
notifyBeforeAddMessage: function (messageBytesCount) {

@@ -50,5 +62,5 @@ if (currentBytesCount + messageBytesCount >= bytesLimit) {

}
// Consider the message to be added now rather than in `notifyAfterAddMessage`, because if no message
// was added yet and `notifyAfterAddMessage` is called asynchronously, we still want to notify when a
// flush is needed (for example on page exit).
// Consider the message to be added now rather than in `notifyAfterAddMessage`, because if no
// message was added yet and `notifyAfterAddMessage` is called asynchronously, we still want
// to notify when a flush is needed (for example on page exit).
currentMessagesCount += 1;

@@ -58,2 +70,8 @@ currentBytesCount += messageBytesCount;

},
/**
* Notifies that a message *was* added to a pool of pending messages waiting to be flushed.
*
* This function can be called asynchronously after the message was added, but in this case it
* should not be called if a flush event occurred in between.
*/
notifyAfterAddMessage: function () {

@@ -67,2 +85,8 @@ if (currentMessagesCount >= messagesLimit) {

},
/**
* Notifies that a message was removed from a pool of pending messages waiting to be flushed.
*
* This function needs to be called synchronously, right after removing the message, so no flush
* event can happen after removing the message and before `notifyAfterRemoveMessage`.
*/
notifyAfterRemoveMessage: function (messageBytesCount) {

@@ -69,0 +93,0 @@ currentBytesCount -= messageBytesCount;

import type { EndpointBuilder } from '../domain/configuration';
import type { Context } from '../tools/serialisation/context';
import type { RawError } from '../domain/error/error';
import type { RawError } from '../domain/error/error.types';
import type { FlushReason } from './flushController';

@@ -5,0 +5,0 @@ /**

import type { EndpointType } from '../domain/configuration';
import type { RawError } from '../domain/error/error';
import type { RawError } from '../domain/error/error.types';
import type { Payload, HttpResponse } from './httpRequest';

@@ -4,0 +4,0 @@ export declare const MAX_ONGOING_BYTES_COUNT: number;

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

var timeUtils_1 = require("../tools/utils/timeUtils");
var error_1 = require("../domain/error/error");
var byteUtils_1 = require("../tools/utils/byteUtils");
var responseUtils_1 = require("../tools/utils/responseUtils");
var error_types_1 = require("../domain/error/error.types");
exports.MAX_ONGOING_BYTES_COUNT = 80 * byteUtils_1.ONE_KIBI_BYTE;

@@ -76,3 +76,3 @@ exports.MAX_ONGOING_REQUESTS = 32;

message: "Reached max ".concat(endpointType, " events size queued for upload: ").concat(exports.MAX_QUEUE_BYTES_COUNT / byteUtils_1.ONE_MEBI_BYTE, "MiB"),
source: error_1.ErrorSource.AGENT,
source: error_types_1.ErrorSource.AGENT,
startClocks: (0, timeUtils_1.clocksNow)(),

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

import type { Configuration, EndpointBuilder } from '../domain/configuration';
import type { RawError } from '../domain/error/error';
import type { Context } from '../tools/serialisation/context';
import type { Observable } from '../tools/observable';
import type { PageExitEvent } from '../browser/pageExitObservable';
export declare function startBatchWithReplica<T extends Context>(configuration: Configuration, endpoint: EndpointBuilder, reportError: (error: RawError) => void, pageExitObservable: Observable<PageExitEvent>, replicaEndpoint?: EndpointBuilder): {
import type { RawError } from '../domain/error/error.types';
export declare function startBatchWithReplica<T extends Context>(configuration: Configuration, endpoint: EndpointBuilder, reportError: (error: RawError) => void, pageExitObservable: Observable<PageExitEvent>, sessionExpireObservable: Observable<void>, replicaEndpoint?: EndpointBuilder): {
add(message: T, replicated?: boolean): void;
};

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

var flushController_1 = require("./flushController");
function startBatchWithReplica(configuration, endpoint, reportError, pageExitObservable, replicaEndpoint) {
function startBatchWithReplica(configuration, endpoint, reportError, pageExitObservable, sessionExpireObservable, replicaEndpoint) {
var primaryBatch = createBatch(endpoint);

@@ -20,2 +20,3 @@ var replicaBatch;

pageExitObservable: pageExitObservable,
sessionExpireObservable: sessionExpireObservable,
}), configuration.messageBytesLimit);

@@ -22,0 +23,0 @@ }

@@ -6,3 +6,3 @@ import { catchUserErrors } from '../tools/catchUserErrors';

var publicApi = assign({
version: "4.39.0",
version: "4.40.0",
// 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

@@ -65,3 +65,3 @@ import { timeStampNow } from '../../tools/utils/timeUtils';

var clientToken = _a.clientToken, internalAnalyticsSubdomain = _a.internalAnalyticsSubdomain;
var tags = ["sdk_version:".concat("4.39.0"), "api:".concat(api)].concat(configurationTags);
var tags = ["sdk_version:".concat("4.40.0"), "api:".concat(api)].concat(configurationTags);
if (flushReason && isExperimentalFeatureEnabled(ExperimentalFeature.COLLECT_FLUSH_REASON)) {

@@ -77,3 +77,3 @@ tags.push("flush_reason:".concat(flushReason));

"dd-api-key=".concat(clientToken),
"dd-evp-origin-version=".concat(encodeURIComponent("4.39.0")),
"dd-evp-origin-version=".concat(encodeURIComponent("4.40.0")),
'dd-evp-origin=browser',

@@ -80,0 +80,0 @@ "dd-request-id=".concat(generateUUID()),

import type { StackTrace } from '../tracekit';
import type { ClocksState } from '../../tools/utils/timeUtils';
import type { ErrorSource, ErrorHandling, RawError, RawErrorCause, ErrorWithCause, NonErrorPrefix } from './error.types';
export declare const NO_ERROR_STACK_PRESENT_MESSAGE = "No stack, consider using an instance of Error";
export declare const PROVIDED_ERROR_MESSAGE_PREFIX = "Provided";
export interface ErrorWithCause extends Error {
cause?: Error;
}
export type RawErrorCause = {
message: string;
source: string;
type?: string;
stack?: string;
};
export interface RawError {
startClocks: ClocksState;
message: string;
type?: string;
stack?: string;
source: ErrorSource;
originalError?: unknown;
handling?: ErrorHandling;
handlingStack?: string;
causes?: RawErrorCause[];
}
export declare const ErrorSource: {
readonly AGENT: "agent";
readonly CONSOLE: "console";
readonly CUSTOM: "custom";
readonly LOGGER: "logger";
readonly NETWORK: "network";
readonly SOURCE: "source";
readonly REPORT: "report";
};
export declare const enum ErrorHandling {
HANDLED = "handled",
UNHANDLED = "unhandled"
}
export type ErrorSource = (typeof ErrorSource)[keyof typeof ErrorSource];
type RawErrorParams = {

@@ -44,3 +10,3 @@ stackTrace?: StackTrace;

startClocks: ClocksState;
nonErrorPrefix: string;
nonErrorPrefix: NonErrorPrefix;
source: ErrorSource;

@@ -47,0 +13,0 @@ handling: ErrorHandling;

@@ -8,12 +8,2 @@ import { computeStackTrace } from '../tracekit';

export var NO_ERROR_STACK_PRESENT_MESSAGE = 'No stack, consider using an instance of Error';
export var PROVIDED_ERROR_MESSAGE_PREFIX = 'Provided';
export var ErrorSource = {
AGENT: 'agent',
CONSOLE: 'console',
CUSTOM: 'custom',
LOGGER: 'logger',
NETWORK: 'network',
SOURCE: 'source',
REPORT: 'report',
};
export function computeRawError(_a) {

@@ -31,3 +21,3 @@ var stackTrace = _a.stackTrace, originalError = _a.originalError, handlingStack = _a.handlingStack, startClocks = _a.startClocks, nonErrorPrefix = _a.nonErrorPrefix, source = _a.source, handling = _a.handling;

message: "".concat(nonErrorPrefix, " ").concat(jsonStringify(sanitizedError)),
stack: 'No stack, consider using an instance of Error',
stack: NO_ERROR_STACK_PRESENT_MESSAGE,
handlingStack: handlingStack,

@@ -34,0 +24,0 @@ type: stackTrace && stackTrace.name,

import type { Observable } from '../../tools/observable';
import type { RawError } from './error';
import type { RawError } from './error.types';
export declare function trackRuntimeError(errorObservable: Observable<RawError>): {
stop: () => void;
};
import { clocksNow } from '../../tools/utils/timeUtils';
import { startUnhandledErrorCollection } from '../tracekit';
import { ErrorSource, computeRawError } from './error';
import { computeRawError } from './error';
import { ErrorSource } from './error.types';
export function trackRuntimeError(errorObservable) {

@@ -10,3 +11,3 @@ return startUnhandledErrorCollection(function (stackTrace, originalError) {

startClocks: clocksNow(),
nonErrorPrefix: 'Uncaught',
nonErrorPrefix: "Uncaught" /* NonErrorPrefix.UNCAUGHT */,
source: ErrorSource.SOURCE,

@@ -13,0 +14,0 @@ handling: "unhandled" /* ErrorHandling.UNHANDLED */,

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

import type { RawError } from '../error/error';
import type { RawError } from '../error/error.types';
export type EventRateLimiter = ReturnType<typeof createEventRateLimiter>;

@@ -3,0 +3,0 @@ export declare function createEventRateLimiter(eventType: string, limit: number, onLimitReached: (limitError: RawError) => void): {

import { setTimeout } from '../../tools/timer';
import { ErrorSource } from '../error/error';
import { clocksNow, ONE_MINUTE } from '../../tools/utils/timeUtils';
import { ErrorSource } from '../error/error.types';
export function createEventRateLimiter(eventType, limit, onLimitReached) {

@@ -5,0 +5,0 @@ var eventCount = 0;

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

batch_upload_frequency?: number | undefined;
react_version?: string | undefined;
react_native_version?: string | undefined;
dart_version?: string | undefined;
};

@@ -83,0 +86,0 @@ })[];

import { ConsoleApiName } from '../../tools/display';
import { toStackTraceString } from '../error/error';
import { toStackTraceString, NO_ERROR_STACK_PRESENT_MESSAGE } from '../error/error';
import { getExperimentalFeatures } from '../../tools/experimentalFeatures';

@@ -48,3 +48,3 @@ import { INTAKE_SITE_STAGING, INTAKE_SITE_US1_FED } from '../configuration';

service: telemetryService,
version: "4.39.0",
version: "4.40.0",
source: 'browser',

@@ -128,5 +128,5 @@ _dd: {

error: {
stack: 'Not an instance of error',
stack: NO_ERROR_STACK_PRESENT_MESSAGE,
},
message: "Uncaught ".concat(jsonStringify(e)),
message: "".concat("Uncaught" /* NonErrorPrefix.UNCAUGHT */, " ").concat(jsonStringify(e)),
};

@@ -133,0 +133,0 @@ }

@@ -262,2 +262,14 @@ /**

batch_upload_frequency?: number;
/**
* The version of React used in a ReactNative application
*/
react_version?: string;
/**
* The version of ReactNative used in a ReactNative application
*/
react_native_version?: string;
/**
* The version of Dart used in a Flutter application
*/
dart_version?: string;
[k: string]: unknown;

@@ -264,0 +276,0 @@ };

@@ -19,2 +19,3 @@ export { Configuration, InitConfiguration, buildCookieOptions, validateAndBuildConfiguration, DefaultPrivacyLevel, EndpointBuilder, serializeConfiguration, INTAKE_SITE_AP1, INTAKE_SITE_STAGING, INTAKE_SITE_US1, INTAKE_SITE_US1_FED, INTAKE_SITE_EU1, } from './domain/configuration';

export * from './tools/getGlobalObject';
export { AbstractLifeCycle } from './tools/abstractLifeCycle';
export * from './domain/eventRateLimiter/createEventRateLimiter';

@@ -26,3 +27,4 @@ export * from './tools/utils/browserDetection';

export { instrumentMethod, instrumentMethodAndCallOriginal, instrumentSetter } from './tools/instrumentMethod';
export { ErrorSource, ErrorHandling, computeRawError, createHandlingStack, RawError, RawErrorCause, ErrorWithCause, toStackTraceString, getFileFromStackTraceString, NO_ERROR_STACK_PRESENT_MESSAGE, PROVIDED_ERROR_MESSAGE_PREFIX, } from './domain/error/error';
export { computeRawError, createHandlingStack, toStackTraceString, getFileFromStackTraceString, NO_ERROR_STACK_PRESENT_MESSAGE, } from './domain/error/error';
export { NonErrorPrefix } from './domain/error/error.types';
export { Context, ContextArray, ContextValue } from './tools/serialisation/context';

@@ -57,1 +59,6 @@ export { areCookiesAuthorized, getCookie, setCookie, deleteCookie, COOKIE_ACCESS_DELAY } from './browser/cookie';

export * from './tools/utils/typeUtils';
export { ErrorHandling } from './domain/error/error.types';
export { ErrorSource } from './domain/error/error.types';
export { RawError } from './domain/error/error.types';
export { RawErrorCause } from './domain/error/error.types';
export { ErrorWithCause } from './domain/error/error.types';

@@ -22,2 +22,3 @@ export { buildCookieOptions, validateAndBuildConfiguration, DefaultPrivacyLevel, serializeConfiguration, INTAKE_SITE_AP1, INTAKE_SITE_STAGING, INTAKE_SITE_US1, INTAKE_SITE_US1_FED, INTAKE_SITE_EU1, } from './domain/configuration';

export * from './tools/getGlobalObject';
export { AbstractLifeCycle } from './tools/abstractLifeCycle';
export * from './domain/eventRateLimiter/createEventRateLimiter';

@@ -29,3 +30,3 @@ export * from './tools/utils/browserDetection';

export { instrumentMethod, instrumentMethodAndCallOriginal, instrumentSetter } from './tools/instrumentMethod';
export { ErrorSource, computeRawError, createHandlingStack, toStackTraceString, getFileFromStackTraceString, NO_ERROR_STACK_PRESENT_MESSAGE, PROVIDED_ERROR_MESSAGE_PREFIX, } from './domain/error/error';
export { computeRawError, createHandlingStack, toStackTraceString, getFileFromStackTraceString, NO_ERROR_STACK_PRESENT_MESSAGE, } from './domain/error/error';
export { areCookiesAuthorized, getCookie, setCookie, deleteCookie, COOKIE_ACCESS_DELAY } from './browser/cookie';

@@ -59,2 +60,3 @@ export { initXhrObservable } from './browser/xhrObservable';

export * from './tools/utils/typeUtils';
export { ErrorSource } from './domain/error/error.types';
//# sourceMappingURL=index.js.map

@@ -14,3 +14,2 @@ /**

RESOURCE_PAGE_STATES = "resource_page_states",
CLICKMAP = "clickmap",
COLLECT_FLUSH_REASON = "collect_flush_reason",

@@ -17,0 +16,0 @@ SANITIZE_INPUTS = "sanitize_inputs"

@@ -18,3 +18,2 @@ /**

ExperimentalFeature["RESOURCE_PAGE_STATES"] = "resource_page_states";
ExperimentalFeature["CLICKMAP"] = "clickmap";
ExperimentalFeature["COLLECT_FLUSH_REASON"] = "collect_flush_reason";

@@ -21,0 +20,0 @@ ExperimentalFeature["SANITIZE_INPUTS"] = "sanitize_inputs";

import type { PageExitEvent, PageExitReason } from '../browser/pageExitObservable';
import { Observable } from '../tools/observable';
import type { Duration } from '../tools/utils/timeUtils';
export type FlushReason = PageExitReason | 'duration_limit' | 'bytes_limit' | 'messages_limit';
export type FlushReason = PageExitReason | 'duration_limit' | 'bytes_limit' | 'messages_limit' | 'session_expire';
export type FlushController = ReturnType<typeof createFlushController>;

@@ -16,10 +16,34 @@ export interface FlushEvent {

pageExitObservable: Observable<PageExitEvent>;
sessionExpireObservable: Observable<void>;
}
export declare function createFlushController({ messagesLimit, bytesLimit, durationLimit, pageExitObservable, }: FlushControllerOptions): {
/**
* Returns a "flush controller", responsible of notifying when flushing a pool of pending data needs
* to happen. The implementation is designed to support both synchronous and asynchronous usages,
* but relies on invariants described in each method documentation to keep a coherent state.
*/
export declare function createFlushController({ messagesLimit, bytesLimit, durationLimit, pageExitObservable, sessionExpireObservable, }: FlushControllerOptions): {
flushObservable: Observable<FlushEvent>;
readonly messagesCount: number;
/**
* Notifies that a message will be added to a pool of pending messages waiting to be flushed.
*
* This function needs to be called synchronously, right before adding the message, so no flush
* event can happen after `notifyBeforeAddMessage` and before adding the message.
*/
notifyBeforeAddMessage(messageBytesCount: number): void;
/**
* Notifies that a message *was* added to a pool of pending messages waiting to be flushed.
*
* This function can be called asynchronously after the message was added, but in this case it
* should not be called if a flush event occurred in between.
*/
notifyAfterAddMessage(): void;
/**
* Notifies that a message was removed from a pool of pending messages waiting to be flushed.
*
* This function needs to be called synchronously, right after removing the message, so no flush
* event can happen after removing the message and before `notifyAfterRemoveMessage`.
*/
notifyAfterRemoveMessage(messageBytesCount: number): void;
};
export {};
import { Observable } from '../tools/observable';
import { clearTimeout, setTimeout } from '../tools/timer';
/**
* Returns a "flush controller", responsible of notifying when flushing a pool of pending data needs
* to happen. The implementation is designed to support both synchronous and asynchronous usages,
* but relies on invariants described in each method documentation to keep a coherent state.
*/
export function createFlushController(_a) {
var messagesLimit = _a.messagesLimit, bytesLimit = _a.bytesLimit, durationLimit = _a.durationLimit, pageExitObservable = _a.pageExitObservable;
var messagesLimit = _a.messagesLimit, bytesLimit = _a.bytesLimit, durationLimit = _a.durationLimit, pageExitObservable = _a.pageExitObservable, sessionExpireObservable = _a.sessionExpireObservable;
var flushObservable = new Observable();
pageExitObservable.subscribe(function (event) { return flush(event.reason); });
sessionExpireObservable.subscribe(function () { return flush('session_expire'); });
var currentBytesCount = 0;

@@ -41,2 +47,8 @@ var currentMessagesCount = 0;

},
/**
* Notifies that a message will be added to a pool of pending messages waiting to be flushed.
*
* This function needs to be called synchronously, right before adding the message, so no flush
* event can happen after `notifyBeforeAddMessage` and before adding the message.
*/
notifyBeforeAddMessage: function (messageBytesCount) {

@@ -46,5 +58,5 @@ if (currentBytesCount + messageBytesCount >= bytesLimit) {

}
// Consider the message to be added now rather than in `notifyAfterAddMessage`, because if no message
// was added yet and `notifyAfterAddMessage` is called asynchronously, we still want to notify when a
// flush is needed (for example on page exit).
// Consider the message to be added now rather than in `notifyAfterAddMessage`, because if no
// message was added yet and `notifyAfterAddMessage` is called asynchronously, we still want
// to notify when a flush is needed (for example on page exit).
currentMessagesCount += 1;

@@ -54,2 +66,8 @@ currentBytesCount += messageBytesCount;

},
/**
* Notifies that a message *was* added to a pool of pending messages waiting to be flushed.
*
* This function can be called asynchronously after the message was added, but in this case it
* should not be called if a flush event occurred in between.
*/
notifyAfterAddMessage: function () {

@@ -63,2 +81,8 @@ if (currentMessagesCount >= messagesLimit) {

},
/**
* Notifies that a message was removed from a pool of pending messages waiting to be flushed.
*
* This function needs to be called synchronously, right after removing the message, so no flush
* event can happen after removing the message and before `notifyAfterRemoveMessage`.
*/
notifyAfterRemoveMessage: function (messageBytesCount) {

@@ -65,0 +89,0 @@ currentBytesCount -= messageBytesCount;

import type { EndpointBuilder } from '../domain/configuration';
import type { Context } from '../tools/serialisation/context';
import type { RawError } from '../domain/error/error';
import type { RawError } from '../domain/error/error.types';
import type { FlushReason } from './flushController';

@@ -5,0 +5,0 @@ /**

import type { EndpointType } from '../domain/configuration';
import type { RawError } from '../domain/error/error';
import type { RawError } from '../domain/error/error.types';
import type { Payload, HttpResponse } from './httpRequest';

@@ -4,0 +4,0 @@ export declare const MAX_ONGOING_BYTES_COUNT: number;

import { setTimeout } from '../tools/timer';
import { clocksNow, ONE_MINUTE, ONE_SECOND } from '../tools/utils/timeUtils';
import { ErrorSource } from '../domain/error/error';
import { ONE_MEBI_BYTE, ONE_KIBI_BYTE } from '../tools/utils/byteUtils';
import { isServerError } from '../tools/utils/responseUtils';
import { ErrorSource } from '../domain/error/error.types';
export var MAX_ONGOING_BYTES_COUNT = 80 * ONE_KIBI_BYTE;

@@ -7,0 +7,0 @@ export var MAX_ONGOING_REQUESTS = 32;

import type { Configuration, EndpointBuilder } from '../domain/configuration';
import type { RawError } from '../domain/error/error';
import type { Context } from '../tools/serialisation/context';
import type { Observable } from '../tools/observable';
import type { PageExitEvent } from '../browser/pageExitObservable';
export declare function startBatchWithReplica<T extends Context>(configuration: Configuration, endpoint: EndpointBuilder, reportError: (error: RawError) => void, pageExitObservable: Observable<PageExitEvent>, replicaEndpoint?: EndpointBuilder): {
import type { RawError } from '../domain/error/error.types';
export declare function startBatchWithReplica<T extends Context>(configuration: Configuration, endpoint: EndpointBuilder, reportError: (error: RawError) => void, pageExitObservable: Observable<PageExitEvent>, sessionExpireObservable: Observable<void>, replicaEndpoint?: EndpointBuilder): {
add(message: T, replicated?: boolean): void;
};
import { Batch } from './batch';
import { createHttpRequest } from './httpRequest';
import { createFlushController } from './flushController';
export function startBatchWithReplica(configuration, endpoint, reportError, pageExitObservable, replicaEndpoint) {
export function startBatchWithReplica(configuration, endpoint, reportError, pageExitObservable, sessionExpireObservable, replicaEndpoint) {
var primaryBatch = createBatch(endpoint);

@@ -16,2 +16,3 @@ var replicaBatch;

pageExitObservable: pageExitObservable,
sessionExpireObservable: sessionExpireObservable,
}), configuration.messageBytesLimit);

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

{
"name": "@datadog/browser-core",
"version": "4.39.0",
"version": "4.40.0",
"license": "Apache-2.0",

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

},
"gitHead": "128da89b469c77d6cfdabca15eb3d7ac09c3d5ae"
"gitHead": "4a291821c3e07385b7ab76566bb6aa5d4cc5a80f"
}
import type { StackTrace } from '../tracekit'
import { clocksNow } from '../../tools/utils/timeUtils'
import type { RawErrorCause, ErrorWithCause } from './error'
import {
createHandlingStack,
computeRawError,
getFileFromStackTraceString,
flattenErrorCauses,
ErrorSource,
ErrorHandling,
} from './error'
import { createHandlingStack, computeRawError, getFileFromStackTraceString, flattenErrorCauses } from './error'
import type { RawErrorCause, ErrorWithCause } from './error.types'
import { ErrorHandling, ErrorSource, NonErrorPrefix } from './error.types'

@@ -17,3 +11,3 @@ describe('computeRawError', () => {

startClocks: clocksNow(),
nonErrorPrefix: 'Uncaught',
nonErrorPrefix: NonErrorPrefix.UNCAUGHT,
source: ErrorSource.CUSTOM,

@@ -20,0 +14,0 @@ }

@@ -9,46 +9,6 @@ import type { StackTrace } from '../tracekit'

import { jsonStringify } from '../../tools/serialisation/jsonStringify'
import type { ErrorSource, ErrorHandling, RawError, RawErrorCause, ErrorWithCause, NonErrorPrefix } from './error.types'
export const NO_ERROR_STACK_PRESENT_MESSAGE = 'No stack, consider using an instance of Error'
export const PROVIDED_ERROR_MESSAGE_PREFIX = 'Provided'
export interface ErrorWithCause extends Error {
cause?: Error
}
export type RawErrorCause = {
message: string
source: string
type?: string
stack?: string
}
export interface RawError {
startClocks: ClocksState
message: string
type?: string
stack?: string
source: ErrorSource
originalError?: unknown
handling?: ErrorHandling
handlingStack?: string
causes?: RawErrorCause[]
}
export const ErrorSource = {
AGENT: 'agent',
CONSOLE: 'console',
CUSTOM: 'custom',
LOGGER: 'logger',
NETWORK: 'network',
SOURCE: 'source',
REPORT: 'report',
} as const
export const enum ErrorHandling {
HANDLED = 'handled',
UNHANDLED = 'unhandled',
}
export type ErrorSource = (typeof ErrorSource)[keyof typeof ErrorSource]
type RawErrorParams = {

@@ -60,3 +20,3 @@ stackTrace?: StackTrace

startClocks: ClocksState
nonErrorPrefix: string
nonErrorPrefix: NonErrorPrefix
source: ErrorSource

@@ -85,3 +45,3 @@ handling: ErrorHandling

message: `${nonErrorPrefix} ${jsonStringify(sanitizedError)!}`,
stack: 'No stack, consider using an instance of Error',
stack: NO_ERROR_STACK_PRESENT_MESSAGE,
handlingStack,

@@ -88,0 +48,0 @@ type: stackTrace && stackTrace.name,

import { Observable } from '../../tools/observable'
import type { RawError } from './error'
import { NO_ERROR_STACK_PRESENT_MESSAGE } from './error'
import { trackRuntimeError } from './trackRuntimeError'
import type { RawError } from './error.types'

@@ -76,3 +77,3 @@ describe('runtime error tracker', () => {

expect(collectedError.message).toEqual('Uncaught {"foo":"bar"}')
expect(collectedError.stack).toEqual('No stack, consider using an instance of Error')
expect(collectedError.stack).toEqual(NO_ERROR_STACK_PRESENT_MESSAGE)
done()

@@ -79,0 +80,0 @@ }, 100)

import type { Observable } from '../../tools/observable'
import { clocksNow } from '../../tools/utils/timeUtils'
import { startUnhandledErrorCollection } from '../tracekit'
import { ErrorSource, computeRawError, ErrorHandling } from './error'
import type { RawError } from './error'
import { computeRawError } from './error'
import type { RawError } from './error.types'
import { ErrorHandling, ErrorSource, NonErrorPrefix } from './error.types'

@@ -14,3 +15,3 @@ export function trackRuntimeError(errorObservable: Observable<RawError>) {

startClocks: clocksNow(),
nonErrorPrefix: 'Uncaught',
nonErrorPrefix: NonErrorPrefix.UNCAUGHT,
source: ErrorSource.SOURCE,

@@ -17,0 +18,0 @@ handling: ErrorHandling.UNHANDLED,

import type { Clock } from '../../../test'
import { mockClock } from '../../../test'
import type { RawError } from '../error/error'
import type { RelativeTime } from '../../tools/utils/timeUtils'
import { relativeToClocks, resetNavigationStart, ONE_MINUTE } from '../../tools/utils/timeUtils'
import { noop } from '../../tools/utils/functionUtils'
import type { RawError } from '../error/error.types'
import { createEventRateLimiter } from './createEventRateLimiter'

@@ -8,0 +8,0 @@ import type { EventRateLimiter } from './createEventRateLimiter'

import { setTimeout } from '../../tools/timer'
import type { RawError } from '../error/error'
import { ErrorSource } from '../error/error'
import { clocksNow, ONE_MINUTE } from '../../tools/utils/timeUtils'
import type { RawError } from '../error/error.types'
import { ErrorSource } from '../error/error.types'

@@ -6,0 +6,0 @@ export type EventRateLimiter = ReturnType<typeof createEventRateLimiter>

import type { StackTrace } from '@datadog/browser-core'
import { NO_ERROR_STACK_PRESENT_MESSAGE } from '../error/error'
import { callMonitored } from '../../tools/monitor'

@@ -164,3 +165,3 @@ import type { ExperimentalFeature } from '../../tools/experimentalFeatures'

error: {
stack: 'Not an instance of error',
stack: NO_ERROR_STACK_PRESENT_MESSAGE,
},

@@ -174,3 +175,3 @@ })

error: {
stack: 'Not an instance of error',
stack: NO_ERROR_STACK_PRESENT_MESSAGE,
},

@@ -177,0 +178,0 @@ })

import type { Context } from '../../tools/serialisation/context'
import { ConsoleApiName } from '../../tools/display'
import { toStackTraceString } from '../error/error'
import { toStackTraceString, NO_ERROR_STACK_PRESENT_MESSAGE } from '../error/error'
import { getExperimentalFeatures } from '../../tools/experimentalFeatures'

@@ -17,2 +17,3 @@ import type { Configuration } from '../configuration'

import { combine } from '../../tools/mergeInto'
import { NonErrorPrefix } from '../error/error.types'
import type { TelemetryEvent } from './telemetryEvent.types'

@@ -185,5 +186,5 @@ import type { RawTelemetryConfiguration, RawTelemetryEvent } from './rawTelemetryEvent.types'

error: {
stack: 'Not an instance of error',
stack: NO_ERROR_STACK_PRESENT_MESSAGE,
},
message: `Uncaught ${jsonStringify(e)!}`,
message: `${NonErrorPrefix.UNCAUGHT} ${jsonStringify(e)!}`,
}

@@ -190,0 +191,0 @@ }

@@ -268,2 +268,14 @@ /* eslint-disable */

batch_upload_frequency?: number
/**
* The version of React used in a ReactNative application
*/
react_version?: string
/**
* The version of ReactNative used in a ReactNative application
*/
react_native_version?: string
/**
* The version of Dart used in a Flutter application
*/
dart_version?: string
[k: string]: unknown

@@ -270,0 +282,0 @@ }

@@ -72,2 +72,3 @@ export {

export * from './tools/getGlobalObject'
export { AbstractLifeCycle } from './tools/abstractLifeCycle'
export * from './domain/eventRateLimiter/createEventRateLimiter'

@@ -80,14 +81,9 @@ export * from './tools/utils/browserDetection'

export {
ErrorSource,
ErrorHandling,
computeRawError,
createHandlingStack,
RawError,
RawErrorCause,
ErrorWithCause,
toStackTraceString,
getFileFromStackTraceString,
NO_ERROR_STACK_PRESENT_MESSAGE,
PROVIDED_ERROR_MESSAGE_PREFIX,
} from './domain/error/error'
export { NonErrorPrefix } from './domain/error/error.types'
export { Context, ContextArray, ContextValue } from './tools/serialisation/context'

@@ -130,1 +126,6 @@ export { areCookiesAuthorized, getCookie, setCookie, deleteCookie, COOKIE_ACCESS_DELAY } from './browser/cookie'

export * from './tools/utils/typeUtils'
export { ErrorHandling } from './domain/error/error.types'
export { ErrorSource } from './domain/error/error.types'
export { RawError } from './domain/error/error.types'
export { RawErrorCause } from './domain/error/error.types'
export { ErrorWithCause } from './domain/error/error.types'

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

RESOURCE_PAGE_STATES = 'resource_page_states',
CLICKMAP = 'clickmap',
COLLECT_FLUSH_REASON = 'collect_flush_reason',

@@ -20,0 +19,0 @@ SANITIZE_INPUTS = 'sanitize_inputs',

@@ -20,2 +20,3 @@ import type { Clock } from '../../test'

let pageExitObservable: Observable<PageExitEvent>
let sessionExpireObservable: Observable<void>

@@ -25,2 +26,3 @@ beforeEach(() => {

pageExitObservable = new Observable()
sessionExpireObservable = new Observable()
flushController = createFlushController({

@@ -31,2 +33,3 @@ bytesLimit: BYTES_LIMIT,

pageExitObservable,
sessionExpireObservable,
})

@@ -84,2 +87,29 @@ flushSpy = jasmine.createSpy()

describe('session expire', () => {
it('notifies when the session expires', () => {
flushController.notifyBeforeAddMessage(SMALL_MESSAGE_BYTE_COUNT)
flushController.notifyAfterAddMessage()
sessionExpireObservable.notify()
expect(flushSpy).toHaveBeenCalled()
})
it('flush reason should be "session_expire"', () => {
flushController.notifyBeforeAddMessage(SMALL_MESSAGE_BYTE_COUNT)
flushController.notifyAfterAddMessage()
sessionExpireObservable.notify()
expect(flushSpy.calls.first().args[0].reason).toBe('session_expire')
})
it('does not notify if no message was added', () => {
sessionExpireObservable.notify()
expect(flushSpy).not.toHaveBeenCalled()
})
it('notifies when the session expires even if no message have been fully added yet', () => {
flushController.notifyBeforeAddMessage(SMALL_MESSAGE_BYTE_COUNT)
sessionExpireObservable.notify()
expect(flushSpy).toHaveBeenCalled()
})
})
describe('bytes limit', () => {

@@ -86,0 +116,0 @@ it('notifies when the bytes limit is reached after adding a message', () => {

@@ -7,3 +7,3 @@ import type { PageExitEvent, PageExitReason } from '../browser/pageExitObservable'

export type FlushReason = PageExitReason | 'duration_limit' | 'bytes_limit' | 'messages_limit'
export type FlushReason = PageExitReason | 'duration_limit' | 'bytes_limit' | 'messages_limit' | 'session_expire'

@@ -22,4 +22,10 @@ export type FlushController = ReturnType<typeof createFlushController>

pageExitObservable: Observable<PageExitEvent>
sessionExpireObservable: Observable<void>
}
/**
* Returns a "flush controller", responsible of notifying when flushing a pool of pending data needs
* to happen. The implementation is designed to support both synchronous and asynchronous usages,
* but relies on invariants described in each method documentation to keep a coherent state.
*/
export function createFlushController({

@@ -30,2 +36,3 @@ messagesLimit,

pageExitObservable,
sessionExpireObservable,
}: FlushControllerOptions) {

@@ -35,2 +42,3 @@ const flushObservable = new Observable<FlushEvent>()

pageExitObservable.subscribe((event) => flush(event.reason))
sessionExpireObservable.subscribe(() => flush('session_expire'))

@@ -79,2 +87,8 @@ let currentBytesCount = 0

/**
* Notifies that a message will be added to a pool of pending messages waiting to be flushed.
*
* This function needs to be called synchronously, right before adding the message, so no flush
* event can happen after `notifyBeforeAddMessage` and before adding the message.
*/
notifyBeforeAddMessage(messageBytesCount: number) {

@@ -84,5 +98,5 @@ if (currentBytesCount + messageBytesCount >= bytesLimit) {

}
// Consider the message to be added now rather than in `notifyAfterAddMessage`, because if no message
// was added yet and `notifyAfterAddMessage` is called asynchronously, we still want to notify when a
// flush is needed (for example on page exit).
// Consider the message to be added now rather than in `notifyAfterAddMessage`, because if no
// message was added yet and `notifyAfterAddMessage` is called asynchronously, we still want
// to notify when a flush is needed (for example on page exit).
currentMessagesCount += 1

@@ -93,2 +107,8 @@ currentBytesCount += messageBytesCount

/**
* Notifies that a message *was* added to a pool of pending messages waiting to be flushed.
*
* This function can be called asynchronously after the message was added, but in this case it
* should not be called if a flush event occurred in between.
*/
notifyAfterAddMessage() {

@@ -102,2 +122,8 @@ if (currentMessagesCount >= messagesLimit) {

/**
* Notifies that a message was removed from a pool of pending messages waiting to be flushed.
*
* This function needs to be called synchronously, right after removing the message, so no flush
* event can happen after removing the message and before `notifyAfterRemoveMessage`.
*/
notifyAfterRemoveMessage(messageBytesCount: number) {

@@ -104,0 +130,0 @@ currentBytesCount -= messageBytesCount

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

import { monitor } from '../tools/monitor'
import type { RawError } from '../domain/error/error'
import { addEventListener } from '../browser/addEventListener'
import type { RawError } from '../domain/error/error.types'
import { newRetryState, sendWithRetryStrategy } from './sendWithRetryStrategy'

@@ -9,0 +9,0 @@ import type { FlushReason } from './flushController'

import { mockClock, restoreNavigatorOnLine, setNavigatorOnLine } from '../../test'
import type { Clock } from '../../test'
import { ErrorSource } from '../domain/error/error'
import { ErrorSource } from '../domain/error/error.types'
import type { RetryState } from './sendWithRetryStrategy'

@@ -5,0 +5,0 @@ import {

import type { EndpointType } from '../domain/configuration'
import { setTimeout } from '../tools/timer'
import type { RawError } from '../domain/error/error'
import { clocksNow, ONE_MINUTE, ONE_SECOND } from '../tools/utils/timeUtils'
import { ErrorSource } from '../domain/error/error'
import { ONE_MEBI_BYTE, ONE_KIBI_BYTE } from '../tools/utils/byteUtils'
import { isServerError } from '../tools/utils/responseUtils'
import type { RawError } from '../domain/error/error.types'
import { ErrorSource } from '../domain/error/error.types'
import type { Payload, HttpResponse } from './httpRequest'

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

import type { Configuration, EndpointBuilder } from '../domain/configuration'
import type { RawError } from '../domain/error/error'
import type { Context } from '../tools/serialisation/context'
import type { Observable } from '../tools/observable'
import type { PageExitEvent } from '../browser/pageExitObservable'
import type { RawError } from '../domain/error/error.types'
import { Batch } from './batch'

@@ -15,2 +15,3 @@ import { createHttpRequest } from './httpRequest'

pageExitObservable: Observable<PageExitEvent>,
sessionExpireObservable: Observable<void>,
replicaEndpoint?: EndpointBuilder

@@ -32,2 +33,3 @@ ) {

pageExitObservable,
sessionExpireObservable,
}),

@@ -34,0 +36,0 @@ configuration.messageBytesLimit

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc