@openobserve/browser-core 0.2.12-beta.21 → 0.2.12-beta.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/boot/displayAlreadyInitializedError.d.ts +1 -1
- package/cjs/boot/init.d.ts +1 -1
- package/cjs/boot/init.js +1 -1
- package/cjs/browser/addEventListener.d.ts +1 -1
- package/cjs/browser/addEventListener.js +1 -1
- package/cjs/domain/configuration/configuration.js +5 -4
- package/cjs/domain/configuration/configuration.js.map +1 -1
- package/cjs/domain/configuration/endpointBuilder.js +21 -12
- package/cjs/domain/configuration/endpointBuilder.js.map +1 -1
- package/cjs/domain/context/storeContextManager.js +1 -1
- package/cjs/domain/tags.js +1 -1
- package/cjs/domain/telemetry/telemetry.js +2 -2
- package/esm/boot/displayAlreadyInitializedError.d.ts +2 -0
- package/esm/boot/displayAlreadyInitializedError.js +7 -0
- package/esm/boot/displayAlreadyInitializedError.js.map +1 -0
- package/esm/boot/init.d.ts +14 -0
- package/esm/boot/init.js +35 -0
- package/esm/boot/init.js.map +1 -0
- package/esm/browser/addEventListener.d.ts +87 -0
- package/esm/browser/addEventListener.js +51 -0
- package/esm/browser/addEventListener.js.map +1 -0
- package/esm/browser/browser.types.d.ts +51 -0
- package/esm/browser/browser.types.js +5 -0
- package/esm/browser/browser.types.js.map +1 -0
- package/esm/browser/cookie.d.ts +28 -0
- package/esm/browser/cookie.js +103 -0
- package/esm/browser/cookie.js.map +1 -0
- package/esm/browser/fetchObservable.d.ts +38 -0
- package/esm/browser/fetchObservable.js +99 -0
- package/esm/browser/fetchObservable.js.map +1 -0
- package/esm/browser/pageMayExitObservable.d.ts +14 -0
- package/esm/browser/pageMayExitObservable.js +40 -0
- package/esm/browser/pageMayExitObservable.js.map +1 -0
- package/esm/browser/runOnReadyState.d.ts +5 -0
- package/esm/browser/runOnReadyState.js +16 -0
- package/esm/browser/runOnReadyState.js.map +1 -0
- package/esm/browser/xhrObservable.d.ts +24 -0
- package/esm/browser/xhrObservable.js +83 -0
- package/esm/browser/xhrObservable.js.map +1 -0
- package/esm/domain/allowedTrackingOrigins.d.ts +4 -0
- package/esm/domain/allowedTrackingOrigins.js +21 -0
- package/esm/domain/allowedTrackingOrigins.js.map +1 -0
- package/esm/domain/bufferedData.d.ts +14 -0
- package/esm/domain/bufferedData.js +19 -0
- package/esm/domain/bufferedData.js.map +1 -0
- package/esm/domain/configuration/configuration.d.ts +312 -0
- package/esm/domain/configuration/configuration.js +132 -0
- package/esm/domain/configuration/configuration.js.map +1 -0
- package/esm/domain/configuration/endpointBuilder.d.ts +12 -0
- package/esm/domain/configuration/endpointBuilder.js +81 -0
- package/esm/domain/configuration/endpointBuilder.js.map +1 -0
- package/esm/domain/configuration/index.d.ts +5 -0
- package/esm/domain/configuration/index.js +4 -0
- package/esm/domain/configuration/index.js.map +1 -0
- package/esm/domain/configuration/transportConfiguration.d.ts +20 -0
- package/esm/domain/configuration/transportConfiguration.js +50 -0
- package/esm/domain/configuration/transportConfiguration.js.map +1 -0
- package/esm/domain/connectivity/connectivity.d.ts +14 -0
- package/esm/domain/connectivity/connectivity.js +11 -0
- package/esm/domain/connectivity/connectivity.js.map +1 -0
- package/esm/domain/connectivity/index.d.ts +1 -0
- package/esm/domain/connectivity/index.js +2 -0
- package/esm/domain/connectivity/index.js.map +1 -0
- package/esm/domain/console/consoleObservable.d.ts +21 -0
- package/esm/domain/console/consoleObservable.js +80 -0
- package/esm/domain/console/consoleObservable.js.map +1 -0
- package/esm/domain/context/contextConstants.d.ts +21 -0
- package/esm/domain/context/contextConstants.js +15 -0
- package/esm/domain/context/contextConstants.js.map +1 -0
- package/esm/domain/context/contextManager.d.ts +19 -0
- package/esm/domain/context/contextManager.js +57 -0
- package/esm/domain/context/contextManager.js.map +1 -0
- package/esm/domain/context/contextUtils.d.ts +5 -0
- package/esm/domain/context/contextUtils.js +13 -0
- package/esm/domain/context/contextUtils.js.map +1 -0
- package/esm/domain/context/defineContextMethod.d.ts +6 -0
- package/esm/domain/context/defineContextMethod.js +17 -0
- package/esm/domain/context/defineContextMethod.js.map +1 -0
- package/esm/domain/context/storeContextManager.d.ts +6 -0
- package/esm/domain/context/storeContextManager.js +35 -0
- package/esm/domain/context/storeContextManager.js.map +1 -0
- package/esm/domain/contexts/accountContext.d.ts +26 -0
- package/esm/domain/contexts/accountContext.js +29 -0
- package/esm/domain/contexts/accountContext.js.map +1 -0
- package/esm/domain/contexts/globalContext.d.ts +18 -0
- package/esm/domain/contexts/globalContext.js +17 -0
- package/esm/domain/contexts/globalContext.js.map +1 -0
- package/esm/domain/contexts/rumInternalContext.type.d.ts +14 -0
- package/esm/domain/contexts/rumInternalContext.type.js +2 -0
- package/esm/domain/contexts/rumInternalContext.type.js.map +1 -0
- package/esm/domain/contexts/userContext.d.ts +29 -0
- package/esm/domain/contexts/userContext.js +41 -0
- package/esm/domain/contexts/userContext.js.map +1 -0
- package/esm/domain/deflate/deflate.types.d.ts +40 -0
- package/esm/domain/deflate/deflate.types.js +2 -0
- package/esm/domain/deflate/deflate.types.js.map +1 -0
- package/esm/domain/deflate/index.d.ts +1 -0
- package/esm/domain/deflate/index.js +2 -0
- package/esm/domain/deflate/index.js.map +1 -0
- package/esm/domain/error/error.d.ts +23 -0
- package/esm/domain/error/error.js +65 -0
- package/esm/domain/error/error.js.map +1 -0
- package/esm/domain/error/error.types.d.ts +47 -0
- package/esm/domain/error/error.types.js +10 -0
- package/esm/domain/error/error.types.js.map +1 -0
- package/esm/domain/error/trackRuntimeError.d.ts +11 -0
- package/esm/domain/error/trackRuntimeError.js +43 -0
- package/esm/domain/error/trackRuntimeError.js.map +1 -0
- package/esm/domain/eventRateLimiter/createEventRateLimiter.d.ts +5 -0
- package/esm/domain/eventRateLimiter/createEventRateLimiter.js +38 -0
- package/esm/domain/eventRateLimiter/createEventRateLimiter.js.map +1 -0
- package/esm/domain/extension/extensionUtils.d.ts +10 -0
- package/esm/domain/extension/extensionUtils.js +25 -0
- package/esm/domain/extension/extensionUtils.js.map +1 -0
- package/esm/domain/intakeSites.d.ts +8 -0
- package/esm/domain/intakeSites.js +8 -0
- package/esm/domain/intakeSites.js.map +1 -0
- package/esm/domain/report/browser.types.d.ts +34 -0
- package/esm/domain/report/browser.types.js +2 -0
- package/esm/domain/report/browser.types.js.map +1 -0
- package/esm/domain/report/reportObservable.d.ts +14 -0
- package/esm/domain/report/reportObservable.js +95 -0
- package/esm/domain/report/reportObservable.js.map +1 -0
- package/esm/domain/resourceUtils.d.ts +18 -0
- package/esm/domain/resourceUtils.js +17 -0
- package/esm/domain/resourceUtils.js.map +1 -0
- package/esm/domain/session/oldCookiesMigration.d.ts +11 -0
- package/esm/domain/session/oldCookiesMigration.js +36 -0
- package/esm/domain/session/oldCookiesMigration.js.map +1 -0
- package/esm/domain/session/sessionConstants.d.ts +15 -0
- package/esm/domain/session/sessionConstants.js +13 -0
- package/esm/domain/session/sessionConstants.js.map +1 -0
- package/esm/domain/session/sessionManager.d.ts +28 -0
- package/esm/domain/session/sessionManager.js +196 -0
- package/esm/domain/session/sessionManager.js.map +1 -0
- package/esm/domain/session/sessionState.d.ts +16 -0
- package/esm/domain/session/sessionState.js +60 -0
- package/esm/domain/session/sessionState.js.map +1 -0
- package/esm/domain/session/sessionStateValidation.d.ts +3 -0
- package/esm/domain/session/sessionStateValidation.js +7 -0
- package/esm/domain/session/sessionStateValidation.js.map +1 -0
- package/esm/domain/session/sessionStore.d.ts +38 -0
- package/esm/domain/session/sessionStore.js +179 -0
- package/esm/domain/session/sessionStore.js.map +1 -0
- package/esm/domain/session/sessionStoreOperations.d.ts +12 -0
- package/esm/domain/session/sessionStoreOperations.js +114 -0
- package/esm/domain/session/sessionStoreOperations.js.map +1 -0
- package/esm/domain/session/storeStrategies/sessionInCookie.d.ts +12 -0
- package/esm/domain/session/storeStrategies/sessionInCookie.js +98 -0
- package/esm/domain/session/storeStrategies/sessionInCookie.js.map +1 -0
- package/esm/domain/session/storeStrategies/sessionInLocalStorage.d.ts +6 -0
- package/esm/domain/session/storeStrategies/sessionInLocalStorage.js +37 -0
- package/esm/domain/session/storeStrategies/sessionInLocalStorage.js.map +1 -0
- package/esm/domain/session/storeStrategies/sessionStoreStrategy.d.ts +16 -0
- package/esm/domain/session/storeStrategies/sessionStoreStrategy.js +2 -0
- package/esm/domain/session/storeStrategies/sessionStoreStrategy.js.map +1 -0
- package/esm/domain/synthetics/syntheticsWorkerValues.d.ts +12 -0
- package/esm/domain/synthetics/syntheticsWorkerValues.js +24 -0
- package/esm/domain/synthetics/syntheticsWorkerValues.js.map +1 -0
- package/esm/domain/tags.d.ts +6 -0
- package/esm/domain/tags.js +60 -0
- package/esm/domain/tags.js.map +1 -0
- package/esm/domain/telemetry/index.d.ts +4 -0
- package/esm/domain/telemetry/index.js +3 -0
- package/esm/domain/telemetry/index.js.map +1 -0
- package/esm/domain/telemetry/rawTelemetryEvent.types.d.ts +18 -0
- package/esm/domain/telemetry/rawTelemetryEvent.types.js +6 -0
- package/esm/domain/telemetry/rawTelemetryEvent.types.js.map +1 -0
- package/esm/domain/telemetry/telemetry.d.ts +56 -0
- package/esm/domain/telemetry/telemetry.js +228 -0
- package/esm/domain/telemetry/telemetry.js.map +1 -0
- package/esm/domain/telemetry/telemetryEvent.types.d.ts +866 -0
- package/esm/domain/telemetry/telemetryEvent.types.js +6 -0
- package/esm/domain/telemetry/telemetryEvent.types.js.map +1 -0
- package/esm/domain/trackingConsent.d.ts +13 -0
- package/esm/domain/trackingConsent.js +24 -0
- package/esm/domain/trackingConsent.js.map +1 -0
- package/esm/index.d.ts +100 -0
- package/esm/index.js +76 -0
- package/esm/index.js.map +1 -0
- package/esm/tools/abstractHooks.d.ts +24 -0
- package/esm/tools/abstractHooks.js +37 -0
- package/esm/tools/abstractHooks.js.map +1 -0
- package/esm/tools/abstractLifeCycle.d.ts +23 -0
- package/esm/tools/abstractLifeCycle.js +24 -0
- package/esm/tools/abstractLifeCycle.js.map +1 -0
- package/esm/tools/boundedBuffer.d.ts +16 -0
- package/esm/tools/boundedBuffer.js +29 -0
- package/esm/tools/boundedBuffer.js.map +1 -0
- package/esm/tools/catchUserErrors.d.ts +1 -0
- package/esm/tools/catchUserErrors.js +12 -0
- package/esm/tools/catchUserErrors.js.map +1 -0
- package/esm/tools/display.d.ts +38 -0
- package/esm/tools/display.js +41 -0
- package/esm/tools/display.js.map +1 -0
- package/esm/tools/encoder.d.ts +54 -0
- package/esm/tools/encoder.js +37 -0
- package/esm/tools/encoder.js.map +1 -0
- package/esm/tools/experimentalFeatures.d.ts +21 -0
- package/esm/tools/experimentalFeatures.js +42 -0
- package/esm/tools/experimentalFeatures.js.map +1 -0
- package/esm/tools/getZoneJsOriginalValue.d.ts +19 -0
- package/esm/tools/getZoneJsOriginalValue.js +26 -0
- package/esm/tools/getZoneJsOriginalValue.js.map +1 -0
- package/esm/tools/globalObject.d.ts +19 -0
- package/esm/tools/globalObject.js +40 -0
- package/esm/tools/globalObject.js.map +1 -0
- package/esm/tools/instrumentMethod.d.ts +75 -0
- package/esm/tools/instrumentMethod.js +114 -0
- package/esm/tools/instrumentMethod.js.map +1 -0
- package/esm/tools/matchOption.d.ts +8 -0
- package/esm/tools/matchOption.js +31 -0
- package/esm/tools/matchOption.js.map +1 -0
- package/esm/tools/mergeInto.d.ts +25 -0
- package/esm/tools/mergeInto.js +93 -0
- package/esm/tools/mergeInto.js.map +1 -0
- package/esm/tools/monitor.d.ts +9 -0
- package/esm/tools/monitor.js +52 -0
- package/esm/tools/monitor.js.map +1 -0
- package/esm/tools/observable.d.ts +30 -0
- package/esm/tools/observable.js +83 -0
- package/esm/tools/observable.js.map +1 -0
- package/esm/tools/queueMicrotask.d.ts +1 -0
- package/esm/tools/queueMicrotask.js +14 -0
- package/esm/tools/queueMicrotask.js.map +1 -0
- package/esm/tools/readBytesFromStream.d.ts +10 -0
- package/esm/tools/readBytesFromStream.js +25 -0
- package/esm/tools/readBytesFromStream.js.map +1 -0
- package/esm/tools/requestIdleCallback.d.ts +12 -0
- package/esm/tools/requestIdleCallback.js +30 -0
- package/esm/tools/requestIdleCallback.js.map +1 -0
- package/esm/tools/sendToExtension.d.ts +3 -0
- package/esm/tools/sendToExtension.js +8 -0
- package/esm/tools/sendToExtension.js.map +1 -0
- package/esm/tools/serialisation/context.d.ts +9 -0
- package/esm/tools/serialisation/context.js +2 -0
- package/esm/tools/serialisation/context.js.map +1 -0
- package/esm/tools/serialisation/jsonStringify.d.ts +13 -0
- package/esm/tools/serialisation/jsonStringify.js +44 -0
- package/esm/tools/serialisation/jsonStringify.js.map +1 -0
- package/esm/tools/serialisation/sanitize.d.ts +18 -0
- package/esm/tools/serialisation/sanitize.js +185 -0
- package/esm/tools/serialisation/sanitize.js.map +1 -0
- package/esm/tools/stackTrace/computeStackTrace.d.ts +25 -0
- package/esm/tools/stackTrace/computeStackTrace.js +183 -0
- package/esm/tools/stackTrace/computeStackTrace.js.map +1 -0
- package/esm/tools/stackTrace/handlingStack.d.ts +10 -0
- package/esm/tools/stackTrace/handlingStack.js +41 -0
- package/esm/tools/stackTrace/handlingStack.js.map +1 -0
- package/esm/tools/taskQueue.d.ts +15 -0
- package/esm/tools/taskQueue.js +50 -0
- package/esm/tools/taskQueue.js.map +1 -0
- package/esm/tools/timer.d.ts +5 -0
- package/esm/tools/timer.js +16 -0
- package/esm/tools/timer.js.map +1 -0
- package/esm/tools/utils/arrayUtils.d.ts +3 -0
- package/esm/tools/utils/arrayUtils.js +15 -0
- package/esm/tools/utils/arrayUtils.js.map +1 -0
- package/esm/tools/utils/browserDetection.d.ts +8 -0
- package/esm/tools/utils/browserDetection.js +28 -0
- package/esm/tools/utils/browserDetection.js.map +1 -0
- package/esm/tools/utils/byteUtils.d.ts +8 -0
- package/esm/tools/utils/byteUtils.js +29 -0
- package/esm/tools/utils/byteUtils.js.map +1 -0
- package/esm/tools/utils/functionUtils.d.ts +8 -0
- package/esm/tools/utils/functionUtils.js +39 -0
- package/esm/tools/utils/functionUtils.js.map +1 -0
- package/esm/tools/utils/numberUtils.d.ts +9 -0
- package/esm/tools/utils/numberUtils.js +18 -0
- package/esm/tools/utils/numberUtils.js.map +1 -0
- package/esm/tools/utils/objectUtils.d.ts +10 -0
- package/esm/tools/utils/objectUtils.js +17 -0
- package/esm/tools/utils/objectUtils.js.map +1 -0
- package/esm/tools/utils/polyfills.d.ts +7 -0
- package/esm/tools/utils/polyfills.js +18 -0
- package/esm/tools/utils/polyfills.js.map +1 -0
- package/esm/tools/utils/responseUtils.d.ts +2 -0
- package/esm/tools/utils/responseUtils.js +13 -0
- package/esm/tools/utils/responseUtils.js.map +1 -0
- package/esm/tools/utils/stringUtils.d.ts +23 -0
- package/esm/tools/utils/stringUtils.js +84 -0
- package/esm/tools/utils/stringUtils.js.map +1 -0
- package/esm/tools/utils/timeUtils.d.ts +53 -0
- package/esm/tools/utils/timeUtils.js +84 -0
- package/esm/tools/utils/timeUtils.js.map +1 -0
- package/esm/tools/utils/timezone.d.ts +1 -0
- package/esm/tools/utils/timezone.js +10 -0
- package/esm/tools/utils/timezone.js.map +1 -0
- package/esm/tools/utils/typeUtils.d.ts +4 -0
- package/esm/tools/utils/typeUtils.js +13 -0
- package/esm/tools/utils/typeUtils.js.map +1 -0
- package/esm/tools/utils/urlPolyfill.d.ts +5 -0
- package/esm/tools/utils/urlPolyfill.js +52 -0
- package/esm/tools/utils/urlPolyfill.js.map +1 -0
- package/esm/tools/valueHistory.d.ts +27 -0
- package/esm/tools/valueHistory.js +100 -0
- package/esm/tools/valueHistory.js.map +1 -0
- package/esm/transport/batch.d.ts +16 -0
- package/esm/transport/batch.js +106 -0
- package/esm/transport/batch.js.map +1 -0
- package/esm/transport/eventBridge.d.ts +21 -0
- package/esm/transport/eventBridge.js +41 -0
- package/esm/transport/eventBridge.js.map +1 -0
- package/esm/transport/flushController.d.ts +65 -0
- package/esm/transport/flushController.js +119 -0
- package/esm/transport/flushController.js.map +1 -0
- package/esm/transport/httpRequest.d.ts +56 -0
- package/esm/transport/httpRequest.js +89 -0
- package/esm/transport/httpRequest.js.map +1 -0
- package/esm/transport/index.d.ts +7 -0
- package/esm/transport/index.js +5 -0
- package/esm/transport/index.js.map +1 -0
- package/esm/transport/sendWithRetryStrategy.d.ts +41 -0
- package/esm/transport/sendWithRetryStrategy.js +158 -0
- package/esm/transport/sendWithRetryStrategy.js.map +1 -0
- package/package.json +1 -1
- package/src/boot/displayAlreadyInitializedError.ts +1 -1
- package/src/boot/init.ts +1 -1
- package/src/browser/addEventListener.ts +2 -2
- package/src/domain/configuration/configuration.ts +6 -5
- package/src/domain/configuration/endpointBuilder.ts +25 -15
- package/src/domain/context/storeContextManager.ts +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { DefaultPrivacyLevel } from '../domain/configuration';
|
|
2
|
+
export interface BrowserWindowWithEventBridge extends Window {
|
|
3
|
+
DatadogEventBridge?: DatadogEventBridge;
|
|
4
|
+
}
|
|
5
|
+
export interface DatadogEventBridge {
|
|
6
|
+
getCapabilities?(): string;
|
|
7
|
+
getPrivacyLevel?(): DefaultPrivacyLevel;
|
|
8
|
+
getAllowedWebViewHosts(): string;
|
|
9
|
+
send(msg: string): void;
|
|
10
|
+
}
|
|
11
|
+
export declare const enum BridgeCapability {
|
|
12
|
+
RECORDS = "records"
|
|
13
|
+
}
|
|
14
|
+
export declare function getEventBridge<T, E>(): {
|
|
15
|
+
getCapabilities(): BridgeCapability[];
|
|
16
|
+
getPrivacyLevel(): DefaultPrivacyLevel | undefined;
|
|
17
|
+
getAllowedWebViewHosts(): string[];
|
|
18
|
+
send(eventType: T, event: E, viewId?: string): void;
|
|
19
|
+
} | undefined;
|
|
20
|
+
export declare function bridgeSupports(capability: BridgeCapability): boolean;
|
|
21
|
+
export declare function canUseEventBridge(currentHost?: string): boolean;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { getGlobalObject } from '../tools/globalObject';
|
|
2
|
+
export function getEventBridge() {
|
|
3
|
+
const eventBridgeGlobal = getEventBridgeGlobal();
|
|
4
|
+
if (!eventBridgeGlobal) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
return {
|
|
8
|
+
getCapabilities() {
|
|
9
|
+
var _a;
|
|
10
|
+
return JSON.parse(((_a = eventBridgeGlobal.getCapabilities) === null || _a === void 0 ? void 0 : _a.call(eventBridgeGlobal)) || '[]');
|
|
11
|
+
},
|
|
12
|
+
getPrivacyLevel() {
|
|
13
|
+
var _a;
|
|
14
|
+
return (_a = eventBridgeGlobal.getPrivacyLevel) === null || _a === void 0 ? void 0 : _a.call(eventBridgeGlobal);
|
|
15
|
+
},
|
|
16
|
+
getAllowedWebViewHosts() {
|
|
17
|
+
return JSON.parse(eventBridgeGlobal.getAllowedWebViewHosts());
|
|
18
|
+
},
|
|
19
|
+
send(eventType, event, viewId) {
|
|
20
|
+
const view = viewId ? { id: viewId } : undefined;
|
|
21
|
+
eventBridgeGlobal.send(JSON.stringify({ eventType, event, view }));
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export function bridgeSupports(capability) {
|
|
26
|
+
const bridge = getEventBridge();
|
|
27
|
+
return !!bridge && bridge.getCapabilities().includes(capability);
|
|
28
|
+
}
|
|
29
|
+
export function canUseEventBridge(currentHost) {
|
|
30
|
+
var _a;
|
|
31
|
+
if (currentHost === void 0) { currentHost = (_a = getGlobalObject().location) === null || _a === void 0 ? void 0 : _a.hostname; }
|
|
32
|
+
const bridge = getEventBridge();
|
|
33
|
+
return (!!bridge &&
|
|
34
|
+
bridge
|
|
35
|
+
.getAllowedWebViewHosts()
|
|
36
|
+
.some((allowedHost) => currentHost === allowedHost || currentHost.endsWith(`.${allowedHost}`)));
|
|
37
|
+
}
|
|
38
|
+
function getEventBridgeGlobal() {
|
|
39
|
+
return getGlobalObject().DatadogEventBridge;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=eventBridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eventBridge.js","sourceRoot":"","sources":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AAsB,EAAE;aACxB,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,KAAK,WAAW,IAAI,WAAW,CAAC,QAAQ,CAAC,IAAI,WAAW,EAAE,CAAC,CAAC,CACjG,CAAA;AACH,CAAC;AAED,SAAS,oBAAoB;IAC3B,OAAO,eAAe,EAAgC,CAAC,kBAAkB,CAAA;AAC3E,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { PageMayExitEvent, PageExitReason } from '../browser/pageMayExitObservable';
|
|
2
|
+
import { Observable } from '../tools/observable';
|
|
3
|
+
import type { Duration } from '../tools/utils/timeUtils';
|
|
4
|
+
export type FlushReason = PageExitReason | 'duration_limit' | 'bytes_limit' | 'messages_limit' | 'session_expire';
|
|
5
|
+
/**
|
|
6
|
+
* flush automatically, aim to be lower than ALB connection timeout
|
|
7
|
+
* to maximize connection reuse.
|
|
8
|
+
*/
|
|
9
|
+
export declare const FLUSH_DURATION_LIMIT: Duration;
|
|
10
|
+
/**
|
|
11
|
+
* When using the SDK in a Worker Environment, we limit the batch size to 1 to ensure it can be sent
|
|
12
|
+
* in a single event.
|
|
13
|
+
*/
|
|
14
|
+
export declare const MESSAGES_LIMIT: number;
|
|
15
|
+
export type FlushController = ReturnType<typeof createFlushController>;
|
|
16
|
+
export interface FlushEvent {
|
|
17
|
+
reason: FlushReason;
|
|
18
|
+
bytesCount: number;
|
|
19
|
+
messagesCount: number;
|
|
20
|
+
}
|
|
21
|
+
interface FlushControllerOptions {
|
|
22
|
+
pageMayExitObservable: Observable<PageMayExitEvent>;
|
|
23
|
+
sessionExpireObservable: Observable<void>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Returns a "flush controller", responsible of notifying when flushing a pool of pending data needs
|
|
27
|
+
* to happen. The implementation is designed to support both synchronous and asynchronous usages,
|
|
28
|
+
* but relies on invariants described in each method documentation to keep a coherent state.
|
|
29
|
+
*/
|
|
30
|
+
export declare function createFlushController({ pageMayExitObservable, sessionExpireObservable }: FlushControllerOptions): {
|
|
31
|
+
flushObservable: Observable<FlushEvent>;
|
|
32
|
+
readonly messagesCount: number;
|
|
33
|
+
/**
|
|
34
|
+
* Notifies that a message will be added to a pool of pending messages waiting to be flushed.
|
|
35
|
+
*
|
|
36
|
+
* This function needs to be called synchronously, right before adding the message, so no flush
|
|
37
|
+
* event can happen after `notifyBeforeAddMessage` and before adding the message.
|
|
38
|
+
*
|
|
39
|
+
* @param estimatedMessageBytesCount - an estimation of the message bytes count once it is
|
|
40
|
+
* actually added.
|
|
41
|
+
*/
|
|
42
|
+
notifyBeforeAddMessage(estimatedMessageBytesCount: number): void;
|
|
43
|
+
/**
|
|
44
|
+
* Notifies that a message *was* added to a pool of pending messages waiting to be flushed.
|
|
45
|
+
*
|
|
46
|
+
* This function can be called asynchronously after the message was added, but in this case it
|
|
47
|
+
* should not be called if a flush event occurred in between.
|
|
48
|
+
*
|
|
49
|
+
* @param messageBytesCountDiff - the difference between the estimated message bytes count and
|
|
50
|
+
* its actual bytes count once added to the pool.
|
|
51
|
+
*/
|
|
52
|
+
notifyAfterAddMessage(messageBytesCountDiff?: number): void;
|
|
53
|
+
/**
|
|
54
|
+
* Notifies that a message was removed from a pool of pending messages waiting to be flushed.
|
|
55
|
+
*
|
|
56
|
+
* This function needs to be called synchronously, right after removing the message, so no flush
|
|
57
|
+
* event can happen after removing the message and before `notifyAfterRemoveMessage`.
|
|
58
|
+
*
|
|
59
|
+
* @param messageBytesCount - the message bytes count that was added to the pool. Should
|
|
60
|
+
* correspond to the sum of bytes counts passed to `notifyBeforeAddMessage` and
|
|
61
|
+
* `notifyAfterAddMessage`.
|
|
62
|
+
*/
|
|
63
|
+
notifyAfterRemoveMessage(messageBytesCount: number): void;
|
|
64
|
+
};
|
|
65
|
+
export {};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { isWorkerEnvironment } from '../tools/globalObject';
|
|
2
|
+
import { Observable } from '../tools/observable';
|
|
3
|
+
import { clearTimeout, setTimeout } from '../tools/timer';
|
|
4
|
+
import { ONE_SECOND } from '../tools/utils/timeUtils';
|
|
5
|
+
import { RECOMMENDED_REQUEST_BYTES_LIMIT } from './httpRequest';
|
|
6
|
+
/**
|
|
7
|
+
* flush automatically, aim to be lower than ALB connection timeout
|
|
8
|
+
* to maximize connection reuse.
|
|
9
|
+
*/
|
|
10
|
+
export const FLUSH_DURATION_LIMIT = (30 * ONE_SECOND);
|
|
11
|
+
/**
|
|
12
|
+
* When using the SDK in a Worker Environment, we limit the batch size to 1 to ensure it can be sent
|
|
13
|
+
* in a single event.
|
|
14
|
+
*/
|
|
15
|
+
export const MESSAGES_LIMIT = isWorkerEnvironment ? 1 : 50;
|
|
16
|
+
/**
|
|
17
|
+
* Returns a "flush controller", responsible of notifying when flushing a pool of pending data needs
|
|
18
|
+
* to happen. The implementation is designed to support both synchronous and asynchronous usages,
|
|
19
|
+
* but relies on invariants described in each method documentation to keep a coherent state.
|
|
20
|
+
*/
|
|
21
|
+
export function createFlushController({ pageMayExitObservable, sessionExpireObservable }) {
|
|
22
|
+
const pageMayExitSubscription = pageMayExitObservable.subscribe((event) => flush(event.reason));
|
|
23
|
+
const sessionExpireSubscription = sessionExpireObservable.subscribe(() => flush('session_expire'));
|
|
24
|
+
const flushObservable = new Observable(() => () => {
|
|
25
|
+
pageMayExitSubscription.unsubscribe();
|
|
26
|
+
sessionExpireSubscription.unsubscribe();
|
|
27
|
+
});
|
|
28
|
+
let currentBytesCount = 0;
|
|
29
|
+
let currentMessagesCount = 0;
|
|
30
|
+
function flush(flushReason) {
|
|
31
|
+
if (currentMessagesCount === 0) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const messagesCount = currentMessagesCount;
|
|
35
|
+
const bytesCount = currentBytesCount;
|
|
36
|
+
currentMessagesCount = 0;
|
|
37
|
+
currentBytesCount = 0;
|
|
38
|
+
cancelDurationLimitTimeout();
|
|
39
|
+
flushObservable.notify({
|
|
40
|
+
reason: flushReason,
|
|
41
|
+
messagesCount,
|
|
42
|
+
bytesCount,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
let durationLimitTimeoutId;
|
|
46
|
+
function scheduleDurationLimitTimeout() {
|
|
47
|
+
if (durationLimitTimeoutId === undefined) {
|
|
48
|
+
durationLimitTimeoutId = setTimeout(() => {
|
|
49
|
+
flush('duration_limit');
|
|
50
|
+
}, FLUSH_DURATION_LIMIT);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function cancelDurationLimitTimeout() {
|
|
54
|
+
clearTimeout(durationLimitTimeoutId);
|
|
55
|
+
durationLimitTimeoutId = undefined;
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
flushObservable,
|
|
59
|
+
get messagesCount() {
|
|
60
|
+
return currentMessagesCount;
|
|
61
|
+
},
|
|
62
|
+
/**
|
|
63
|
+
* Notifies that a message will be added to a pool of pending messages waiting to be flushed.
|
|
64
|
+
*
|
|
65
|
+
* This function needs to be called synchronously, right before adding the message, so no flush
|
|
66
|
+
* event can happen after `notifyBeforeAddMessage` and before adding the message.
|
|
67
|
+
*
|
|
68
|
+
* @param estimatedMessageBytesCount - an estimation of the message bytes count once it is
|
|
69
|
+
* actually added.
|
|
70
|
+
*/
|
|
71
|
+
notifyBeforeAddMessage(estimatedMessageBytesCount) {
|
|
72
|
+
if (currentBytesCount + estimatedMessageBytesCount >= RECOMMENDED_REQUEST_BYTES_LIMIT) {
|
|
73
|
+
flush('bytes_limit');
|
|
74
|
+
}
|
|
75
|
+
// Consider the message to be added now rather than in `notifyAfterAddMessage`, because if no
|
|
76
|
+
// message was added yet and `notifyAfterAddMessage` is called asynchronously, we still want
|
|
77
|
+
// to notify when a flush is needed (for example on page exit).
|
|
78
|
+
currentMessagesCount += 1;
|
|
79
|
+
currentBytesCount += estimatedMessageBytesCount;
|
|
80
|
+
scheduleDurationLimitTimeout();
|
|
81
|
+
},
|
|
82
|
+
/**
|
|
83
|
+
* Notifies that a message *was* added to a pool of pending messages waiting to be flushed.
|
|
84
|
+
*
|
|
85
|
+
* This function can be called asynchronously after the message was added, but in this case it
|
|
86
|
+
* should not be called if a flush event occurred in between.
|
|
87
|
+
*
|
|
88
|
+
* @param messageBytesCountDiff - the difference between the estimated message bytes count and
|
|
89
|
+
* its actual bytes count once added to the pool.
|
|
90
|
+
*/
|
|
91
|
+
notifyAfterAddMessage(messageBytesCountDiff = 0) {
|
|
92
|
+
currentBytesCount += messageBytesCountDiff;
|
|
93
|
+
if (currentMessagesCount >= MESSAGES_LIMIT) {
|
|
94
|
+
flush('messages_limit');
|
|
95
|
+
}
|
|
96
|
+
else if (currentBytesCount >= RECOMMENDED_REQUEST_BYTES_LIMIT) {
|
|
97
|
+
flush('bytes_limit');
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
/**
|
|
101
|
+
* Notifies that a message was removed from a pool of pending messages waiting to be flushed.
|
|
102
|
+
*
|
|
103
|
+
* This function needs to be called synchronously, right after removing the message, so no flush
|
|
104
|
+
* event can happen after removing the message and before `notifyAfterRemoveMessage`.
|
|
105
|
+
*
|
|
106
|
+
* @param messageBytesCount - the message bytes count that was added to the pool. Should
|
|
107
|
+
* correspond to the sum of bytes counts passed to `notifyBeforeAddMessage` and
|
|
108
|
+
* `notifyAfterAddMessage`.
|
|
109
|
+
*/
|
|
110
|
+
notifyAfterRemoveMessage(messageBytesCount) {
|
|
111
|
+
currentBytesCount -= messageBytesCount;
|
|
112
|
+
currentMessagesCount -= 1;
|
|
113
|
+
if (currentMessagesCount === 0) {
|
|
114
|
+
cancelDurationLimitTimeout();
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=flushController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flushController.js","sourceRoot":"","sources":["../../src/transport/flushController.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC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AI,iBAAiB,CAAA;YACtC,oBAAoB,IAAI,CAAC,CAAA;YACzB,IAAI,oBAAoB,KAAK,CAAC,EAAE,CAAC;gBAC/B,0BAA0B,EAAE,CAAA;YAC9B,CAAC;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { EndpointBuilder } from '../domain/configuration';
|
|
2
|
+
import type { Context } from '../tools/serialisation/context';
|
|
3
|
+
import type { RawError } from '../domain/error/error.types';
|
|
4
|
+
import { Observable } from '../tools/observable';
|
|
5
|
+
/**
|
|
6
|
+
* beacon payload max queue size implementation is 64kb
|
|
7
|
+
* ensure that we leave room for logs, rum and potential other users
|
|
8
|
+
*/
|
|
9
|
+
export declare const RECOMMENDED_REQUEST_BYTES_LIMIT: number;
|
|
10
|
+
/**
|
|
11
|
+
* Use POST request without content type to:
|
|
12
|
+
* - avoid CORS preflight requests
|
|
13
|
+
* - allow usage of sendBeacon
|
|
14
|
+
*
|
|
15
|
+
* multiple elements are sent separated by \n in order
|
|
16
|
+
* to be parsed correctly without content type header
|
|
17
|
+
*/
|
|
18
|
+
export interface HttpRequest<Body extends Payload = Payload> {
|
|
19
|
+
observable: Observable<HttpRequestEvent<Body>>;
|
|
20
|
+
send(this: void, payload: Body): void;
|
|
21
|
+
sendOnExit(this: void, payload: Body): void;
|
|
22
|
+
}
|
|
23
|
+
export interface HttpResponse extends Context {
|
|
24
|
+
status: number;
|
|
25
|
+
type?: ResponseType;
|
|
26
|
+
}
|
|
27
|
+
export interface BandwidthStats {
|
|
28
|
+
ongoingByteCount: number;
|
|
29
|
+
ongoingRequestCount: number;
|
|
30
|
+
}
|
|
31
|
+
export type HttpRequestEvent<Body extends Payload = Payload> = {
|
|
32
|
+
type: 'failure';
|
|
33
|
+
bandwidth: BandwidthStats;
|
|
34
|
+
payload: Body;
|
|
35
|
+
} | {
|
|
36
|
+
type: 'queue-full';
|
|
37
|
+
bandwidth: BandwidthStats;
|
|
38
|
+
payload: Body;
|
|
39
|
+
} | {
|
|
40
|
+
type: 'success';
|
|
41
|
+
bandwidth: BandwidthStats;
|
|
42
|
+
payload: Body;
|
|
43
|
+
};
|
|
44
|
+
export interface Payload {
|
|
45
|
+
data: string | FormData | Blob;
|
|
46
|
+
bytesCount: number;
|
|
47
|
+
retry?: RetryInfo;
|
|
48
|
+
encoding?: 'deflate';
|
|
49
|
+
}
|
|
50
|
+
export interface RetryInfo {
|
|
51
|
+
count: number;
|
|
52
|
+
lastFailureStatus: number;
|
|
53
|
+
}
|
|
54
|
+
export declare function createHttpRequest<Body extends Payload = Payload>(endpointBuilders: EndpointBuilder[], reportError: (error: RawError) => void, bytesLimit?: number): HttpRequest<Body>;
|
|
55
|
+
export declare function fetchKeepAliveStrategy(endpointBuilder: EndpointBuilder, bytesLimit: number, payload: Payload, onResponse?: (r: HttpResponse) => void): void;
|
|
56
|
+
export declare function fetchStrategy(endpointBuilder: EndpointBuilder, payload: Payload, onResponse?: (r: HttpResponse) => void): void;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { monitor, monitorError } from '../tools/monitor';
|
|
2
|
+
import { isExperimentalFeatureEnabled, ExperimentalFeature } from '../tools/experimentalFeatures';
|
|
3
|
+
import { Observable } from '../tools/observable';
|
|
4
|
+
import { ONE_KIBI_BYTE } from '../tools/utils/byteUtils';
|
|
5
|
+
import { newRetryState, sendWithRetryStrategy } from './sendWithRetryStrategy';
|
|
6
|
+
/**
|
|
7
|
+
* beacon payload max queue size implementation is 64kb
|
|
8
|
+
* ensure that we leave room for logs, rum and potential other users
|
|
9
|
+
*/
|
|
10
|
+
export const RECOMMENDED_REQUEST_BYTES_LIMIT = 16 * ONE_KIBI_BYTE;
|
|
11
|
+
export function createHttpRequest(endpointBuilders, reportError, bytesLimit = RECOMMENDED_REQUEST_BYTES_LIMIT) {
|
|
12
|
+
const observable = new Observable();
|
|
13
|
+
const retryState = newRetryState();
|
|
14
|
+
return {
|
|
15
|
+
observable,
|
|
16
|
+
send: (payload) => {
|
|
17
|
+
for (const endpointBuilder of endpointBuilders) {
|
|
18
|
+
sendWithRetryStrategy(payload, retryState, (payload, onResponse) => {
|
|
19
|
+
if (isExperimentalFeatureEnabled(ExperimentalFeature.AVOID_FETCH_KEEPALIVE)) {
|
|
20
|
+
fetchStrategy(endpointBuilder, payload, onResponse);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
fetchKeepAliveStrategy(endpointBuilder, bytesLimit, payload, onResponse);
|
|
24
|
+
}
|
|
25
|
+
}, endpointBuilder.trackType, reportError, observable);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
/**
|
|
29
|
+
* Since fetch keepalive behaves like regular fetch on Firefox,
|
|
30
|
+
* keep using sendBeaconStrategy on exit
|
|
31
|
+
*/
|
|
32
|
+
sendOnExit: (payload) => {
|
|
33
|
+
for (const endpointBuilder of endpointBuilders) {
|
|
34
|
+
sendBeaconStrategy(endpointBuilder, bytesLimit, payload);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function sendBeaconStrategy(endpointBuilder, bytesLimit, payload) {
|
|
40
|
+
const canUseBeacon = !!navigator.sendBeacon && payload.bytesCount < bytesLimit;
|
|
41
|
+
if (canUseBeacon) {
|
|
42
|
+
try {
|
|
43
|
+
const beaconUrl = endpointBuilder.build('beacon', payload);
|
|
44
|
+
const isQueued = navigator.sendBeacon(beaconUrl, payload.data);
|
|
45
|
+
if (isQueued) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
reportBeaconError(e);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
fetchStrategy(endpointBuilder, payload);
|
|
54
|
+
}
|
|
55
|
+
let hasReportedBeaconError = false;
|
|
56
|
+
function reportBeaconError(e) {
|
|
57
|
+
if (!hasReportedBeaconError) {
|
|
58
|
+
hasReportedBeaconError = true;
|
|
59
|
+
monitorError(e);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export function fetchKeepAliveStrategy(endpointBuilder, bytesLimit, payload, onResponse) {
|
|
63
|
+
const canUseKeepAlive = isKeepAliveSupported() && payload.bytesCount < bytesLimit;
|
|
64
|
+
if (canUseKeepAlive) {
|
|
65
|
+
const fetchUrl = endpointBuilder.build('fetch-keepalive', payload);
|
|
66
|
+
fetch(fetchUrl, { method: 'POST', body: payload.data, keepalive: true, mode: 'cors' })
|
|
67
|
+
.then(monitor((response) => onResponse === null || onResponse === void 0 ? void 0 : onResponse({ status: response.status, type: response.type })))
|
|
68
|
+
.catch(monitor(() => fetchStrategy(endpointBuilder, payload, onResponse)));
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
fetchStrategy(endpointBuilder, payload, onResponse);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export function fetchStrategy(endpointBuilder, payload, onResponse) {
|
|
75
|
+
const fetchUrl = endpointBuilder.build('fetch', payload);
|
|
76
|
+
fetch(fetchUrl, { method: 'POST', body: payload.data, mode: 'cors' })
|
|
77
|
+
.then(monitor((response) => onResponse === null || onResponse === void 0 ? void 0 : onResponse({ status: response.status, type: response.type })))
|
|
78
|
+
.catch(monitor(() => onResponse === null || onResponse === void 0 ? void 0 : onResponse({ status: 0 })));
|
|
79
|
+
}
|
|
80
|
+
function isKeepAliveSupported() {
|
|
81
|
+
// Request can throw, cf https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#errors
|
|
82
|
+
try {
|
|
83
|
+
return window.Request && 'keepalive' in new Request('http://a');
|
|
84
|
+
}
|
|
85
|
+
catch (_a) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=httpRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpRequest.js","sourceRoot":"","sources":["../../src/transport/httpRequest.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,E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P,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { BandwidthStats, HttpRequest, HttpRequestEvent, Payload, RetryInfo } from './httpRequest';
|
|
2
|
+
export { createHttpRequest } from './httpRequest';
|
|
3
|
+
export type { BrowserWindowWithEventBridge, DatadogEventBridge } from './eventBridge';
|
|
4
|
+
export { canUseEventBridge, bridgeSupports, getEventBridge, BridgeCapability } from './eventBridge';
|
|
5
|
+
export { createBatch } from './batch';
|
|
6
|
+
export type { FlushController, FlushEvent, FlushReason } from './flushController';
|
|
7
|
+
export { createFlushController, FLUSH_DURATION_LIMIT } from './flushController';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createHttpRequest } from './httpRequest';
|
|
2
|
+
export { canUseEventBridge, bridgeSupports, getEventBridge } from './eventBridge';
|
|
3
|
+
export { createBatch } from './batch';
|
|
4
|
+
export { createFlushController, FLUSH_DURATION_LIMIT } from './flushController';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAEjD,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,cAAc,EAAoB,MAAM,eAAe,CAAA;AACnG,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAErC,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { TrackType } from '../domain/configuration';
|
|
2
|
+
import type { RawError } from '../domain/error/error.types';
|
|
3
|
+
import type { Observable } from '../tools/observable';
|
|
4
|
+
import type { Payload, HttpRequestEvent, HttpResponse, BandwidthStats } from './httpRequest';
|
|
5
|
+
export declare const MAX_ONGOING_BYTES_COUNT: number;
|
|
6
|
+
export declare const MAX_ONGOING_REQUESTS = 32;
|
|
7
|
+
export declare const MAX_QUEUE_BYTES_COUNT: number;
|
|
8
|
+
export declare const MAX_BACKOFF_TIME: number;
|
|
9
|
+
export declare const INITIAL_BACKOFF_TIME = 1000;
|
|
10
|
+
declare const enum TransportStatus {
|
|
11
|
+
UP = 0,
|
|
12
|
+
FAILURE_DETECTED = 1,
|
|
13
|
+
DOWN = 2
|
|
14
|
+
}
|
|
15
|
+
export interface RetryState<Body extends Payload> {
|
|
16
|
+
transportStatus: TransportStatus;
|
|
17
|
+
currentBackoffTime: number;
|
|
18
|
+
bandwidthMonitor: ReturnType<typeof newBandwidthMonitor>;
|
|
19
|
+
queuedPayloads: ReturnType<typeof newPayloadQueue<Body>>;
|
|
20
|
+
queueFullReported: boolean;
|
|
21
|
+
}
|
|
22
|
+
type SendStrategy<Body extends Payload> = (payload: Body, onResponse: (r: HttpResponse) => void) => void;
|
|
23
|
+
export declare function sendWithRetryStrategy<Body extends Payload>(payload: Body, state: RetryState<Body>, sendStrategy: SendStrategy<Body>, trackType: TrackType, reportError: (error: RawError) => void, requestObservable: Observable<HttpRequestEvent<Body>>): void;
|
|
24
|
+
export declare function newRetryState<Body extends Payload>(): RetryState<Body>;
|
|
25
|
+
declare function newPayloadQueue<Body extends Payload>(): {
|
|
26
|
+
bytesCount: number;
|
|
27
|
+
enqueue(payload: Body): boolean;
|
|
28
|
+
first(): Body;
|
|
29
|
+
dequeue(): Body | undefined;
|
|
30
|
+
size(): number;
|
|
31
|
+
isFull(): boolean;
|
|
32
|
+
};
|
|
33
|
+
declare function newBandwidthMonitor(): {
|
|
34
|
+
ongoingRequestCount: number;
|
|
35
|
+
ongoingByteCount: number;
|
|
36
|
+
canHandle(payload: Payload): boolean;
|
|
37
|
+
add(payload: Payload): void;
|
|
38
|
+
remove(payload: Payload): void;
|
|
39
|
+
stats(): BandwidthStats;
|
|
40
|
+
};
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { setTimeout } from '../tools/timer';
|
|
2
|
+
import { clocksNow, ONE_MINUTE, ONE_SECOND } from '../tools/utils/timeUtils';
|
|
3
|
+
import { ONE_MEBI_BYTE, ONE_KIBI_BYTE } from '../tools/utils/byteUtils';
|
|
4
|
+
import { isServerError } from '../tools/utils/responseUtils';
|
|
5
|
+
import { ErrorSource } from '../domain/error/error.types';
|
|
6
|
+
export const MAX_ONGOING_BYTES_COUNT = 80 * ONE_KIBI_BYTE;
|
|
7
|
+
export const MAX_ONGOING_REQUESTS = 32;
|
|
8
|
+
export const MAX_QUEUE_BYTES_COUNT = 20 * ONE_MEBI_BYTE;
|
|
9
|
+
export const MAX_BACKOFF_TIME = ONE_MINUTE;
|
|
10
|
+
export const INITIAL_BACKOFF_TIME = ONE_SECOND;
|
|
11
|
+
export function sendWithRetryStrategy(payload, state, sendStrategy, trackType, reportError, requestObservable) {
|
|
12
|
+
if (state.transportStatus === 0 /* TransportStatus.UP */ &&
|
|
13
|
+
state.queuedPayloads.size() === 0 &&
|
|
14
|
+
state.bandwidthMonitor.canHandle(payload)) {
|
|
15
|
+
send(payload, state, sendStrategy, requestObservable, {
|
|
16
|
+
onSuccess: () => retryQueuedPayloads(0 /* RetryReason.AFTER_SUCCESS */, state, sendStrategy, trackType, reportError, requestObservable),
|
|
17
|
+
onFailure: () => {
|
|
18
|
+
if (!state.queuedPayloads.enqueue(payload)) {
|
|
19
|
+
requestObservable.notify({ type: 'queue-full', bandwidth: state.bandwidthMonitor.stats(), payload });
|
|
20
|
+
}
|
|
21
|
+
scheduleRetry(state, sendStrategy, trackType, reportError, requestObservable);
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
if (!state.queuedPayloads.enqueue(payload)) {
|
|
27
|
+
requestObservable.notify({ type: 'queue-full', bandwidth: state.bandwidthMonitor.stats(), payload });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function scheduleRetry(state, sendStrategy, trackType, reportError, requestObservable) {
|
|
32
|
+
if (state.transportStatus !== 2 /* TransportStatus.DOWN */) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
setTimeout(() => {
|
|
36
|
+
const payload = state.queuedPayloads.first();
|
|
37
|
+
send(payload, state, sendStrategy, requestObservable, {
|
|
38
|
+
onSuccess: () => {
|
|
39
|
+
state.queuedPayloads.dequeue();
|
|
40
|
+
state.currentBackoffTime = INITIAL_BACKOFF_TIME;
|
|
41
|
+
retryQueuedPayloads(1 /* RetryReason.AFTER_RESUME */, state, sendStrategy, trackType, reportError, requestObservable);
|
|
42
|
+
},
|
|
43
|
+
onFailure: () => {
|
|
44
|
+
state.currentBackoffTime = Math.min(MAX_BACKOFF_TIME, state.currentBackoffTime * 2);
|
|
45
|
+
scheduleRetry(state, sendStrategy, trackType, reportError, requestObservable);
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}, state.currentBackoffTime);
|
|
49
|
+
}
|
|
50
|
+
function send(payload, state, sendStrategy, requestObservable, { onSuccess, onFailure }) {
|
|
51
|
+
state.bandwidthMonitor.add(payload);
|
|
52
|
+
sendStrategy(payload, (response) => {
|
|
53
|
+
state.bandwidthMonitor.remove(payload);
|
|
54
|
+
if (!shouldRetryRequest(response)) {
|
|
55
|
+
state.transportStatus = 0 /* TransportStatus.UP */;
|
|
56
|
+
requestObservable.notify({ type: 'success', bandwidth: state.bandwidthMonitor.stats(), payload });
|
|
57
|
+
onSuccess();
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
// do not consider transport down if another ongoing request could succeed
|
|
61
|
+
state.transportStatus =
|
|
62
|
+
state.bandwidthMonitor.ongoingRequestCount > 0 ? 1 /* TransportStatus.FAILURE_DETECTED */ : 2 /* TransportStatus.DOWN */;
|
|
63
|
+
payload.retry = {
|
|
64
|
+
count: payload.retry ? payload.retry.count + 1 : 1,
|
|
65
|
+
lastFailureStatus: response.status,
|
|
66
|
+
};
|
|
67
|
+
requestObservable.notify({ type: 'failure', bandwidth: state.bandwidthMonitor.stats(), payload });
|
|
68
|
+
onFailure();
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function retryQueuedPayloads(reason, state, sendStrategy, trackType, reportError, requestObservable) {
|
|
73
|
+
if (reason === 0 /* RetryReason.AFTER_SUCCESS */ && state.queuedPayloads.isFull() && !state.queueFullReported) {
|
|
74
|
+
reportError({
|
|
75
|
+
message: `Reached max ${trackType} events size queued for upload: ${MAX_QUEUE_BYTES_COUNT / ONE_MEBI_BYTE}MiB`,
|
|
76
|
+
source: ErrorSource.AGENT,
|
|
77
|
+
startClocks: clocksNow(),
|
|
78
|
+
});
|
|
79
|
+
state.queueFullReported = true;
|
|
80
|
+
}
|
|
81
|
+
const previousQueue = state.queuedPayloads;
|
|
82
|
+
state.queuedPayloads = newPayloadQueue();
|
|
83
|
+
while (previousQueue.size() > 0) {
|
|
84
|
+
sendWithRetryStrategy(previousQueue.dequeue(), state, sendStrategy, trackType, reportError, requestObservable);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function shouldRetryRequest(response) {
|
|
88
|
+
return (response.type !== 'opaque' &&
|
|
89
|
+
((response.status === 0 && !navigator.onLine) ||
|
|
90
|
+
response.status === 408 ||
|
|
91
|
+
response.status === 429 ||
|
|
92
|
+
isServerError(response.status)));
|
|
93
|
+
}
|
|
94
|
+
export function newRetryState() {
|
|
95
|
+
return {
|
|
96
|
+
transportStatus: 0 /* TransportStatus.UP */,
|
|
97
|
+
currentBackoffTime: INITIAL_BACKOFF_TIME,
|
|
98
|
+
bandwidthMonitor: newBandwidthMonitor(),
|
|
99
|
+
queuedPayloads: newPayloadQueue(),
|
|
100
|
+
queueFullReported: false,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function newPayloadQueue() {
|
|
104
|
+
const queue = [];
|
|
105
|
+
return {
|
|
106
|
+
bytesCount: 0,
|
|
107
|
+
enqueue(payload) {
|
|
108
|
+
if (this.isFull()) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
queue.push(payload);
|
|
112
|
+
this.bytesCount += payload.bytesCount;
|
|
113
|
+
return true;
|
|
114
|
+
},
|
|
115
|
+
first() {
|
|
116
|
+
return queue[0];
|
|
117
|
+
},
|
|
118
|
+
dequeue() {
|
|
119
|
+
const payload = queue.shift();
|
|
120
|
+
if (payload) {
|
|
121
|
+
this.bytesCount -= payload.bytesCount;
|
|
122
|
+
}
|
|
123
|
+
return payload;
|
|
124
|
+
},
|
|
125
|
+
size() {
|
|
126
|
+
return queue.length;
|
|
127
|
+
},
|
|
128
|
+
isFull() {
|
|
129
|
+
return this.bytesCount >= MAX_QUEUE_BYTES_COUNT;
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function newBandwidthMonitor() {
|
|
134
|
+
return {
|
|
135
|
+
ongoingRequestCount: 0,
|
|
136
|
+
ongoingByteCount: 0,
|
|
137
|
+
canHandle(payload) {
|
|
138
|
+
return (this.ongoingRequestCount === 0 ||
|
|
139
|
+
(this.ongoingByteCount + payload.bytesCount <= MAX_ONGOING_BYTES_COUNT &&
|
|
140
|
+
this.ongoingRequestCount < MAX_ONGOING_REQUESTS));
|
|
141
|
+
},
|
|
142
|
+
add(payload) {
|
|
143
|
+
this.ongoingRequestCount += 1;
|
|
144
|
+
this.ongoingByteCount += payload.bytesCount;
|
|
145
|
+
},
|
|
146
|
+
remove(payload) {
|
|
147
|
+
this.ongoingRequestCount -= 1;
|
|
148
|
+
this.ongoingByteCount -= payload.bytesCount;
|
|
149
|
+
},
|
|
150
|
+
stats() {
|
|
151
|
+
return {
|
|
152
|
+
ongoingByteCount: this.ongoingByteCount,
|
|
153
|
+
ongoingRequestCount: this.ongoingRequestCount,
|
|
154
|
+
};
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=sendWithRetryStrategy.js.map
|
|
@@ -0,0 +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