@zuplo/cli 7.15.1 → 7.15.3
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/node_modules/@posthog/core/dist/featureFlagLocalEvaluation.d.ts.map +1 -1
- package/node_modules/@posthog/core/dist/featureFlagLocalEvaluation.js +17 -2
- package/node_modules/@posthog/core/dist/featureFlagLocalEvaluation.mjs +17 -2
- package/node_modules/@posthog/core/dist/logs/index.d.ts +18 -1
- package/node_modules/@posthog/core/dist/logs/index.d.ts.map +1 -1
- package/node_modules/@posthog/core/dist/logs/index.js +22 -3
- package/node_modules/@posthog/core/dist/logs/index.mjs +22 -3
- package/node_modules/@posthog/core/dist/metrics/index.d.ts +9 -0
- package/node_modules/@posthog/core/dist/metrics/index.d.ts.map +1 -1
- package/node_modules/@posthog/core/dist/metrics/index.js +13 -0
- package/node_modules/@posthog/core/dist/metrics/index.mjs +13 -0
- package/node_modules/@posthog/core/package.json +2 -2
- package/node_modules/@posthog/core/src/featureFlagLocalEvaluation.ts +23 -2
- package/node_modules/@posthog/core/src/logs/index.spec.ts +119 -0
- package/node_modules/@posthog/core/src/logs/index.ts +57 -3
- package/node_modules/@posthog/core/src/metrics/index.spec.ts +70 -0
- package/node_modules/@posthog/core/src/metrics/index.ts +30 -0
- package/node_modules/@posthog/types/dist/posthog-config.d.ts +4 -0
- package/node_modules/@posthog/types/dist/posthog-config.d.ts.map +1 -1
- package/node_modules/@posthog/types/package.json +1 -1
- package/node_modules/@posthog/types/src/posthog-config.ts +4 -0
- package/node_modules/@zuplo/core/customer.cli.minified.js +236 -236
- package/node_modules/@zuplo/core/index.minified.js +241 -241
- package/node_modules/@zuplo/core/package.json +1 -1
- package/node_modules/@zuplo/graphql/package.json +1 -1
- package/node_modules/@zuplo/openapi-tools/package.json +1 -1
- package/node_modules/@zuplo/otel/package.json +1 -1
- package/node_modules/@zuplo/runtime/package.json +1 -1
- package/package.json +11 -11
|
@@ -1 +1 @@
|
|
|
1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EAAE,GACtC,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAK7B;AAED,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,GAAG,SAAS,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,EAC3E,SAAS,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,GAC7C,QAAQ,GAAG,IAAI,CAMjB"}
|
|
@@ -417,13 +417,28 @@ function relativeDateParseForFeatureFlagMatching(value) {
|
|
|
417
417
|
if ('h' === interval) parsedDt.setUTCHours(parsedDt.getUTCHours() - number);
|
|
418
418
|
else if ('d' === interval) parsedDt.setUTCDate(parsedDt.getUTCDate() - number);
|
|
419
419
|
else if ('w' === interval) parsedDt.setUTCDate(parsedDt.getUTCDate() - 7 * number);
|
|
420
|
-
else if ('m' === interval)
|
|
420
|
+
else if ('m' === interval) subtractUTCMonths(parsedDt, number);
|
|
421
421
|
else {
|
|
422
422
|
if ('y' !== interval) return null;
|
|
423
|
-
|
|
423
|
+
subtractUTCYears(parsedDt, number);
|
|
424
424
|
}
|
|
425
425
|
return parsedDt;
|
|
426
426
|
}
|
|
427
|
+
function subtractUTCMonths(date, months) {
|
|
428
|
+
const year = date.getUTCFullYear();
|
|
429
|
+
const month = date.getUTCMonth();
|
|
430
|
+
let day = date.getUTCDate();
|
|
431
|
+
for(let step = 1; step <= months && day > 28; step++){
|
|
432
|
+
const lastDayOfMonth = new Date(Date.UTC(year, month - step + 1, 0)).getUTCDate();
|
|
433
|
+
day = Math.min(day, lastDayOfMonth);
|
|
434
|
+
}
|
|
435
|
+
date.setUTCFullYear(year, month - months, day);
|
|
436
|
+
}
|
|
437
|
+
function subtractUTCYears(date, years) {
|
|
438
|
+
const month = date.getUTCMonth();
|
|
439
|
+
const day = years > 0 && 1 === month && 29 === date.getUTCDate() ? 28 : date.getUTCDate();
|
|
440
|
+
date.setUTCFullYear(date.getUTCFullYear() - years, month, day);
|
|
441
|
+
}
|
|
427
442
|
function parseDateFilter(value) {
|
|
428
443
|
if ('boolean' == typeof value) throw new InconclusiveMatchError('Date operations cannot be performed on boolean values');
|
|
429
444
|
return relativeDateParseForFeatureFlagMatching(String(value)) ?? convertToDateTime(value);
|
|
@@ -375,13 +375,28 @@ function relativeDateParseForFeatureFlagMatching(value) {
|
|
|
375
375
|
if ('h' === interval) parsedDt.setUTCHours(parsedDt.getUTCHours() - number);
|
|
376
376
|
else if ('d' === interval) parsedDt.setUTCDate(parsedDt.getUTCDate() - number);
|
|
377
377
|
else if ('w' === interval) parsedDt.setUTCDate(parsedDt.getUTCDate() - 7 * number);
|
|
378
|
-
else if ('m' === interval)
|
|
378
|
+
else if ('m' === interval) subtractUTCMonths(parsedDt, number);
|
|
379
379
|
else {
|
|
380
380
|
if ('y' !== interval) return null;
|
|
381
|
-
|
|
381
|
+
subtractUTCYears(parsedDt, number);
|
|
382
382
|
}
|
|
383
383
|
return parsedDt;
|
|
384
384
|
}
|
|
385
|
+
function subtractUTCMonths(date, months) {
|
|
386
|
+
const year = date.getUTCFullYear();
|
|
387
|
+
const month = date.getUTCMonth();
|
|
388
|
+
let day = date.getUTCDate();
|
|
389
|
+
for(let step = 1; step <= months && day > 28; step++){
|
|
390
|
+
const lastDayOfMonth = new Date(Date.UTC(year, month - step + 1, 0)).getUTCDate();
|
|
391
|
+
day = Math.min(day, lastDayOfMonth);
|
|
392
|
+
}
|
|
393
|
+
date.setUTCFullYear(year, month - months, day);
|
|
394
|
+
}
|
|
395
|
+
function subtractUTCYears(date, years) {
|
|
396
|
+
const month = date.getUTCMonth();
|
|
397
|
+
const day = years > 0 && 1 === month && 29 === date.getUTCDate() ? 28 : date.getUTCDate();
|
|
398
|
+
date.setUTCFullYear(date.getUTCFullYear() - years, month, day);
|
|
399
|
+
}
|
|
385
400
|
function parseDateFilter(value) {
|
|
386
401
|
if ('boolean' == typeof value) throw new InconclusiveMatchError('Date operations cannot be performed on boolean values');
|
|
387
402
|
return relativeDateParseForFeatureFlagMatching(String(value)) ?? convertToDateTime(value);
|
|
@@ -8,6 +8,7 @@ export declare class PostHogLogs {
|
|
|
8
8
|
private readonly _onReady;
|
|
9
9
|
private readonly _waitForStoragePersist;
|
|
10
10
|
private readonly _scopeName?;
|
|
11
|
+
private readonly _isConsentWithdrawn;
|
|
11
12
|
private _maxBufferSize;
|
|
12
13
|
private _maxQueueSize;
|
|
13
14
|
private _flushIntervalMs;
|
|
@@ -16,6 +17,7 @@ export declare class PostHogLogs {
|
|
|
16
17
|
private _flushPromise;
|
|
17
18
|
private _evictedSinceAdvance;
|
|
18
19
|
private _queueGeneration;
|
|
20
|
+
private _backgroundFlushPromise;
|
|
19
21
|
private _retryAfter;
|
|
20
22
|
private _consecutiveFlushFailures;
|
|
21
23
|
private _flushJitter;
|
|
@@ -24,13 +26,15 @@ export declare class PostHogLogs {
|
|
|
24
26
|
private _intervalWindowStart;
|
|
25
27
|
private _intervalLogCount;
|
|
26
28
|
private _droppedWarned;
|
|
27
|
-
constructor(_instance: LogsHost, _config: ResolvedPostHogLogsConfig, _logger: Logger, _getContext: () => LogSdkContext, _onReady: (fn: () => void) => void, _waitForStoragePersist?: () => Promise<void>, _scopeName?: string | undefined);
|
|
29
|
+
constructor(_instance: LogsHost, _config: ResolvedPostHogLogsConfig, _logger: Logger, _getContext: () => LogSdkContext, _onReady: (fn: () => void) => void, _waitForStoragePersist?: () => Promise<void>, _scopeName?: string | undefined, _isConsentWithdrawn?: () => boolean);
|
|
28
30
|
/**
|
|
29
31
|
* Drops every queued record. A batch this instance has in flight is retired with
|
|
30
32
|
* them, so it can neither re-send what was just purged nor advance past records
|
|
31
33
|
* captured after this call.
|
|
32
34
|
*/
|
|
33
35
|
clearQueue(): void;
|
|
36
|
+
/** True while the endpoint's `Retry-After` window is open, so a host's automatic flush can skip logs. */
|
|
37
|
+
get throttled(): boolean;
|
|
34
38
|
/**
|
|
35
39
|
* Clears the flush timer and rate-cap state. The host owns the record queue
|
|
36
40
|
* and clears it separately (the browser empties its in-memory store).
|
|
@@ -88,6 +92,12 @@ export declare class PostHogLogs {
|
|
|
88
92
|
*/
|
|
89
93
|
flush(): Promise<void>;
|
|
90
94
|
private _flushInner;
|
|
95
|
+
/**
|
|
96
|
+
* Drops the queue once consent is withdrawn. Records carry the distinct id and
|
|
97
|
+
* session id, so whatever is still queued when the user opts out must not be
|
|
98
|
+
* exported, by a pending timer or by a drain already under way.
|
|
99
|
+
*/
|
|
100
|
+
private _discardQueueIfConsentWithdrawn;
|
|
91
101
|
private _persistQueueAdvance;
|
|
92
102
|
private _buildResourceAttributes;
|
|
93
103
|
private _enqueue;
|
|
@@ -118,6 +128,13 @@ export declare class PostHogLogs {
|
|
|
118
128
|
* unhandled-rejection logs — the next regular flush cycle will retry.
|
|
119
129
|
*/
|
|
120
130
|
flushWithTimeout(timeoutMs: number): Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* `flush()` for a host that drives logs from its own flush cycle. Never rejects, and when
|
|
133
|
+
* records remain (a failed send, or captures that landed mid-flush) re-arms the timer with
|
|
134
|
+
* backoff, as the pipeline's own timer flush does. A bare `flush()` clears the timer and
|
|
135
|
+
* leaves nothing to retry the records once traffic stops.
|
|
136
|
+
*/
|
|
137
|
+
flushInBackground(): Promise<void>;
|
|
121
138
|
private _flushInBackground;
|
|
122
139
|
}
|
|
123
140
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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;AAK3D,OAAO,KAAK,EAAoB,iBAAiB,EAAE,aAAa,EAAE,QAAQ,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAItH,qBAAa,WAAW;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/logs/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM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require("../utils/retry-after.js");
|
|
38
38
|
const backoff_js_namespaceObject = require("../utils/backoff.js");
|
|
39
39
|
class PostHogLogs {
|
|
40
|
-
constructor(_instance, _config, _logger, _getContext, _onReady, _waitForStoragePersist = ()=>Promise.resolve(), _scopeName){
|
|
40
|
+
constructor(_instance, _config, _logger, _getContext, _onReady, _waitForStoragePersist = ()=>Promise.resolve(), _scopeName, _isConsentWithdrawn = ()=>false){
|
|
41
41
|
this._instance = _instance;
|
|
42
42
|
this._config = _config;
|
|
43
43
|
this._logger = _logger;
|
|
@@ -45,10 +45,12 @@ class PostHogLogs {
|
|
|
45
45
|
this._onReady = _onReady;
|
|
46
46
|
this._waitForStoragePersist = _waitForStoragePersist;
|
|
47
47
|
this._scopeName = _scopeName;
|
|
48
|
+
this._isConsentWithdrawn = _isConsentWithdrawn;
|
|
48
49
|
this._flushTimer = new flush_timer_js_namespaceObject.FlushTimer(()=>this._flushInBackground());
|
|
49
50
|
this._flushPromise = null;
|
|
50
51
|
this._evictedSinceAdvance = 0;
|
|
51
52
|
this._queueGeneration = 0;
|
|
53
|
+
this._backgroundFlushPromise = null;
|
|
52
54
|
this._retryAfter = new retry_after_js_namespaceObject.RetryAfterWindow();
|
|
53
55
|
this._consecutiveFlushFailures = 0;
|
|
54
56
|
this._flushJitter = backoff_js_namespaceObject.NO_JITTER;
|
|
@@ -66,6 +68,9 @@ class PostHogLogs {
|
|
|
66
68
|
this._queueGeneration++;
|
|
67
69
|
this._instance.setPersistedProperty(external_types_js_namespaceObject.PostHogPersistedProperty.LogsQueue, []);
|
|
68
70
|
}
|
|
71
|
+
get throttled() {
|
|
72
|
+
return this._retryAfter.isOpen();
|
|
73
|
+
}
|
|
69
74
|
reset() {
|
|
70
75
|
this._flushTimer.clear();
|
|
71
76
|
this._intervalWindowStart = 0;
|
|
@@ -148,11 +153,13 @@ class PostHogLogs {
|
|
|
148
153
|
}
|
|
149
154
|
async _flushInner() {
|
|
150
155
|
this._flushTimer.clear();
|
|
156
|
+
if (this._discardQueueIfConsentWithdrawn()) return;
|
|
151
157
|
let queue = this._instance.getPersistedProperty(external_types_js_namespaceObject.PostHogPersistedProperty.LogsQueue) ?? [];
|
|
152
158
|
if (0 === queue.length) return;
|
|
153
159
|
const originalQueueLength = queue.length;
|
|
154
160
|
let sentCount = 0;
|
|
155
161
|
while(queue.length > 0 && sentCount < originalQueueLength){
|
|
162
|
+
if (this._discardQueueIfConsentWithdrawn()) return;
|
|
156
163
|
const generation = this._queueGeneration;
|
|
157
164
|
this._evictedSinceAdvance = 0;
|
|
158
165
|
const batchSize = Math.min(queue.length, this._maxBatchRecordsPerPost);
|
|
@@ -177,6 +184,11 @@ class PostHogLogs {
|
|
|
177
184
|
if ('fatal' === outcome.kind) throw outcome.error;
|
|
178
185
|
}
|
|
179
186
|
}
|
|
187
|
+
_discardQueueIfConsentWithdrawn() {
|
|
188
|
+
if (!this._isConsentWithdrawn()) return false;
|
|
189
|
+
if (this._hasQueuedRecords()) this.clearQueue();
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
180
192
|
async _persistQueueAdvance(consumed) {
|
|
181
193
|
const evicted = this._evictedSinceAdvance;
|
|
182
194
|
const drop = Math.max(0, consumed - evicted);
|
|
@@ -223,8 +235,9 @@ class PostHogLogs {
|
|
|
223
235
|
flushPromise.catch(()=>{});
|
|
224
236
|
});
|
|
225
237
|
}
|
|
226
|
-
|
|
227
|
-
this.
|
|
238
|
+
flushInBackground() {
|
|
239
|
+
if (this._backgroundFlushPromise) return this._backgroundFlushPromise;
|
|
240
|
+
const promise = this.flush().then(()=>{
|
|
228
241
|
this._consecutiveFlushFailures = 0;
|
|
229
242
|
this._flushJitter = backoff_js_namespaceObject.NO_JITTER;
|
|
230
243
|
}, (err)=>{
|
|
@@ -232,8 +245,14 @@ class PostHogLogs {
|
|
|
232
245
|
this._flushJitter = (0, backoff_js_namespaceObject.drawJitter)();
|
|
233
246
|
this._logger.error('PostHog logs flush failed:', err);
|
|
234
247
|
}).finally(()=>{
|
|
248
|
+
if (this._backgroundFlushPromise === promise) this._backgroundFlushPromise = null;
|
|
235
249
|
if (!this._instance.isDisabled && this._hasQueuedRecords()) this._flushTimer.armNoEarlierThan(this._nextFlushDelay());
|
|
236
250
|
});
|
|
251
|
+
this._backgroundFlushPromise = promise;
|
|
252
|
+
return promise;
|
|
253
|
+
}
|
|
254
|
+
_flushInBackground() {
|
|
255
|
+
this.flushInBackground();
|
|
237
256
|
}
|
|
238
257
|
}
|
|
239
258
|
exports.PostHogLogs = __webpack_exports__.PostHogLogs;
|
|
@@ -5,7 +5,7 @@ import { FlushTimer } from "../utils/flush-timer.mjs";
|
|
|
5
5
|
import { RetryAfterWindow } from "../utils/retry-after.mjs";
|
|
6
6
|
import { MAX_FLUSH_BACKOFF_MS, NO_JITTER, backoffDelayMs, drawJitter } from "../utils/backoff.mjs";
|
|
7
7
|
class PostHogLogs {
|
|
8
|
-
constructor(_instance, _config, _logger, _getContext, _onReady, _waitForStoragePersist = ()=>Promise.resolve(), _scopeName){
|
|
8
|
+
constructor(_instance, _config, _logger, _getContext, _onReady, _waitForStoragePersist = ()=>Promise.resolve(), _scopeName, _isConsentWithdrawn = ()=>false){
|
|
9
9
|
this._instance = _instance;
|
|
10
10
|
this._config = _config;
|
|
11
11
|
this._logger = _logger;
|
|
@@ -13,10 +13,12 @@ class PostHogLogs {
|
|
|
13
13
|
this._onReady = _onReady;
|
|
14
14
|
this._waitForStoragePersist = _waitForStoragePersist;
|
|
15
15
|
this._scopeName = _scopeName;
|
|
16
|
+
this._isConsentWithdrawn = _isConsentWithdrawn;
|
|
16
17
|
this._flushTimer = new FlushTimer(()=>this._flushInBackground());
|
|
17
18
|
this._flushPromise = null;
|
|
18
19
|
this._evictedSinceAdvance = 0;
|
|
19
20
|
this._queueGeneration = 0;
|
|
21
|
+
this._backgroundFlushPromise = null;
|
|
20
22
|
this._retryAfter = new RetryAfterWindow();
|
|
21
23
|
this._consecutiveFlushFailures = 0;
|
|
22
24
|
this._flushJitter = NO_JITTER;
|
|
@@ -34,6 +36,9 @@ class PostHogLogs {
|
|
|
34
36
|
this._queueGeneration++;
|
|
35
37
|
this._instance.setPersistedProperty(PostHogPersistedProperty.LogsQueue, []);
|
|
36
38
|
}
|
|
39
|
+
get throttled() {
|
|
40
|
+
return this._retryAfter.isOpen();
|
|
41
|
+
}
|
|
37
42
|
reset() {
|
|
38
43
|
this._flushTimer.clear();
|
|
39
44
|
this._intervalWindowStart = 0;
|
|
@@ -116,11 +121,13 @@ class PostHogLogs {
|
|
|
116
121
|
}
|
|
117
122
|
async _flushInner() {
|
|
118
123
|
this._flushTimer.clear();
|
|
124
|
+
if (this._discardQueueIfConsentWithdrawn()) return;
|
|
119
125
|
let queue = this._instance.getPersistedProperty(PostHogPersistedProperty.LogsQueue) ?? [];
|
|
120
126
|
if (0 === queue.length) return;
|
|
121
127
|
const originalQueueLength = queue.length;
|
|
122
128
|
let sentCount = 0;
|
|
123
129
|
while(queue.length > 0 && sentCount < originalQueueLength){
|
|
130
|
+
if (this._discardQueueIfConsentWithdrawn()) return;
|
|
124
131
|
const generation = this._queueGeneration;
|
|
125
132
|
this._evictedSinceAdvance = 0;
|
|
126
133
|
const batchSize = Math.min(queue.length, this._maxBatchRecordsPerPost);
|
|
@@ -145,6 +152,11 @@ class PostHogLogs {
|
|
|
145
152
|
if ('fatal' === outcome.kind) throw outcome.error;
|
|
146
153
|
}
|
|
147
154
|
}
|
|
155
|
+
_discardQueueIfConsentWithdrawn() {
|
|
156
|
+
if (!this._isConsentWithdrawn()) return false;
|
|
157
|
+
if (this._hasQueuedRecords()) this.clearQueue();
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
148
160
|
async _persistQueueAdvance(consumed) {
|
|
149
161
|
const evicted = this._evictedSinceAdvance;
|
|
150
162
|
const drop = Math.max(0, consumed - evicted);
|
|
@@ -191,8 +203,9 @@ class PostHogLogs {
|
|
|
191
203
|
flushPromise.catch(()=>{});
|
|
192
204
|
});
|
|
193
205
|
}
|
|
194
|
-
|
|
195
|
-
this.
|
|
206
|
+
flushInBackground() {
|
|
207
|
+
if (this._backgroundFlushPromise) return this._backgroundFlushPromise;
|
|
208
|
+
const promise = this.flush().then(()=>{
|
|
196
209
|
this._consecutiveFlushFailures = 0;
|
|
197
210
|
this._flushJitter = NO_JITTER;
|
|
198
211
|
}, (err)=>{
|
|
@@ -200,8 +213,14 @@ class PostHogLogs {
|
|
|
200
213
|
this._flushJitter = drawJitter();
|
|
201
214
|
this._logger.error('PostHog logs flush failed:', err);
|
|
202
215
|
}).finally(()=>{
|
|
216
|
+
if (this._backgroundFlushPromise === promise) this._backgroundFlushPromise = null;
|
|
203
217
|
if (!this._instance.isDisabled && this._hasQueuedRecords()) this._flushTimer.armNoEarlierThan(this._nextFlushDelay());
|
|
204
218
|
});
|
|
219
|
+
this._backgroundFlushPromise = promise;
|
|
220
|
+
return promise;
|
|
221
|
+
}
|
|
222
|
+
_flushInBackground() {
|
|
223
|
+
this.flushInBackground();
|
|
205
224
|
}
|
|
206
225
|
}
|
|
207
226
|
export { PostHogLogs };
|
|
@@ -26,6 +26,7 @@ export declare class PostHogMetrics {
|
|
|
26
26
|
private _series;
|
|
27
27
|
private readonly _flushTimer;
|
|
28
28
|
private _flushPromise;
|
|
29
|
+
private _queuedFlush;
|
|
29
30
|
private _seriesCapWarned;
|
|
30
31
|
private _typeByName;
|
|
31
32
|
private _typeCollisionWarned;
|
|
@@ -42,6 +43,14 @@ export declare class PostHogMetrics {
|
|
|
42
43
|
histogram(name: string, value: number, options?: HistogramOptions): void;
|
|
43
44
|
/** Sends everything aggregated so far without waiting for the flush interval. */
|
|
44
45
|
flush(): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* A flush for callers that ask once per unit of work (a served request, say) rather than once per window.
|
|
48
|
+
* Callers share one queued flush, so at most one send is in flight and one waits behind it however often
|
|
49
|
+
* this is called, and every sample captured before the call is in one of them. While a failed send is
|
|
50
|
+
* backing off it starts nothing and the retry timer owns the next send.
|
|
51
|
+
*/
|
|
52
|
+
flushCoalesced(): Promise<void>;
|
|
53
|
+
private _isBackingOff;
|
|
45
54
|
/**
|
|
46
55
|
* Synchronously snapshots the current window into an OTLP payload and
|
|
47
56
|
* resets it, bypassing the flush serializer entirely — for unload-time
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/metrics/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EAOhB,kBAAkB,EAEnB,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAetC,OAAO,KAAK,EAAE,WAAW,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAA;AAqCxE;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,cAAc;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/metrics/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EAOhB,kBAAkB,EAEnB,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAetC,OAAO,KAAK,EAAE,WAAW,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAA;AAqCxE;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,cAAc;IAoCvB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO;IArC1B,OAAO,CAAC,OAAO,CAAiC;IAChD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAI3B;IAGD,OAAO,CAAC,aAAa,CAA6B;IAElD,OAAO,CAAC,YAAY,CAA6B;IAEjD,OAAO,CAAC,gBAAgB,CAAQ;IAIhC,OAAO,CAAC,WAAW,CAAgC;IACnD,OAAO,CAAC,oBAAoB,CAAoB;IAKh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AAQ;IAsDtB,OAAO,CAAC,aAAa;IASrB;;;OAGG;IACH,OAAO,CAAC,aAAa;IA6DrB,oFAAoF;IACpF,OAAO,CAAC,gBAAgB;CAoCzB;AAoDD,OAAO,EAAE,uBAAuB,EAAE,8BAA8B,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAA;AACnH,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAC/C,YAAY,EAAE,WAAW,EAAE,oBAAoB,EAAE,4BAA4B,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA"}
|
|
@@ -53,6 +53,7 @@ class PostHogMetrics {
|
|
|
53
53
|
this._logger.error('Metrics flush failed:', e);
|
|
54
54
|
}));
|
|
55
55
|
this._flushPromise = null;
|
|
56
|
+
this._queuedFlush = null;
|
|
56
57
|
this._seriesCapWarned = false;
|
|
57
58
|
this._typeByName = new Map();
|
|
58
59
|
this._typeCollisionWarned = new Set();
|
|
@@ -104,6 +105,17 @@ class PostHogMetrics {
|
|
|
104
105
|
this._flushPromise = p;
|
|
105
106
|
return p;
|
|
106
107
|
}
|
|
108
|
+
flushCoalesced() {
|
|
109
|
+
if (this._isBackingOff()) return this._flushPromise ?? Promise.resolve();
|
|
110
|
+
if (!this._queuedFlush) this._queuedFlush = (this._flushPromise ?? Promise.resolve()).catch(()=>{}).then(()=>{
|
|
111
|
+
this._queuedFlush = null;
|
|
112
|
+
return this._isBackingOff() ? void 0 : this.flush();
|
|
113
|
+
});
|
|
114
|
+
return this._queuedFlush;
|
|
115
|
+
}
|
|
116
|
+
_isBackingOff() {
|
|
117
|
+
return this._consecutiveFlushFailures > 0 || this._retryAfter.remainingMs() > 0;
|
|
118
|
+
}
|
|
107
119
|
drainWindow() {
|
|
108
120
|
if (0 === this._series.size) return null;
|
|
109
121
|
const window = this._series;
|
|
@@ -117,6 +129,7 @@ class PostHogMetrics {
|
|
|
117
129
|
this._flushJitter = backoff_js_namespaceObject.NO_JITTER;
|
|
118
130
|
this._flushTimer.clear();
|
|
119
131
|
this._flushPromise = null;
|
|
132
|
+
this._queuedFlush = null;
|
|
120
133
|
this._startWindow();
|
|
121
134
|
this._boundsByHistogram = new Map();
|
|
122
135
|
this._boundsCapWarned = false;
|
|
@@ -16,6 +16,7 @@ class PostHogMetrics {
|
|
|
16
16
|
this._logger.error('Metrics flush failed:', e);
|
|
17
17
|
}));
|
|
18
18
|
this._flushPromise = null;
|
|
19
|
+
this._queuedFlush = null;
|
|
19
20
|
this._seriesCapWarned = false;
|
|
20
21
|
this._typeByName = new Map();
|
|
21
22
|
this._typeCollisionWarned = new Set();
|
|
@@ -67,6 +68,17 @@ class PostHogMetrics {
|
|
|
67
68
|
this._flushPromise = p;
|
|
68
69
|
return p;
|
|
69
70
|
}
|
|
71
|
+
flushCoalesced() {
|
|
72
|
+
if (this._isBackingOff()) return this._flushPromise ?? Promise.resolve();
|
|
73
|
+
if (!this._queuedFlush) this._queuedFlush = (this._flushPromise ?? Promise.resolve()).catch(()=>{}).then(()=>{
|
|
74
|
+
this._queuedFlush = null;
|
|
75
|
+
return this._isBackingOff() ? void 0 : this.flush();
|
|
76
|
+
});
|
|
77
|
+
return this._queuedFlush;
|
|
78
|
+
}
|
|
79
|
+
_isBackingOff() {
|
|
80
|
+
return this._consecutiveFlushFailures > 0 || this._retryAfter.remainingMs() > 0;
|
|
81
|
+
}
|
|
70
82
|
drainWindow() {
|
|
71
83
|
if (0 === this._series.size) return null;
|
|
72
84
|
const window = this._series;
|
|
@@ -80,6 +92,7 @@ class PostHogMetrics {
|
|
|
80
92
|
this._flushJitter = NO_JITTER;
|
|
81
93
|
this._flushTimer.clear();
|
|
82
94
|
this._flushPromise = null;
|
|
95
|
+
this._queuedFlush = null;
|
|
83
96
|
this._startWindow();
|
|
84
97
|
this._boundsByHistogram = new Map();
|
|
85
98
|
this._boundsCapWarned = false;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.67.1",
|
|
4
4
|
"bugs": {
|
|
5
5
|
"url": "https://github.com/PostHog/posthog-js/issues"
|
|
6
6
|
},
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
}
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@posthog/types": "^1.
|
|
75
|
+
"@posthog/types": "^1.423.0"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@rslib/core": "0.23.2",
|
|
@@ -478,13 +478,34 @@ export function relativeDateParseForFeatureFlagMatching(value: string): Date | n
|
|
|
478
478
|
if (interval === 'h') parsedDt.setUTCHours(parsedDt.getUTCHours() - number)
|
|
479
479
|
else if (interval === 'd') parsedDt.setUTCDate(parsedDt.getUTCDate() - number)
|
|
480
480
|
else if (interval === 'w') parsedDt.setUTCDate(parsedDt.getUTCDate() - number * 7)
|
|
481
|
-
else if (interval === 'm')
|
|
482
|
-
else if (interval === 'y')
|
|
481
|
+
else if (interval === 'm') subtractUTCMonths(parsedDt, number)
|
|
482
|
+
else if (interval === 'y') subtractUTCYears(parsedDt, number)
|
|
483
483
|
else return null
|
|
484
484
|
|
|
485
485
|
return parsedDt
|
|
486
486
|
}
|
|
487
487
|
|
|
488
|
+
// The SDK spec subtracts months one at a time and clamps the day after every step, so
|
|
489
|
+
// March 31 minus one month is February 28 and minus two months is January 28.
|
|
490
|
+
function subtractUTCMonths(date: Date, months: number): void {
|
|
491
|
+
const year = date.getUTCFullYear()
|
|
492
|
+
const month = date.getUTCMonth()
|
|
493
|
+
let day = date.getUTCDate()
|
|
494
|
+
// Every month has at least 28 days, so nothing can clamp further after that.
|
|
495
|
+
for (let step = 1; step <= months && day > 28; step++) {
|
|
496
|
+
const lastDayOfMonth = new Date(Date.UTC(year, month - step + 1, 0)).getUTCDate()
|
|
497
|
+
day = Math.min(day, lastDayOfMonth)
|
|
498
|
+
}
|
|
499
|
+
date.setUTCFullYear(year, month - months, day)
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
function subtractUTCYears(date: Date, years: number): void {
|
|
503
|
+
const month = date.getUTCMonth()
|
|
504
|
+
// The year before a leap year is never a leap year, so February 29 clamps on the first step.
|
|
505
|
+
const day = years > 0 && month === 1 && date.getUTCDate() === 29 ? 28 : date.getUTCDate()
|
|
506
|
+
date.setUTCFullYear(date.getUTCFullYear() - years, month, day)
|
|
507
|
+
}
|
|
508
|
+
|
|
488
509
|
function parseDateFilter(value: FeatureFlagPropertyValue): Date {
|
|
489
510
|
if (typeof value === 'boolean') {
|
|
490
511
|
throw new InconclusiveMatchError('Date operations cannot be performed on boolean values')
|
|
@@ -2300,3 +2300,122 @@ describe('PostHogLogs', () => {
|
|
|
2300
2300
|
})
|
|
2301
2301
|
})
|
|
2302
2302
|
})
|
|
2303
|
+
|
|
2304
|
+
describe('PostHogLogs consent and shared background flush', () => {
|
|
2305
|
+
const create = (instance: any, logger: Logger = createMockLogger(), config = resolveForTest()): PostHogLogs =>
|
|
2306
|
+
new PostHogLogs(
|
|
2307
|
+
instance,
|
|
2308
|
+
config,
|
|
2309
|
+
logger,
|
|
2310
|
+
getContextFor(instance),
|
|
2311
|
+
immediateOnReady,
|
|
2312
|
+
undefined,
|
|
2313
|
+
undefined,
|
|
2314
|
+
() => instance.consentWithdrawn === true
|
|
2315
|
+
)
|
|
2316
|
+
|
|
2317
|
+
it('discards queued records instead of exporting them after opt-out', async () => {
|
|
2318
|
+
const instance = createMockInstance()
|
|
2319
|
+
const logs = create(instance)
|
|
2320
|
+
logs.captureLog({ body: 'before opt-out' })
|
|
2321
|
+
|
|
2322
|
+
instance.consentWithdrawn = true
|
|
2323
|
+
await logs.flush()
|
|
2324
|
+
|
|
2325
|
+
expect(instance._sendLogsBatch).not.toHaveBeenCalled()
|
|
2326
|
+
expect(readQueue(instance)).toHaveLength(0)
|
|
2327
|
+
|
|
2328
|
+
// Opting back in does not resurrect what was captured before the withdrawal.
|
|
2329
|
+
instance.consentWithdrawn = false
|
|
2330
|
+
await logs.flush()
|
|
2331
|
+
expect(instance._sendLogsBatch).not.toHaveBeenCalled()
|
|
2332
|
+
})
|
|
2333
|
+
|
|
2334
|
+
it('stops a drain under way when the user opts out between batches', async () => {
|
|
2335
|
+
let releaseFirst: () => void = () => {}
|
|
2336
|
+
const instance = createMockInstance({
|
|
2337
|
+
_sendLogsBatch: vi.fn(
|
|
2338
|
+
() =>
|
|
2339
|
+
new Promise((resolve) => {
|
|
2340
|
+
releaseFirst = () => resolve({ kind: 'ok' })
|
|
2341
|
+
})
|
|
2342
|
+
),
|
|
2343
|
+
})
|
|
2344
|
+
const logs = create(instance, createMockLogger(), resolveForTest({ maxBatchRecordsPerPost: 1 }))
|
|
2345
|
+
logs.captureLog({ body: 'first' })
|
|
2346
|
+
logs.captureLog({ body: 'second' })
|
|
2347
|
+
|
|
2348
|
+
const flushing = logs.flush()
|
|
2349
|
+
await Promise.resolve()
|
|
2350
|
+
instance.consentWithdrawn = true
|
|
2351
|
+
releaseFirst()
|
|
2352
|
+
await flushing
|
|
2353
|
+
|
|
2354
|
+
expect(instance._sendLogsBatch).toHaveBeenCalledTimes(1)
|
|
2355
|
+
expect(readQueue(instance)).toHaveLength(0)
|
|
2356
|
+
})
|
|
2357
|
+
|
|
2358
|
+
it('does not retry a 413-rejected batch after the user opts out', async () => {
|
|
2359
|
+
let rejectFirst: () => void = () => {}
|
|
2360
|
+
const instance = createMockInstance({
|
|
2361
|
+
_sendLogsBatch: vi.fn(
|
|
2362
|
+
() =>
|
|
2363
|
+
new Promise((resolve) => {
|
|
2364
|
+
rejectFirst = () => resolve({ kind: 'too-large' })
|
|
2365
|
+
})
|
|
2366
|
+
),
|
|
2367
|
+
})
|
|
2368
|
+
const logs = create(instance, createMockLogger(), resolveForTest({ maxBatchRecordsPerPost: 4 }))
|
|
2369
|
+
logs.captureLog({ body: 'a' })
|
|
2370
|
+
logs.captureLog({ body: 'b' })
|
|
2371
|
+
|
|
2372
|
+
const flushing = logs.flush()
|
|
2373
|
+
await Promise.resolve()
|
|
2374
|
+
instance.consentWithdrawn = true
|
|
2375
|
+
rejectFirst()
|
|
2376
|
+
await flushing
|
|
2377
|
+
|
|
2378
|
+
expect(instance._sendLogsBatch).toHaveBeenCalledTimes(1)
|
|
2379
|
+
expect(readQueue(instance)).toHaveLength(0)
|
|
2380
|
+
})
|
|
2381
|
+
|
|
2382
|
+
it('shares one background wrapper across overlapping callers', async () => {
|
|
2383
|
+
let failSend: () => void = () => {}
|
|
2384
|
+
const instance = createMockInstance({
|
|
2385
|
+
_sendLogsBatch: vi.fn(
|
|
2386
|
+
() =>
|
|
2387
|
+
new Promise((resolve) => {
|
|
2388
|
+
failSend = () => resolve({ kind: 'retry-later', error: new Error('down') })
|
|
2389
|
+
})
|
|
2390
|
+
),
|
|
2391
|
+
})
|
|
2392
|
+
const logger = createMockLogger()
|
|
2393
|
+
const logs = create(instance, logger)
|
|
2394
|
+
logs.captureLog({ body: 'slow' })
|
|
2395
|
+
|
|
2396
|
+
const first = logs.flushInBackground()
|
|
2397
|
+
const second = logs.flushInBackground()
|
|
2398
|
+
expect(second).toBe(first)
|
|
2399
|
+
await Promise.resolve()
|
|
2400
|
+
failSend()
|
|
2401
|
+
await Promise.all([first, second])
|
|
2402
|
+
|
|
2403
|
+
expect(instance._sendLogsBatch).toHaveBeenCalledTimes(1)
|
|
2404
|
+
expect(logger.error).toHaveBeenCalledTimes(1)
|
|
2405
|
+
})
|
|
2406
|
+
|
|
2407
|
+
it('keeps flushing a host whose optedOut is only a shutdown gate when no consent callback is given', async () => {
|
|
2408
|
+
const instance = createMockInstance({ optedOut: false })
|
|
2409
|
+
const logs = new PostHogLogs(
|
|
2410
|
+
instance,
|
|
2411
|
+
resolveForTest(),
|
|
2412
|
+
createMockLogger(),
|
|
2413
|
+
getContextFor(instance),
|
|
2414
|
+
immediateOnReady
|
|
2415
|
+
)
|
|
2416
|
+
logs.captureLog({ body: 'final flush' })
|
|
2417
|
+
instance.optedOut = true
|
|
2418
|
+
await logs.flush()
|
|
2419
|
+
expect(instance._sendLogsBatch).toHaveBeenCalledTimes(1)
|
|
2420
|
+
})
|
|
2421
|
+
})
|