@datadog/browser-core
Advanced tools
Comparing version 5.16.0 to 5.17.1
@@ -9,3 +9,3 @@ "use strict"; | ||
var publicApi = (0, polyfills_1.assign)({ | ||
version: "5.16.0", | ||
version: "5.17.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 |
@@ -5,2 +5,3 @@ import type { Duration } from '../../tools/utils/timeUtils'; | ||
import type { TransportConfiguration } from './transportConfiguration'; | ||
export declare const DOC_LINK = "https://docs.datadoghq.com/getting_started/site/"; | ||
export declare const DefaultPrivacyLevel: { | ||
@@ -7,0 +8,0 @@ readonly ALLOW: "allow"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.serializeConfiguration = exports.validateAndBuildConfiguration = exports.TraceContextInjection = exports.DefaultPrivacyLevel = void 0; | ||
exports.serializeConfiguration = exports.validateAndBuildConfiguration = exports.TraceContextInjection = exports.DefaultPrivacyLevel = exports.DOC_LINK = void 0; | ||
var catchUserErrors_1 = require("../../tools/catchUserErrors"); | ||
@@ -15,2 +15,3 @@ var display_1 = require("../../tools/display"); | ||
var transportConfiguration_1 = require("./transportConfiguration"); | ||
exports.DOC_LINK = 'https://docs.datadoghq.com/getting_started/site/'; | ||
exports.DefaultPrivacyLevel = { | ||
@@ -25,2 +26,5 @@ ALLOW: 'allow', | ||
}; | ||
function isDatadogSite(site) { | ||
return /(datadog|ddog|datad0g|dd0g)/.test(site); | ||
} | ||
function validateAndBuildConfiguration(initConfiguration) { | ||
@@ -55,2 +59,6 @@ var _a, _b, _c, _d, _e; | ||
} | ||
if (initConfiguration.site && !isDatadogSite(initConfiguration.site)) { | ||
display_1.display.error("Site should be a valid Datadog site. Learn more here: ".concat(exports.DOC_LINK, ".")); | ||
return; | ||
} | ||
// Set the experimental feature flags as early as possible, so we can use them in most places | ||
@@ -57,0 +65,0 @@ if (Array.isArray(initConfiguration.enableExperimentalFeatures)) { |
@@ -61,3 +61,3 @@ "use strict"; | ||
var retry = _b.retry, flushReason = _b.flushReason, encoding = _b.encoding; | ||
var tags = ["sdk_version:".concat("5.16.0"), "api:".concat(api)].concat(configurationTags); | ||
var tags = ["sdk_version:".concat("5.17.1"), "api:".concat(api)].concat(configurationTags); | ||
if (flushReason && (0, experimentalFeatures_1.isExperimentalFeatureEnabled)(experimentalFeatures_1.ExperimentalFeature.COLLECT_FLUSH_REASON)) { | ||
@@ -73,3 +73,3 @@ tags.push("flush_reason:".concat(flushReason)); | ||
"dd-api-key=".concat(clientToken), | ||
"dd-evp-origin-version=".concat(encodeURIComponent("5.16.0")), | ||
"dd-evp-origin-version=".concat(encodeURIComponent("5.17.1")), | ||
'dd-evp-origin=browser', | ||
@@ -76,0 +76,0 @@ "dd-request-id=".concat((0, stringUtils_1.generateUUID)()), |
@@ -11,3 +11,4 @@ "use strict"; | ||
var jsonStringify_1 = require("../../tools/serialisation/jsonStringify"); | ||
var computeStackTrace_1 = require("../error/computeStackTrace"); | ||
var computeStackTrace_1 = require("../../tools/stackTrace/computeStackTrace"); | ||
var handlingStack_1 = require("../../tools/stackTrace/handlingStack"); | ||
var consoleObservablesByApi = {}; | ||
@@ -37,3 +38,3 @@ function initConsoleObservable(apis) { | ||
originalConsoleApi.apply(console, params); | ||
var handlingStack = (0, error_1.createHandlingStack)(); | ||
var handlingStack = (0, handlingStack_1.createHandlingStack)(); | ||
(0, monitor_1.callMonitored)(function () { | ||
@@ -55,3 +56,3 @@ observable.notify(buildConsoleLog(params, api, handlingStack)); | ||
var firstErrorParam = (0, polyfills_1.find)(params, function (param) { return param instanceof Error; }); | ||
stack = firstErrorParam ? (0, error_1.toStackTraceString)((0, computeStackTrace_1.computeStackTrace)(firstErrorParam)) : undefined; | ||
stack = firstErrorParam ? (0, handlingStack_1.toStackTraceString)((0, computeStackTrace_1.computeStackTrace)(firstErrorParam)) : undefined; | ||
fingerprint = (0, error_1.tryToGetFingerprint)(firstErrorParam); | ||
@@ -74,3 +75,3 @@ causes = firstErrorParam ? (0, error_1.flattenErrorCauses)(firstErrorParam, 'console') : undefined; | ||
if (param instanceof Error) { | ||
return (0, error_1.formatErrorMessage)((0, computeStackTrace_1.computeStackTrace)(param)); | ||
return (0, handlingStack_1.formatErrorMessage)((0, computeStackTrace_1.computeStackTrace)(param)); | ||
} | ||
@@ -77,0 +78,0 @@ return (0, jsonStringify_1.jsonStringify)((0, sanitize_1.sanitize)(param), undefined, 2); |
import type { ClocksState } from '../../tools/utils/timeUtils'; | ||
import type { StackTrace } from '../../tools/stackTrace/computeStackTrace'; | ||
import type { ErrorSource, ErrorHandling, RawError, RawErrorCause, ErrorWithCause, NonErrorPrefix } from './error.types'; | ||
import type { StackTrace } from './computeStackTrace'; | ||
export declare const NO_ERROR_STACK_PRESENT_MESSAGE = "No stack, consider using an instance of Error"; | ||
@@ -16,14 +16,4 @@ type RawErrorParams = { | ||
export declare function tryToGetFingerprint(originalError: unknown): string | undefined; | ||
export declare function toStackTraceString(stack: StackTrace): string; | ||
export declare function getFileFromStackTraceString(stack: string): string | undefined; | ||
export declare function formatErrorMessage(stack: StackTrace): string; | ||
/** | ||
Creates a stacktrace without SDK internal frames. | ||
Constraints: | ||
- Has to be called at the utmost position of the call stack. | ||
- No monitored function should encapsulate it, that is why we need to use callMonitored inside it. | ||
*/ | ||
export declare function createHandlingStack(): string; | ||
export declare function flattenErrorCauses(error: ErrorWithCause, parentSource: ErrorSource): RawErrorCause[] | undefined; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.flattenErrorCauses = exports.createHandlingStack = exports.formatErrorMessage = exports.getFileFromStackTraceString = exports.toStackTraceString = exports.tryToGetFingerprint = exports.computeRawError = exports.NO_ERROR_STACK_PRESENT_MESSAGE = void 0; | ||
var monitor_1 = require("../../tools/monitor"); | ||
exports.flattenErrorCauses = exports.getFileFromStackTraceString = exports.tryToGetFingerprint = exports.computeRawError = exports.NO_ERROR_STACK_PRESENT_MESSAGE = void 0; | ||
var sanitize_1 = require("../../tools/serialisation/sanitize"); | ||
var functionUtils_1 = require("../../tools/utils/functionUtils"); | ||
var jsonStringify_1 = require("../../tools/serialisation/jsonStringify"); | ||
var computeStackTrace_1 = require("./computeStackTrace"); | ||
var computeStackTrace_1 = require("../../tools/stackTrace/computeStackTrace"); | ||
var handlingStack_1 = require("../../tools/stackTrace/handlingStack"); | ||
exports.NO_ERROR_STACK_PRESENT_MESSAGE = 'No stack, consider using an instance of Error'; | ||
@@ -15,3 +14,3 @@ function computeRawError(_a) { | ||
var stack = hasUsableStack(isErrorInstance, stackTrace) | ||
? toStackTraceString(stackTrace) | ||
? (0, handlingStack_1.toStackTraceString)(stackTrace) | ||
: exports.NO_ERROR_STACK_PRESENT_MESSAGE; | ||
@@ -61,14 +60,2 @@ var causes = isErrorInstance ? flattenErrorCauses(originalError, source) : undefined; | ||
exports.tryToGetFingerprint = tryToGetFingerprint; | ||
function toStackTraceString(stack) { | ||
var result = formatErrorMessage(stack); | ||
stack.stack.forEach(function (frame) { | ||
var func = frame.func === '?' ? '<anonymous>' : frame.func; | ||
var args = frame.args && frame.args.length > 0 ? "(".concat(frame.args.join(', '), ")") : ''; | ||
var line = frame.line ? ":".concat(frame.line) : ''; | ||
var column = frame.line && frame.column ? ":".concat(frame.column) : ''; | ||
result += "\n at ".concat(func).concat(args, " @ ").concat(frame.url).concat(line).concat(column); | ||
}); | ||
return result; | ||
} | ||
exports.toStackTraceString = toStackTraceString; | ||
function getFileFromStackTraceString(stack) { | ||
@@ -79,40 +66,2 @@ var _a; | ||
exports.getFileFromStackTraceString = getFileFromStackTraceString; | ||
function formatErrorMessage(stack) { | ||
return "".concat(stack.name || 'Error', ": ").concat(stack.message); | ||
} | ||
exports.formatErrorMessage = formatErrorMessage; | ||
/** | ||
Creates a stacktrace without SDK internal frames. | ||
Constraints: | ||
- Has to be called at the utmost position of the call stack. | ||
- No monitored function should encapsulate it, that is why we need to use callMonitored inside it. | ||
*/ | ||
function createHandlingStack() { | ||
/** | ||
* Skip the two internal frames: | ||
* - SDK API (console.error, ...) | ||
* - this function | ||
* in order to keep only the user calls | ||
*/ | ||
var internalFramesToSkip = 2; | ||
var error = new Error(); | ||
var formattedStack; | ||
// IE needs to throw the error to fill in the stack trace | ||
if (!error.stack) { | ||
try { | ||
throw error; | ||
} | ||
catch (e) { | ||
(0, functionUtils_1.noop)(); | ||
} | ||
} | ||
(0, monitor_1.callMonitored)(function () { | ||
var stackTrace = (0, computeStackTrace_1.computeStackTrace)(error); | ||
stackTrace.stack = stackTrace.stack.slice(internalFramesToSkip); | ||
formattedStack = toStackTraceString(stackTrace); | ||
}); | ||
return formattedStack; | ||
} | ||
exports.createHandlingStack = createHandlingStack; | ||
function flattenErrorCauses(error, parentSource) { | ||
@@ -127,3 +76,3 @@ var currentError = error; | ||
type: stackTrace === null || stackTrace === void 0 ? void 0 : stackTrace.name, | ||
stack: stackTrace && toStackTraceString(stackTrace), | ||
stack: stackTrace && (0, handlingStack_1.toStackTraceString)(stackTrace), | ||
}); | ||
@@ -130,0 +79,0 @@ currentError = currentError.cause; |
import type { Observable } from '../../tools/observable'; | ||
import type { StackTrace } from './computeStackTrace'; | ||
import type { StackTrace } from '../../tools/stackTrace/computeStackTrace'; | ||
import type { RawError } from './error.types'; | ||
@@ -4,0 +4,0 @@ export type UnhandledErrorCallback = (stackTrace: StackTrace, originalError?: any) => any; |
@@ -6,3 +6,3 @@ "use strict"; | ||
var timeUtils_1 = require("../../tools/utils/timeUtils"); | ||
var computeStackTrace_1 = require("./computeStackTrace"); | ||
var computeStackTrace_1 = require("../../tools/stackTrace/computeStackTrace"); | ||
var error_1 = require("./error"); | ||
@@ -9,0 +9,0 @@ var error_types_1 = require("./error.types"); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.initReportObservable = exports.RawReportType = void 0; | ||
var error_1 = require("../error/error"); | ||
var handlingStack_1 = require("../../tools/stackTrace/handlingStack"); | ||
var monitor_1 = require("../../tools/monitor"); | ||
@@ -80,3 +80,3 @@ var observable_1 = require("../../tools/observable"); | ||
return sourceFile | ||
? (0, error_1.toStackTraceString)({ | ||
? (0, handlingStack_1.toStackTraceString)({ | ||
name: name, | ||
@@ -83,0 +83,0 @@ message: message, |
@@ -33,3 +33,3 @@ "use strict"; | ||
} | ||
if (!(0, sessionState_1.isSessionInExpiredState)(session)) { | ||
if ((0, sessionState_1.isSessionStarted)(session)) { | ||
(0, sessionState_1.expandSessionState)(session); | ||
@@ -36,0 +36,0 @@ cookieStoreStrategy.persistSession(session); |
@@ -48,2 +48,3 @@ "use strict"; | ||
trackVisibility(configuration, function () { return sessionStore.expandSession(); }); | ||
trackResume(configuration, function () { return sessionStore.restartSession(); }); | ||
function buildSessionContext() { | ||
@@ -85,2 +86,6 @@ return { | ||
} | ||
function trackResume(configuration, cb) { | ||
var stop = (0, addEventListener_1.addEventListener)(configuration, window, addEventListener_1.DOM_EVENT.RESUME, cb, { capture: true }).stop; | ||
stopCallbacks.push(stop); | ||
} | ||
//# sourceMappingURL=sessionManager.js.map |
@@ -0,1 +1,2 @@ | ||
export declare const EXPIRED = "1"; | ||
export interface SessionState { | ||
@@ -5,5 +6,8 @@ id?: string; | ||
expire?: string; | ||
lock?: string; | ||
isExpired?: typeof EXPIRED; | ||
[key: string]: string | undefined; | ||
} | ||
export declare function getExpiredSessionState(): SessionState; | ||
export declare function isSessionInNotStartedState(session: SessionState): boolean; | ||
export declare function isSessionStarted(session: SessionState): boolean; | ||
export declare function isSessionInExpiredState(session: SessionState): boolean; | ||
@@ -10,0 +14,0 @@ export declare function expandSessionState(session: SessionState): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.toSessionState = exports.toSessionString = exports.expandSessionState = exports.isSessionInExpiredState = void 0; | ||
exports.toSessionState = exports.toSessionString = exports.expandSessionState = exports.isSessionInExpiredState = exports.isSessionStarted = exports.isSessionInNotStartedState = exports.getExpiredSessionState = exports.EXPIRED = void 0; | ||
var objectUtils_1 = require("../../tools/utils/objectUtils"); | ||
@@ -8,8 +8,30 @@ var polyfills_1 = require("../../tools/utils/polyfills"); | ||
var sessionConstants_1 = require("./sessionConstants"); | ||
var SESSION_ENTRY_REGEXP = /^([a-z]+)=([a-z0-9-]+)$/; | ||
var SESSION_ENTRY_REGEXP = /^([a-zA-Z]+)=([a-z0-9-]+)$/; | ||
var SESSION_ENTRY_SEPARATOR = '&'; | ||
function isSessionInExpiredState(session) { | ||
exports.EXPIRED = '1'; | ||
function getExpiredSessionState() { | ||
return { | ||
isExpired: exports.EXPIRED, | ||
}; | ||
} | ||
exports.getExpiredSessionState = getExpiredSessionState; | ||
function isSessionInNotStartedState(session) { | ||
return (0, objectUtils_1.isEmptyObject)(session); | ||
} | ||
exports.isSessionInNotStartedState = isSessionInNotStartedState; | ||
function isSessionStarted(session) { | ||
return !isSessionInNotStartedState(session); | ||
} | ||
exports.isSessionStarted = isSessionStarted; | ||
function isSessionInExpiredState(session) { | ||
return session.isExpired !== undefined || !isActiveSession(session); | ||
} | ||
exports.isSessionInExpiredState = isSessionInExpiredState; | ||
// An active session is a session in either `Tracked` or `NotTracked` state | ||
function isActiveSession(sessionState) { | ||
// created and expire can be undefined for versions which was not storing them | ||
// these checks could be removed when older versions will not be available/live anymore | ||
return ((sessionState.created === undefined || (0, timeUtils_1.dateNow)() - Number(sessionState.created) < sessionConstants_1.SESSION_TIME_OUT_DELAY) && | ||
(sessionState.expire === undefined || (0, timeUtils_1.dateNow)() < Number(sessionState.expire))); | ||
} | ||
function expandSessionState(session) { | ||
@@ -16,0 +38,0 @@ session.expire = String((0, timeUtils_1.dateNow)() + sessionConstants_1.SESSION_EXPIRATION_DELAY); |
@@ -9,2 +9,3 @@ import { Observable } from '../../tools/observable'; | ||
getSession: () => SessionState; | ||
restartSession: () => void; | ||
renewObservable: Observable<void>; | ||
@@ -11,0 +12,0 @@ expireObservable: Observable<void>; |
@@ -9,4 +9,4 @@ "use strict"; | ||
var stringUtils_1 = require("../../tools/utils/stringUtils"); | ||
var sessionConstants_1 = require("./sessionConstants"); | ||
var sessionInCookie_1 = require("./storeStrategies/sessionInCookie"); | ||
var sessionState_1 = require("./sessionState"); | ||
var sessionInLocalStorage_1 = require("./storeStrategies/sessionInLocalStorage"); | ||
@@ -44,5 +44,6 @@ var sessionStoreOperations_1 = require("./sessionStoreOperations"); | ||
: (0, sessionInLocalStorage_1.initLocalStorageStrategy)(); | ||
var clearSession = sessionStoreStrategy.clearSession, retrieveSession = sessionStoreStrategy.retrieveSession; | ||
var expireSession = sessionStoreStrategy.expireSession; | ||
var watchSessionTimeoutId = (0, timer_1.setInterval)(watchSession, exports.STORAGE_POLL_DELAY); | ||
var sessionCache = retrieveActiveSession(); | ||
var sessionCache; | ||
startSession(); | ||
var _a = (0, functionUtils_1.throttle)(function () { | ||
@@ -52,2 +53,5 @@ var isTracked; | ||
process: function (sessionState) { | ||
if ((0, sessionState_1.isSessionInNotStartedState)(sessionState)) { | ||
return; | ||
} | ||
var synchronizedSession = synchronizeSession(sessionState); | ||
@@ -77,3 +81,3 @@ isTracked = expandOrRenewSessionState(synchronizedSession); | ||
(0, sessionStoreOperations_1.processSessionStoreOperations)({ | ||
process: function (sessionState) { return (!isActiveSession(sessionState) ? {} : undefined); }, | ||
process: function (sessionState) { return ((0, sessionState_1.isSessionInExpiredState)(sessionState) ? (0, sessionState_1.getExpiredSessionState)() : undefined); }, | ||
after: synchronizeSession, | ||
@@ -83,4 +87,4 @@ }, sessionStoreStrategy); | ||
function synchronizeSession(sessionState) { | ||
if (!isActiveSession(sessionState)) { | ||
sessionState = {}; | ||
if ((0, sessionState_1.isSessionInExpiredState)(sessionState)) { | ||
sessionState = (0, sessionState_1.getExpiredSessionState)(); | ||
} | ||
@@ -97,5 +101,21 @@ if (hasSessionInCache()) { | ||
} | ||
function startSession() { | ||
(0, sessionStoreOperations_1.processSessionStoreOperations)({ | ||
process: function (sessionState) { | ||
if ((0, sessionState_1.isSessionInNotStartedState)(sessionState)) { | ||
return (0, sessionState_1.getExpiredSessionState)(); | ||
} | ||
}, | ||
after: function (sessionState) { | ||
sessionCache = sessionState; | ||
}, | ||
}, sessionStoreStrategy); | ||
} | ||
function expandOrRenewSessionState(sessionState) { | ||
if ((0, sessionState_1.isSessionInNotStartedState)(sessionState)) { | ||
return false; | ||
} | ||
var _a = computeSessionState(sessionState[productKey]), trackingType = _a.trackingType, isTracked = _a.isTracked; | ||
sessionState[productKey] = trackingType; | ||
delete sessionState.isExpired; | ||
if (isTracked && !sessionState.id) { | ||
@@ -114,3 +134,3 @@ sessionState.id = (0, stringUtils_1.generateUUID)(); | ||
function expireSessionInCache() { | ||
sessionCache = {}; | ||
sessionCache = (0, sessionState_1.getExpiredSessionState)(); | ||
expireObservable.notify(); | ||
@@ -122,15 +142,2 @@ } | ||
} | ||
function retrieveActiveSession() { | ||
var session = retrieveSession(); | ||
if (isActiveSession(session)) { | ||
return session; | ||
} | ||
return {}; | ||
} | ||
function isActiveSession(sessionState) { | ||
// created and expire can be undefined for versions which was not storing them | ||
// these checks could be removed when older versions will not be available/live anymore | ||
return ((sessionState.created === undefined || (0, timeUtils_1.dateNow)() - Number(sessionState.created) < sessionConstants_1.SESSION_TIME_OUT_DELAY) && | ||
(sessionState.expire === undefined || (0, timeUtils_1.dateNow)() < Number(sessionState.expire))); | ||
} | ||
return { | ||
@@ -142,6 +149,7 @@ expandOrRenewSession: throttledExpandOrRenewSession, | ||
expireObservable: expireObservable, | ||
restartSession: startSession, | ||
expire: function () { | ||
cancelExpandOrRenewSession(); | ||
clearSession(); | ||
synchronizeSession({}); | ||
expireSession(); | ||
synchronizeSession((0, sessionState_1.getExpiredSessionState)()); | ||
}, | ||
@@ -148,0 +156,0 @@ stop: function () { |
@@ -6,2 +6,3 @@ "use strict"; | ||
var stringUtils_1 = require("../../tools/utils/stringUtils"); | ||
var polyfills_1 = require("../../tools/utils/polyfills"); | ||
var sessionState_1 = require("./sessionState"); | ||
@@ -15,3 +16,15 @@ exports.LOCK_RETRY_DELAY = 10; | ||
if (numberOfRetries === void 0) { numberOfRetries = 0; } | ||
var isLockEnabled = sessionStoreStrategy.isLockEnabled, retrieveSession = sessionStoreStrategy.retrieveSession, persistSession = sessionStoreStrategy.persistSession, clearSession = sessionStoreStrategy.clearSession; | ||
var isLockEnabled = sessionStoreStrategy.isLockEnabled, persistSession = sessionStoreStrategy.persistSession, expireSession = sessionStoreStrategy.expireSession; | ||
var persistWithLock = function (session) { return persistSession((0, polyfills_1.assign)({}, session, { lock: currentLock })); }; | ||
var retrieveStore = function () { | ||
var session = sessionStoreStrategy.retrieveSession(); | ||
var lock = session.lock; | ||
if (session.lock) { | ||
delete session.lock; | ||
} | ||
return { | ||
session: session, | ||
lock: lock, | ||
}; | ||
}; | ||
if (!ongoingOperations) { | ||
@@ -29,6 +42,6 @@ ongoingOperations = operations; | ||
var currentLock; | ||
var currentSession = retrieveSession(); | ||
var currentStore = retrieveStore(); | ||
if (isLockEnabled) { | ||
// if someone has lock, retry later | ||
if (currentSession.lock) { | ||
if (currentStore.lock) { | ||
retryLater(operations, sessionStoreStrategy, numberOfRetries); | ||
@@ -39,7 +52,6 @@ return; | ||
currentLock = (0, stringUtils_1.generateUUID)(); | ||
currentSession.lock = currentLock; | ||
persistSession(currentSession); | ||
persistWithLock(currentStore.session); | ||
// if lock is not acquired, retry later | ||
currentSession = retrieveSession(); | ||
if (currentSession.lock !== currentLock) { | ||
currentStore = retrieveStore(); | ||
if (currentStore.lock !== currentLock) { | ||
retryLater(operations, sessionStoreStrategy, numberOfRetries); | ||
@@ -49,7 +61,7 @@ return; | ||
} | ||
var processedSession = operations.process(currentSession); | ||
var processedSession = operations.process(currentStore.session); | ||
if (isLockEnabled) { | ||
// if lock corrupted after process, retry later | ||
currentSession = retrieveSession(); | ||
if (currentSession.lock !== currentLock) { | ||
currentStore = retrieveStore(); | ||
if (currentStore.lock !== currentLock) { | ||
retryLater(operations, sessionStoreStrategy, numberOfRetries); | ||
@@ -61,7 +73,7 @@ return; | ||
if ((0, sessionState_1.isSessionInExpiredState)(processedSession)) { | ||
clearSession(); | ||
expireSession(); | ||
} | ||
else { | ||
(0, sessionState_1.expandSessionState)(processedSession); | ||
persistSession(processedSession); | ||
isLockEnabled ? persistWithLock(processedSession) : persistSession(processedSession); | ||
} | ||
@@ -74,10 +86,9 @@ } | ||
// if lock corrupted after persist, retry later | ||
currentSession = retrieveSession(); | ||
if (currentSession.lock !== currentLock) { | ||
currentStore = retrieveStore(); | ||
if (currentStore.lock !== currentLock) { | ||
retryLater(operations, sessionStoreStrategy, numberOfRetries); | ||
return; | ||
} | ||
delete currentSession.lock; | ||
persistSession(currentSession); | ||
processedSession = currentSession; | ||
persistSession(currentStore.session); | ||
processedSession = currentStore.session; | ||
} | ||
@@ -87,3 +98,3 @@ } | ||
// up-to-date session state value => the value could have been modified by another tab | ||
(_a = operations.after) === null || _a === void 0 ? void 0 : _a.call(operations, processedSession || currentSession); | ||
(_a = operations.after) === null || _a === void 0 ? void 0 : _a.call(operations, processedSession || currentStore.session); | ||
next(sessionStoreStrategy); | ||
@@ -90,0 +101,0 @@ } |
@@ -24,3 +24,3 @@ "use strict"; | ||
retrieveSession: retrieveSessionCookie, | ||
clearSession: deleteSessionCookie(cookieOptions), | ||
expireSession: function () { return expireSessionCookie(cookieOptions); }, | ||
}; | ||
@@ -36,2 +36,5 @@ (0, oldCookiesMigration_1.tryOldCookiesMigration)(cookieStore); | ||
} | ||
function expireSessionCookie(options) { | ||
(0, cookie_1.setCookie)(sessionStoreStrategy_1.SESSION_STORE_KEY, (0, sessionState_1.toSessionString)((0, sessionState_1.getExpiredSessionState)()), sessionConstants_1.SESSION_TIME_OUT_DELAY, options); | ||
} | ||
function retrieveSessionCookie() { | ||
@@ -41,7 +44,2 @@ var sessionString = (0, cookie_1.getCookie)(sessionStoreStrategy_1.SESSION_STORE_KEY); | ||
} | ||
function deleteSessionCookie(options) { | ||
return function () { | ||
(0, cookie_1.deleteCookie)(sessionStoreStrategy_1.SESSION_STORE_KEY, options); | ||
}; | ||
} | ||
function buildCookieOptions(initConfiguration) { | ||
@@ -48,0 +46,0 @@ var cookieOptions = {}; |
@@ -27,3 +27,3 @@ "use strict"; | ||
retrieveSession: retrieveSessionFromLocalStorage, | ||
clearSession: clearSessionFromLocalStorage, | ||
expireSession: expireSessionFromLocalStorage, | ||
}; | ||
@@ -39,5 +39,5 @@ } | ||
} | ||
function clearSessionFromLocalStorage() { | ||
localStorage.removeItem(sessionStoreStrategy_1.SESSION_STORE_KEY); | ||
function expireSessionFromLocalStorage() { | ||
persistInLocalStorage((0, sessionState_1.getExpiredSessionState)()); | ||
} | ||
//# sourceMappingURL=sessionInLocalStorage.js.map |
@@ -14,3 +14,3 @@ import type { CookieOptions } from '../../../browser/cookie'; | ||
retrieveSession: () => SessionState; | ||
clearSession: () => void; | ||
expireSession: () => void; | ||
} |
import type { Context } from '../../tools/serialisation/context'; | ||
import type { Configuration } from '../configuration'; | ||
import { Observable } from '../../tools/observable'; | ||
import type { StackTrace } from '../error/computeStackTrace'; | ||
import type { StackTrace } from '../../tools/stackTrace/computeStackTrace'; | ||
import type { TelemetryEvent } from './telemetryEvent.types'; | ||
@@ -65,2 +65,3 @@ import type { RawTelemetryConfiguration, RawTelemetryUsage } from './rawTelemetryEvent.types'; | ||
default_privacy_level?: string | undefined; | ||
enable_privacy_for_action_name?: boolean | undefined; | ||
use_excluded_activity_urls?: boolean | undefined; | ||
@@ -67,0 +68,0 @@ use_worker_url?: boolean | undefined; |
@@ -6,2 +6,3 @@ "use strict"; | ||
var error_1 = require("../error/error"); | ||
var handlingStack_1 = require("../../tools/stackTrace/handlingStack"); | ||
var experimentalFeatures_1 = require("../../tools/experimentalFeatures"); | ||
@@ -17,3 +18,3 @@ var configuration_1 = require("../configuration"); | ||
var mergeInto_1 = require("../../tools/mergeInto"); | ||
var computeStackTrace_1 = require("../error/computeStackTrace"); | ||
var computeStackTrace_1 = require("../../tools/stackTrace/computeStackTrace"); | ||
var connectivity_1 = require("../connectivity"); | ||
@@ -63,3 +64,3 @@ var rawTelemetryEvent_types_1 = require("./rawTelemetryEvent.types"); | ||
service: telemetryService, | ||
version: "5.16.0", | ||
version: "5.17.1", | ||
source: 'browser', | ||
@@ -157,3 +158,3 @@ _dd: { | ||
kind: stackTrace.name, | ||
stack: (0, error_1.toStackTraceString)(scrubCustomerFrames(stackTrace)), | ||
stack: (0, handlingStack_1.toStackTraceString)(scrubCustomerFrames(stackTrace)), | ||
}, | ||
@@ -160,0 +161,0 @@ message: stackTrace.message, |
@@ -199,2 +199,6 @@ /** | ||
/** | ||
* Privacy control for action name | ||
*/ | ||
enable_privacy_for_action_name?: boolean; | ||
/** | ||
* Whether the request origins list to ignore when computing the page activity is used | ||
@@ -201,0 +205,0 @@ */ |
@@ -5,3 +5,3 @@ export { Configuration, InitConfiguration, validateAndBuildConfiguration, DefaultPrivacyLevel, TraceContextInjection, EndpointBuilder, serializeConfiguration, INTAKE_SITE_STAGING, INTAKE_SITE_US1, INTAKE_SITE_US1_FED, INTAKE_SITE_EU1, } from './domain/configuration'; | ||
export { trackRuntimeError } from './domain/error/trackRuntimeError'; | ||
export { computeStackTrace, StackTrace } from './domain/error/computeStackTrace'; | ||
export { computeStackTrace, StackTrace } from './tools/stackTrace/computeStackTrace'; | ||
export { defineGlobal, makePublicApi } from './boot/init'; | ||
@@ -30,3 +30,3 @@ export { displayAlreadyInitializedError } from './boot/displayAlreadyInitializedError'; | ||
export { instrumentMethod, instrumentSetter, InstrumentedMethodCall } from './tools/instrumentMethod'; | ||
export { computeRawError, createHandlingStack, toStackTraceString, getFileFromStackTraceString, NO_ERROR_STACK_PRESENT_MESSAGE, } from './domain/error/error'; | ||
export { computeRawError, getFileFromStackTraceString, NO_ERROR_STACK_PRESENT_MESSAGE } from './domain/error/error'; | ||
export { NonErrorPrefix } from './domain/error/error.types'; | ||
@@ -69,1 +69,2 @@ export { Context, ContextArray, ContextValue } from './tools/serialisation/context'; | ||
export * from './domain/connectivity'; | ||
export * from './tools/stackTrace/handlingStack'; |
@@ -18,3 +18,3 @@ "use strict"; | ||
exports.instrumentMethod = exports.getZoneJsOriginalValue = exports.runOnReadyState = exports.sendToExtension = exports.AbstractLifeCycle = exports.createIdentityEncoder = exports.createFlushController = exports.startBatchWithReplica = exports.bridgeSupports = exports.getEventBridge = exports.canUseEventBridge = exports.createHttpRequest = exports.SESSION_TIME_OUT_DELAY = exports.stopSessionManager = exports.startSessionManager = exports.Observable = exports.setDebugMode = exports.callMonitored = exports.monitor = exports.monitored = exports.addTelemetryUsage = exports.addTelemetryConfiguration = exports.isTelemetryReplicationAllowed = exports.resetTelemetry = exports.startFakeTelemetry = exports.addTelemetryError = exports.addTelemetryDebug = exports.startTelemetry = exports.RawReportType = exports.initReportObservable = exports.displayAlreadyInitializedError = exports.makePublicApi = exports.defineGlobal = exports.computeStackTrace = exports.trackRuntimeError = exports.ExperimentalFeature = exports.getExperimentalFeatures = exports.resetExperimentalFeatures = exports.addExperimentalFeatures = exports.isExperimentalFeatureEnabled = exports.createTrackingConsentState = exports.TrackingConsent = exports.INTAKE_SITE_EU1 = exports.INTAKE_SITE_US1_FED = exports.INTAKE_SITE_US1 = exports.INTAKE_SITE_STAGING = exports.serializeConfiguration = exports.TraceContextInjection = exports.DefaultPrivacyLevel = exports.validateAndBuildConfiguration = void 0; | ||
exports.ErrorSource = exports.sanitizeUser = exports.checkUser = exports.getSyntheticsResultId = exports.getSyntheticsTestId = exports.willSyntheticsInjectRum = exports.SESSION_STORE_KEY = exports.STORAGE_POLL_DELAY = exports.readBytesFromStream = exports.CLEAR_OLD_VALUES_INTERVAL = exports.ValueHistory = exports.CUSTOMER_DATA_BYTES_LIMIT = exports.createCustomerDataTracker = exports.createCustomerDataTrackerManager = exports.removeStorageListeners = exports.storeContextManager = exports.createContextManager = exports.catchUserErrors = exports.BoundedBuffer = exports.resetConsoleObservable = exports.initConsoleObservable = exports.isPageExitReason = exports.PageExitReason = exports.createPageExitObservable = exports.initFetchObservable = exports.initXhrObservable = exports.resetInitCookies = exports.deleteCookie = exports.setCookie = exports.getInitCookie = exports.getCookie = exports.areCookiesAuthorized = exports.NO_ERROR_STACK_PRESENT_MESSAGE = exports.getFileFromStackTraceString = exports.toStackTraceString = exports.createHandlingStack = exports.computeRawError = exports.instrumentSetter = void 0; | ||
exports.ErrorSource = exports.sanitizeUser = exports.checkUser = exports.getSyntheticsResultId = exports.getSyntheticsTestId = exports.willSyntheticsInjectRum = exports.SESSION_STORE_KEY = exports.STORAGE_POLL_DELAY = exports.readBytesFromStream = exports.CLEAR_OLD_VALUES_INTERVAL = exports.ValueHistory = exports.CUSTOMER_DATA_BYTES_LIMIT = exports.createCustomerDataTracker = exports.createCustomerDataTrackerManager = exports.removeStorageListeners = exports.storeContextManager = exports.createContextManager = exports.catchUserErrors = exports.BoundedBuffer = exports.resetConsoleObservable = exports.initConsoleObservable = exports.isPageExitReason = exports.PageExitReason = exports.createPageExitObservable = exports.initFetchObservable = exports.initXhrObservable = exports.resetInitCookies = exports.deleteCookie = exports.setCookie = exports.getInitCookie = exports.getCookie = exports.areCookiesAuthorized = exports.NO_ERROR_STACK_PRESENT_MESSAGE = exports.getFileFromStackTraceString = exports.computeRawError = exports.instrumentSetter = void 0; | ||
var configuration_1 = require("./domain/configuration"); | ||
@@ -40,3 +40,3 @@ Object.defineProperty(exports, "validateAndBuildConfiguration", { enumerable: true, get: function () { return configuration_1.validateAndBuildConfiguration; } }); | ||
Object.defineProperty(exports, "trackRuntimeError", { enumerable: true, get: function () { return trackRuntimeError_1.trackRuntimeError; } }); | ||
var computeStackTrace_1 = require("./domain/error/computeStackTrace"); | ||
var computeStackTrace_1 = require("./tools/stackTrace/computeStackTrace"); | ||
Object.defineProperty(exports, "computeStackTrace", { enumerable: true, get: function () { return computeStackTrace_1.computeStackTrace; } }); | ||
@@ -103,4 +103,2 @@ var init_1 = require("./boot/init"); | ||
Object.defineProperty(exports, "computeRawError", { enumerable: true, get: function () { return error_1.computeRawError; } }); | ||
Object.defineProperty(exports, "createHandlingStack", { enumerable: true, get: function () { return error_1.createHandlingStack; } }); | ||
Object.defineProperty(exports, "toStackTraceString", { enumerable: true, get: function () { return error_1.toStackTraceString; } }); | ||
Object.defineProperty(exports, "getFileFromStackTraceString", { enumerable: true, get: function () { return error_1.getFileFromStackTraceString; } }); | ||
@@ -173,2 +171,3 @@ Object.defineProperty(exports, "NO_ERROR_STACK_PRESENT_MESSAGE", { enumerable: true, get: function () { return error_1.NO_ERROR_STACK_PRESENT_MESSAGE; } }); | ||
__exportStar(require("./domain/connectivity"), exports); | ||
__exportStar(require("./tools/stackTrace/handlingStack"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -12,3 +12,2 @@ /** | ||
PAGEHIDE = "pagehide", | ||
FEATURE_FLAGS = "feature_flags", | ||
RESOURCE_PAGE_STATES = "resource_page_states", | ||
@@ -15,0 +14,0 @@ COLLECT_FLUSH_REASON = "collect_flush_reason", |
@@ -19,3 +19,2 @@ "use strict"; | ||
ExperimentalFeature["PAGEHIDE"] = "pagehide"; | ||
ExperimentalFeature["FEATURE_FLAGS"] = "feature_flags"; | ||
ExperimentalFeature["RESOURCE_PAGE_STATES"] = "resource_page_states"; | ||
@@ -22,0 +21,0 @@ ExperimentalFeature["COLLECT_FLUSH_REASON"] = "collect_flush_reason"; |
@@ -6,3 +6,3 @@ import { catchUserErrors } from '../tools/catchUserErrors'; | ||
var publicApi = assign({ | ||
version: "5.16.0", | ||
version: "5.17.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 |
@@ -5,2 +5,3 @@ import type { Duration } from '../../tools/utils/timeUtils'; | ||
import type { TransportConfiguration } from './transportConfiguration'; | ||
export declare const DOC_LINK = "https://docs.datadoghq.com/getting_started/site/"; | ||
export declare const DefaultPrivacyLevel: { | ||
@@ -7,0 +8,0 @@ readonly ALLOW: "allow"; |
@@ -12,2 +12,3 @@ import { catchUserErrors } from '../../tools/catchUserErrors'; | ||
import { computeTransportConfiguration } from './transportConfiguration'; | ||
export var DOC_LINK = 'https://docs.datadoghq.com/getting_started/site/'; | ||
export var DefaultPrivacyLevel = { | ||
@@ -22,2 +23,5 @@ ALLOW: 'allow', | ||
}; | ||
function isDatadogSite(site) { | ||
return /(datadog|ddog|datad0g|dd0g)/.test(site); | ||
} | ||
export function validateAndBuildConfiguration(initConfiguration) { | ||
@@ -52,2 +56,6 @@ var _a, _b, _c, _d, _e; | ||
} | ||
if (initConfiguration.site && !isDatadogSite(initConfiguration.site)) { | ||
display.error("Site should be a valid Datadog site. Learn more here: ".concat(DOC_LINK, ".")); | ||
return; | ||
} | ||
// Set the experimental feature flags as early as possible, so we can use them in most places | ||
@@ -54,0 +62,0 @@ if (Array.isArray(initConfiguration.enableExperimentalFeatures)) { |
@@ -57,3 +57,3 @@ import { timeStampNow } from '../../tools/utils/timeUtils'; | ||
var retry = _b.retry, flushReason = _b.flushReason, encoding = _b.encoding; | ||
var tags = ["sdk_version:".concat("5.16.0"), "api:".concat(api)].concat(configurationTags); | ||
var tags = ["sdk_version:".concat("5.17.1"), "api:".concat(api)].concat(configurationTags); | ||
if (flushReason && isExperimentalFeatureEnabled(ExperimentalFeature.COLLECT_FLUSH_REASON)) { | ||
@@ -69,3 +69,3 @@ tags.push("flush_reason:".concat(flushReason)); | ||
"dd-api-key=".concat(clientToken), | ||
"dd-evp-origin-version=".concat(encodeURIComponent("5.16.0")), | ||
"dd-evp-origin-version=".concat(encodeURIComponent("5.17.1")), | ||
'dd-evp-origin=browser', | ||
@@ -72,0 +72,0 @@ "dd-request-id=".concat(generateUUID()), |
@@ -1,2 +0,2 @@ | ||
import { createHandlingStack, flattenErrorCauses, formatErrorMessage, toStackTraceString, tryToGetFingerprint, } from '../error/error'; | ||
import { flattenErrorCauses, tryToGetFingerprint } from '../error/error'; | ||
import { mergeObservables, Observable } from '../../tools/observable'; | ||
@@ -8,3 +8,4 @@ import { ConsoleApiName, globalConsole } from '../../tools/display'; | ||
import { jsonStringify } from '../../tools/serialisation/jsonStringify'; | ||
import { computeStackTrace } from '../error/computeStackTrace'; | ||
import { computeStackTrace } from '../../tools/stackTrace/computeStackTrace'; | ||
import { createHandlingStack, toStackTraceString, formatErrorMessage } from '../../tools/stackTrace/handlingStack'; | ||
var consoleObservablesByApi = {}; | ||
@@ -11,0 +12,0 @@ export function initConsoleObservable(apis) { |
import type { ClocksState } from '../../tools/utils/timeUtils'; | ||
import type { StackTrace } from '../../tools/stackTrace/computeStackTrace'; | ||
import type { ErrorSource, ErrorHandling, RawError, RawErrorCause, ErrorWithCause, NonErrorPrefix } from './error.types'; | ||
import type { StackTrace } from './computeStackTrace'; | ||
export declare const NO_ERROR_STACK_PRESENT_MESSAGE = "No stack, consider using an instance of Error"; | ||
@@ -16,14 +16,4 @@ type RawErrorParams = { | ||
export declare function tryToGetFingerprint(originalError: unknown): string | undefined; | ||
export declare function toStackTraceString(stack: StackTrace): string; | ||
export declare function getFileFromStackTraceString(stack: string): string | undefined; | ||
export declare function formatErrorMessage(stack: StackTrace): string; | ||
/** | ||
Creates a stacktrace without SDK internal frames. | ||
Constraints: | ||
- Has to be called at the utmost position of the call stack. | ||
- No monitored function should encapsulate it, that is why we need to use callMonitored inside it. | ||
*/ | ||
export declare function createHandlingStack(): string; | ||
export declare function flattenErrorCauses(error: ErrorWithCause, parentSource: ErrorSource): RawErrorCause[] | undefined; | ||
export {}; |
@@ -1,6 +0,5 @@ | ||
import { callMonitored } from '../../tools/monitor'; | ||
import { sanitize } from '../../tools/serialisation/sanitize'; | ||
import { noop } from '../../tools/utils/functionUtils'; | ||
import { jsonStringify } from '../../tools/serialisation/jsonStringify'; | ||
import { computeStackTrace } from './computeStackTrace'; | ||
import { computeStackTrace } from '../../tools/stackTrace/computeStackTrace'; | ||
import { toStackTraceString } from '../../tools/stackTrace/handlingStack'; | ||
export var NO_ERROR_STACK_PRESENT_MESSAGE = 'No stack, consider using an instance of Error'; | ||
@@ -55,13 +54,2 @@ export function computeRawError(_a) { | ||
} | ||
export function toStackTraceString(stack) { | ||
var result = formatErrorMessage(stack); | ||
stack.stack.forEach(function (frame) { | ||
var func = frame.func === '?' ? '<anonymous>' : frame.func; | ||
var args = frame.args && frame.args.length > 0 ? "(".concat(frame.args.join(', '), ")") : ''; | ||
var line = frame.line ? ":".concat(frame.line) : ''; | ||
var column = frame.line && frame.column ? ":".concat(frame.column) : ''; | ||
result += "\n at ".concat(func).concat(args, " @ ").concat(frame.url).concat(line).concat(column); | ||
}); | ||
return result; | ||
} | ||
export function getFileFromStackTraceString(stack) { | ||
@@ -71,38 +59,2 @@ var _a; | ||
} | ||
export function formatErrorMessage(stack) { | ||
return "".concat(stack.name || 'Error', ": ").concat(stack.message); | ||
} | ||
/** | ||
Creates a stacktrace without SDK internal frames. | ||
Constraints: | ||
- Has to be called at the utmost position of the call stack. | ||
- No monitored function should encapsulate it, that is why we need to use callMonitored inside it. | ||
*/ | ||
export function createHandlingStack() { | ||
/** | ||
* Skip the two internal frames: | ||
* - SDK API (console.error, ...) | ||
* - this function | ||
* in order to keep only the user calls | ||
*/ | ||
var internalFramesToSkip = 2; | ||
var error = new Error(); | ||
var formattedStack; | ||
// IE needs to throw the error to fill in the stack trace | ||
if (!error.stack) { | ||
try { | ||
throw error; | ||
} | ||
catch (e) { | ||
noop(); | ||
} | ||
} | ||
callMonitored(function () { | ||
var stackTrace = computeStackTrace(error); | ||
stackTrace.stack = stackTrace.stack.slice(internalFramesToSkip); | ||
formattedStack = toStackTraceString(stackTrace); | ||
}); | ||
return formattedStack; | ||
} | ||
export function flattenErrorCauses(error, parentSource) { | ||
@@ -109,0 +61,0 @@ var currentError = error; |
import type { Observable } from '../../tools/observable'; | ||
import type { StackTrace } from './computeStackTrace'; | ||
import type { StackTrace } from '../../tools/stackTrace/computeStackTrace'; | ||
import type { RawError } from './error.types'; | ||
@@ -4,0 +4,0 @@ export type UnhandledErrorCallback = (stackTrace: StackTrace, originalError?: any) => any; |
import { instrumentMethod } from '../../tools/instrumentMethod'; | ||
import { clocksNow } from '../../tools/utils/timeUtils'; | ||
import { computeStackTrace, computeStackTraceFromOnErrorMessage } from './computeStackTrace'; | ||
import { computeStackTrace, computeStackTraceFromOnErrorMessage } from '../../tools/stackTrace/computeStackTrace'; | ||
import { computeRawError } from './error'; | ||
@@ -5,0 +5,0 @@ import { ErrorSource } from './error.types'; |
@@ -1,2 +0,2 @@ | ||
import { toStackTraceString } from '../error/error'; | ||
import { toStackTraceString } from '../../tools/stackTrace/handlingStack'; | ||
import { monitor } from '../../tools/monitor'; | ||
@@ -3,0 +3,0 @@ import { mergeObservables, Observable } from '../../tools/observable'; |
import { getInitCookie } from '../../browser/cookie'; | ||
import { SESSION_STORE_KEY } from './storeStrategies/sessionStoreStrategy'; | ||
import { expandSessionState, isSessionInExpiredState } from './sessionState'; | ||
import { expandSessionState, isSessionStarted } from './sessionState'; | ||
export var OLD_SESSION_COOKIE_NAME = '_dd'; | ||
@@ -30,3 +30,3 @@ export var OLD_RUM_COOKIE_NAME = '_dd_r'; | ||
} | ||
if (!isSessionInExpiredState(session)) { | ||
if (isSessionStarted(session)) { | ||
expandSessionState(session); | ||
@@ -33,0 +33,0 @@ cookieStoreStrategy.persistSession(session); |
@@ -45,2 +45,3 @@ import { Observable } from '../../tools/observable'; | ||
trackVisibility(configuration, function () { return sessionStore.expandSession(); }); | ||
trackResume(configuration, function () { return sessionStore.restartSession(); }); | ||
function buildSessionContext() { | ||
@@ -80,2 +81,6 @@ return { | ||
} | ||
function trackResume(configuration, cb) { | ||
var stop = addEventListener(configuration, window, DOM_EVENT.RESUME, cb, { capture: true }).stop; | ||
stopCallbacks.push(stop); | ||
} | ||
//# sourceMappingURL=sessionManager.js.map |
@@ -0,1 +1,2 @@ | ||
export declare const EXPIRED = "1"; | ||
export interface SessionState { | ||
@@ -5,5 +6,8 @@ id?: string; | ||
expire?: string; | ||
lock?: string; | ||
isExpired?: typeof EXPIRED; | ||
[key: string]: string | undefined; | ||
} | ||
export declare function getExpiredSessionState(): SessionState; | ||
export declare function isSessionInNotStartedState(session: SessionState): boolean; | ||
export declare function isSessionStarted(session: SessionState): boolean; | ||
export declare function isSessionInExpiredState(session: SessionState): boolean; | ||
@@ -10,0 +14,0 @@ export declare function expandSessionState(session: SessionState): void; |
import { isEmptyObject } from '../../tools/utils/objectUtils'; | ||
import { objectEntries } from '../../tools/utils/polyfills'; | ||
import { dateNow } from '../../tools/utils/timeUtils'; | ||
import { SESSION_EXPIRATION_DELAY } from './sessionConstants'; | ||
var SESSION_ENTRY_REGEXP = /^([a-z]+)=([a-z0-9-]+)$/; | ||
import { SESSION_EXPIRATION_DELAY, SESSION_TIME_OUT_DELAY } from './sessionConstants'; | ||
var SESSION_ENTRY_REGEXP = /^([a-zA-Z]+)=([a-z0-9-]+)$/; | ||
var SESSION_ENTRY_SEPARATOR = '&'; | ||
export function isSessionInExpiredState(session) { | ||
export var EXPIRED = '1'; | ||
export function getExpiredSessionState() { | ||
return { | ||
isExpired: EXPIRED, | ||
}; | ||
} | ||
export function isSessionInNotStartedState(session) { | ||
return isEmptyObject(session); | ||
} | ||
export function isSessionStarted(session) { | ||
return !isSessionInNotStartedState(session); | ||
} | ||
export function isSessionInExpiredState(session) { | ||
return session.isExpired !== undefined || !isActiveSession(session); | ||
} | ||
// An active session is a session in either `Tracked` or `NotTracked` state | ||
function isActiveSession(sessionState) { | ||
// created and expire can be undefined for versions which was not storing them | ||
// these checks could be removed when older versions will not be available/live anymore | ||
return ((sessionState.created === undefined || dateNow() - Number(sessionState.created) < SESSION_TIME_OUT_DELAY) && | ||
(sessionState.expire === undefined || dateNow() < Number(sessionState.expire))); | ||
} | ||
export function expandSessionState(session) { | ||
@@ -11,0 +30,0 @@ session.expire = String(dateNow() + SESSION_EXPIRATION_DELAY); |
@@ -9,2 +9,3 @@ import { Observable } from '../../tools/observable'; | ||
getSession: () => SessionState; | ||
restartSession: () => void; | ||
renewObservable: Observable<void>; | ||
@@ -11,0 +12,0 @@ expireObservable: Observable<void>; |
@@ -6,4 +6,4 @@ import { clearInterval, setInterval } from '../../tools/timer'; | ||
import { generateUUID } from '../../tools/utils/stringUtils'; | ||
import { SESSION_TIME_OUT_DELAY } from './sessionConstants'; | ||
import { selectCookieStrategy, initCookieStrategy } from './storeStrategies/sessionInCookie'; | ||
import { getExpiredSessionState, isSessionInExpiredState, isSessionInNotStartedState } from './sessionState'; | ||
import { initLocalStorageStrategy, selectLocalStorageStrategy } from './storeStrategies/sessionInLocalStorage'; | ||
@@ -40,5 +40,6 @@ import { processSessionStoreOperations } from './sessionStoreOperations'; | ||
: initLocalStorageStrategy(); | ||
var clearSession = sessionStoreStrategy.clearSession, retrieveSession = sessionStoreStrategy.retrieveSession; | ||
var expireSession = sessionStoreStrategy.expireSession; | ||
var watchSessionTimeoutId = setInterval(watchSession, STORAGE_POLL_DELAY); | ||
var sessionCache = retrieveActiveSession(); | ||
var sessionCache; | ||
startSession(); | ||
var _a = throttle(function () { | ||
@@ -48,2 +49,5 @@ var isTracked; | ||
process: function (sessionState) { | ||
if (isSessionInNotStartedState(sessionState)) { | ||
return; | ||
} | ||
var synchronizedSession = synchronizeSession(sessionState); | ||
@@ -73,3 +77,3 @@ isTracked = expandOrRenewSessionState(synchronizedSession); | ||
processSessionStoreOperations({ | ||
process: function (sessionState) { return (!isActiveSession(sessionState) ? {} : undefined); }, | ||
process: function (sessionState) { return (isSessionInExpiredState(sessionState) ? getExpiredSessionState() : undefined); }, | ||
after: synchronizeSession, | ||
@@ -79,4 +83,4 @@ }, sessionStoreStrategy); | ||
function synchronizeSession(sessionState) { | ||
if (!isActiveSession(sessionState)) { | ||
sessionState = {}; | ||
if (isSessionInExpiredState(sessionState)) { | ||
sessionState = getExpiredSessionState(); | ||
} | ||
@@ -93,5 +97,21 @@ if (hasSessionInCache()) { | ||
} | ||
function startSession() { | ||
processSessionStoreOperations({ | ||
process: function (sessionState) { | ||
if (isSessionInNotStartedState(sessionState)) { | ||
return getExpiredSessionState(); | ||
} | ||
}, | ||
after: function (sessionState) { | ||
sessionCache = sessionState; | ||
}, | ||
}, sessionStoreStrategy); | ||
} | ||
function expandOrRenewSessionState(sessionState) { | ||
if (isSessionInNotStartedState(sessionState)) { | ||
return false; | ||
} | ||
var _a = computeSessionState(sessionState[productKey]), trackingType = _a.trackingType, isTracked = _a.isTracked; | ||
sessionState[productKey] = trackingType; | ||
delete sessionState.isExpired; | ||
if (isTracked && !sessionState.id) { | ||
@@ -110,3 +130,3 @@ sessionState.id = generateUUID(); | ||
function expireSessionInCache() { | ||
sessionCache = {}; | ||
sessionCache = getExpiredSessionState(); | ||
expireObservable.notify(); | ||
@@ -118,15 +138,2 @@ } | ||
} | ||
function retrieveActiveSession() { | ||
var session = retrieveSession(); | ||
if (isActiveSession(session)) { | ||
return session; | ||
} | ||
return {}; | ||
} | ||
function isActiveSession(sessionState) { | ||
// created and expire can be undefined for versions which was not storing them | ||
// these checks could be removed when older versions will not be available/live anymore | ||
return ((sessionState.created === undefined || dateNow() - Number(sessionState.created) < SESSION_TIME_OUT_DELAY) && | ||
(sessionState.expire === undefined || dateNow() < Number(sessionState.expire))); | ||
} | ||
return { | ||
@@ -138,6 +145,7 @@ expandOrRenewSession: throttledExpandOrRenewSession, | ||
expireObservable: expireObservable, | ||
restartSession: startSession, | ||
expire: function () { | ||
cancelExpandOrRenewSession(); | ||
clearSession(); | ||
synchronizeSession({}); | ||
expireSession(); | ||
synchronizeSession(getExpiredSessionState()); | ||
}, | ||
@@ -144,0 +152,0 @@ stop: function () { |
import { setTimeout } from '../../tools/timer'; | ||
import { generateUUID } from '../../tools/utils/stringUtils'; | ||
import { assign } from '../../tools/utils/polyfills'; | ||
import { expandSessionState, isSessionInExpiredState } from './sessionState'; | ||
@@ -11,3 +12,15 @@ export var LOCK_RETRY_DELAY = 10; | ||
if (numberOfRetries === void 0) { numberOfRetries = 0; } | ||
var isLockEnabled = sessionStoreStrategy.isLockEnabled, retrieveSession = sessionStoreStrategy.retrieveSession, persistSession = sessionStoreStrategy.persistSession, clearSession = sessionStoreStrategy.clearSession; | ||
var isLockEnabled = sessionStoreStrategy.isLockEnabled, persistSession = sessionStoreStrategy.persistSession, expireSession = sessionStoreStrategy.expireSession; | ||
var persistWithLock = function (session) { return persistSession(assign({}, session, { lock: currentLock })); }; | ||
var retrieveStore = function () { | ||
var session = sessionStoreStrategy.retrieveSession(); | ||
var lock = session.lock; | ||
if (session.lock) { | ||
delete session.lock; | ||
} | ||
return { | ||
session: session, | ||
lock: lock, | ||
}; | ||
}; | ||
if (!ongoingOperations) { | ||
@@ -25,6 +38,6 @@ ongoingOperations = operations; | ||
var currentLock; | ||
var currentSession = retrieveSession(); | ||
var currentStore = retrieveStore(); | ||
if (isLockEnabled) { | ||
// if someone has lock, retry later | ||
if (currentSession.lock) { | ||
if (currentStore.lock) { | ||
retryLater(operations, sessionStoreStrategy, numberOfRetries); | ||
@@ -35,7 +48,6 @@ return; | ||
currentLock = generateUUID(); | ||
currentSession.lock = currentLock; | ||
persistSession(currentSession); | ||
persistWithLock(currentStore.session); | ||
// if lock is not acquired, retry later | ||
currentSession = retrieveSession(); | ||
if (currentSession.lock !== currentLock) { | ||
currentStore = retrieveStore(); | ||
if (currentStore.lock !== currentLock) { | ||
retryLater(operations, sessionStoreStrategy, numberOfRetries); | ||
@@ -45,7 +57,7 @@ return; | ||
} | ||
var processedSession = operations.process(currentSession); | ||
var processedSession = operations.process(currentStore.session); | ||
if (isLockEnabled) { | ||
// if lock corrupted after process, retry later | ||
currentSession = retrieveSession(); | ||
if (currentSession.lock !== currentLock) { | ||
currentStore = retrieveStore(); | ||
if (currentStore.lock !== currentLock) { | ||
retryLater(operations, sessionStoreStrategy, numberOfRetries); | ||
@@ -57,7 +69,7 @@ return; | ||
if (isSessionInExpiredState(processedSession)) { | ||
clearSession(); | ||
expireSession(); | ||
} | ||
else { | ||
expandSessionState(processedSession); | ||
persistSession(processedSession); | ||
isLockEnabled ? persistWithLock(processedSession) : persistSession(processedSession); | ||
} | ||
@@ -70,10 +82,9 @@ } | ||
// if lock corrupted after persist, retry later | ||
currentSession = retrieveSession(); | ||
if (currentSession.lock !== currentLock) { | ||
currentStore = retrieveStore(); | ||
if (currentStore.lock !== currentLock) { | ||
retryLater(operations, sessionStoreStrategy, numberOfRetries); | ||
return; | ||
} | ||
delete currentSession.lock; | ||
persistSession(currentSession); | ||
processedSession = currentSession; | ||
persistSession(currentStore.session); | ||
processedSession = currentStore.session; | ||
} | ||
@@ -83,3 +94,3 @@ } | ||
// up-to-date session state value => the value could have been modified by another tab | ||
(_a = operations.after) === null || _a === void 0 ? void 0 : _a.call(operations, processedSession || currentSession); | ||
(_a = operations.after) === null || _a === void 0 ? void 0 : _a.call(operations, processedSession || currentStore.session); | ||
next(sessionStoreStrategy); | ||
@@ -86,0 +97,0 @@ } |
import { isChromium } from '../../../tools/utils/browserDetection'; | ||
import { getCurrentSite, areCookiesAuthorized, deleteCookie, getCookie, setCookie } from '../../../browser/cookie'; | ||
import { getCurrentSite, areCookiesAuthorized, getCookie, setCookie } from '../../../browser/cookie'; | ||
import { tryOldCookiesMigration } from '../oldCookiesMigration'; | ||
import { SESSION_EXPIRATION_DELAY } from '../sessionConstants'; | ||
import { toSessionString, toSessionState } from '../sessionState'; | ||
import { SESSION_EXPIRATION_DELAY, SESSION_TIME_OUT_DELAY } from '../sessionConstants'; | ||
import { toSessionString, toSessionState, getExpiredSessionState } from '../sessionState'; | ||
import { SESSION_STORE_KEY } from './sessionStoreStrategy'; | ||
@@ -20,3 +20,3 @@ export function selectCookieStrategy(initConfiguration) { | ||
retrieveSession: retrieveSessionCookie, | ||
clearSession: deleteSessionCookie(cookieOptions), | ||
expireSession: function () { return expireSessionCookie(cookieOptions); }, | ||
}; | ||
@@ -31,2 +31,5 @@ tryOldCookiesMigration(cookieStore); | ||
} | ||
function expireSessionCookie(options) { | ||
setCookie(SESSION_STORE_KEY, toSessionString(getExpiredSessionState()), SESSION_TIME_OUT_DELAY, options); | ||
} | ||
function retrieveSessionCookie() { | ||
@@ -36,7 +39,2 @@ var sessionString = getCookie(SESSION_STORE_KEY); | ||
} | ||
function deleteSessionCookie(options) { | ||
return function () { | ||
deleteCookie(SESSION_STORE_KEY, options); | ||
}; | ||
} | ||
export function buildCookieOptions(initConfiguration) { | ||
@@ -43,0 +41,0 @@ var cookieOptions = {}; |
import { generateUUID } from '../../../tools/utils/stringUtils'; | ||
import { toSessionString, toSessionState } from '../sessionState'; | ||
import { toSessionString, toSessionState, getExpiredSessionState } from '../sessionState'; | ||
import { SESSION_STORE_KEY } from './sessionStoreStrategy'; | ||
@@ -23,3 +23,3 @@ var LOCAL_STORAGE_TEST_KEY = '_dd_test_'; | ||
retrieveSession: retrieveSessionFromLocalStorage, | ||
clearSession: clearSessionFromLocalStorage, | ||
expireSession: expireSessionFromLocalStorage, | ||
}; | ||
@@ -34,5 +34,5 @@ } | ||
} | ||
function clearSessionFromLocalStorage() { | ||
localStorage.removeItem(SESSION_STORE_KEY); | ||
function expireSessionFromLocalStorage() { | ||
persistInLocalStorage(getExpiredSessionState()); | ||
} | ||
//# sourceMappingURL=sessionInLocalStorage.js.map |
@@ -14,3 +14,3 @@ import type { CookieOptions } from '../../../browser/cookie'; | ||
retrieveSession: () => SessionState; | ||
clearSession: () => void; | ||
expireSession: () => void; | ||
} |
import type { Context } from '../../tools/serialisation/context'; | ||
import type { Configuration } from '../configuration'; | ||
import { Observable } from '../../tools/observable'; | ||
import type { StackTrace } from '../error/computeStackTrace'; | ||
import type { StackTrace } from '../../tools/stackTrace/computeStackTrace'; | ||
import type { TelemetryEvent } from './telemetryEvent.types'; | ||
@@ -65,2 +65,3 @@ import type { RawTelemetryConfiguration, RawTelemetryUsage } from './rawTelemetryEvent.types'; | ||
default_privacy_level?: string | undefined; | ||
enable_privacy_for_action_name?: boolean | undefined; | ||
use_excluded_activity_urls?: boolean | undefined; | ||
@@ -67,0 +68,0 @@ use_worker_url?: boolean | undefined; |
import { ConsoleApiName } from '../../tools/display'; | ||
import { toStackTraceString, NO_ERROR_STACK_PRESENT_MESSAGE } from '../error/error'; | ||
import { NO_ERROR_STACK_PRESENT_MESSAGE } from '../error/error'; | ||
import { toStackTraceString } from '../../tools/stackTrace/handlingStack'; | ||
import { getExperimentalFeatures } from '../../tools/experimentalFeatures'; | ||
@@ -13,3 +14,3 @@ import { INTAKE_SITE_STAGING, INTAKE_SITE_US1_FED } from '../configuration'; | ||
import { combine } from '../../tools/mergeInto'; | ||
import { computeStackTrace } from '../error/computeStackTrace'; | ||
import { computeStackTrace } from '../../tools/stackTrace/computeStackTrace'; | ||
import { getConnectivity } from '../connectivity'; | ||
@@ -59,3 +60,3 @@ import { TelemetryType } from './rawTelemetryEvent.types'; | ||
service: telemetryService, | ||
version: "5.16.0", | ||
version: "5.17.1", | ||
source: 'browser', | ||
@@ -62,0 +63,0 @@ _dd: { |
@@ -199,2 +199,6 @@ /** | ||
/** | ||
* Privacy control for action name | ||
*/ | ||
enable_privacy_for_action_name?: boolean; | ||
/** | ||
* Whether the request origins list to ignore when computing the page activity is used | ||
@@ -201,0 +205,0 @@ */ |
@@ -5,3 +5,3 @@ export { Configuration, InitConfiguration, validateAndBuildConfiguration, DefaultPrivacyLevel, TraceContextInjection, EndpointBuilder, serializeConfiguration, INTAKE_SITE_STAGING, INTAKE_SITE_US1, INTAKE_SITE_US1_FED, INTAKE_SITE_EU1, } from './domain/configuration'; | ||
export { trackRuntimeError } from './domain/error/trackRuntimeError'; | ||
export { computeStackTrace, StackTrace } from './domain/error/computeStackTrace'; | ||
export { computeStackTrace, StackTrace } from './tools/stackTrace/computeStackTrace'; | ||
export { defineGlobal, makePublicApi } from './boot/init'; | ||
@@ -30,3 +30,3 @@ export { displayAlreadyInitializedError } from './boot/displayAlreadyInitializedError'; | ||
export { instrumentMethod, instrumentSetter, InstrumentedMethodCall } from './tools/instrumentMethod'; | ||
export { computeRawError, createHandlingStack, toStackTraceString, getFileFromStackTraceString, NO_ERROR_STACK_PRESENT_MESSAGE, } from './domain/error/error'; | ||
export { computeRawError, getFileFromStackTraceString, NO_ERROR_STACK_PRESENT_MESSAGE } from './domain/error/error'; | ||
export { NonErrorPrefix } from './domain/error/error.types'; | ||
@@ -69,1 +69,2 @@ export { Context, ContextArray, ContextValue } from './tools/serialisation/context'; | ||
export * from './domain/connectivity'; | ||
export * from './tools/stackTrace/handlingStack'; |
@@ -5,3 +5,3 @@ export { validateAndBuildConfiguration, DefaultPrivacyLevel, TraceContextInjection, serializeConfiguration, INTAKE_SITE_STAGING, INTAKE_SITE_US1, INTAKE_SITE_US1_FED, INTAKE_SITE_EU1, } from './domain/configuration'; | ||
export { trackRuntimeError } from './domain/error/trackRuntimeError'; | ||
export { computeStackTrace } from './domain/error/computeStackTrace'; | ||
export { computeStackTrace } from './tools/stackTrace/computeStackTrace'; | ||
export { defineGlobal, makePublicApi } from './boot/init'; | ||
@@ -33,3 +33,3 @@ export { displayAlreadyInitializedError } from './boot/displayAlreadyInitializedError'; | ||
export { instrumentMethod, instrumentSetter } from './tools/instrumentMethod'; | ||
export { computeRawError, createHandlingStack, toStackTraceString, getFileFromStackTraceString, NO_ERROR_STACK_PRESENT_MESSAGE, } from './domain/error/error'; | ||
export { computeRawError, getFileFromStackTraceString, NO_ERROR_STACK_PRESENT_MESSAGE } from './domain/error/error'; | ||
export { areCookiesAuthorized, getCookie, getInitCookie, setCookie, deleteCookie, resetInitCookies, } from './browser/cookie'; | ||
@@ -68,2 +68,3 @@ export { initXhrObservable } from './browser/xhrObservable'; | ||
export * from './domain/connectivity'; | ||
export * from './tools/stackTrace/handlingStack'; | ||
//# sourceMappingURL=index.js.map |
@@ -12,3 +12,2 @@ /** | ||
PAGEHIDE = "pagehide", | ||
FEATURE_FLAGS = "feature_flags", | ||
RESOURCE_PAGE_STATES = "resource_page_states", | ||
@@ -15,0 +14,0 @@ COLLECT_FLUSH_REASON = "collect_flush_reason", |
@@ -16,3 +16,2 @@ /** | ||
ExperimentalFeature["PAGEHIDE"] = "pagehide"; | ||
ExperimentalFeature["FEATURE_FLAGS"] = "feature_flags"; | ||
ExperimentalFeature["RESOURCE_PAGE_STATES"] = "resource_page_states"; | ||
@@ -19,0 +18,0 @@ ExperimentalFeature["COLLECT_FLUSH_REASON"] = "collect_flush_reason"; |
{ | ||
"name": "@datadog/browser-core", | ||
"version": "5.16.0", | ||
"version": "5.17.1", | ||
"license": "Apache-2.0", | ||
@@ -26,3 +26,3 @@ "main": "cjs/index.js", | ||
}, | ||
"gitHead": "7fd800d615f6e6a689597d064e709ac7fc0914ec" | ||
"gitHead": "78b120d4775a8601f021adbba6df66ccfb07d8d2" | ||
} |
@@ -17,2 +17,3 @@ import { catchUserErrors } from '../../tools/catchUserErrors' | ||
export const DOC_LINK = 'https://docs.datadoghq.com/getting_started/site/' | ||
export const DefaultPrivacyLevel = { | ||
@@ -111,2 +112,5 @@ ALLOW: 'allow', | ||
} | ||
function isDatadogSite(site: string) { | ||
return /(datadog|ddog|datad0g|dd0g)/.test(site) | ||
} | ||
@@ -153,2 +157,7 @@ export function validateAndBuildConfiguration(initConfiguration: InitConfiguration): Configuration | undefined { | ||
if (initConfiguration.site && !isDatadogSite(initConfiguration.site)) { | ||
display.error(`Site should be a valid Datadog site. Learn more here: ${DOC_LINK}.`) | ||
return | ||
} | ||
// Set the experimental feature flags as early as possible, so we can use them in most places | ||
@@ -155,0 +164,0 @@ if (Array.isArray(initConfiguration.enableExperimentalFeatures)) { |
@@ -1,8 +0,2 @@ | ||
import { | ||
createHandlingStack, | ||
flattenErrorCauses, | ||
formatErrorMessage, | ||
toStackTraceString, | ||
tryToGetFingerprint, | ||
} from '../error/error' | ||
import { flattenErrorCauses, tryToGetFingerprint } from '../error/error' | ||
import { mergeObservables, Observable } from '../../tools/observable' | ||
@@ -14,4 +8,5 @@ import { ConsoleApiName, globalConsole } from '../../tools/display' | ||
import { jsonStringify } from '../../tools/serialisation/jsonStringify' | ||
import { computeStackTrace } from '../error/computeStackTrace' | ||
import type { RawErrorCause } from '../error/error.types' | ||
import { computeStackTrace } from '../../tools/stackTrace/computeStackTrace' | ||
import { createHandlingStack, toStackTraceString, formatErrorMessage } from '../../tools/stackTrace/handlingStack' | ||
@@ -18,0 +13,0 @@ export interface ConsoleLog { |
@@ -1,9 +0,8 @@ | ||
import { callMonitored } from '../../tools/monitor' | ||
import { sanitize } from '../../tools/serialisation/sanitize' | ||
import type { ClocksState } from '../../tools/utils/timeUtils' | ||
import { noop } from '../../tools/utils/functionUtils' | ||
import { jsonStringify } from '../../tools/serialisation/jsonStringify' | ||
import type { StackTrace } from '../../tools/stackTrace/computeStackTrace' | ||
import { computeStackTrace } from '../../tools/stackTrace/computeStackTrace' | ||
import { toStackTraceString } from '../../tools/stackTrace/handlingStack' | ||
import type { ErrorSource, ErrorHandling, RawError, RawErrorCause, ErrorWithCause, NonErrorPrefix } from './error.types' | ||
import type { StackTrace } from './computeStackTrace' | ||
import { computeStackTrace } from './computeStackTrace' | ||
@@ -89,14 +88,2 @@ export const NO_ERROR_STACK_PRESENT_MESSAGE = 'No stack, consider using an instance of Error' | ||
export function toStackTraceString(stack: StackTrace) { | ||
let result = formatErrorMessage(stack) | ||
stack.stack.forEach((frame) => { | ||
const func = frame.func === '?' ? '<anonymous>' : frame.func | ||
const args = frame.args && frame.args.length > 0 ? `(${frame.args.join(', ')})` : '' | ||
const line = frame.line ? `:${frame.line}` : '' | ||
const column = frame.line && frame.column ? `:${frame.column}` : '' | ||
result += `\n at ${func!}${args} @ ${frame.url!}${line}${column}` | ||
}) | ||
return result | ||
} | ||
export function getFileFromStackTraceString(stack: string) { | ||
@@ -106,42 +93,2 @@ return /@ (.+)/.exec(stack)?.[1] | ||
export function formatErrorMessage(stack: StackTrace) { | ||
return `${stack.name || 'Error'}: ${stack.message!}` | ||
} | ||
/** | ||
Creates a stacktrace without SDK internal frames. | ||
Constraints: | ||
- Has to be called at the utmost position of the call stack. | ||
- No monitored function should encapsulate it, that is why we need to use callMonitored inside it. | ||
*/ | ||
export function createHandlingStack(): string { | ||
/** | ||
* Skip the two internal frames: | ||
* - SDK API (console.error, ...) | ||
* - this function | ||
* in order to keep only the user calls | ||
*/ | ||
const internalFramesToSkip = 2 | ||
const error = new Error() | ||
let formattedStack: string | ||
// IE needs to throw the error to fill in the stack trace | ||
if (!error.stack) { | ||
try { | ||
throw error | ||
} catch (e) { | ||
noop() | ||
} | ||
} | ||
callMonitored(() => { | ||
const stackTrace = computeStackTrace(error) | ||
stackTrace.stack = stackTrace.stack.slice(internalFramesToSkip) | ||
formattedStack = toStackTraceString(stackTrace) | ||
}) | ||
return formattedStack! | ||
} | ||
export function flattenErrorCauses(error: ErrorWithCause, parentSource: ErrorSource): RawErrorCause[] | undefined { | ||
@@ -148,0 +95,0 @@ let currentError = error |
import { instrumentMethod } from '../../tools/instrumentMethod' | ||
import type { Observable } from '../../tools/observable' | ||
import { clocksNow } from '../../tools/utils/timeUtils' | ||
import type { StackTrace } from './computeStackTrace' | ||
import { computeStackTrace, computeStackTraceFromOnErrorMessage } from './computeStackTrace' | ||
import type { StackTrace } from '../../tools/stackTrace/computeStackTrace' | ||
import { computeStackTrace, computeStackTraceFromOnErrorMessage } from '../../tools/stackTrace/computeStackTrace' | ||
import { computeRawError } from './error' | ||
@@ -7,0 +7,0 @@ import type { RawError } from './error.types' |
@@ -1,2 +0,2 @@ | ||
import { toStackTraceString } from '../error/error' | ||
import { toStackTraceString } from '../../tools/stackTrace/handlingStack' | ||
import { monitor } from '../../tools/monitor' | ||
@@ -3,0 +3,0 @@ import { mergeObservables, Observable } from '../../tools/observable' |
@@ -5,3 +5,3 @@ import { getInitCookie } from '../../browser/cookie' | ||
import type { SessionState } from './sessionState' | ||
import { expandSessionState, isSessionInExpiredState } from './sessionState' | ||
import { expandSessionState, isSessionStarted } from './sessionState' | ||
@@ -38,3 +38,3 @@ export const OLD_SESSION_COOKIE_NAME = '_dd' | ||
if (!isSessionInExpiredState(session)) { | ||
if (isSessionStarted(session)) { | ||
expandSessionState(session) | ||
@@ -41,0 +41,0 @@ cookieStoreStrategy.persistSession(session) |
@@ -73,2 +73,3 @@ import { Observable } from '../../tools/observable' | ||
trackVisibility(configuration, () => sessionStore.expandSession()) | ||
trackResume(configuration, () => sessionStore.restartSession()) | ||
@@ -121,1 +122,6 @@ function buildSessionContext() { | ||
} | ||
function trackResume(configuration: Configuration, cb: () => void) { | ||
const { stop } = addEventListener(configuration, window, DOM_EVENT.RESUME, cb, { capture: true }) | ||
stopCallbacks.push(stop) | ||
} |
import { isEmptyObject } from '../../tools/utils/objectUtils' | ||
import { objectEntries } from '../../tools/utils/polyfills' | ||
import { dateNow } from '../../tools/utils/timeUtils' | ||
import { SESSION_EXPIRATION_DELAY } from './sessionConstants' | ||
import { SESSION_EXPIRATION_DELAY, SESSION_TIME_OUT_DELAY } from './sessionConstants' | ||
const SESSION_ENTRY_REGEXP = /^([a-z]+)=([a-z0-9-]+)$/ | ||
const SESSION_ENTRY_REGEXP = /^([a-zA-Z]+)=([a-z0-9-]+)$/ | ||
const SESSION_ENTRY_SEPARATOR = '&' | ||
export const EXPIRED = '1' | ||
export interface SessionState { | ||
@@ -13,3 +15,3 @@ id?: string | ||
expire?: string | ||
lock?: string | ||
isExpired?: typeof EXPIRED | ||
@@ -19,6 +21,30 @@ [key: string]: string | undefined | ||
export function isSessionInExpiredState(session: SessionState) { | ||
export function getExpiredSessionState(): SessionState { | ||
return { | ||
isExpired: EXPIRED, | ||
} | ||
} | ||
export function isSessionInNotStartedState(session: SessionState) { | ||
return isEmptyObject(session) | ||
} | ||
export function isSessionStarted(session: SessionState) { | ||
return !isSessionInNotStartedState(session) | ||
} | ||
export function isSessionInExpiredState(session: SessionState) { | ||
return session.isExpired !== undefined || !isActiveSession(session) | ||
} | ||
// An active session is a session in either `Tracked` or `NotTracked` state | ||
function isActiveSession(sessionState: SessionState) { | ||
// created and expire can be undefined for versions which was not storing them | ||
// these checks could be removed when older versions will not be available/live anymore | ||
return ( | ||
(sessionState.created === undefined || dateNow() - Number(sessionState.created) < SESSION_TIME_OUT_DELAY) && | ||
(sessionState.expire === undefined || dateNow() < Number(sessionState.expire)) | ||
) | ||
} | ||
export function expandSessionState(session: SessionState) { | ||
@@ -30,3 +56,3 @@ session.expire = String(dateNow() + SESSION_EXPIRATION_DELAY) | ||
return objectEntries(session) | ||
.map(([key, value]) => `${key}=${value as string}`) | ||
.map(([key, value]) => `${key}=${value}`) | ||
.join(SESSION_ENTRY_SEPARATOR) | ||
@@ -33,0 +59,0 @@ } |
@@ -7,5 +7,5 @@ import { clearInterval, setInterval } from '../../tools/timer' | ||
import type { InitConfiguration } from '../configuration' | ||
import { SESSION_TIME_OUT_DELAY } from './sessionConstants' | ||
import { selectCookieStrategy, initCookieStrategy } from './storeStrategies/sessionInCookie' | ||
import type { SessionStoreStrategyType } from './storeStrategies/sessionStoreStrategy' | ||
import { getExpiredSessionState, isSessionInExpiredState, isSessionInNotStartedState } from './sessionState' | ||
import type { SessionState } from './sessionState' | ||
@@ -19,2 +19,3 @@ import { initLocalStorageStrategy, selectLocalStorageStrategy } from './storeStrategies/sessionInLocalStorage' | ||
getSession: () => SessionState | ||
restartSession: () => void | ||
renewObservable: Observable<void> | ||
@@ -65,7 +66,9 @@ expireObservable: Observable<void> | ||
: initLocalStorageStrategy() | ||
const { clearSession, retrieveSession } = sessionStoreStrategy | ||
const { expireSession } = sessionStoreStrategy | ||
const watchSessionTimeoutId = setInterval(watchSession, STORAGE_POLL_DELAY) | ||
let sessionCache: SessionState = retrieveActiveSession() | ||
let sessionCache: SessionState | ||
startSession() | ||
const { throttled: throttledExpandOrRenewSession, cancel: cancelExpandOrRenewSession } = throttle(() => { | ||
@@ -76,2 +79,6 @@ let isTracked: boolean | ||
process: (sessionState) => { | ||
if (isSessionInNotStartedState(sessionState)) { | ||
return | ||
} | ||
const synchronizedSession = synchronizeSession(sessionState) | ||
@@ -109,3 +116,3 @@ isTracked = expandOrRenewSessionState(synchronizedSession) | ||
{ | ||
process: (sessionState) => (!isActiveSession(sessionState) ? {} : undefined), | ||
process: (sessionState) => (isSessionInExpiredState(sessionState) ? getExpiredSessionState() : undefined), | ||
after: synchronizeSession, | ||
@@ -118,4 +125,4 @@ }, | ||
function synchronizeSession(sessionState: SessionState) { | ||
if (!isActiveSession(sessionState)) { | ||
sessionState = {} | ||
if (isSessionInExpiredState(sessionState)) { | ||
sessionState = getExpiredSessionState() | ||
} | ||
@@ -132,5 +139,26 @@ if (hasSessionInCache()) { | ||
function startSession() { | ||
processSessionStoreOperations( | ||
{ | ||
process: (sessionState) => { | ||
if (isSessionInNotStartedState(sessionState)) { | ||
return getExpiredSessionState() | ||
} | ||
}, | ||
after: (sessionState) => { | ||
sessionCache = sessionState | ||
}, | ||
}, | ||
sessionStoreStrategy | ||
) | ||
} | ||
function expandOrRenewSessionState(sessionState: SessionState) { | ||
if (isSessionInNotStartedState(sessionState)) { | ||
return false | ||
} | ||
const { trackingType, isTracked } = computeSessionState(sessionState[productKey]) | ||
sessionState[productKey] = trackingType | ||
delete sessionState.isExpired | ||
if (isTracked && !sessionState.id) { | ||
@@ -152,3 +180,3 @@ sessionState.id = generateUUID() | ||
function expireSessionInCache() { | ||
sessionCache = {} | ||
sessionCache = getExpiredSessionState() | ||
expireObservable.notify() | ||
@@ -162,19 +190,2 @@ } | ||
function retrieveActiveSession(): SessionState { | ||
const session = retrieveSession() | ||
if (isActiveSession(session)) { | ||
return session | ||
} | ||
return {} | ||
} | ||
function isActiveSession(sessionState: SessionState) { | ||
// created and expire can be undefined for versions which was not storing them | ||
// these checks could be removed when older versions will not be available/live anymore | ||
return ( | ||
(sessionState.created === undefined || dateNow() - Number(sessionState.created) < SESSION_TIME_OUT_DELAY) && | ||
(sessionState.expire === undefined || dateNow() < Number(sessionState.expire)) | ||
) | ||
} | ||
return { | ||
@@ -186,6 +197,7 @@ expandOrRenewSession: throttledExpandOrRenewSession, | ||
expireObservable, | ||
restartSession: startSession, | ||
expire: () => { | ||
cancelExpandOrRenewSession() | ||
clearSession() | ||
synchronizeSession({}) | ||
expireSession() | ||
synchronizeSession(getExpiredSessionState()) | ||
}, | ||
@@ -192,0 +204,0 @@ stop: () => { |
import { setTimeout } from '../../tools/timer' | ||
import { generateUUID } from '../../tools/utils/stringUtils' | ||
import { assign } from '../../tools/utils/polyfills' | ||
import type { SessionStoreStrategy } from './storeStrategies/sessionStoreStrategy' | ||
@@ -22,4 +23,18 @@ import type { SessionState } from './sessionState' | ||
) { | ||
const { isLockEnabled, retrieveSession, persistSession, clearSession } = sessionStoreStrategy | ||
const { isLockEnabled, persistSession, expireSession } = sessionStoreStrategy | ||
const persistWithLock = (session: SessionState) => persistSession(assign({}, session, { lock: currentLock })) | ||
const retrieveStore = () => { | ||
const session = sessionStoreStrategy.retrieveSession() | ||
const lock = session.lock | ||
if (session.lock) { | ||
delete session.lock | ||
} | ||
return { | ||
session, | ||
lock, | ||
} | ||
} | ||
if (!ongoingOperations) { | ||
@@ -37,6 +52,6 @@ ongoingOperations = operations | ||
let currentLock: string | ||
let currentSession = retrieveSession() | ||
let currentStore = retrieveStore() | ||
if (isLockEnabled) { | ||
// if someone has lock, retry later | ||
if (currentSession.lock) { | ||
if (currentStore.lock) { | ||
retryLater(operations, sessionStoreStrategy, numberOfRetries) | ||
@@ -47,7 +62,6 @@ return | ||
currentLock = generateUUID() | ||
currentSession.lock = currentLock | ||
persistSession(currentSession) | ||
persistWithLock(currentStore.session) | ||
// if lock is not acquired, retry later | ||
currentSession = retrieveSession() | ||
if (currentSession.lock !== currentLock) { | ||
currentStore = retrieveStore() | ||
if (currentStore.lock !== currentLock) { | ||
retryLater(operations, sessionStoreStrategy, numberOfRetries) | ||
@@ -57,7 +71,7 @@ return | ||
} | ||
let processedSession = operations.process(currentSession) | ||
let processedSession = operations.process(currentStore.session) | ||
if (isLockEnabled) { | ||
// if lock corrupted after process, retry later | ||
currentSession = retrieveSession() | ||
if (currentSession.lock !== currentLock!) { | ||
currentStore = retrieveStore() | ||
if (currentStore.lock !== currentLock!) { | ||
retryLater(operations, sessionStoreStrategy, numberOfRetries) | ||
@@ -69,6 +83,6 @@ return | ||
if (isSessionInExpiredState(processedSession)) { | ||
clearSession() | ||
expireSession() | ||
} else { | ||
expandSessionState(processedSession) | ||
persistSession(processedSession) | ||
isLockEnabled ? persistWithLock(processedSession) : persistSession(processedSession) | ||
} | ||
@@ -81,10 +95,9 @@ } | ||
// if lock corrupted after persist, retry later | ||
currentSession = retrieveSession() | ||
if (currentSession.lock !== currentLock!) { | ||
currentStore = retrieveStore() | ||
if (currentStore.lock !== currentLock!) { | ||
retryLater(operations, sessionStoreStrategy, numberOfRetries) | ||
return | ||
} | ||
delete currentSession.lock | ||
persistSession(currentSession) | ||
processedSession = currentSession | ||
persistSession(currentStore.session) | ||
processedSession = currentStore.session | ||
} | ||
@@ -94,3 +107,3 @@ } | ||
// up-to-date session state value => the value could have been modified by another tab | ||
operations.after?.(processedSession || currentSession) | ||
operations.after?.(processedSession || currentStore.session) | ||
next(sessionStoreStrategy) | ||
@@ -97,0 +110,0 @@ } |
import { isChromium } from '../../../tools/utils/browserDetection' | ||
import type { CookieOptions } from '../../../browser/cookie' | ||
import { getCurrentSite, areCookiesAuthorized, deleteCookie, getCookie, setCookie } from '../../../browser/cookie' | ||
import { getCurrentSite, areCookiesAuthorized, getCookie, setCookie } from '../../../browser/cookie' | ||
import type { InitConfiguration } from '../../configuration' | ||
import { tryOldCookiesMigration } from '../oldCookiesMigration' | ||
import { SESSION_EXPIRATION_DELAY } from '../sessionConstants' | ||
import { SESSION_EXPIRATION_DELAY, SESSION_TIME_OUT_DELAY } from '../sessionConstants' | ||
import type { SessionState } from '../sessionState' | ||
import { toSessionString, toSessionState } from '../sessionState' | ||
import { toSessionString, toSessionState, getExpiredSessionState } from '../sessionState' | ||
import type { SessionStoreStrategy, SessionStoreStrategyType } from './sessionStoreStrategy' | ||
@@ -26,3 +26,3 @@ import { SESSION_STORE_KEY } from './sessionStoreStrategy' | ||
retrieveSession: retrieveSessionCookie, | ||
clearSession: deleteSessionCookie(cookieOptions), | ||
expireSession: () => expireSessionCookie(cookieOptions), | ||
} | ||
@@ -41,2 +41,6 @@ | ||
function expireSessionCookie(options: CookieOptions) { | ||
setCookie(SESSION_STORE_KEY, toSessionString(getExpiredSessionState()), SESSION_TIME_OUT_DELAY, options) | ||
} | ||
function retrieveSessionCookie(): SessionState { | ||
@@ -47,8 +51,2 @@ const sessionString = getCookie(SESSION_STORE_KEY) | ||
function deleteSessionCookie(options: CookieOptions) { | ||
return () => { | ||
deleteCookie(SESSION_STORE_KEY, options) | ||
} | ||
} | ||
export function buildCookieOptions(initConfiguration: InitConfiguration) { | ||
@@ -55,0 +53,0 @@ const cookieOptions: CookieOptions = {} |
import { generateUUID } from '../../../tools/utils/stringUtils' | ||
import type { SessionState } from '../sessionState' | ||
import { toSessionString, toSessionState } from '../sessionState' | ||
import { toSessionString, toSessionState, getExpiredSessionState } from '../sessionState' | ||
import type { SessionStoreStrategy, SessionStoreStrategyType } from './sessionStoreStrategy' | ||
@@ -27,3 +27,3 @@ import { SESSION_STORE_KEY } from './sessionStoreStrategy' | ||
retrieveSession: retrieveSessionFromLocalStorage, | ||
clearSession: clearSessionFromLocalStorage, | ||
expireSession: expireSessionFromLocalStorage, | ||
} | ||
@@ -41,4 +41,4 @@ } | ||
function clearSessionFromLocalStorage() { | ||
localStorage.removeItem(SESSION_STORE_KEY) | ||
function expireSessionFromLocalStorage() { | ||
persistInLocalStorage(getExpiredSessionState()) | ||
} |
@@ -12,3 +12,3 @@ import type { CookieOptions } from '../../../browser/cookie' | ||
retrieveSession: () => SessionState | ||
clearSession: () => void | ||
expireSession: () => void | ||
} |
import type { Context } from '../../tools/serialisation/context' | ||
import { ConsoleApiName } from '../../tools/display' | ||
import { toStackTraceString, NO_ERROR_STACK_PRESENT_MESSAGE } from '../error/error' | ||
import { NO_ERROR_STACK_PRESENT_MESSAGE } from '../error/error' | ||
import { toStackTraceString } from '../../tools/stackTrace/handlingStack' | ||
import { getExperimentalFeatures } from '../../tools/experimentalFeatures' | ||
@@ -16,4 +17,4 @@ import type { Configuration } from '../configuration' | ||
import { NonErrorPrefix } from '../error/error.types' | ||
import type { StackTrace } from '../error/computeStackTrace' | ||
import { computeStackTrace } from '../error/computeStackTrace' | ||
import type { StackTrace } from '../../tools/stackTrace/computeStackTrace' | ||
import { computeStackTrace } from '../../tools/stackTrace/computeStackTrace' | ||
import { getConnectivity } from '../connectivity' | ||
@@ -20,0 +21,0 @@ import type { TelemetryEvent } from './telemetryEvent.types' |
@@ -205,2 +205,6 @@ /* eslint-disable */ | ||
/** | ||
* Privacy control for action name | ||
*/ | ||
enable_privacy_for_action_name?: boolean | ||
/** | ||
* Whether the request origins list to ignore when computing the page activity is used | ||
@@ -207,0 +211,0 @@ */ |
@@ -23,3 +23,3 @@ export { | ||
export { trackRuntimeError } from './domain/error/trackRuntimeError' | ||
export { computeStackTrace, StackTrace } from './domain/error/computeStackTrace' | ||
export { computeStackTrace, StackTrace } from './tools/stackTrace/computeStackTrace' | ||
export { defineGlobal, makePublicApi } from './boot/init' | ||
@@ -84,9 +84,3 @@ export { displayAlreadyInitializedError } from './boot/displayAlreadyInitializedError' | ||
export { instrumentMethod, instrumentSetter, InstrumentedMethodCall } from './tools/instrumentMethod' | ||
export { | ||
computeRawError, | ||
createHandlingStack, | ||
toStackTraceString, | ||
getFileFromStackTraceString, | ||
NO_ERROR_STACK_PRESENT_MESSAGE, | ||
} from './domain/error/error' | ||
export { computeRawError, getFileFromStackTraceString, NO_ERROR_STACK_PRESENT_MESSAGE } from './domain/error/error' | ||
export { NonErrorPrefix } from './domain/error/error.types' | ||
@@ -147,1 +141,2 @@ export { Context, ContextArray, ContextValue } from './tools/serialisation/context' | ||
export * from './domain/connectivity' | ||
export * from './tools/stackTrace/handlingStack' |
@@ -15,3 +15,2 @@ /** | ||
PAGEHIDE = 'pagehide', | ||
FEATURE_FLAGS = 'feature_flags', | ||
RESOURCE_PAGE_STATES = 'resource_page_states', | ||
@@ -18,0 +17,0 @@ COLLECT_FLUSH_REASON = 'collect_flush_reason', |
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
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
1096970
641
19330