@posthog/core 1.52.2 → 1.53.0
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/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +82 -21
- package/dist/index.mjs +4 -0
- package/dist/logs/index.d.ts +3 -2
- package/dist/logs/index.d.ts.map +1 -1
- package/dist/logs/index.js +28 -22
- package/dist/logs/index.mjs +29 -23
- package/dist/logs/logs-utils.js +1 -1
- package/dist/logs/logs-utils.mjs +2 -2
- package/dist/logs/types.d.ts +2 -2
- package/dist/metrics/index.d.ts +5 -2
- package/dist/metrics/index.d.ts.map +1 -1
- package/dist/metrics/index.js +28 -14
- package/dist/metrics/index.mjs +29 -15
- package/dist/metrics/metrics-utils.d.ts.map +1 -1
- package/dist/metrics/metrics-utils.js +1 -2
- package/dist/metrics/metrics-utils.mjs +2 -3
- package/dist/metrics/types.d.ts +7 -0
- package/dist/metrics/types.d.ts.map +1 -1
- package/dist/posthog-core-stateless.d.ts +32 -4
- package/dist/posthog-core-stateless.d.ts.map +1 -1
- package/dist/posthog-core-stateless.js +68 -20
- package/dist/posthog-core-stateless.mjs +68 -20
- package/dist/traces/config.d.ts +13 -0
- package/dist/traces/config.d.ts.map +1 -0
- package/dist/traces/config.js +101 -0
- package/dist/traces/config.mjs +63 -0
- package/dist/traces/context.d.ts +18 -0
- package/dist/traces/context.d.ts.map +1 -0
- package/dist/traces/context.js +53 -0
- package/dist/traces/context.mjs +15 -0
- package/dist/traces/ids.d.ts +12 -0
- package/dist/traces/ids.d.ts.map +1 -0
- package/dist/traces/ids.js +92 -0
- package/dist/traces/ids.mjs +42 -0
- package/dist/traces/index.d.ts +150 -0
- package/dist/traces/index.d.ts.map +1 -0
- package/dist/traces/index.js +551 -0
- package/dist/traces/index.mjs +513 -0
- package/dist/traces/otlp.d.ts +24 -0
- package/dist/traces/otlp.d.ts.map +1 -0
- package/dist/traces/otlp.js +158 -0
- package/dist/traces/otlp.mjs +108 -0
- package/dist/traces/sanitize.d.ts +32 -0
- package/dist/traces/sanitize.d.ts.map +1 -0
- package/dist/traces/sanitize.js +93 -0
- package/dist/traces/sanitize.mjs +43 -0
- package/dist/traces/span.d.ts +189 -0
- package/dist/traces/span.d.ts.map +1 -0
- package/dist/traces/span.js +533 -0
- package/dist/traces/span.mjs +462 -0
- package/dist/traces/traceparent.d.ts +51 -0
- package/dist/traces/traceparent.d.ts.map +1 -0
- package/dist/traces/traceparent.js +116 -0
- package/dist/traces/traceparent.mjs +63 -0
- package/dist/traces/types.d.ts +114 -0
- package/dist/traces/types.d.ts.map +1 -0
- package/dist/traces/types.js +18 -0
- package/dist/traces/types.mjs +1 -0
- package/dist/utils/backoff.d.ts +23 -0
- package/dist/utils/backoff.d.ts.map +1 -0
- package/dist/utils/backoff.js +65 -0
- package/dist/utils/backoff.mjs +14 -0
- package/dist/utils/flush-timer.d.ts +26 -0
- package/dist/utils/flush-timer.d.ts.map +1 -0
- package/dist/utils/flush-timer.js +67 -0
- package/dist/utils/flush-timer.mjs +29 -0
- package/dist/utils/json-utils.d.ts +7 -0
- package/dist/utils/json-utils.d.ts.map +1 -1
- package/dist/utils/json-utils.js +27 -0
- package/dist/utils/json-utils.mjs +25 -1
- package/dist/utils/otlp-resource.d.ts +13 -2
- package/dist/utils/otlp-resource.d.ts.map +1 -1
- package/dist/utils/otlp-resource.js +34 -7
- package/dist/utils/otlp-resource.mjs +26 -2
- package/dist/utils/retry-after.d.ts +55 -0
- package/dist/utils/retry-after.d.ts.map +1 -0
- package/dist/utils/retry-after.js +95 -0
- package/dist/utils/retry-after.mjs +50 -0
- package/package.json +3 -3
- package/src/index.ts +18 -0
- package/src/logs/index.spec.ts +490 -2
- package/src/logs/index.ts +63 -31
- package/src/logs/logs-utils.ts +2 -2
- package/src/logs/types.ts +2 -2
- package/src/metrics/index.spec.ts +304 -0
- package/src/metrics/index.ts +53 -16
- package/src/metrics/metrics-utils.ts +2 -3
- package/src/metrics/types.ts +10 -2
- package/src/posthog-core-stateless.ts +157 -38
- package/src/traces/config.spec.ts +271 -0
- package/src/traces/config.ts +142 -0
- package/src/traces/context.ts +30 -0
- package/src/traces/ids.spec.ts +115 -0
- package/src/traces/ids.ts +75 -0
- package/src/traces/index.spec.ts +3187 -0
- package/src/traces/index.ts +1060 -0
- package/src/traces/live-spans.spec.ts +69 -0
- package/src/traces/otlp.spec.ts +368 -0
- package/src/traces/otlp.ts +191 -0
- package/src/traces/sanitize.ts +116 -0
- package/src/traces/span.spec.ts +1122 -0
- package/src/traces/span.ts +822 -0
- package/src/traces/traceparent.spec.ts +184 -0
- package/src/traces/traceparent.ts +172 -0
- package/src/traces/types.ts +140 -0
- package/src/utils/backoff.ts +44 -0
- package/src/utils/flush-timer.ts +50 -0
- package/src/utils/json-utils.ts +33 -0
- package/src/utils/otlp-resource.spec.ts +55 -9
- package/src/utils/otlp-resource.ts +45 -4
- package/src/utils/retry-after.ts +135 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Longest `Retry-After` the SDK will wait. A rate-limit window can legitimately
|
|
3
|
+
* be long, but nothing upstream of the SDK bounds this header — it is as likely
|
|
4
|
+
* to come from a proxy or CDN as from PostHog — and an unbounded value would
|
|
5
|
+
* strand a queue for hours, so the wait is capped and the retry happens early.
|
|
6
|
+
*/
|
|
7
|
+
export declare const MAX_RETRY_AFTER_MS: number;
|
|
8
|
+
/**
|
|
9
|
+
* `Retry-After` as milliseconds from now. The header is either delta-seconds or
|
|
10
|
+
* an HTTP-date; anything else, a date already in the past, or a non-positive
|
|
11
|
+
* delta yields `undefined` so the caller keeps its own backoff. The result is
|
|
12
|
+
* capped at `MAX_RETRY_AFTER_MS`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseRetryAfterMs(value: unknown, now?: number): number | undefined;
|
|
15
|
+
/** The part of an export outcome the window reads. */
|
|
16
|
+
export type RetryAfterOutcome = {
|
|
17
|
+
kind: 'ok' | 'retry-later' | 'too-large' | 'fatal';
|
|
18
|
+
retryAfterMs?: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The wait an ingestion endpoint asked for, shared by the logs, metrics and
|
|
22
|
+
* traces export queues.
|
|
23
|
+
*
|
|
24
|
+
* Held as an absolute deadline rather than a duration, so a timer armed while
|
|
25
|
+
* the wait is already part-served counts down the remainder instead of
|
|
26
|
+
* restarting it.
|
|
27
|
+
*/
|
|
28
|
+
export declare class RetryAfterWindow {
|
|
29
|
+
private _until;
|
|
30
|
+
private _installedAt;
|
|
31
|
+
/**
|
|
32
|
+
* Folds one export outcome into the window.
|
|
33
|
+
*
|
|
34
|
+
* A refusal naming a longer wait than the one being served pushes the
|
|
35
|
+
* deadline out, but never past `MAX_RETRY_AFTER_MS` from where the window was
|
|
36
|
+
* first installed. That ceiling is the SDK's own policy rather than OTLP's,
|
|
37
|
+
* which asks for the header to be honoured and names no cap: a host flushing
|
|
38
|
+
* faster than the window is long would otherwise refresh the deadline forever
|
|
39
|
+
* and never recover, since logs gates its size trigger and `onReconnect` on
|
|
40
|
+
* the window and metrics re-arms its timer from it. The cost is that a wait
|
|
41
|
+
* longer than the ceiling is served short.
|
|
42
|
+
*
|
|
43
|
+
* The deadline is never pulled in, so a shorter header cannot cut a wait the
|
|
44
|
+
* endpoint already asked for.
|
|
45
|
+
*/
|
|
46
|
+
record(outcome: RetryAfterOutcome): void;
|
|
47
|
+
/**
|
|
48
|
+
* Milliseconds left of the wait, `0` when none is open. Closes a window it
|
|
49
|
+
* finds spent, so a later backward clock step cannot bring it back.
|
|
50
|
+
*/
|
|
51
|
+
remainingMs(): number;
|
|
52
|
+
isOpen(): boolean;
|
|
53
|
+
reset(): void;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=retry-after.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry-after.d.ts","sourceRoot":"","sources":["../../src/utils/retry-after.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,QAAa,CAAA;AAS5C;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,GAAE,MAAmB,GAAG,MAAM,GAAG,SAAS,CAuB9F;AAED,sDAAsD;AACtD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,IAAI,GAAG,aAAa,GAAG,WAAW,GAAG,OAAO,CAAA;IAClD,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED;;;;;;;GAOG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAI;IAClB,OAAO,CAAC,YAAY,CAAI;IAExB;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI;IA8BxC;;;OAGG;IACH,WAAW,IAAI,MAAM;IAarB,MAAM,IAAI,OAAO;IAIjB,KAAK,IAAI,IAAI;CAId"}
|
|
@@ -0,0 +1,95 @@
|
|
|
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
|
+
const MAX_RETRY_AFTER_MS = 300000;
|
|
31
|
+
const CLOCK_STEP_TOLERANCE_MS = 5000;
|
|
32
|
+
function parseRetryAfterMs(value, now = Date.now()) {
|
|
33
|
+
if ('string' != typeof value || !value) return;
|
|
34
|
+
const raw = value.trim();
|
|
35
|
+
const trimmed = /^\d+\s*,/.test(raw) ? raw.slice(0, raw.indexOf(',')).trim() : raw;
|
|
36
|
+
const seconds = /^\d+$/.test(trimmed) ? Number(trimmed) : 0 / 0;
|
|
37
|
+
if (!Number.isFinite(seconds) && /^[+-]?[\d.]+$/.test(trimmed)) return;
|
|
38
|
+
const ms = Number.isFinite(seconds) ? 1000 * seconds : Date.parse(trimmed) - now;
|
|
39
|
+
if (!Number.isFinite(ms) || ms <= 0) return;
|
|
40
|
+
return Math.min(ms, MAX_RETRY_AFTER_MS);
|
|
41
|
+
}
|
|
42
|
+
class RetryAfterWindow {
|
|
43
|
+
record(outcome) {
|
|
44
|
+
if ('too-large' === outcome.kind) return;
|
|
45
|
+
if ('retry-later' !== outcome.kind) return void this.reset();
|
|
46
|
+
if (!outcome.retryAfterMs) return;
|
|
47
|
+
const open = this.isOpen();
|
|
48
|
+
const now = Date.now();
|
|
49
|
+
const asked = Math.min(outcome.retryAfterMs, MAX_RETRY_AFTER_MS);
|
|
50
|
+
if (!open) {
|
|
51
|
+
this._installedAt = now;
|
|
52
|
+
this._until = now + asked;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
this._until = Math.max(this._until, Math.min(now + asked, this._installedAt + MAX_RETRY_AFTER_MS));
|
|
56
|
+
}
|
|
57
|
+
remainingMs() {
|
|
58
|
+
const now = Date.now();
|
|
59
|
+
if (now < this._installedAt - CLOCK_STEP_TOLERANCE_MS) {
|
|
60
|
+
this.reset();
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
63
|
+
const remaining = Math.min(MAX_RETRY_AFTER_MS, Math.max(0, this._until - now));
|
|
64
|
+
if (0 === remaining) this.reset();
|
|
65
|
+
return remaining;
|
|
66
|
+
}
|
|
67
|
+
isOpen() {
|
|
68
|
+
return this.remainingMs() > 0;
|
|
69
|
+
}
|
|
70
|
+
reset() {
|
|
71
|
+
this._until = 0;
|
|
72
|
+
this._installedAt = 0;
|
|
73
|
+
}
|
|
74
|
+
constructor(){
|
|
75
|
+
this._until = 0;
|
|
76
|
+
this._installedAt = 0;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
80
|
+
RetryAfterWindow: ()=>RetryAfterWindow,
|
|
81
|
+
parseRetryAfterMs: ()=>parseRetryAfterMs
|
|
82
|
+
}, {
|
|
83
|
+
MAX_RETRY_AFTER_MS: MAX_RETRY_AFTER_MS
|
|
84
|
+
});
|
|
85
|
+
exports.MAX_RETRY_AFTER_MS = __webpack_exports__.MAX_RETRY_AFTER_MS;
|
|
86
|
+
exports.RetryAfterWindow = __webpack_exports__.RetryAfterWindow;
|
|
87
|
+
exports.parseRetryAfterMs = __webpack_exports__.parseRetryAfterMs;
|
|
88
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
89
|
+
"MAX_RETRY_AFTER_MS",
|
|
90
|
+
"RetryAfterWindow",
|
|
91
|
+
"parseRetryAfterMs"
|
|
92
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
93
|
+
Object.defineProperty(exports, '__esModule', {
|
|
94
|
+
value: true
|
|
95
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const MAX_RETRY_AFTER_MS = 300000;
|
|
2
|
+
const CLOCK_STEP_TOLERANCE_MS = 5000;
|
|
3
|
+
function parseRetryAfterMs(value, now = Date.now()) {
|
|
4
|
+
if ('string' != typeof value || !value) return;
|
|
5
|
+
const raw = value.trim();
|
|
6
|
+
const trimmed = /^\d+\s*,/.test(raw) ? raw.slice(0, raw.indexOf(',')).trim() : raw;
|
|
7
|
+
const seconds = /^\d+$/.test(trimmed) ? Number(trimmed) : 0 / 0;
|
|
8
|
+
if (!Number.isFinite(seconds) && /^[+-]?[\d.]+$/.test(trimmed)) return;
|
|
9
|
+
const ms = Number.isFinite(seconds) ? 1000 * seconds : Date.parse(trimmed) - now;
|
|
10
|
+
if (!Number.isFinite(ms) || ms <= 0) return;
|
|
11
|
+
return Math.min(ms, MAX_RETRY_AFTER_MS);
|
|
12
|
+
}
|
|
13
|
+
class RetryAfterWindow {
|
|
14
|
+
record(outcome) {
|
|
15
|
+
if ('too-large' === outcome.kind) return;
|
|
16
|
+
if ('retry-later' !== outcome.kind) return void this.reset();
|
|
17
|
+
if (!outcome.retryAfterMs) return;
|
|
18
|
+
const open = this.isOpen();
|
|
19
|
+
const now = Date.now();
|
|
20
|
+
const asked = Math.min(outcome.retryAfterMs, MAX_RETRY_AFTER_MS);
|
|
21
|
+
if (!open) {
|
|
22
|
+
this._installedAt = now;
|
|
23
|
+
this._until = now + asked;
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
this._until = Math.max(this._until, Math.min(now + asked, this._installedAt + MAX_RETRY_AFTER_MS));
|
|
27
|
+
}
|
|
28
|
+
remainingMs() {
|
|
29
|
+
const now = Date.now();
|
|
30
|
+
if (now < this._installedAt - CLOCK_STEP_TOLERANCE_MS) {
|
|
31
|
+
this.reset();
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
const remaining = Math.min(MAX_RETRY_AFTER_MS, Math.max(0, this._until - now));
|
|
35
|
+
if (0 === remaining) this.reset();
|
|
36
|
+
return remaining;
|
|
37
|
+
}
|
|
38
|
+
isOpen() {
|
|
39
|
+
return this.remainingMs() > 0;
|
|
40
|
+
}
|
|
41
|
+
reset() {
|
|
42
|
+
this._until = 0;
|
|
43
|
+
this._installedAt = 0;
|
|
44
|
+
}
|
|
45
|
+
constructor(){
|
|
46
|
+
this._until = 0;
|
|
47
|
+
this._installedAt = 0;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export { MAX_RETRY_AFTER_MS, RetryAfterWindow, parseRetryAfterMs };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.53.0",
|
|
4
4
|
"bugs": {
|
|
5
5
|
"url": "https://github.com/PostHog/posthog-js/issues"
|
|
6
6
|
},
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@posthog/types": "^1.
|
|
73
|
+
"@posthog/types": "^1.411.0"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@rslib/core": "0.23.2",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"lint:fix": "oxlint --report-unused-disable-directives-severity error src --fix",
|
|
85
85
|
"build": "rslib build",
|
|
86
86
|
"dev": "rslib build -w",
|
|
87
|
-
"test:unit": "vitest run",
|
|
87
|
+
"test:unit": "NODE_OPTIONS=--expose-gc vitest run",
|
|
88
88
|
"package": "pnpm pack --out $PACKAGE_DEST/%s.tgz"
|
|
89
89
|
}
|
|
90
90
|
}
|
package/src/index.ts
CHANGED
|
@@ -87,6 +87,24 @@ export type {
|
|
|
87
87
|
Metrics,
|
|
88
88
|
MetricsConfig,
|
|
89
89
|
} from './metrics/types'
|
|
90
|
+
export { PostHogTraces } from './traces'
|
|
91
|
+
export { SyncSpanContextManager } from './traces/context'
|
|
92
|
+
export { inertSpan, runWithActiveSpan } from './traces/span'
|
|
93
|
+
export { resolveTracesConfig } from './traces/config'
|
|
94
|
+
export type { ResolvedTracesConfig, SpanContextManager, TraceSdkContext } from './traces/types'
|
|
95
|
+
// The `beforeSpanSend` shapes come straight from @posthog/types: hooks see the
|
|
96
|
+
// public record, not core's internal one, which also carries `traceState`.
|
|
97
|
+
export type { SpanRecord, BeforeSpanSendFn } from '@posthog/types'
|
|
98
|
+
export type {
|
|
99
|
+
Span,
|
|
100
|
+
SpanAttributes,
|
|
101
|
+
SpanAttributeValue,
|
|
102
|
+
SpanKind,
|
|
103
|
+
SpanStatusCode,
|
|
104
|
+
SpanTimeInput,
|
|
105
|
+
StartSpanOptions,
|
|
106
|
+
TracesConfig,
|
|
107
|
+
} from './traces/types'
|
|
90
108
|
export { uuidv7 } from './vendor/uuidv7'
|
|
91
109
|
export * from './cookie'
|
|
92
110
|
export * from './posthog-core'
|