posthog-node 5.74.0 → 6.0.1
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/MIGRATION.md +556 -0
- package/README.md +3 -1
- package/dist/ai-capture/routing.d.ts +0 -3
- package/dist/ai-capture/routing.d.ts.map +1 -1
- package/dist/ai-capture/routing.js +2 -14
- package/dist/ai-capture/routing.mjs +1 -4
- package/dist/capture-lane/lane.d.ts +109 -0
- package/dist/capture-lane/lane.d.ts.map +1 -0
- package/dist/capture-lane/lane.js +308 -0
- package/dist/capture-lane/lane.mjs +270 -0
- package/dist/capture-lane/limits.d.ts +7 -0
- package/dist/capture-lane/limits.d.ts.map +1 -0
- package/dist/{capture-v1/config.js → capture-lane/limits.js} +13 -11
- package/dist/capture-lane/limits.mjs +4 -0
- package/dist/capture-lane/settings.d.ts +30 -0
- package/dist/capture-lane/settings.d.ts.map +1 -0
- package/dist/capture-lane/settings.js +100 -0
- package/dist/capture-lane/settings.mjs +47 -0
- package/dist/capture-v1/compression.d.ts +18 -0
- package/dist/capture-v1/compression.d.ts.map +1 -0
- package/dist/capture-v1/compression.js +70 -0
- package/dist/capture-v1/compression.mjs +26 -0
- package/dist/capture-v1/errors.d.ts +23 -7
- package/dist/capture-v1/errors.d.ts.map +1 -1
- package/dist/capture-v1/errors.js +37 -8
- package/dist/capture-v1/errors.mjs +29 -6
- package/dist/capture-v1/sender.d.ts +63 -23
- package/dist/capture-v1/sender.d.ts.map +1 -1
- package/dist/capture-v1/sender.js +281 -74
- package/dist/capture-v1/sender.mjs +275 -77
- package/dist/capture-v1/serialize.d.ts +28 -0
- package/dist/capture-v1/serialize.d.ts.map +1 -0
- package/dist/capture-v1/serialize.js +82 -0
- package/dist/capture-v1/serialize.mjs +38 -0
- package/dist/capture-v1/transform.d.ts +10 -25
- package/dist/capture-v1/transform.d.ts.map +1 -1
- package/dist/capture-v1/transform.js +33 -64
- package/dist/capture-v1/transform.mjs +28 -53
- package/dist/capture-v1/types.d.ts +16 -14
- package/dist/capture-v1/types.d.ts.map +1 -1
- package/dist/capture-v1/types.js +27 -1
- package/dist/capture-v1/types.mjs +3 -1
- package/dist/capture-v1/uuid.d.ts +9 -0
- package/dist/capture-v1/uuid.d.ts.map +1 -0
- package/dist/capture-v1/uuid.js +75 -0
- package/dist/capture-v1/uuid.mjs +34 -0
- package/dist/client.d.ts +203 -96
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +456 -228
- package/dist/client.mjs +455 -227
- package/dist/compression.node.d.ts +13 -0
- package/dist/compression.node.d.ts.map +1 -0
- package/dist/{capture-v1/routing.js → compression.node.js} +23 -16
- package/dist/compression.node.mjs +18 -0
- package/dist/entrypoints/index.node.d.ts +2 -0
- package/dist/entrypoints/index.node.d.ts.map +1 -1
- package/dist/entrypoints/index.node.js +11 -4
- package/dist/entrypoints/index.node.mjs +4 -0
- package/dist/event-defaults.d.ts +46 -0
- package/dist/event-defaults.d.ts.map +1 -0
- package/dist/event-defaults.js +141 -0
- package/dist/event-defaults.mjs +79 -0
- package/dist/exports.d.ts +3 -0
- package/dist/exports.d.ts.map +1 -1
- package/dist/exports.js +22 -11
- package/dist/exports.mjs +1 -0
- package/dist/extensions/context/context.d.ts +0 -1
- package/dist/extensions/context/context.d.ts.map +1 -1
- package/dist/extensions/context/context.js +4 -3
- package/dist/extensions/context/context.mjs +4 -3
- package/dist/extensions/context/event-context.d.ts.map +1 -1
- package/dist/extensions/context/event-context.js +3 -0
- package/dist/extensions/context/event-context.mjs +3 -0
- package/dist/extensions/context/types.d.ts +9 -1
- package/dist/extensions/context/types.d.ts.map +1 -1
- package/dist/extensions/error-tracking/index.d.ts +1 -1
- package/dist/extensions/error-tracking/index.d.ts.map +1 -1
- package/dist/extensions/error-tracking/index.js +71 -7
- package/dist/extensions/error-tracking/index.mjs +75 -11
- package/dist/extensions/express.d.ts +8 -0
- package/dist/extensions/express.d.ts.map +1 -1
- package/dist/extensions/express.js +3 -3
- package/dist/extensions/express.mjs +4 -4
- package/dist/extensions/fetch-request.d.ts.map +1 -1
- package/dist/extensions/fetch-request.js +2 -2
- package/dist/extensions/fetch-request.mjs +3 -3
- package/dist/extensions/nestjs.d.ts.map +1 -1
- package/dist/extensions/nestjs.js +7 -4
- package/dist/extensions/nestjs.mjs +8 -5
- package/dist/extensions/tracing-headers.d.ts +7 -0
- package/dist/extensions/tracing-headers.d.ts.map +1 -1
- package/dist/extensions/tracing-headers.js +11 -1
- package/dist/extensions/tracing-headers.mjs +9 -2
- package/dist/flag-events.d.ts +1 -1
- package/dist/flag-events.d.ts.map +1 -1
- package/dist/flag-events.js +2 -2
- package/dist/flag-events.mjs +2 -2
- package/dist/types.d.ts +191 -27
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.mjs +1 -1
- package/package.json +3 -2
- package/src/ai-capture/routing.ts +0 -6
- package/src/capture-lane/lane.ts +414 -0
- package/src/capture-lane/limits.ts +8 -0
- package/src/capture-lane/settings.ts +119 -0
- package/src/capture-v1/compression.ts +50 -0
- package/src/capture-v1/errors.ts +50 -11
- package/src/capture-v1/sender.ts +405 -111
- package/src/capture-v1/serialize.ts +77 -0
- package/src/capture-v1/transform.ts +59 -92
- package/src/capture-v1/types.ts +19 -15
- package/src/capture-v1/uuid.ts +53 -0
- package/src/client.ts +847 -424
- package/src/compression.node.ts +30 -0
- package/src/entrypoints/index.node.ts +6 -0
- package/src/event-defaults.ts +177 -0
- package/src/exports.ts +3 -0
- package/src/extensions/context/context.ts +4 -4
- package/src/extensions/context/event-context.ts +3 -1
- package/src/extensions/context/types.ts +10 -1
- package/src/extensions/error-tracking/index.ts +51 -7
- package/src/extensions/express.ts +12 -3
- package/src/extensions/fetch-request.ts +7 -3
- package/src/extensions/nestjs.ts +9 -5
- package/src/extensions/tracing-headers.ts +26 -7
- package/src/flag-events.ts +5 -2
- package/src/types.ts +211 -44
- package/src/version.ts +1 -1
- package/dist/ai-capture/batching.d.ts +0 -11
- package/dist/ai-capture/batching.d.ts.map +0 -1
- package/dist/ai-capture/batching.js +0 -77
- package/dist/ai-capture/batching.mjs +0 -36
- package/dist/capture-v1/config.d.ts +0 -11
- package/dist/capture-v1/config.d.ts.map +0 -1
- package/dist/capture-v1/config.mjs +0 -8
- package/dist/capture-v1/routing.d.ts +0 -21
- package/dist/capture-v1/routing.d.ts.map +0 -1
- package/dist/capture-v1/routing.mjs +0 -7
- package/src/ai-capture/batching.ts +0 -47
- package/src/capture-v1/config.ts +0 -18
- package/src/capture-v1/routing.ts +0 -28
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Serialized event bytes a lane aims to fit in one request. */
|
|
2
|
+
export declare const CAPTURE_BATCH_TARGET_BYTES: number;
|
|
3
|
+
/** Capture's request body limit: a larger analytics event can never be accepted. */
|
|
4
|
+
export declare const ANALYTICS_MAX_EVENT_BYTES: number;
|
|
5
|
+
/** The AI endpoint rejects an event whose serialized `properties` are larger than this. */
|
|
6
|
+
export declare const AI_MAX_PROPERTIES_BYTES: number;
|
|
7
|
+
//# sourceMappingURL=limits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../../src/capture-lane/limits.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,eAAO,MAAM,0BAA0B,QAAkB,CAAA;AAEzD,oFAAoF;AACpF,eAAO,MAAM,yBAAyB,QAAmB,CAAA;AAEzD,2FAA2F;AAC3F,eAAO,MAAM,uBAAuB,QAAkB,CAAA"}
|
|
@@ -27,19 +27,21 @@ var __webpack_require__ = {};
|
|
|
27
27
|
})();
|
|
28
28
|
var __webpack_exports__ = {};
|
|
29
29
|
__webpack_require__.r(__webpack_exports__);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
38
|
-
resolveCaptureMode: ()=>resolveCaptureMode
|
|
30
|
+
const CAPTURE_BATCH_TARGET_BYTES = 5242880;
|
|
31
|
+
const ANALYTICS_MAX_EVENT_BYTES = 10485760;
|
|
32
|
+
const AI_MAX_PROPERTIES_BYTES = 8388608;
|
|
33
|
+
__webpack_require__.d(__webpack_exports__, {}, {
|
|
34
|
+
AI_MAX_PROPERTIES_BYTES: AI_MAX_PROPERTIES_BYTES,
|
|
35
|
+
ANALYTICS_MAX_EVENT_BYTES: ANALYTICS_MAX_EVENT_BYTES,
|
|
36
|
+
CAPTURE_BATCH_TARGET_BYTES: CAPTURE_BATCH_TARGET_BYTES
|
|
39
37
|
});
|
|
40
|
-
exports.
|
|
38
|
+
exports.AI_MAX_PROPERTIES_BYTES = __webpack_exports__.AI_MAX_PROPERTIES_BYTES;
|
|
39
|
+
exports.ANALYTICS_MAX_EVENT_BYTES = __webpack_exports__.ANALYTICS_MAX_EVENT_BYTES;
|
|
40
|
+
exports.CAPTURE_BATCH_TARGET_BYTES = __webpack_exports__.CAPTURE_BATCH_TARGET_BYTES;
|
|
41
41
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
42
|
-
"
|
|
42
|
+
"AI_MAX_PROPERTIES_BYTES",
|
|
43
|
+
"ANALYTICS_MAX_EVENT_BYTES",
|
|
44
|
+
"CAPTURE_BATCH_TARGET_BYTES"
|
|
43
45
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
44
46
|
Object.defineProperty(exports, '__esModule', {
|
|
45
47
|
value: true
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type CaptureCompression } from '../capture-v1/compression';
|
|
2
|
+
import type { PostHogOptions } from '../types';
|
|
3
|
+
export declare const DEFAULT_CAPTURE_MAX_RETRIES = 3;
|
|
4
|
+
export declare const MAX_CAPTURE_MAX_RETRIES = 9;
|
|
5
|
+
export declare const DEFAULT_REQUEST_TIMEOUT_MS = 10000;
|
|
6
|
+
export declare const DEFAULT_AI_REQUEST_TIMEOUT_MS = 30000;
|
|
7
|
+
export declare const DEFAULT_AI_MAX_QUEUE_SIZE = 1000;
|
|
8
|
+
/** Capture settings resolved once per client from `PostHogOptions`. */
|
|
9
|
+
export interface CaptureSettings {
|
|
10
|
+
/** Retries after the first attempt, for both lanes. */
|
|
11
|
+
maxRetries: number;
|
|
12
|
+
analytics: CaptureLaneSettings;
|
|
13
|
+
ai: CaptureLaneSettings & {
|
|
14
|
+
/** Queued AI events; the analytics queue size stays a client setting. */
|
|
15
|
+
maxQueueSize: number;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export interface CaptureLaneSettings {
|
|
19
|
+
/** The requested body encoding; the runtime may not support it. */
|
|
20
|
+
compression: CaptureCompression;
|
|
21
|
+
requestTimeoutMs: number;
|
|
22
|
+
}
|
|
23
|
+
type LogInvalid = (message: string) => void;
|
|
24
|
+
/**
|
|
25
|
+
* Validates the capture options. An invalid value is reported once through `logInvalid` and
|
|
26
|
+
* behaves as if it were not set, so a bad option never throws.
|
|
27
|
+
*/
|
|
28
|
+
export declare function resolveCaptureSettings(options: PostHogOptions, logInvalid: LogInvalid): CaptureSettings;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=settings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../src/capture-lane/settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AACzF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAE9C,eAAO,MAAM,2BAA2B,IAAI,CAAA;AAC5C,eAAO,MAAM,uBAAuB,IAAI,CAAA;AACxC,eAAO,MAAM,0BAA0B,QAAS,CAAA;AAChD,eAAO,MAAM,6BAA6B,QAAS,CAAA;AACnD,eAAO,MAAM,yBAAyB,OAAO,CAAA;AAE7C,uEAAuE;AACvE,MAAM,WAAW,eAAe;IAC9B,uDAAuD;IACvD,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,mBAAmB,CAAA;IAC9B,EAAE,EAAE,mBAAmB,GAAG;QACxB,yEAAyE;QACzE,YAAY,EAAE,MAAM,CAAA;KACrB,CAAA;CACF;AAED,MAAM,WAAW,mBAAmB;IAClC,mEAAmE;IACnE,WAAW,EAAE,kBAAkB,CAAA;IAC/B,gBAAgB,EAAE,MAAM,CAAA;CACzB;AAED,KAAK,UAAU,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;AAK3C;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,GAAG,eAAe,CA4BvG"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
DEFAULT_AI_MAX_QUEUE_SIZE: ()=>DEFAULT_AI_MAX_QUEUE_SIZE,
|
|
32
|
+
DEFAULT_AI_REQUEST_TIMEOUT_MS: ()=>DEFAULT_AI_REQUEST_TIMEOUT_MS,
|
|
33
|
+
DEFAULT_CAPTURE_MAX_RETRIES: ()=>DEFAULT_CAPTURE_MAX_RETRIES,
|
|
34
|
+
DEFAULT_REQUEST_TIMEOUT_MS: ()=>DEFAULT_REQUEST_TIMEOUT_MS,
|
|
35
|
+
MAX_CAPTURE_MAX_RETRIES: ()=>MAX_CAPTURE_MAX_RETRIES,
|
|
36
|
+
resolveCaptureSettings: ()=>resolveCaptureSettings
|
|
37
|
+
});
|
|
38
|
+
const compression_js_namespaceObject = require("../capture-v1/compression.js");
|
|
39
|
+
const DEFAULT_CAPTURE_MAX_RETRIES = 3;
|
|
40
|
+
const MAX_CAPTURE_MAX_RETRIES = 9;
|
|
41
|
+
const DEFAULT_REQUEST_TIMEOUT_MS = 10000;
|
|
42
|
+
const DEFAULT_AI_REQUEST_TIMEOUT_MS = 30000;
|
|
43
|
+
const DEFAULT_AI_MAX_QUEUE_SIZE = 1000;
|
|
44
|
+
const isIntegerInRange = (value, min, max)=>'number' == typeof value && Number.isInteger(value) && value >= min && value <= max;
|
|
45
|
+
function resolveCaptureSettings(options, logInvalid) {
|
|
46
|
+
return {
|
|
47
|
+
maxRetries: resolveMaxRetries(options, logInvalid),
|
|
48
|
+
analytics: {
|
|
49
|
+
compression: resolveCompression('captureCompression', options.captureCompression, logInvalid) ?? (options.disableCompression ? 'none' : 'gzip'),
|
|
50
|
+
requestTimeoutMs: options.requestTimeout ?? DEFAULT_REQUEST_TIMEOUT_MS
|
|
51
|
+
},
|
|
52
|
+
ai: {
|
|
53
|
+
compression: resolveCompression('captureAiCompression', options.captureAiCompression, logInvalid) ?? 'gzip',
|
|
54
|
+
requestTimeoutMs: resolvePositive('captureAiRequestTimeoutMs', options.captureAiRequestTimeoutMs, DEFAULT_AI_REQUEST_TIMEOUT_MS, logInvalid, {
|
|
55
|
+
integer: false
|
|
56
|
+
}),
|
|
57
|
+
maxQueueSize: resolvePositive('captureAiMaxQueueSize', options.captureAiMaxQueueSize, DEFAULT_AI_MAX_QUEUE_SIZE, logInvalid, {
|
|
58
|
+
integer: true
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function resolveCompression(name, value, logInvalid) {
|
|
64
|
+
if (null == value) return;
|
|
65
|
+
if (compression_js_namespaceObject.CAPTURE_COMPRESSIONS.includes(value)) return value;
|
|
66
|
+
logInvalid(`${name} must be one of ${compression_js_namespaceObject.CAPTURE_COMPRESSIONS.map((codec)=>`'${codec}'`).join(', ')}; using the default.`);
|
|
67
|
+
}
|
|
68
|
+
const MAX_SETTING_VALUE = 2147483647;
|
|
69
|
+
function resolvePositive(name, value, fallback, logInvalid, { integer }) {
|
|
70
|
+
if (null == value) return fallback;
|
|
71
|
+
if ('number' == typeof value && value > 0 && value <= MAX_SETTING_VALUE && (integer ? Number.isSafeInteger(value) : Number.isFinite(value))) return value;
|
|
72
|
+
logInvalid(`${name} must be a positive ${integer ? 'integer' : 'number'} up to ${MAX_SETTING_VALUE}; using the default.`);
|
|
73
|
+
return fallback;
|
|
74
|
+
}
|
|
75
|
+
function resolveMaxRetries(options, logInvalid) {
|
|
76
|
+
const { captureMaxRetries, fetchRetryCount } = options;
|
|
77
|
+
if (null != captureMaxRetries) {
|
|
78
|
+
if (isIntegerInRange(captureMaxRetries, 0, MAX_CAPTURE_MAX_RETRIES)) return captureMaxRetries;
|
|
79
|
+
logInvalid(`captureMaxRetries must be an integer from 0 to ${MAX_CAPTURE_MAX_RETRIES}; using the default.`);
|
|
80
|
+
}
|
|
81
|
+
if ('number' == typeof fetchRetryCount && Number.isFinite(fetchRetryCount)) return Math.min(Math.max(Math.trunc(fetchRetryCount), 0), MAX_CAPTURE_MAX_RETRIES);
|
|
82
|
+
return DEFAULT_CAPTURE_MAX_RETRIES;
|
|
83
|
+
}
|
|
84
|
+
exports.DEFAULT_AI_MAX_QUEUE_SIZE = __webpack_exports__.DEFAULT_AI_MAX_QUEUE_SIZE;
|
|
85
|
+
exports.DEFAULT_AI_REQUEST_TIMEOUT_MS = __webpack_exports__.DEFAULT_AI_REQUEST_TIMEOUT_MS;
|
|
86
|
+
exports.DEFAULT_CAPTURE_MAX_RETRIES = __webpack_exports__.DEFAULT_CAPTURE_MAX_RETRIES;
|
|
87
|
+
exports.DEFAULT_REQUEST_TIMEOUT_MS = __webpack_exports__.DEFAULT_REQUEST_TIMEOUT_MS;
|
|
88
|
+
exports.MAX_CAPTURE_MAX_RETRIES = __webpack_exports__.MAX_CAPTURE_MAX_RETRIES;
|
|
89
|
+
exports.resolveCaptureSettings = __webpack_exports__.resolveCaptureSettings;
|
|
90
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
91
|
+
"DEFAULT_AI_MAX_QUEUE_SIZE",
|
|
92
|
+
"DEFAULT_AI_REQUEST_TIMEOUT_MS",
|
|
93
|
+
"DEFAULT_CAPTURE_MAX_RETRIES",
|
|
94
|
+
"DEFAULT_REQUEST_TIMEOUT_MS",
|
|
95
|
+
"MAX_CAPTURE_MAX_RETRIES",
|
|
96
|
+
"resolveCaptureSettings"
|
|
97
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
98
|
+
Object.defineProperty(exports, '__esModule', {
|
|
99
|
+
value: true
|
|
100
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { CAPTURE_COMPRESSIONS } from "../capture-v1/compression.mjs";
|
|
2
|
+
const DEFAULT_CAPTURE_MAX_RETRIES = 3;
|
|
3
|
+
const MAX_CAPTURE_MAX_RETRIES = 9;
|
|
4
|
+
const DEFAULT_REQUEST_TIMEOUT_MS = 10000;
|
|
5
|
+
const DEFAULT_AI_REQUEST_TIMEOUT_MS = 30000;
|
|
6
|
+
const DEFAULT_AI_MAX_QUEUE_SIZE = 1000;
|
|
7
|
+
const isIntegerInRange = (value, min, max)=>'number' == typeof value && Number.isInteger(value) && value >= min && value <= max;
|
|
8
|
+
function resolveCaptureSettings(options, logInvalid) {
|
|
9
|
+
return {
|
|
10
|
+
maxRetries: resolveMaxRetries(options, logInvalid),
|
|
11
|
+
analytics: {
|
|
12
|
+
compression: resolveCompression('captureCompression', options.captureCompression, logInvalid) ?? (options.disableCompression ? 'none' : 'gzip'),
|
|
13
|
+
requestTimeoutMs: options.requestTimeout ?? DEFAULT_REQUEST_TIMEOUT_MS
|
|
14
|
+
},
|
|
15
|
+
ai: {
|
|
16
|
+
compression: resolveCompression('captureAiCompression', options.captureAiCompression, logInvalid) ?? 'gzip',
|
|
17
|
+
requestTimeoutMs: resolvePositive('captureAiRequestTimeoutMs', options.captureAiRequestTimeoutMs, DEFAULT_AI_REQUEST_TIMEOUT_MS, logInvalid, {
|
|
18
|
+
integer: false
|
|
19
|
+
}),
|
|
20
|
+
maxQueueSize: resolvePositive('captureAiMaxQueueSize', options.captureAiMaxQueueSize, DEFAULT_AI_MAX_QUEUE_SIZE, logInvalid, {
|
|
21
|
+
integer: true
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function resolveCompression(name, value, logInvalid) {
|
|
27
|
+
if (null == value) return;
|
|
28
|
+
if (CAPTURE_COMPRESSIONS.includes(value)) return value;
|
|
29
|
+
logInvalid(`${name} must be one of ${CAPTURE_COMPRESSIONS.map((codec)=>`'${codec}'`).join(', ')}; using the default.`);
|
|
30
|
+
}
|
|
31
|
+
const MAX_SETTING_VALUE = 2147483647;
|
|
32
|
+
function resolvePositive(name, value, fallback, logInvalid, { integer }) {
|
|
33
|
+
if (null == value) return fallback;
|
|
34
|
+
if ('number' == typeof value && value > 0 && value <= MAX_SETTING_VALUE && (integer ? Number.isSafeInteger(value) : Number.isFinite(value))) return value;
|
|
35
|
+
logInvalid(`${name} must be a positive ${integer ? 'integer' : 'number'} up to ${MAX_SETTING_VALUE}; using the default.`);
|
|
36
|
+
return fallback;
|
|
37
|
+
}
|
|
38
|
+
function resolveMaxRetries(options, logInvalid) {
|
|
39
|
+
const { captureMaxRetries, fetchRetryCount } = options;
|
|
40
|
+
if (null != captureMaxRetries) {
|
|
41
|
+
if (isIntegerInRange(captureMaxRetries, 0, MAX_CAPTURE_MAX_RETRIES)) return captureMaxRetries;
|
|
42
|
+
logInvalid(`captureMaxRetries must be an integer from 0 to ${MAX_CAPTURE_MAX_RETRIES}; using the default.`);
|
|
43
|
+
}
|
|
44
|
+
if ('number' == typeof fetchRetryCount && Number.isFinite(fetchRetryCount)) return Math.min(Math.max(Math.trunc(fetchRetryCount), 0), MAX_CAPTURE_MAX_RETRIES);
|
|
45
|
+
return DEFAULT_CAPTURE_MAX_RETRIES;
|
|
46
|
+
}
|
|
47
|
+
export { DEFAULT_AI_MAX_QUEUE_SIZE, DEFAULT_AI_REQUEST_TIMEOUT_MS, DEFAULT_CAPTURE_MAX_RETRIES, DEFAULT_REQUEST_TIMEOUT_MS, MAX_CAPTURE_MAX_RETRIES, resolveCaptureSettings };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const CAPTURE_COMPRESSIONS: readonly ['none', 'gzip', 'deflate', 'zstd'];
|
|
2
|
+
/** A capture request body encoding; `deflate` is zlib-wrapped, as HTTP `Content-Encoding: deflate` requires. */
|
|
3
|
+
export type CaptureCompression = (typeof CAPTURE_COMPRESSIONS)[number];
|
|
4
|
+
export type CaptureCodec = Exclude<CaptureCompression, 'none'>;
|
|
5
|
+
/** Compresses capture request bodies with the codecs one runtime provides. */
|
|
6
|
+
export interface CaptureCompressor {
|
|
7
|
+
supports(codec: CaptureCodec): boolean;
|
|
8
|
+
/** Resolves to null, or rejects, when compression fails; the sender then sends the body uncompressed. */
|
|
9
|
+
compress(payload: string, codec: CaptureCodec): Promise<Uint8Array | null>;
|
|
10
|
+
}
|
|
11
|
+
/** Uses CompressionStream, so it works wherever the runtime has one. It has no zstd. */
|
|
12
|
+
export declare const webCompressor: CaptureCompressor;
|
|
13
|
+
/**
|
|
14
|
+
* The codec a lane sends with: `requested` when the runtime has it, gzip in place of an unavailable
|
|
15
|
+
* zstd, or no compression when the runtime cannot compress at all.
|
|
16
|
+
*/
|
|
17
|
+
export declare function resolveCaptureCodec(requested: CaptureCompression, compressor: CaptureCompressor, onZstdUnavailable: (fallback: CaptureCompression) => void): CaptureCompression;
|
|
18
|
+
//# sourceMappingURL=compression.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compression.d.ts","sourceRoot":"","sources":["../../src/capture-v1/compression.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,oBAAoB,YAAI,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,CAAU,CAAA;AAEhF,gHAAgH;AAChH,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAA;AAEtE,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAA;AAE9D,8EAA8E;AAC9E,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAA;IACtC,yGAAyG;IACzG,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAA;CAC3E;AAED,wFAAwF;AACxF,eAAO,MAAM,aAAa,EAAE,iBAa3B,CAAA;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,kBAAkB,EAC7B,UAAU,EAAE,iBAAiB,EAC7B,iBAAiB,EAAE,CAAC,QAAQ,EAAE,kBAAkB,KAAK,IAAI,GACxD,kBAAkB,CASpB"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
CAPTURE_COMPRESSIONS: ()=>CAPTURE_COMPRESSIONS,
|
|
32
|
+
resolveCaptureCodec: ()=>resolveCaptureCodec,
|
|
33
|
+
webCompressor: ()=>webCompressor
|
|
34
|
+
});
|
|
35
|
+
const core_namespaceObject = require("@posthog/core");
|
|
36
|
+
const CAPTURE_COMPRESSIONS = [
|
|
37
|
+
'none',
|
|
38
|
+
'gzip',
|
|
39
|
+
'deflate',
|
|
40
|
+
'zstd'
|
|
41
|
+
];
|
|
42
|
+
const webCompressor = {
|
|
43
|
+
supports: (codec)=>'zstd' !== codec && (0, core_namespaceObject.isGzipSupported)(),
|
|
44
|
+
async compress (payload, codec) {
|
|
45
|
+
if ('gzip' === codec) {
|
|
46
|
+
const compressed = await (0, core_namespaceObject.gzipCompress)(payload, false);
|
|
47
|
+
return compressed && new Uint8Array(await compressed.arrayBuffer());
|
|
48
|
+
}
|
|
49
|
+
if ('deflate' !== codec) return null;
|
|
50
|
+
const stream = new Response(payload).body.pipeThrough(new globalThis.CompressionStream('deflate'));
|
|
51
|
+
return new Uint8Array(await new Response(stream).arrayBuffer());
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
function resolveCaptureCodec(requested, compressor, onZstdUnavailable) {
|
|
55
|
+
if ('none' === requested || compressor.supports(requested)) return requested;
|
|
56
|
+
const fallback = compressor.supports('gzip') ? 'gzip' : 'none';
|
|
57
|
+
if ('zstd' === requested) onZstdUnavailable(fallback);
|
|
58
|
+
return fallback;
|
|
59
|
+
}
|
|
60
|
+
exports.CAPTURE_COMPRESSIONS = __webpack_exports__.CAPTURE_COMPRESSIONS;
|
|
61
|
+
exports.resolveCaptureCodec = __webpack_exports__.resolveCaptureCodec;
|
|
62
|
+
exports.webCompressor = __webpack_exports__.webCompressor;
|
|
63
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
64
|
+
"CAPTURE_COMPRESSIONS",
|
|
65
|
+
"resolveCaptureCodec",
|
|
66
|
+
"webCompressor"
|
|
67
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
68
|
+
Object.defineProperty(exports, '__esModule', {
|
|
69
|
+
value: true
|
|
70
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { gzipCompress, isGzipSupported } from "@posthog/core";
|
|
2
|
+
const CAPTURE_COMPRESSIONS = [
|
|
3
|
+
'none',
|
|
4
|
+
'gzip',
|
|
5
|
+
'deflate',
|
|
6
|
+
'zstd'
|
|
7
|
+
];
|
|
8
|
+
const webCompressor = {
|
|
9
|
+
supports: (codec)=>'zstd' !== codec && isGzipSupported(),
|
|
10
|
+
async compress (payload, codec) {
|
|
11
|
+
if ('gzip' === codec) {
|
|
12
|
+
const compressed = await gzipCompress(payload, false);
|
|
13
|
+
return compressed && new Uint8Array(await compressed.arrayBuffer());
|
|
14
|
+
}
|
|
15
|
+
if ('deflate' !== codec) return null;
|
|
16
|
+
const stream = new Response(payload).body.pipeThrough(new globalThis.CompressionStream('deflate'));
|
|
17
|
+
return new Uint8Array(await new Response(stream).arrayBuffer());
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
function resolveCaptureCodec(requested, compressor, onZstdUnavailable) {
|
|
21
|
+
if ('none' === requested || compressor.supports(requested)) return requested;
|
|
22
|
+
const fallback = compressor.supports('gzip') ? 'gzip' : 'none';
|
|
23
|
+
if ('zstd' === requested) onZstdUnavailable(fallback);
|
|
24
|
+
return fallback;
|
|
25
|
+
}
|
|
26
|
+
export { CAPTURE_COMPRESSIONS, resolveCaptureCodec, webCompressor };
|
|
@@ -1,32 +1,48 @@
|
|
|
1
|
+
import type { CaptureEndpoint } from './types';
|
|
1
2
|
/** A single event the server explicitly rejected (`drop`). */
|
|
2
|
-
export interface
|
|
3
|
+
export interface CaptureDroppedEvent {
|
|
3
4
|
uuid: string;
|
|
4
5
|
details?: string;
|
|
5
6
|
}
|
|
6
|
-
export interface
|
|
7
|
+
export interface CaptureErrorParams {
|
|
8
|
+
/** The capture lane the batch was sent to. */
|
|
9
|
+
endpoint: CaptureEndpoint;
|
|
7
10
|
requestId: string;
|
|
8
11
|
/** Events the server rejected outright (billing/validation). */
|
|
9
|
-
drops:
|
|
12
|
+
drops: CaptureDroppedEvent[];
|
|
10
13
|
/** UUIDs of events still pending `retry` after the attempt budget was exhausted, or lost to a batch-level failure. */
|
|
11
14
|
retryExhausted: string[];
|
|
12
15
|
/** The underlying transport/HTTP/parse failure, when the whole batch failed. */
|
|
13
16
|
cause?: unknown;
|
|
14
17
|
}
|
|
15
18
|
/**
|
|
16
|
-
* Surfaced on the client error channel whenever a
|
|
19
|
+
* Surfaced on the client error channel whenever a capture batch did not
|
|
17
20
|
* fully deliver: some events were `drop`ped, some `retry` events outlived the
|
|
18
21
|
* attempt budget, or the batch hit a terminal transport/HTTP/parse failure.
|
|
19
22
|
*
|
|
20
23
|
* A 2xx with drops is still a partial failure and is reported here — a
|
|
21
24
|
* successful HTTP status does not mean every event was accepted.
|
|
22
25
|
*/
|
|
23
|
-
export declare class
|
|
26
|
+
export declare class CaptureError extends Error {
|
|
24
27
|
name: string;
|
|
28
|
+
readonly endpoint: CaptureEndpoint;
|
|
25
29
|
readonly requestId: string;
|
|
26
|
-
readonly drops:
|
|
30
|
+
readonly drops: CaptureDroppedEvent[];
|
|
27
31
|
readonly retryExhausted: string[];
|
|
28
32
|
cause?: unknown;
|
|
29
|
-
constructor({ requestId, drops, retryExhausted, cause }:
|
|
33
|
+
constructor({ endpoint, requestId, drops, retryExhausted, cause }: CaptureErrorParams);
|
|
30
34
|
private static buildMessage;
|
|
31
35
|
}
|
|
36
|
+
/** Counts of undelivered events by cause, in the order the causes first occurred. */
|
|
37
|
+
export declare class CaptureLossTally {
|
|
38
|
+
private readonly counts;
|
|
39
|
+
add(cause: string, count: number): void;
|
|
40
|
+
get total(): number;
|
|
41
|
+
entries(): [cause: string, count: number][];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The one line logged for a capture loss when nothing listens for `'error'`. It holds the lane,
|
|
45
|
+
* counts and causes only: never server response text, event content or uuids.
|
|
46
|
+
*/
|
|
47
|
+
export declare function describeCaptureLoss(endpoint: CaptureEndpoint, loss: CaptureLossTally): string;
|
|
32
48
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/capture-v1/errors.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/capture-v1/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE9C,8DAA8D;AAC9D,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,kBAAkB;IACjC,8CAA8C;IAC9C,QAAQ,EAAE,eAAe,CAAA;IACzB,SAAS,EAAE,MAAM,CAAA;IACjB,gEAAgE;IAChE,KAAK,EAAE,mBAAmB,EAAE,CAAA;IAC5B,sHAAsH;IACtH,cAAc,EAAE,MAAM,EAAE,CAAA;IACxB,gFAAgF;IAChF,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED;;;;;;;GAOG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC,IAAI,SAAiB;IACrB,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAA;IAClC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,KAAK,EAAE,mBAAmB,EAAE,CAAA;IACrC,QAAQ,CAAC,cAAc,EAAE,MAAM,EAAE,CAAA;IACjC,KAAK,CAAC,EAAE,OAAO,CAAA;IAEf,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,EAAE,kBAAkB,EAOpF;IAED,OAAO,CAAC,MAAM,CAAC,YAAY;CAa5B;AAED,qFAAqF;AACrF,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA4B;IAEnD,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAItC;IAED,IAAI,KAAK,IAAI,MAAM,CAMlB;IAED,OAAO,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,CAE1C;CACF;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,eAAe,EAAE,IAAI,EAAE,gBAAgB,GAAG,MAAM,CAG7F"}
|
|
@@ -27,26 +27,55 @@ var __webpack_require__ = {};
|
|
|
27
27
|
})();
|
|
28
28
|
var __webpack_exports__ = {};
|
|
29
29
|
__webpack_require__.r(__webpack_exports__);
|
|
30
|
-
class
|
|
31
|
-
constructor({ requestId, drops, retryExhausted, cause }){
|
|
32
|
-
super(
|
|
30
|
+
class CaptureError extends Error {
|
|
31
|
+
constructor({ endpoint, requestId, drops, retryExhausted, cause }){
|
|
32
|
+
super(CaptureError.buildMessage(endpoint, requestId, drops, retryExhausted, cause)), this.name = 'CaptureError';
|
|
33
|
+
this.endpoint = endpoint;
|
|
33
34
|
this.requestId = requestId;
|
|
34
35
|
this.drops = drops;
|
|
35
36
|
this.retryExhausted = retryExhausted;
|
|
36
37
|
this.cause = cause;
|
|
37
38
|
}
|
|
38
|
-
static buildMessage(requestId, drops, retryExhausted, cause) {
|
|
39
|
-
let message = `Capture
|
|
39
|
+
static buildMessage(endpoint, requestId, drops, retryExhausted, cause) {
|
|
40
|
+
let message = `Capture batch ${requestId} to ${endpoint} did not fully deliver: ${drops.length} dropped, ${retryExhausted.length} undelivered`;
|
|
40
41
|
if (cause instanceof Error) message += ` (${cause.message})`;
|
|
41
42
|
return message;
|
|
42
43
|
}
|
|
43
44
|
}
|
|
45
|
+
class CaptureLossTally {
|
|
46
|
+
add(cause, count) {
|
|
47
|
+
if (count > 0) this.counts.set(cause, (this.counts.get(cause) ?? 0) + count);
|
|
48
|
+
}
|
|
49
|
+
get total() {
|
|
50
|
+
let total = 0;
|
|
51
|
+
for (const count of this.counts.values())total += count;
|
|
52
|
+
return total;
|
|
53
|
+
}
|
|
54
|
+
entries() {
|
|
55
|
+
return [
|
|
56
|
+
...this.counts
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
constructor(){
|
|
60
|
+
this.counts = new Map();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function describeCaptureLoss(endpoint, loss) {
|
|
64
|
+
const causes = loss.entries().map(([cause, count])=>`${count} ${cause}`);
|
|
65
|
+
return `${loss.total} event(s) were not delivered to ${endpoint}: ${causes.join(', ')}`;
|
|
66
|
+
}
|
|
44
67
|
__webpack_require__.d(__webpack_exports__, {
|
|
45
|
-
|
|
68
|
+
CaptureError: ()=>CaptureError,
|
|
69
|
+
CaptureLossTally: ()=>CaptureLossTally,
|
|
70
|
+
describeCaptureLoss: ()=>describeCaptureLoss
|
|
46
71
|
});
|
|
47
|
-
exports.
|
|
72
|
+
exports.CaptureError = __webpack_exports__.CaptureError;
|
|
73
|
+
exports.CaptureLossTally = __webpack_exports__.CaptureLossTally;
|
|
74
|
+
exports.describeCaptureLoss = __webpack_exports__.describeCaptureLoss;
|
|
48
75
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
49
|
-
"
|
|
76
|
+
"CaptureError",
|
|
77
|
+
"CaptureLossTally",
|
|
78
|
+
"describeCaptureLoss"
|
|
50
79
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
51
80
|
Object.defineProperty(exports, '__esModule', {
|
|
52
81
|
value: true
|
|
@@ -1,15 +1,38 @@
|
|
|
1
|
-
class
|
|
2
|
-
constructor({ requestId, drops, retryExhausted, cause }){
|
|
3
|
-
super(
|
|
1
|
+
class CaptureError extends Error {
|
|
2
|
+
constructor({ endpoint, requestId, drops, retryExhausted, cause }){
|
|
3
|
+
super(CaptureError.buildMessage(endpoint, requestId, drops, retryExhausted, cause)), this.name = 'CaptureError';
|
|
4
|
+
this.endpoint = endpoint;
|
|
4
5
|
this.requestId = requestId;
|
|
5
6
|
this.drops = drops;
|
|
6
7
|
this.retryExhausted = retryExhausted;
|
|
7
8
|
this.cause = cause;
|
|
8
9
|
}
|
|
9
|
-
static buildMessage(requestId, drops, retryExhausted, cause) {
|
|
10
|
-
let message = `Capture
|
|
10
|
+
static buildMessage(endpoint, requestId, drops, retryExhausted, cause) {
|
|
11
|
+
let message = `Capture batch ${requestId} to ${endpoint} did not fully deliver: ${drops.length} dropped, ${retryExhausted.length} undelivered`;
|
|
11
12
|
if (cause instanceof Error) message += ` (${cause.message})`;
|
|
12
13
|
return message;
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
|
-
|
|
16
|
+
class CaptureLossTally {
|
|
17
|
+
add(cause, count) {
|
|
18
|
+
if (count > 0) this.counts.set(cause, (this.counts.get(cause) ?? 0) + count);
|
|
19
|
+
}
|
|
20
|
+
get total() {
|
|
21
|
+
let total = 0;
|
|
22
|
+
for (const count of this.counts.values())total += count;
|
|
23
|
+
return total;
|
|
24
|
+
}
|
|
25
|
+
entries() {
|
|
26
|
+
return [
|
|
27
|
+
...this.counts
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
constructor(){
|
|
31
|
+
this.counts = new Map();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function describeCaptureLoss(endpoint, loss) {
|
|
35
|
+
const causes = loss.entries().map(([cause, count])=>`${count} ${cause}`);
|
|
36
|
+
return `${loss.total} event(s) were not delivered to ${endpoint}: ${causes.join(', ')}`;
|
|
37
|
+
}
|
|
38
|
+
export { CaptureError, CaptureLossTally, describeCaptureLoss };
|