@posthog/core 1.46.3 → 1.46.5
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/dist/error-tracking/coercers/error-coercer.js +2 -2
- package/dist/error-tracking/coercers/error-coercer.mjs +2 -2
- package/dist/error-tracking/coercers/error-event-coercer.d.ts +2 -0
- package/dist/error-tracking/coercers/error-event-coercer.d.ts.map +1 -1
- package/dist/error-tracking/coercers/error-event-coercer.js +19 -7
- package/dist/error-tracking/coercers/error-event-coercer.mjs +20 -8
- package/dist/error-tracking/coercers/object-coercer.d.ts +1 -0
- package/dist/error-tracking/coercers/object-coercer.d.ts.map +1 -1
- package/dist/error-tracking/coercers/object-coercer.js +9 -1
- package/dist/error-tracking/coercers/object-coercer.mjs +9 -1
- package/dist/logs/index.d.ts.map +1 -1
- package/dist/logs/index.js +4 -17
- package/dist/logs/index.mjs +5 -18
- package/dist/posthog-core-stateless.d.ts.map +1 -1
- package/dist/posthog-core-stateless.js +5 -15
- package/dist/posthog-core-stateless.mjs +6 -16
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +32 -0
- package/dist/utils/index.mjs +21 -1
- package/package.json +1 -1
- package/src/error-tracking/coercers/error-coercer.ts +2 -2
- package/src/error-tracking/coercers/error-event-coercer.spec.ts +109 -0
- package/src/error-tracking/coercers/error-event-coercer.ts +36 -12
- package/src/error-tracking/coercers/object-coercer.ts +12 -1
- package/src/error-tracking/error-properties-builder.coerce.spec.ts +42 -0
- package/src/logs/index.spec.ts +37 -0
- package/src/logs/index.ts +7 -18
- package/src/posthog-core-stateless.ts +6 -15
- package/src/utils/index.ts +26 -0
|
@@ -26,10 +26,10 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
27
|
ErrorCoercer: ()=>ErrorCoercer
|
|
28
28
|
});
|
|
29
|
-
const
|
|
29
|
+
const type_utils_js_namespaceObject = require("../../utils/type-utils.js");
|
|
30
30
|
class ErrorCoercer {
|
|
31
31
|
match(err) {
|
|
32
|
-
return (0,
|
|
32
|
+
return (0, type_utils_js_namespaceObject.isError)(err);
|
|
33
33
|
}
|
|
34
34
|
coerce(err, ctx) {
|
|
35
35
|
return {
|
|
@@ -7,6 +7,8 @@ export declare class ErrorEventCoercer implements ErrorTrackingCoercer<ErrorEven
|
|
|
7
7
|
constructor();
|
|
8
8
|
match(err: unknown): err is ErrorEventLike;
|
|
9
9
|
coerce(err: ErrorEventLike, ctx: CoercingContext): ExceptionLike;
|
|
10
|
+
private _hasUsableMessage;
|
|
11
|
+
private _buildLocationStack;
|
|
10
12
|
}
|
|
11
13
|
export {};
|
|
12
14
|
//# sourceMappingURL=error-event-coercer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-event-coercer.d.ts","sourceRoot":"","sources":["../../../src/error-tracking/coercers/error-event-coercer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAO/E,UAAU,cAAc;IACtB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;
|
|
1
|
+
{"version":3,"file":"error-event-coercer.d.ts","sourceRoot":"","sources":["../../../src/error-tracking/coercers/error-event-coercer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAO/E,UAAU,cAAc;IACtB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAQD,qBAAa,iBAAkB,YAAW,oBAAoB,CAAC,cAAc,CAAC;;IAG5E,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,cAAc;IAQ1C,MAAM,CAAC,GAAG,EAAE,cAAc,EAAE,GAAG,EAAE,eAAe,GAAG,aAAa;IAahE,OAAO,CAAC,iBAAiB;IAIzB,OAAO,CAAC,mBAAmB;CAU5B"}
|
|
@@ -30,17 +30,29 @@ const index_js_namespaceObject = require("../../utils/index.js");
|
|
|
30
30
|
class ErrorEventCoercer {
|
|
31
31
|
constructor(){}
|
|
32
32
|
match(err) {
|
|
33
|
-
|
|
33
|
+
if (!(0, index_js_namespaceObject.isErrorEvent)(err)) return false;
|
|
34
|
+
const errorEvent = err;
|
|
35
|
+
return void 0 != errorEvent.error || this._hasUsableMessage(errorEvent);
|
|
34
36
|
}
|
|
35
37
|
coerce(err, ctx) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
stack:
|
|
38
|
+
if (void 0 != err.error) return ctx.apply(err.error);
|
|
39
|
+
const exceptionLike = ctx.apply(err.message);
|
|
40
|
+
return {
|
|
41
|
+
...exceptionLike,
|
|
42
|
+
stack: this._buildLocationStack(err) ?? exceptionLike.stack,
|
|
41
43
|
synthetic: true
|
|
42
44
|
};
|
|
43
|
-
|
|
45
|
+
}
|
|
46
|
+
_hasUsableMessage(err) {
|
|
47
|
+
return (0, index_js_namespaceObject.isString)(err.message) && err.message.length > 0;
|
|
48
|
+
}
|
|
49
|
+
_buildLocationStack(err) {
|
|
50
|
+
const location = err;
|
|
51
|
+
if ((0, index_js_namespaceObject.isString)(location.filename) && location.filename.length > 0) {
|
|
52
|
+
const lineno = location.lineno ?? 0;
|
|
53
|
+
const colno = location.colno ?? 0;
|
|
54
|
+
return `Error\n at ${location.filename}:${lineno}:${colno}`;
|
|
55
|
+
}
|
|
44
56
|
}
|
|
45
57
|
}
|
|
46
58
|
exports.ErrorEventCoercer = __webpack_exports__.ErrorEventCoercer;
|
|
@@ -1,18 +1,30 @@
|
|
|
1
|
-
import { isErrorEvent } from "../../utils/index.mjs";
|
|
1
|
+
import { isErrorEvent, isString } from "../../utils/index.mjs";
|
|
2
2
|
class ErrorEventCoercer {
|
|
3
3
|
constructor(){}
|
|
4
4
|
match(err) {
|
|
5
|
-
|
|
5
|
+
if (!isErrorEvent(err)) return false;
|
|
6
|
+
const errorEvent = err;
|
|
7
|
+
return void 0 != errorEvent.error || this._hasUsableMessage(errorEvent);
|
|
6
8
|
}
|
|
7
9
|
coerce(err, ctx) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
stack:
|
|
10
|
+
if (void 0 != err.error) return ctx.apply(err.error);
|
|
11
|
+
const exceptionLike = ctx.apply(err.message);
|
|
12
|
+
return {
|
|
13
|
+
...exceptionLike,
|
|
14
|
+
stack: this._buildLocationStack(err) ?? exceptionLike.stack,
|
|
13
15
|
synthetic: true
|
|
14
16
|
};
|
|
15
|
-
|
|
17
|
+
}
|
|
18
|
+
_hasUsableMessage(err) {
|
|
19
|
+
return isString(err.message) && err.message.length > 0;
|
|
20
|
+
}
|
|
21
|
+
_buildLocationStack(err) {
|
|
22
|
+
const location = err;
|
|
23
|
+
if (isString(location.filename) && location.filename.length > 0) {
|
|
24
|
+
const lineno = location.lineno ?? 0;
|
|
25
|
+
const colno = location.colno ?? 0;
|
|
26
|
+
return `Error\n at ${location.filename}:${lineno}:${colno}`;
|
|
27
|
+
}
|
|
16
28
|
}
|
|
17
29
|
}
|
|
18
30
|
export { ErrorEventCoercer };
|
|
@@ -6,6 +6,7 @@ export declare class ObjectCoercer implements ErrorTrackingCoercer<ObjectLike> {
|
|
|
6
6
|
getType(err: Record<string, unknown>): string;
|
|
7
7
|
getValue(err: object): string;
|
|
8
8
|
private isSeverityLevel;
|
|
9
|
+
private getStack;
|
|
9
10
|
/** If a plain object has a property that is an `Error`, return this error. */
|
|
10
11
|
private getErrorPropertyFromObject;
|
|
11
12
|
private getObjectClassName;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object-coercer.d.ts","sourceRoot":"","sources":["../../../src/error-tracking/coercers/object-coercer.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,oBAAoB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 +39,7 @@ class ObjectCoercer {
|
|
|
39
39
|
return {
|
|
40
40
|
type: this.getType(candidate),
|
|
41
41
|
value: this.getValue(candidate),
|
|
42
|
-
stack: ctx.syntheticException?.stack,
|
|
42
|
+
stack: this.getStack(candidate) ?? ctx.syntheticException?.stack,
|
|
43
43
|
level: this.isSeverityLevel(candidate.level) ? candidate.level : 'error',
|
|
44
44
|
synthetic: true
|
|
45
45
|
};
|
|
@@ -61,6 +61,14 @@ class ObjectCoercer {
|
|
|
61
61
|
isSeverityLevel(x) {
|
|
62
62
|
return (0, index_js_namespaceObject.isString)(x) && !(0, index_js_namespaceObject.isEmptyString)(x) && external_types_js_namespaceObject.severityLevels.indexOf(x) >= 0;
|
|
63
63
|
}
|
|
64
|
+
getStack(candidate) {
|
|
65
|
+
try {
|
|
66
|
+
if ((0, index_js_namespaceObject.isString)(candidate.stacktrace) && candidate.stacktrace.length > 0) return candidate.stacktrace;
|
|
67
|
+
return (0, index_js_namespaceObject.isString)(candidate.stack) && candidate.stack.length > 0 ? candidate.stack : void 0;
|
|
68
|
+
} catch {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
64
72
|
getErrorPropertyFromObject(obj) {
|
|
65
73
|
for(const prop in obj)if (Object.prototype.hasOwnProperty.call(obj, prop)) {
|
|
66
74
|
const value = obj[prop];
|
|
@@ -11,7 +11,7 @@ class ObjectCoercer {
|
|
|
11
11
|
return {
|
|
12
12
|
type: this.getType(candidate),
|
|
13
13
|
value: this.getValue(candidate),
|
|
14
|
-
stack: ctx.syntheticException?.stack,
|
|
14
|
+
stack: this.getStack(candidate) ?? ctx.syntheticException?.stack,
|
|
15
15
|
level: this.isSeverityLevel(candidate.level) ? candidate.level : 'error',
|
|
16
16
|
synthetic: true
|
|
17
17
|
};
|
|
@@ -33,6 +33,14 @@ class ObjectCoercer {
|
|
|
33
33
|
isSeverityLevel(x) {
|
|
34
34
|
return isString(x) && !isEmptyString(x) && severityLevels.indexOf(x) >= 0;
|
|
35
35
|
}
|
|
36
|
+
getStack(candidate) {
|
|
37
|
+
try {
|
|
38
|
+
if (isString(candidate.stacktrace) && candidate.stacktrace.length > 0) return candidate.stacktrace;
|
|
39
|
+
return isString(candidate.stack) && candidate.stack.length > 0 ? candidate.stack : void 0;
|
|
40
|
+
} catch {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
36
44
|
getErrorPropertyFromObject(obj) {
|
|
37
45
|
for(const prop in obj)if (Object.prototype.hasOwnProperty.call(obj, prop)) {
|
|
38
46
|
const value = obj[prop];
|
package/dist/logs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/logs/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAA4B,MAAM,UAAU,CAAA;AAE3D,OAAO,KAAK,EAAoB,iBAAiB,EAAE,aAAa,EAAE,QAAQ,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAKtH,qBAAa,WAAW;IAgCpB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAMzB,OAAO,CAAC,QAAQ,CAAC,sBAAsB;IAIvC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC;IA7C9B,OAAO,CAAC,cAAc,CAAQ;IAG9B,OAAO,CAAC,aAAa,CAAQ;IAC7B,OAAO,CAAC,gBAAgB,CAAQ;IAIhC,OAAO,CAAC,uBAAuB,CAAQ;IACvC,OAAO,CAAC,WAAW,CAAC,CAAmC;IAGvD,OAAO,CAAC,aAAa,CAA6B;IAGlD,OAAO,CAAC,oBAAoB,CAAI;IAGhC,OAAO,CAAC,yBAAyB,CAAI;IAMrC,OAAO,CAAC,gBAAgB,CAAQ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e;IAwBvB;;;;;;;;;OASG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAad,WAAW;YAuEX,oBAAoB;IAYlC,OAAO,CAAC,wBAAwB;IAIhC,OAAO,CAAC,QAAQ;IA+BhB,OAAO,CAAC,cAAc;IAatB,OAAO,CAAC,eAAe;IAKvB,OAAO,CAAC,iBAAiB;IAKzB;;;;;;;;;OASG;IACG,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAcjD;;;;;;;;;;;OAWG;IACG,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASxD,OAAO,CAAC,kBAAkB;IAqB1B,OAAO,CAAC,gBAAgB;CAMzB"}
|
package/dist/logs/index.js
CHANGED
|
@@ -196,26 +196,13 @@ class PostHogLogs {
|
|
|
196
196
|
this._clearFlushTimer();
|
|
197
197
|
const flushPromise = this.flush().catch(()=>{});
|
|
198
198
|
if (void 0 === timeoutMs) return void await flushPromise;
|
|
199
|
-
await
|
|
200
|
-
flushPromise,
|
|
201
|
-
new Promise((resolve)=>(0, index_js_namespaceObject.safeSetTimeout)(resolve, timeoutMs))
|
|
202
|
-
]);
|
|
199
|
+
await (0, index_js_namespaceObject.raceWithTimeout)(flushPromise, timeoutMs);
|
|
203
200
|
}
|
|
204
201
|
async flushWithTimeout(timeoutMs) {
|
|
205
|
-
let timedOut = false;
|
|
206
202
|
const flushPromise = this.flush();
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}, timeoutMs));
|
|
211
|
-
try {
|
|
212
|
-
await Promise.race([
|
|
213
|
-
flushPromise,
|
|
214
|
-
timerPromise
|
|
215
|
-
]);
|
|
216
|
-
} finally{
|
|
217
|
-
if (timedOut) flushPromise.catch(()=>{});
|
|
218
|
-
}
|
|
203
|
+
await (0, index_js_namespaceObject.raceWithTimeout)(flushPromise, timeoutMs, ()=>{
|
|
204
|
+
flushPromise.catch(()=>{});
|
|
205
|
+
});
|
|
219
206
|
}
|
|
220
207
|
_flushInBackground() {
|
|
221
208
|
this.flush().then(()=>{
|
package/dist/logs/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { buildOtlpLogRecord, buildOtlpLogsPayload, buildResourceAttributes } from "./logs-utils.mjs";
|
|
2
2
|
import { PostHogPersistedProperty } from "../types.mjs";
|
|
3
|
-
import { isArray, safeSetTimeout } from "../utils/index.mjs";
|
|
3
|
+
import { isArray, raceWithTimeout, safeSetTimeout } from "../utils/index.mjs";
|
|
4
4
|
const MAX_FLUSH_BACKOFF_EXPONENT = 6;
|
|
5
5
|
class PostHogLogs {
|
|
6
6
|
constructor(_instance, _config, _logger, _getContext, _onReady, _waitForStoragePersist = ()=>Promise.resolve(), _scopeName){
|
|
@@ -168,26 +168,13 @@ class PostHogLogs {
|
|
|
168
168
|
this._clearFlushTimer();
|
|
169
169
|
const flushPromise = this.flush().catch(()=>{});
|
|
170
170
|
if (void 0 === timeoutMs) return void await flushPromise;
|
|
171
|
-
await
|
|
172
|
-
flushPromise,
|
|
173
|
-
new Promise((resolve)=>safeSetTimeout(resolve, timeoutMs))
|
|
174
|
-
]);
|
|
171
|
+
await raceWithTimeout(flushPromise, timeoutMs);
|
|
175
172
|
}
|
|
176
173
|
async flushWithTimeout(timeoutMs) {
|
|
177
|
-
let timedOut = false;
|
|
178
174
|
const flushPromise = this.flush();
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}, timeoutMs));
|
|
183
|
-
try {
|
|
184
|
-
await Promise.race([
|
|
185
|
-
flushPromise,
|
|
186
|
-
timerPromise
|
|
187
|
-
]);
|
|
188
|
-
} finally{
|
|
189
|
-
if (timedOut) flushPromise.catch(()=>{});
|
|
190
|
-
}
|
|
175
|
+
await raceWithTimeout(flushPromise, timeoutMs, ()=>{
|
|
176
|
+
flushPromise.catch(()=>{});
|
|
177
|
+
});
|
|
191
178
|
}
|
|
192
179
|
_flushInBackground() {
|
|
193
180
|
this.flush().then(()=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"posthog-core-stateless.d.ts","sourceRoot":"","sources":["../src/posthog-core-stateless.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACzE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAA;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAGnD,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,QAAQ,EACR,mBAAmB,EACnB,gBAAgB,EAGhB,yBAAyB,EACzB,iBAAiB,EACjB,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,wBAAwB,EAExB,MAAM,EACN,cAAc,EAEf,MAAM,SAAS,CAAA;AAChB,OAAO,EAML,gBAAgB,
|
|
1
|
+
{"version":3,"file":"posthog-core-stateless.d.ts","sourceRoot":"","sources":["../src/posthog-core-stateless.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACzE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAA;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAGnD,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,QAAQ,EACR,mBAAmB,EACnB,gBAAgB,EAGhB,yBAAyB,EACzB,iBAAiB,EACjB,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,wBAAwB,EAExB,MAAM,EACN,cAAc,EAEf,MAAM,SAAS,CAAA;AAChB,OAAO,EAML,gBAAgB,EAOjB,MAAM,SAAS,CAAA;AAEhB,OAAO,EACL,sBAAsB,EAMvB,MAAM,kBAAkB,CAAA;AAyBzB,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AS,CAAC,gBAAgB,IAAI;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE;IAavD;;;;;;;;;;;OAWG;cACa,SAAS,CACvB,aAAa,EAAE,CAAC,sBAAsB,GAAG,SAAS,CAAC,EAAE,EACrD,YAAY,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,EACxC,MAAM,GAAE,MAA4B,GACnC,OAAO,CAAC,IAAI,CAAC;YAiCF,MAAM;YAmCN,WAAW;IAsFzB;;;;;;;;;OASG;IACG,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAwC7E;;;;;OAKG;IACG,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,uBAAuB,CAAC;YA2CxE,cAAc;IAsDtB,SAAS,CAAC,iBAAiB,GAAE,MAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAyDjE;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,QAAQ,CAAC,iBAAiB,GAAE,MAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAYjE"}
|
|
@@ -918,21 +918,11 @@ class PostHogCoreStateless {
|
|
|
918
918
|
await logFlushError(e);
|
|
919
919
|
}
|
|
920
920
|
};
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
this._logger.error('Timed out while shutting down PostHog');
|
|
927
|
-
hasTimedOut = true;
|
|
928
|
-
reject('Timeout while shutting down PostHog. Some events may not have been sent.');
|
|
929
|
-
}, shutdownTimeoutMs);
|
|
930
|
-
}),
|
|
931
|
-
doShutdown()
|
|
932
|
-
]);
|
|
933
|
-
} finally{
|
|
934
|
-
clearTimeout(timeoutHandle);
|
|
935
|
-
}
|
|
921
|
+
return (0, index_js_namespaceObject.raceWithTimeout)(doShutdown(), shutdownTimeoutMs, ()=>{
|
|
922
|
+
this._logger.error('Timed out while shutting down PostHog');
|
|
923
|
+
hasTimedOut = true;
|
|
924
|
+
throw 'Timeout while shutting down PostHog. Some events may not have been sent.';
|
|
925
|
+
});
|
|
936
926
|
}
|
|
937
927
|
async shutdown(shutdownTimeoutMs = 30000) {
|
|
938
928
|
if (this.shutdownPromise) this._logger.warn('shutdown() called while already shutting down. shutdown() is meant to be called once before process exit - use flush() for per-request cleanup');
|
|
@@ -2,7 +2,7 @@ import { SimpleEventEmitter } from "./eventemitter.mjs";
|
|
|
2
2
|
import { getFeatureFlagValue, minimizeFlagCalledEventProperties, normalizeFlagsResponse } from "./featureFlagUtils.mjs";
|
|
3
3
|
import { gzipCompress, isGzipSupported } from "./gzip.mjs";
|
|
4
4
|
import { PostHogPersistedProperty } from "./types.mjs";
|
|
5
|
-
import { PromiseQueue, STRING_FORMAT, allSettled, createLogger, currentISOTime, getEventUuid, removeTrailingSlash, retriable, safeJsonStringify, safeSetTimeout } from "./utils/index.mjs";
|
|
5
|
+
import { PromiseQueue, STRING_FORMAT, allSettled, createLogger, currentISOTime, getEventUuid, raceWithTimeout, removeTrailingSlash, retriable, safeJsonStringify, safeSetTimeout } from "./utils/index.mjs";
|
|
6
6
|
import { uuidv7 } from "./vendor/uuidv7.mjs";
|
|
7
7
|
import { ErrorCoercer, ErrorPropertiesBuilder, ObjectCoercer, PrimitiveCoercer, StringCoercer, createDefaultStackParser } from "./error-tracking/index.mjs";
|
|
8
8
|
class PostHogFetchHttpError extends Error {
|
|
@@ -885,21 +885,11 @@ class PostHogCoreStateless {
|
|
|
885
885
|
await logFlushError(e);
|
|
886
886
|
}
|
|
887
887
|
};
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
this._logger.error('Timed out while shutting down PostHog');
|
|
894
|
-
hasTimedOut = true;
|
|
895
|
-
reject('Timeout while shutting down PostHog. Some events may not have been sent.');
|
|
896
|
-
}, shutdownTimeoutMs);
|
|
897
|
-
}),
|
|
898
|
-
doShutdown()
|
|
899
|
-
]);
|
|
900
|
-
} finally{
|
|
901
|
-
clearTimeout(timeoutHandle);
|
|
902
|
-
}
|
|
888
|
+
return raceWithTimeout(doShutdown(), shutdownTimeoutMs, ()=>{
|
|
889
|
+
this._logger.error('Timed out while shutting down PostHog');
|
|
890
|
+
hasTimedOut = true;
|
|
891
|
+
throw 'Timeout while shutting down PostHog. Some events may not have been sent.';
|
|
892
|
+
});
|
|
903
893
|
}
|
|
904
894
|
async shutdown(shutdownTimeoutMs = 30000) {
|
|
905
895
|
if (this.shutdownPromise) this._logger.warn('shutdown() called while already shutting down. shutdown() is meant to be called once before process exit - use flush() for per-request cleanup');
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export declare function retriable<T>(fn: () => Promise<T>, props: RetriableOptio
|
|
|
24
24
|
export declare function currentTimestamp(): number;
|
|
25
25
|
export declare function currentISOTime(): string;
|
|
26
26
|
export declare function safeSetTimeout(fn: () => void, timeout: number): any;
|
|
27
|
+
export declare function raceWithTimeout<T>(promise: Promise<T>, timeoutMs: number, onTimeout?: () => void): Promise<T | void>;
|
|
27
28
|
export declare const isPromise: (obj: any) => obj is Promise<any>;
|
|
28
29
|
export declare const isError: (x: unknown) => x is Error;
|
|
29
30
|
export declare function getFetch(): FetchLike | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEpC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,yBAAyB,CAAA;AACvC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,UAAU,CAAA;AACxB,cAAc,oBAAoB,CAAA;AAElC,eAAO,MAAM,aAAa,SAAS,CAAA;AAEnC,eAAO,MAAM,UAAU,QAAoE,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raceWithTimeout: ()=>raceWithTimeout,
|
|
86
87
|
removeTrailingSlash: ()=>removeTrailingSlash,
|
|
87
88
|
retriable: ()=>retriable,
|
|
88
89
|
safeSetTimeout: ()=>safeSetTimeout,
|
|
@@ -104,6 +105,7 @@ var __webpack_exports__ = {};
|
|
|
104
105
|
"stripUrlHash",
|
|
105
106
|
"STRING_FORMAT",
|
|
106
107
|
"currentTimestamp",
|
|
108
|
+
"raceWithTimeout",
|
|
107
109
|
"getFetch",
|
|
108
110
|
"getEventUuid",
|
|
109
111
|
"isPromise"
|
|
@@ -127,6 +129,7 @@ var __webpack_exports__ = {};
|
|
|
127
129
|
"stripUrlHash",
|
|
128
130
|
"STRING_FORMAT",
|
|
129
131
|
"currentTimestamp",
|
|
132
|
+
"raceWithTimeout",
|
|
130
133
|
"getFetch",
|
|
131
134
|
"getEventUuid",
|
|
132
135
|
"isPromise"
|
|
@@ -150,6 +153,7 @@ var __webpack_exports__ = {};
|
|
|
150
153
|
"stripUrlHash",
|
|
151
154
|
"STRING_FORMAT",
|
|
152
155
|
"currentTimestamp",
|
|
156
|
+
"raceWithTimeout",
|
|
153
157
|
"getFetch",
|
|
154
158
|
"getEventUuid",
|
|
155
159
|
"isPromise"
|
|
@@ -173,6 +177,7 @@ var __webpack_exports__ = {};
|
|
|
173
177
|
"stripUrlHash",
|
|
174
178
|
"STRING_FORMAT",
|
|
175
179
|
"currentTimestamp",
|
|
180
|
+
"raceWithTimeout",
|
|
176
181
|
"getFetch",
|
|
177
182
|
"getEventUuid",
|
|
178
183
|
"isPromise"
|
|
@@ -196,6 +201,7 @@ var __webpack_exports__ = {};
|
|
|
196
201
|
"stripUrlHash",
|
|
197
202
|
"STRING_FORMAT",
|
|
198
203
|
"currentTimestamp",
|
|
204
|
+
"raceWithTimeout",
|
|
199
205
|
"getFetch",
|
|
200
206
|
"getEventUuid",
|
|
201
207
|
"isPromise"
|
|
@@ -219,6 +225,7 @@ var __webpack_exports__ = {};
|
|
|
219
225
|
"stripUrlHash",
|
|
220
226
|
"STRING_FORMAT",
|
|
221
227
|
"currentTimestamp",
|
|
228
|
+
"raceWithTimeout",
|
|
222
229
|
"getFetch",
|
|
223
230
|
"getEventUuid",
|
|
224
231
|
"isPromise"
|
|
@@ -242,6 +249,7 @@ var __webpack_exports__ = {};
|
|
|
242
249
|
"stripUrlHash",
|
|
243
250
|
"STRING_FORMAT",
|
|
244
251
|
"currentTimestamp",
|
|
252
|
+
"raceWithTimeout",
|
|
245
253
|
"getFetch",
|
|
246
254
|
"getEventUuid",
|
|
247
255
|
"isPromise"
|
|
@@ -265,6 +273,7 @@ var __webpack_exports__ = {};
|
|
|
265
273
|
"stripUrlHash",
|
|
266
274
|
"STRING_FORMAT",
|
|
267
275
|
"currentTimestamp",
|
|
276
|
+
"raceWithTimeout",
|
|
268
277
|
"getFetch",
|
|
269
278
|
"getEventUuid",
|
|
270
279
|
"isPromise"
|
|
@@ -288,6 +297,7 @@ var __webpack_exports__ = {};
|
|
|
288
297
|
"stripUrlHash",
|
|
289
298
|
"STRING_FORMAT",
|
|
290
299
|
"currentTimestamp",
|
|
300
|
+
"raceWithTimeout",
|
|
291
301
|
"getFetch",
|
|
292
302
|
"getEventUuid",
|
|
293
303
|
"isPromise"
|
|
@@ -342,6 +352,26 @@ var __webpack_exports__ = {};
|
|
|
342
352
|
t?.unref && t?.unref();
|
|
343
353
|
return t;
|
|
344
354
|
}
|
|
355
|
+
async function raceWithTimeout(promise, timeoutMs, onTimeout) {
|
|
356
|
+
let timeoutHandle;
|
|
357
|
+
try {
|
|
358
|
+
return await Promise.race([
|
|
359
|
+
promise,
|
|
360
|
+
new Promise((resolve, reject)=>{
|
|
361
|
+
timeoutHandle = safeSetTimeout(()=>{
|
|
362
|
+
try {
|
|
363
|
+
onTimeout?.();
|
|
364
|
+
resolve();
|
|
365
|
+
} catch (error) {
|
|
366
|
+
reject(error);
|
|
367
|
+
}
|
|
368
|
+
}, timeoutMs);
|
|
369
|
+
})
|
|
370
|
+
]);
|
|
371
|
+
} finally{
|
|
372
|
+
clearTimeout(timeoutHandle);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
345
375
|
const isPromise = (obj)=>obj && 'function' == typeof obj.then;
|
|
346
376
|
const isError = (x)=>x instanceof Error;
|
|
347
377
|
function getFetch() {
|
|
@@ -368,6 +398,7 @@ exports.getFetch = __webpack_exports__.getFetch;
|
|
|
368
398
|
exports.isError = __webpack_exports__.isError;
|
|
369
399
|
exports.isPromise = __webpack_exports__.isPromise;
|
|
370
400
|
exports.isValidUUID = __webpack_exports__.isValidUUID;
|
|
401
|
+
exports.raceWithTimeout = __webpack_exports__.raceWithTimeout;
|
|
371
402
|
exports.removeTrailingSlash = __webpack_exports__.removeTrailingSlash;
|
|
372
403
|
exports.retriable = __webpack_exports__.retriable;
|
|
373
404
|
exports.safeSetTimeout = __webpack_exports__.safeSetTimeout;
|
|
@@ -384,6 +415,7 @@ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
|
384
415
|
"isError",
|
|
385
416
|
"isPromise",
|
|
386
417
|
"isValidUUID",
|
|
418
|
+
"raceWithTimeout",
|
|
387
419
|
"removeTrailingSlash",
|
|
388
420
|
"retriable",
|
|
389
421
|
"safeSetTimeout",
|
package/dist/utils/index.mjs
CHANGED
|
@@ -54,6 +54,26 @@ function safeSetTimeout(fn, timeout) {
|
|
|
54
54
|
t?.unref && t?.unref();
|
|
55
55
|
return t;
|
|
56
56
|
}
|
|
57
|
+
async function raceWithTimeout(promise, timeoutMs, onTimeout) {
|
|
58
|
+
let timeoutHandle;
|
|
59
|
+
try {
|
|
60
|
+
return await Promise.race([
|
|
61
|
+
promise,
|
|
62
|
+
new Promise((resolve, reject)=>{
|
|
63
|
+
timeoutHandle = safeSetTimeout(()=>{
|
|
64
|
+
try {
|
|
65
|
+
onTimeout?.();
|
|
66
|
+
resolve();
|
|
67
|
+
} catch (error) {
|
|
68
|
+
reject(error);
|
|
69
|
+
}
|
|
70
|
+
}, timeoutMs);
|
|
71
|
+
})
|
|
72
|
+
]);
|
|
73
|
+
} finally{
|
|
74
|
+
clearTimeout(timeoutHandle);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
57
77
|
const isPromise = (obj)=>obj && 'function' == typeof obj.then;
|
|
58
78
|
const isError = (x)=>x instanceof Error;
|
|
59
79
|
function getFetch() {
|
|
@@ -68,4 +88,4 @@ function allSettled(promises) {
|
|
|
68
88
|
reason
|
|
69
89
|
}))));
|
|
70
90
|
}
|
|
71
|
-
export { STRING_FORMAT, UUID_REGEX, allSettled, assert, currentISOTime, currentTimestamp, getEventUuid, getFetch, isError, isPromise, isValidUUID, removeTrailingSlash, retriable, safeSetTimeout, stripUrlHash };
|
|
91
|
+
export { STRING_FORMAT, UUID_REGEX, allSettled, assert, currentISOTime, currentTimestamp, getEventUuid, getFetch, isError, isPromise, isValidUUID, raceWithTimeout, removeTrailingSlash, retriable, safeSetTimeout, stripUrlHash };
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isError } from '@/utils/type-utils'
|
|
2
2
|
import { CoercingContext, ErrorTrackingCoercer, ExceptionLike } from '../types'
|
|
3
3
|
|
|
4
4
|
export class ErrorCoercer implements ErrorTrackingCoercer<Error> {
|
|
5
5
|
match(err: unknown): err is Error {
|
|
6
|
-
return
|
|
6
|
+
return isError(err)
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
coerce(err: Error, ctx: CoercingContext): ExceptionLike {
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { ErrorPropertiesBuilder } from '../error-properties-builder'
|
|
2
|
+
import { createDefaultStackParser } from '../parsers'
|
|
3
|
+
import { Exception } from '../types'
|
|
4
|
+
import { ErrorCoercer } from './error-coercer'
|
|
5
|
+
import { ErrorEventCoercer } from './error-event-coercer'
|
|
6
|
+
import { EventCoercer } from './event-coercer'
|
|
7
|
+
import { ObjectCoercer } from './object-coercer'
|
|
8
|
+
import { PrimitiveCoercer } from './primitive-coercer'
|
|
9
|
+
import { StringCoercer } from './string-coercer'
|
|
10
|
+
|
|
11
|
+
// `ErrorEvent` is not available in the Node test environment, so use its runtime brand.
|
|
12
|
+
class FakeErrorEvent {
|
|
13
|
+
message?: string
|
|
14
|
+
error?: unknown
|
|
15
|
+
filename?: string
|
|
16
|
+
lineno?: number
|
|
17
|
+
colno?: number;
|
|
18
|
+
[Symbol.toStringTag] = 'ErrorEvent'
|
|
19
|
+
|
|
20
|
+
constructor(init: Partial<Omit<FakeErrorEvent, typeof Symbol.toStringTag>> = {}) {
|
|
21
|
+
Object.assign(this, init)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe('ErrorEventCoercer', () => {
|
|
26
|
+
const coercer = new ErrorEventCoercer()
|
|
27
|
+
const errorPropertiesBuilder = new ErrorPropertiesBuilder(
|
|
28
|
+
[coercer, new ErrorCoercer(), new EventCoercer(), new ObjectCoercer(), new StringCoercer(), new PrimitiveCoercer()],
|
|
29
|
+
createDefaultStackParser()
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
function buildException(input: unknown, syntheticException?: Error): Exception {
|
|
33
|
+
return errorPropertiesBuilder.buildFromUnknown(input, { syntheticException }).$exception_list[0]
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
it.each([
|
|
37
|
+
{
|
|
38
|
+
name: 'an ErrorEvent carrying an Error',
|
|
39
|
+
input: new FakeErrorEvent({ error: new Error('boom') }),
|
|
40
|
+
expected: true,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: 'an ErrorEvent carrying a message',
|
|
44
|
+
input: new FakeErrorEvent({ message: 'Script error.' }),
|
|
45
|
+
expected: true,
|
|
46
|
+
},
|
|
47
|
+
{ name: 'an ErrorEvent without an error or message', input: new FakeErrorEvent(), expected: false },
|
|
48
|
+
{ name: 'an ErrorEvent with an empty message', input: new FakeErrorEvent({ message: '' }), expected: false },
|
|
49
|
+
{ name: 'a non-ErrorEvent', input: { message: 'not an ErrorEvent' }, expected: false },
|
|
50
|
+
])('matches $name: $expected', ({ input, expected }) => {
|
|
51
|
+
expect(coercer.match(input)).toBe(expected)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('unwraps the Error carried by the ErrorEvent', () => {
|
|
55
|
+
const error = new Error('Something broke')
|
|
56
|
+
error.name = 'CustomTestError'
|
|
57
|
+
|
|
58
|
+
expect(buildException(new FakeErrorEvent({ message: 'ignored', error }))).toMatchObject({
|
|
59
|
+
type: 'CustomTestError',
|
|
60
|
+
value: 'Something broke',
|
|
61
|
+
mechanism: { synthetic: false },
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('preserves the message and location when there is no Error object', () => {
|
|
66
|
+
const exception = buildException(
|
|
67
|
+
new FakeErrorEvent({
|
|
68
|
+
message: 'Uncaught TypeError: x is not a function',
|
|
69
|
+
filename: 'https://example.com/app.js',
|
|
70
|
+
lineno: 42,
|
|
71
|
+
colno: 13,
|
|
72
|
+
})
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
expect(exception).toMatchObject({
|
|
76
|
+
type: 'TypeError',
|
|
77
|
+
value: 'x is not a function',
|
|
78
|
+
mechanism: { synthetic: true },
|
|
79
|
+
stacktrace: {
|
|
80
|
+
frames: [
|
|
81
|
+
expect.objectContaining({
|
|
82
|
+
filename: 'https://example.com/app.js',
|
|
83
|
+
lineno: 42,
|
|
84
|
+
colno: 13,
|
|
85
|
+
}),
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it('does not parse frame-shaped lines from a multiline message', () => {
|
|
92
|
+
const exception = buildException(
|
|
93
|
+
new FakeErrorEvent({
|
|
94
|
+
message: 'Something broke\n at injected (https://example.com/injected.js:1:2)',
|
|
95
|
+
filename: 'https://example.com/app.js',
|
|
96
|
+
lineno: 42,
|
|
97
|
+
colno: 13,
|
|
98
|
+
})
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
expect(exception.stacktrace?.frames).toEqual([
|
|
102
|
+
expect.objectContaining({
|
|
103
|
+
filename: 'https://example.com/app.js',
|
|
104
|
+
lineno: 42,
|
|
105
|
+
colno: 13,
|
|
106
|
+
}),
|
|
107
|
+
])
|
|
108
|
+
})
|
|
109
|
+
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CoercingContext, ErrorTrackingCoercer, ExceptionLike } from '../types'
|
|
2
|
-
import { isErrorEvent } from '@/utils'
|
|
2
|
+
import { isErrorEvent, isString } from '@/utils'
|
|
3
3
|
|
|
4
4
|
// Structural subset of the DOM `ErrorEvent`. Avoids leaking a DOM-only global
|
|
5
5
|
// into the public type surface so non-DOM consumers (e.g. React Native, whose
|
|
@@ -10,24 +10,48 @@ interface ErrorEventLike {
|
|
|
10
10
|
error?: unknown
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
interface ErrorEventLocation {
|
|
14
|
+
filename?: string
|
|
15
|
+
lineno?: number
|
|
16
|
+
colno?: number
|
|
17
|
+
}
|
|
18
|
+
|
|
13
19
|
export class ErrorEventCoercer implements ErrorTrackingCoercer<ErrorEventLike> {
|
|
14
20
|
constructor() {}
|
|
15
21
|
|
|
16
22
|
match(err: unknown): err is ErrorEventLike {
|
|
17
|
-
|
|
23
|
+
if (!isErrorEvent(err)) {
|
|
24
|
+
return false
|
|
25
|
+
}
|
|
26
|
+
const errorEvent = err as ErrorEventLike
|
|
27
|
+
return errorEvent.error != undefined || this._hasUsableMessage(errorEvent)
|
|
18
28
|
}
|
|
19
29
|
|
|
20
30
|
coerce(err: ErrorEventLike, ctx: CoercingContext): ExceptionLike {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
if (err.error != undefined) {
|
|
32
|
+
return ctx.apply(err.error)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const exceptionLike = ctx.apply(err.message)
|
|
36
|
+
return {
|
|
37
|
+
...exceptionLike,
|
|
38
|
+
stack: this._buildLocationStack(err) ?? exceptionLike.stack,
|
|
39
|
+
synthetic: true,
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private _hasUsableMessage(err: ErrorEventLike): boolean {
|
|
44
|
+
return isString(err.message) && err.message.length > 0
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private _buildLocationStack(err: ErrorEventLike): string | undefined {
|
|
48
|
+
const location = err as ErrorEventLike & ErrorEventLocation
|
|
49
|
+
if (isString(location.filename) && location.filename.length > 0) {
|
|
50
|
+
const lineno = location.lineno ?? 0
|
|
51
|
+
const colno = location.colno ?? 0
|
|
52
|
+
// The message stays in `value`, which prevents multiline messages from being parsed as extra frames.
|
|
53
|
+
return `Error\n at ${location.filename}:${lineno}:${colno}`
|
|
31
54
|
}
|
|
55
|
+
return undefined
|
|
32
56
|
}
|
|
33
57
|
}
|
|
@@ -21,7 +21,7 @@ export class ObjectCoercer implements ErrorTrackingCoercer<ObjectLike> {
|
|
|
21
21
|
return {
|
|
22
22
|
type: this.getType(candidate),
|
|
23
23
|
value: this.getValue(candidate),
|
|
24
|
-
stack: ctx.syntheticException?.stack,
|
|
24
|
+
stack: this.getStack(candidate) ?? ctx.syntheticException?.stack,
|
|
25
25
|
level: this.isSeverityLevel(candidate.level) ? candidate.level : 'error',
|
|
26
26
|
synthetic: true,
|
|
27
27
|
}
|
|
@@ -55,6 +55,17 @@ export class ObjectCoercer implements ErrorTrackingCoercer<ObjectLike> {
|
|
|
55
55
|
return isString(x) && !isEmptyString(x) && severityLevels.indexOf(x as SeverityLevel) >= 0
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
private getStack(candidate: ObjectLike): string | undefined {
|
|
59
|
+
try {
|
|
60
|
+
if (isString(candidate.stacktrace) && candidate.stacktrace.length > 0) {
|
|
61
|
+
return candidate.stacktrace
|
|
62
|
+
}
|
|
63
|
+
return isString(candidate.stack) && candidate.stack.length > 0 ? candidate.stack : undefined
|
|
64
|
+
} catch {
|
|
65
|
+
return undefined
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
58
69
|
/** If a plain object has a property that is an `Error`, return this error. */
|
|
59
70
|
private getErrorPropertyFromObject(obj: Record<string, unknown>): Error | undefined {
|
|
60
71
|
for (const prop in obj) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { runInNewContext } from 'node:vm'
|
|
2
|
+
|
|
1
3
|
import {
|
|
2
4
|
DOMExceptionCoercer,
|
|
3
5
|
ErrorEventCoercer,
|
|
@@ -110,6 +112,28 @@ describe('ErrorPropertiesBuilder', () => {
|
|
|
110
112
|
})
|
|
111
113
|
})
|
|
112
114
|
|
|
115
|
+
it('should preserve a cross-realm error', () => {
|
|
116
|
+
const crossRealmError = runInNewContext(
|
|
117
|
+
`new TypeError('cross-realm error', {
|
|
118
|
+
cause: new Error('cross-realm cause')
|
|
119
|
+
})`
|
|
120
|
+
)
|
|
121
|
+
expect(crossRealmError).not.toBeInstanceOf(Error)
|
|
122
|
+
|
|
123
|
+
expect(coerceInput(crossRealmError)).toMatchObject({
|
|
124
|
+
type: 'TypeError',
|
|
125
|
+
value: 'cross-realm error',
|
|
126
|
+
stack: crossRealmError.stack,
|
|
127
|
+
synthetic: false,
|
|
128
|
+
cause: {
|
|
129
|
+
type: 'Error',
|
|
130
|
+
value: 'cross-realm cause',
|
|
131
|
+
stack: crossRealmError.cause.stack,
|
|
132
|
+
synthetic: false,
|
|
133
|
+
},
|
|
134
|
+
})
|
|
135
|
+
})
|
|
136
|
+
|
|
113
137
|
it('should handle error with error cause', () => {
|
|
114
138
|
const secondError = new CustomTestError('My original error')
|
|
115
139
|
const firstError = new CustomTestError('My wrapped error', secondError)
|
|
@@ -225,5 +249,23 @@ describe('ErrorPropertiesBuilder', () => {
|
|
|
225
249
|
stack: buriedError.stack,
|
|
226
250
|
})
|
|
227
251
|
})
|
|
252
|
+
|
|
253
|
+
it('should preserve an error-like stack from a CustomEvent wrapping a PromiseRejectionEvent', () => {
|
|
254
|
+
const stack = 'TypeError: Extension context invalidated.\n at extension.js:1:2'
|
|
255
|
+
const customEvent = new CustomEvent('unhandledrejection', {
|
|
256
|
+
detail: {
|
|
257
|
+
reason: {
|
|
258
|
+
name: 'TypeError',
|
|
259
|
+
message: 'Extension context invalidated.',
|
|
260
|
+
stack,
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
})
|
|
264
|
+
|
|
265
|
+
expect(coerceInput(customEvent)).toMatchObject({
|
|
266
|
+
value: "'TypeError' captured as exception with message: 'Extension context invalidated.'",
|
|
267
|
+
stack,
|
|
268
|
+
})
|
|
269
|
+
})
|
|
228
270
|
})
|
|
229
271
|
})
|
package/src/logs/index.spec.ts
CHANGED
|
@@ -1013,6 +1013,28 @@ describe('PostHogLogs', () => {
|
|
|
1013
1013
|
})
|
|
1014
1014
|
})
|
|
1015
1015
|
|
|
1016
|
+
describe('flushWithTimeout', () => {
|
|
1017
|
+
beforeEach(() => jest.useFakeTimers())
|
|
1018
|
+
afterEach(() => jest.useRealTimers())
|
|
1019
|
+
|
|
1020
|
+
it('clears the timeout timer when the flush finishes first', async () => {
|
|
1021
|
+
const logs = new PostHogLogs(
|
|
1022
|
+
mockInstance,
|
|
1023
|
+
resolveForTest(),
|
|
1024
|
+
logger,
|
|
1025
|
+
getContextFor(mockInstance),
|
|
1026
|
+
immediateOnReady
|
|
1027
|
+
)
|
|
1028
|
+
mockInstance.setPersistedProperty(PostHogPersistedProperty.LogsQueue, [
|
|
1029
|
+
{ record: { body: { stringValue: 'a' } } },
|
|
1030
|
+
])
|
|
1031
|
+
|
|
1032
|
+
await logs.flushWithTimeout(5000)
|
|
1033
|
+
|
|
1034
|
+
expect(jest.getTimerCount()).toBe(0)
|
|
1035
|
+
})
|
|
1036
|
+
})
|
|
1037
|
+
|
|
1016
1038
|
describe('shutdown', () => {
|
|
1017
1039
|
beforeEach(() => jest.useFakeTimers())
|
|
1018
1040
|
afterEach(() => jest.useRealTimers())
|
|
@@ -1037,6 +1059,21 @@ describe('PostHogLogs', () => {
|
|
|
1037
1059
|
expect(mockInstance._sendLogsBatch).toHaveBeenCalledTimes(1)
|
|
1038
1060
|
})
|
|
1039
1061
|
|
|
1062
|
+
it('clears the timeout timer when the final flush finishes first', async () => {
|
|
1063
|
+
const logs = new PostHogLogs(
|
|
1064
|
+
mockInstance,
|
|
1065
|
+
resolveForTest({ flushIntervalMs: 5000 }),
|
|
1066
|
+
logger,
|
|
1067
|
+
getContextFor(mockInstance),
|
|
1068
|
+
immediateOnReady
|
|
1069
|
+
)
|
|
1070
|
+
logs.captureLog({ body: 'a' })
|
|
1071
|
+
|
|
1072
|
+
await logs.shutdown(5000)
|
|
1073
|
+
|
|
1074
|
+
expect(jest.getTimerCount()).toBe(0)
|
|
1075
|
+
})
|
|
1076
|
+
|
|
1040
1077
|
it('swallows flush errors so shutdown can complete', async () => {
|
|
1041
1078
|
mockInstance._sendLogsBatch = jest.fn(() => Promise.resolve({ kind: 'fatal', error: new Error('boom') }))
|
|
1042
1079
|
const logs = new PostHogLogs(
|
package/src/logs/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { LogAttributeValue } from '@posthog/types'
|
|
2
2
|
import { buildOtlpLogRecord, buildOtlpLogsPayload, buildResourceAttributes } from './logs-utils'
|
|
3
3
|
import { Logger, PostHogPersistedProperty } from '../types'
|
|
4
|
-
import { isArray, safeSetTimeout } from '../utils'
|
|
4
|
+
import { isArray, raceWithTimeout, safeSetTimeout } from '../utils'
|
|
5
5
|
import type { BufferedLogEntry, CaptureLogOptions, LogSdkContext, LogsHost, ResolvedPostHogLogsConfig } from './types'
|
|
6
6
|
|
|
7
7
|
// Caps the retry backoff at 2^6 = 64× the flush interval.
|
|
@@ -383,7 +383,7 @@ export class PostHogLogs {
|
|
|
383
383
|
await flushPromise
|
|
384
384
|
return
|
|
385
385
|
}
|
|
386
|
-
await
|
|
386
|
+
await raceWithTimeout(flushPromise, timeoutMs)
|
|
387
387
|
}
|
|
388
388
|
|
|
389
389
|
/**
|
|
@@ -399,23 +399,12 @@ export class PostHogLogs {
|
|
|
399
399
|
* unhandled-rejection logs — the next regular flush cycle will retry.
|
|
400
400
|
*/
|
|
401
401
|
async flushWithTimeout(timeoutMs: number): Promise<void> {
|
|
402
|
-
let timedOut = false
|
|
403
402
|
const flushPromise = this.flush()
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
)
|
|
410
|
-
try {
|
|
411
|
-
await Promise.race([flushPromise, timerPromise])
|
|
412
|
-
} finally {
|
|
413
|
-
if (timedOut) {
|
|
414
|
-
// Race lost — flush is still in flight. Attach a no-op rejection
|
|
415
|
-
// handler so a late failure isn't logged as unhandled.
|
|
416
|
-
void flushPromise.catch(() => {})
|
|
417
|
-
}
|
|
418
|
-
}
|
|
403
|
+
await raceWithTimeout(flushPromise, timeoutMs, () => {
|
|
404
|
+
// Race lost — flush is still in flight. Attach a no-op rejection
|
|
405
|
+
// handler so a late failure isn't logged as unhandled.
|
|
406
|
+
void flushPromise.catch(() => {})
|
|
407
|
+
})
|
|
419
408
|
}
|
|
420
409
|
|
|
421
410
|
private _flushInBackground(): void {
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
removeTrailingSlash,
|
|
32
32
|
retriable,
|
|
33
33
|
RetriableOptions,
|
|
34
|
+
raceWithTimeout,
|
|
34
35
|
safeSetTimeout,
|
|
35
36
|
STRING_FORMAT,
|
|
36
37
|
createLogger,
|
|
@@ -1724,21 +1725,11 @@ export abstract class PostHogCoreStateless {
|
|
|
1724
1725
|
}
|
|
1725
1726
|
}
|
|
1726
1727
|
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
this._logger.error('Timed out while shutting down PostHog')
|
|
1733
|
-
hasTimedOut = true
|
|
1734
|
-
reject('Timeout while shutting down PostHog. Some events may not have been sent.')
|
|
1735
|
-
}, shutdownTimeoutMs)
|
|
1736
|
-
}),
|
|
1737
|
-
doShutdown(),
|
|
1738
|
-
])
|
|
1739
|
-
} finally {
|
|
1740
|
-
clearTimeout(timeoutHandle)
|
|
1741
|
-
}
|
|
1728
|
+
return raceWithTimeout(doShutdown(), shutdownTimeoutMs, () => {
|
|
1729
|
+
this._logger.error('Timed out while shutting down PostHog')
|
|
1730
|
+
hasTimedOut = true
|
|
1731
|
+
throw 'Timeout while shutting down PostHog. Some events may not have been sent.'
|
|
1732
|
+
})
|
|
1742
1733
|
}
|
|
1743
1734
|
|
|
1744
1735
|
/**
|
package/src/utils/index.ts
CHANGED
|
@@ -93,6 +93,32 @@ export function safeSetTimeout(fn: () => void, timeout: number): any {
|
|
|
93
93
|
return t
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
export async function raceWithTimeout<T>(
|
|
97
|
+
promise: Promise<T>,
|
|
98
|
+
timeoutMs: number,
|
|
99
|
+
onTimeout?: () => void
|
|
100
|
+
): Promise<T | void> {
|
|
101
|
+
let timeoutHandle: ReturnType<typeof safeSetTimeout> | undefined
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
return await Promise.race([
|
|
105
|
+
promise,
|
|
106
|
+
new Promise<void>((resolve, reject) => {
|
|
107
|
+
timeoutHandle = safeSetTimeout(() => {
|
|
108
|
+
try {
|
|
109
|
+
onTimeout?.()
|
|
110
|
+
resolve()
|
|
111
|
+
} catch (error) {
|
|
112
|
+
reject(error)
|
|
113
|
+
}
|
|
114
|
+
}, timeoutMs)
|
|
115
|
+
}),
|
|
116
|
+
])
|
|
117
|
+
} finally {
|
|
118
|
+
clearTimeout(timeoutHandle)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
96
122
|
// NOTE: We opt for this slightly imperfect check as the global "Promise" object can get mutated in certain environments
|
|
97
123
|
export const isPromise = (obj: any): obj is Promise<any> => {
|
|
98
124
|
return obj && typeof obj.then === 'function'
|