@posthog/core 1.48.12 → 1.49.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.
@@ -1 +1 @@
1
- {"version":3,"file":"gzip.d.ts","sourceRoot":"","sources":["../src/gzip.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAOzC;AAWD,eAAO,MAAM,UAAU,GAAI,MAAM,OAAO,KAAG,OAU1C,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,cAAc,OAAO,EAAE,iBAAiB,OAAO,KAAG,OAE/E,CAAA;AAED,eAAO,MAAM,0BAA0B,GAAI,OAAO,OAAO,KAAG,OAQ3D,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAI,OAAO,OAAO,KAAG,OAQvD,CAAA;AA0DD,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,UAAO,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAgCrH"}
1
+ {"version":3,"file":"gzip.d.ts","sourceRoot":"","sources":["../src/gzip.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAOzC;AAWD,eAAO,MAAM,UAAU,GAAI,MAAM,OAAO,KAAG,OAU1C,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,cAAc,OAAO,EAAE,iBAAiB,OAAO,KAAG,OAE/E,CAAA;AAED,eAAO,MAAM,0BAA0B,GAAI,OAAO,OAAO,KAAG,OAQ3D,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAI,OAAO,OAAO,KAAG,OAQvD,CAAA;AAwDD,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,UAAO,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAgCrH"}
package/dist/gzip.js CHANGED
@@ -32,6 +32,7 @@ __webpack_require__.d(__webpack_exports__, {
32
32
  isGzipData: ()=>isGzipData
33
33
  });
34
34
  const external_types_js_namespaceObject = require("./types.js");
35
+ const index_js_namespaceObject = require("./utils/index.js");
35
36
  function isGzipSupported() {
36
37
  return 'CompressionStream' in globalThis && 'TextEncoder' in globalThis && 'Response' in globalThis && 'function' == typeof Response.prototype.blob;
37
38
  }
@@ -74,9 +75,7 @@ const crc32 = (bytes)=>{
74
75
  return (0xffffffff ^ crc) >>> 0;
75
76
  };
76
77
  const throwNativeGzipValidationError = (reason)=>{
77
- const error = new Error(`Native gzip produced invalid output: ${reason}`);
78
- error.name = NATIVE_GZIP_VALIDATION_ERROR;
79
- throw error;
78
+ throw (0, index_js_namespaceObject.createNamedError)(NATIVE_GZIP_VALIDATION_ERROR, `Native gzip produced invalid output: ${reason}`);
80
79
  };
81
80
  const validateNativeGzip = async (compressed, inputBytes)=>{
82
81
  if (compressed.size < 18) throwNativeGzipValidationError('too-short');
package/dist/gzip.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Compression } from "./types.mjs";
2
+ import { createNamedError } from "./utils/index.mjs";
2
3
  function isGzipSupported() {
3
4
  return 'CompressionStream' in globalThis && 'TextEncoder' in globalThis && 'Response' in globalThis && 'function' == typeof Response.prototype.blob;
4
5
  }
@@ -41,9 +42,7 @@ const crc32 = (bytes)=>{
41
42
  return (0xffffffff ^ crc) >>> 0;
42
43
  };
43
44
  const throwNativeGzipValidationError = (reason)=>{
44
- const error = new Error(`Native gzip produced invalid output: ${reason}`);
45
- error.name = NATIVE_GZIP_VALIDATION_ERROR;
46
- throw error;
45
+ throw createNamedError(NATIVE_GZIP_VALIDATION_ERROR, `Native gzip produced invalid output: ${reason}`);
47
46
  };
48
47
  const validateNativeGzip = async (compressed, inputBytes)=>{
49
48
  if (compressed.size < 18) throwNativeGzipValidationError('too-short');
@@ -15,6 +15,7 @@ export declare class PostHogLogs {
15
15
  private _flushTimer?;
16
16
  private _flushPromise;
17
17
  private _evictedSinceAdvance;
18
+ private _queueGeneration;
18
19
  private _consecutiveFlushFailures;
19
20
  private _rateCapWindowMs;
20
21
  private _maxLogsPerInterval?;
@@ -22,13 +23,29 @@ export declare class PostHogLogs {
22
23
  private _intervalLogCount;
23
24
  private _droppedWarned;
24
25
  constructor(_instance: LogsHost, _config: ResolvedPostHogLogsConfig, _logger: Logger, _getContext: () => LogSdkContext, _onReady: (fn: () => void) => void, _waitForStoragePersist?: () => Promise<void>, _scopeName?: string | undefined);
26
+ /**
27
+ * Drops every queued record. A batch this instance has in flight is retired with
28
+ * them, so it can neither re-send what was just purged nor advance past records
29
+ * captured after this call.
30
+ */
31
+ clearQueue(): void;
25
32
  /**
26
33
  * Clears the flush timer and rate-cap state. The host owns the record queue
27
34
  * and clears it separately (the browser empties its in-memory store).
28
35
  */
29
36
  reset(): void;
30
37
  onReconnect(): void;
31
- captureLog(options: CaptureLogOptions): void;
38
+ /**
39
+ * Captures one log record.
40
+ *
41
+ * @param capturedAt State snapshotted when the event occurred, for a caller that
42
+ * observes an event earlier than it can build the record. Defaults to the identity,
43
+ * session and flags as of now.
44
+ */
45
+ captureLog(options: CaptureLogOptions, capturedAt?: {
46
+ context?: LogSdkContext;
47
+ occurredAtMs?: number;
48
+ }): void;
32
49
  /**
33
50
  * Runs the configured `beforeSend` hook(s) on a capture record:
34
51
  * - single fn OR array of fns (chain, left-to-right)
@@ -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,EAA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AC,IAAI,CAAC;IAcjD;;;;;;;;;;;OAWG;IACG,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASxD,OAAO,CAAC,kBAAkB;IAqB1B,OAAO,CAAC,gBAAgB;CAMzB"}
@@ -41,6 +41,7 @@ class PostHogLogs {
41
41
  this._scopeName = _scopeName;
42
42
  this._flushPromise = null;
43
43
  this._evictedSinceAdvance = 0;
44
+ this._queueGeneration = 0;
44
45
  this._consecutiveFlushFailures = 0;
45
46
  this._intervalWindowStart = 0;
46
47
  this._intervalLogCount = 0;
@@ -52,13 +53,15 @@ class PostHogLogs {
52
53
  this._rateCapWindowMs = _config.rateCapWindowMs;
53
54
  this._maxLogsPerInterval = _config.maxLogsPerInterval;
54
55
  }
56
+ clearQueue() {
57
+ this._queueGeneration++;
58
+ this._instance.setPersistedProperty(external_types_js_namespaceObject.PostHogPersistedProperty.LogsQueue, []);
59
+ }
55
60
  reset() {
56
61
  this._clearFlushTimer();
57
- this._flushPromise = null;
58
62
  this._intervalWindowStart = 0;
59
63
  this._intervalLogCount = 0;
60
64
  this._droppedWarned = false;
61
- this._evictedSinceAdvance = 0;
62
65
  this._consecutiveFlushFailures = 0;
63
66
  this._maxBatchRecordsPerPost = this._config.maxBatchRecordsPerPost;
64
67
  }
@@ -66,7 +69,7 @@ class PostHogLogs {
66
69
  this._consecutiveFlushFailures = 0;
67
70
  this._flushInBackground();
68
71
  }
69
- captureLog(options) {
72
+ captureLog(options, capturedAt) {
70
73
  if (this._instance.isDisabled) return;
71
74
  if (this._instance.optedOut) return;
72
75
  if (!options?.body) return;
@@ -74,7 +77,7 @@ class PostHogLogs {
74
77
  if (null === filtered) return;
75
78
  if (!filtered.body) return void this._logger.info("Log was rejected in beforeSend function");
76
79
  if (!this._checkRateLimit()) return;
77
- const record = (0, external_logs_utils_js_namespaceObject.buildOtlpLogRecord)(filtered, this._getContext(), this._logger);
80
+ const record = (0, external_logs_utils_js_namespaceObject.buildOtlpLogRecord)(filtered, capturedAt?.context ?? this._getContext(), this._logger, capturedAt?.occurredAtMs);
78
81
  const entry = {
79
82
  record
80
83
  };
@@ -134,12 +137,14 @@ class PostHogLogs {
134
137
  const originalQueueLength = queue.length;
135
138
  let sentCount = 0;
136
139
  while(queue.length > 0 && sentCount < originalQueueLength){
140
+ const generation = this._queueGeneration;
137
141
  this._evictedSinceAdvance = 0;
138
142
  const batchSize = Math.min(queue.length, this._maxBatchRecordsPerPost);
139
143
  const batch = queue.slice(0, batchSize);
140
144
  const records = batch.map((e)=>e.record);
141
145
  const payload = (0, external_logs_utils_js_namespaceObject.buildOtlpLogsPayload)(records, this._buildResourceAttributes(), this._scopeName ?? this._instance.getLibraryId(), this._instance.getLibraryVersion());
142
146
  const outcome = await this._instance._sendLogsBatch(payload);
147
+ if (this._queueGeneration !== generation) return;
143
148
  if ('too-large' === outcome.kind && batch.length > 1) {
144
149
  this._maxBatchRecordsPerPost = Math.max(1, Math.floor(batch.length / 2));
145
150
  this._logger.warn(`Received 413 when sending logs batch of size ${batch.length}, reducing batch size to ${this._maxBatchRecordsPerPost}`);
@@ -13,6 +13,7 @@ class PostHogLogs {
13
13
  this._scopeName = _scopeName;
14
14
  this._flushPromise = null;
15
15
  this._evictedSinceAdvance = 0;
16
+ this._queueGeneration = 0;
16
17
  this._consecutiveFlushFailures = 0;
17
18
  this._intervalWindowStart = 0;
18
19
  this._intervalLogCount = 0;
@@ -24,13 +25,15 @@ class PostHogLogs {
24
25
  this._rateCapWindowMs = _config.rateCapWindowMs;
25
26
  this._maxLogsPerInterval = _config.maxLogsPerInterval;
26
27
  }
28
+ clearQueue() {
29
+ this._queueGeneration++;
30
+ this._instance.setPersistedProperty(PostHogPersistedProperty.LogsQueue, []);
31
+ }
27
32
  reset() {
28
33
  this._clearFlushTimer();
29
- this._flushPromise = null;
30
34
  this._intervalWindowStart = 0;
31
35
  this._intervalLogCount = 0;
32
36
  this._droppedWarned = false;
33
- this._evictedSinceAdvance = 0;
34
37
  this._consecutiveFlushFailures = 0;
35
38
  this._maxBatchRecordsPerPost = this._config.maxBatchRecordsPerPost;
36
39
  }
@@ -38,7 +41,7 @@ class PostHogLogs {
38
41
  this._consecutiveFlushFailures = 0;
39
42
  this._flushInBackground();
40
43
  }
41
- captureLog(options) {
44
+ captureLog(options, capturedAt) {
42
45
  if (this._instance.isDisabled) return;
43
46
  if (this._instance.optedOut) return;
44
47
  if (!options?.body) return;
@@ -46,7 +49,7 @@ class PostHogLogs {
46
49
  if (null === filtered) return;
47
50
  if (!filtered.body) return void this._logger.info("Log was rejected in beforeSend function");
48
51
  if (!this._checkRateLimit()) return;
49
- const record = buildOtlpLogRecord(filtered, this._getContext(), this._logger);
52
+ const record = buildOtlpLogRecord(filtered, capturedAt?.context ?? this._getContext(), this._logger, capturedAt?.occurredAtMs);
50
53
  const entry = {
51
54
  record
52
55
  };
@@ -106,12 +109,14 @@ class PostHogLogs {
106
109
  const originalQueueLength = queue.length;
107
110
  let sentCount = 0;
108
111
  while(queue.length > 0 && sentCount < originalQueueLength){
112
+ const generation = this._queueGeneration;
109
113
  this._evictedSinceAdvance = 0;
110
114
  const batchSize = Math.min(queue.length, this._maxBatchRecordsPerPost);
111
115
  const batch = queue.slice(0, batchSize);
112
116
  const records = batch.map((e)=>e.record);
113
117
  const payload = buildOtlpLogsPayload(records, this._buildResourceAttributes(), this._scopeName ?? this._instance.getLibraryId(), this._instance.getLibraryVersion());
114
118
  const outcome = await this._instance._sendLogsBatch(payload);
119
+ if (this._queueGeneration !== generation) return;
115
120
  if ('too-large' === outcome.kind && batch.length > 1) {
116
121
  this._maxBatchRecordsPerPost = Math.max(1, Math.floor(batch.length / 2));
117
122
  this._logger.warn(`Received 413 when sending logs batch of size ${batch.length}, reducing batch size to ${this._maxBatchRecordsPerPost}`);
@@ -5,7 +5,7 @@ export declare function getOtlpSeverityText(level: LogSeverityLevel): OtlpSeveri
5
5
  export declare function getOtlpSeverityNumber(level: LogSeverityLevel): number;
6
6
  export declare function toOtlpAnyValue(value: LogAttributeValue, logger?: Logger): OtlpAnyValue;
7
7
  export declare function toOtlpKeyValueList(attrs: Record<string, LogAttributeValue>, logger?: Logger): OtlpKeyValue[];
8
- export declare function buildOtlpLogRecord(options: CaptureLogOptions, sdkContext: LogSdkContext, logger?: Logger): OtlpLogRecord;
8
+ export declare function buildOtlpLogRecord(options: CaptureLogOptions, sdkContext: LogSdkContext, logger?: Logger, occurredAtMs?: number): OtlpLogRecord;
9
9
  /**
10
10
  * OTLP resource attributes for every batch, shared by the core flush path and
11
11
  * SDK-specific paths that bypass it (e.g. the browser's synchronous sendBeacon
@@ -1 +1 @@
1
- {"version":3,"file":"logs-utils.d.ts","sourceRoot":"","sources":["../../src/logs/logs-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,eAAe,EAEf,gBAAgB,EACjB,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AA4BvE,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,gBAAgB,GAAG,gBAAgB,CAE7E;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,gBAAgB,GAAG,MAAM,CAErE;AAqBD,wBAAgB,cAAc,CAAC,KAAK,EAAE,iBAAiB,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,YAAY,CAQtF;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,YAAY,EAAE,CAM5G;AAmMD,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,iBAAiB,EAC1B,UAAU,EAAE,aAAa,EACzB,MAAM,CAAC,EAAE,MAAM,GACd,aA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,MAAM,GACpB,aAAa,CA+Ef;AAMD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,yBAAyB,EACjC,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GACjB,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CASnC;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,aAAa,EAAE,EAC3B,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,EACrD,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,GACnB,eAAe,CAcjB"}
@@ -215,8 +215,8 @@ function encodeKeyValueList(attrs, logger, state, depth) {
215
215
  }
216
216
  return result;
217
217
  }
218
- function timestampToUnixNano() {
219
- return String(Date.now()) + '000000';
218
+ function timestampToUnixNano(timestampMs = Date.now()) {
219
+ return String(timestampMs) + '000000';
220
220
  }
221
221
  function encodeBody(body) {
222
222
  try {
@@ -225,10 +225,10 @@ function encodeBody(body) {
225
225
  return json_utils_js_namespaceObject.UNSERIALIZABLE_VALUE;
226
226
  }
227
227
  }
228
- function buildOtlpLogRecord(options, sdkContext, logger) {
228
+ function buildOtlpLogRecord(options, sdkContext, logger, occurredAtMs) {
229
229
  const level = options.level || 'info';
230
230
  const { text: severityText, number: severityNumber } = OTLP_SEVERITY_MAP[level] || DEFAULT_OTLP_SEVERITY;
231
- const now = timestampToUnixNano();
231
+ const eventTimeNano = timestampToUnixNano((0, index_js_namespaceObject.isNumber)(occurredAtMs) ? occurredAtMs : void 0);
232
232
  const autoAttributes = {};
233
233
  if (sdkContext.distinctId) autoAttributes.posthogDistinctId = sdkContext.distinctId;
234
234
  if (sdkContext.sessionId) autoAttributes.sessionId = sdkContext.sessionId;
@@ -266,8 +266,8 @@ function buildOtlpLogRecord(options, sdkContext, logger) {
266
266
  }
267
267
  }
268
268
  const record = {
269
- timeUnixNano: now,
270
- observedTimeUnixNano: now,
269
+ timeUnixNano: eventTimeNano,
270
+ observedTimeUnixNano: eventTimeNano,
271
271
  severityNumber,
272
272
  severityText,
273
273
  body: {
@@ -1,4 +1,4 @@
1
- import { isArray, isBoolean, isNull, isNullish, isUndefined } from "../utils/index.mjs";
1
+ import { isArray, isBoolean, isNull, isNullish, isNumber, isUndefined } from "../utils/index.mjs";
2
2
  import { CIRCULAR_VALUE, FUNCTION_VALUE, MAX_JSON_SAFE_VALUE_DEPTH, MAX_JSON_SAFE_VALUE_ITEMS, MAX_JSON_SAFE_VALUE_NODES, TRUNCATED_VALUE, UNSERIALIZABLE_VALUE, sanitizeString } from "../utils/json-utils.mjs";
3
3
  const OTLP_SEVERITY_MAP = {
4
4
  trace: {
@@ -181,8 +181,8 @@ function encodeKeyValueList(attrs, logger, state, depth) {
181
181
  }
182
182
  return result;
183
183
  }
184
- function timestampToUnixNano() {
185
- return String(Date.now()) + '000000';
184
+ function timestampToUnixNano(timestampMs = Date.now()) {
185
+ return String(timestampMs) + '000000';
186
186
  }
187
187
  function encodeBody(body) {
188
188
  try {
@@ -191,10 +191,10 @@ function encodeBody(body) {
191
191
  return UNSERIALIZABLE_VALUE;
192
192
  }
193
193
  }
194
- function buildOtlpLogRecord(options, sdkContext, logger) {
194
+ function buildOtlpLogRecord(options, sdkContext, logger, occurredAtMs) {
195
195
  const level = options.level || 'info';
196
196
  const { text: severityText, number: severityNumber } = OTLP_SEVERITY_MAP[level] || DEFAULT_OTLP_SEVERITY;
197
- const now = timestampToUnixNano();
197
+ const eventTimeNano = timestampToUnixNano(isNumber(occurredAtMs) ? occurredAtMs : void 0);
198
198
  const autoAttributes = {};
199
199
  if (sdkContext.distinctId) autoAttributes.posthogDistinctId = sdkContext.distinctId;
200
200
  if (sdkContext.sessionId) autoAttributes.sessionId = sdkContext.sessionId;
@@ -232,8 +232,8 @@ function buildOtlpLogRecord(options, sdkContext, logger) {
232
232
  }
233
233
  }
234
234
  const record = {
235
- timeUnixNano: now,
236
- observedTimeUnixNano: now,
235
+ timeUnixNano: eventTimeNano,
236
+ observedTimeUnixNano: eventTimeNano,
237
237
  severityNumber,
238
238
  severityText,
239
239
  body: {
@@ -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,qBAAqB,EACrB,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;AAEzB,cAAM,qBAAsB,SAAQ,KAAK;IAO9B,QAAQ,EAAE,oBAAoB;IAC9B,aAAa,EAAE,MAAM;IAC5B,OAAO,CAAC,oBAAoB;IAC5B,OAAO,CAAC,eAAe;IATzB,IAAI,SAA0B;IAC9B,OAAO,CAAC,uBAAuB,CAAC,CAAiB;IACjD,OAAO,CAAC,iBAAiB,CAAC,CAAmC;IAC7D,OAAO,CAAC,iBAAiB,CAAQ;gBAGxB,QAAQ,EAAE,oBAAoB,EAC9B,aAAa,EAAE,MAAM,EACpB,oBAAoB,EAAE,MAAM,EAC5B,eAAe,EAAE,eAAe;IAK1C,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,gBAAgB,IAAI,OAAO,CAE9B;IAED,IAAI,IAAI,IAAI,OAAO,CAAC,MAAM,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,eAAe;IAOvB;;;OAGG;IACH,OAAO,CAAC,eAAe;YAST,sBAAsB;IAsBpC;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,SAAS,CAAC,wBAAwB,IAAI,OAAO,CAAC,IAAI,CAAC;IAInD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,OAAO,CAAC,aAAa;IAmDrB,SAAS,CAAC,gBAAgB,IAAI;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE;IAavD;;;OAGG;IACH,SAAS,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,qBAAqB,GAAG,IAAI,CAAC;IAIxF,SAAS,CAAC,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAItD;;;;;;;;;;;OAWG;cACa,SAAS,CACvB,aAAa,EAAE,CAAC,sBAAsB,GAAG,SAAS,CAAC,EAAE,EACrD,YAAY,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,EACxC,KAAK,GAAE,MAA4B,GAClC,OAAO,CAAC,IAAI,CAAC;YAuCF,MAAM;YAmCN,WAAW;IAsFzB;;;;;;;;;OASG;YACW,cAAc;IAmDtB,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAIvE,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAItF,OAAO,CAAC,cAAc;IAyJhB,SAAS,CAAC,iBAAiB,GAAE,MAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IA0DjE;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,QAAQ,CAAC,iBAAiB,GAAE,MAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAYjE"}
@@ -52,16 +52,14 @@ class PostHogFetchHttpError extends Error {
52
52
  get text() {
53
53
  if (!this.responseBodyTextPromise) if (Date.now() >= this.responseBodyDeadline) {
54
54
  this._bodyReadTimedOut = true;
55
- const timeoutError = new Error('Response body read timed out');
56
- timeoutError.name = 'AbortError';
55
+ const timeoutError = (0, index_js_namespaceObject.createNamedError)('AbortError', 'Response body read timed out');
57
56
  this.cancelResponseBody(timeoutError);
58
57
  this.responseBodyTextPromise = Promise.reject(timeoutError);
59
58
  } else {
60
59
  const responseBodyTimeout = new Promise((_resolve, reject)=>{
61
60
  this.responseBodyTimer = (0, index_js_namespaceObject.safeSetTimeout)(()=>{
62
61
  this._bodyReadTimedOut = true;
63
- const timeoutError = new Error('Response body read timed out');
64
- timeoutError.name = 'AbortError';
62
+ const timeoutError = (0, index_js_namespaceObject.createNamedError)('AbortError', 'Response body read timed out');
65
63
  reject(timeoutError);
66
64
  this.cancelResponseBody(timeoutError);
67
65
  }, this.responseBodyDeadline - Date.now());
@@ -928,8 +926,7 @@ class PostHogCoreStateless {
928
926
  let timer;
929
927
  const deadline = new Promise((_resolve, reject)=>{
930
928
  timer = (0, index_js_namespaceObject.safeSetTimeout)(()=>{
931
- const timeoutError = new Error(`Request timed out after ${timeoutMs}ms`);
932
- timeoutError.name = 'AbortError';
929
+ const timeoutError = (0, index_js_namespaceObject.createNamedError)('AbortError', `Request timed out after ${timeoutMs}ms`);
933
930
  reject(timeoutError);
934
931
  ctrl.abort(timeoutError);
935
932
  }, timeoutMs);
@@ -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, raceWithTimeout, removeTrailingSlash, retriable, safeJsonStringify, safeSetTimeout } from "./utils/index.mjs";
5
+ import { PromiseQueue, STRING_FORMAT, allSettled, createLogger, createNamedError, 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 {
@@ -18,16 +18,14 @@ class PostHogFetchHttpError extends Error {
18
18
  get text() {
19
19
  if (!this.responseBodyTextPromise) if (Date.now() >= this.responseBodyDeadline) {
20
20
  this._bodyReadTimedOut = true;
21
- const timeoutError = new Error('Response body read timed out');
22
- timeoutError.name = 'AbortError';
21
+ const timeoutError = createNamedError('AbortError', 'Response body read timed out');
23
22
  this.cancelResponseBody(timeoutError);
24
23
  this.responseBodyTextPromise = Promise.reject(timeoutError);
25
24
  } else {
26
25
  const responseBodyTimeout = new Promise((_resolve, reject)=>{
27
26
  this.responseBodyTimer = safeSetTimeout(()=>{
28
27
  this._bodyReadTimedOut = true;
29
- const timeoutError = new Error('Response body read timed out');
30
- timeoutError.name = 'AbortError';
28
+ const timeoutError = createNamedError('AbortError', 'Response body read timed out');
31
29
  reject(timeoutError);
32
30
  this.cancelResponseBody(timeoutError);
33
31
  }, this.responseBodyDeadline - Date.now());
@@ -894,8 +892,7 @@ class PostHogCoreStateless {
894
892
  let timer;
895
893
  const deadline = new Promise((_resolve, reject)=>{
896
894
  timer = safeSetTimeout(()=>{
897
- const timeoutError = new Error(`Request timed out after ${timeoutMs}ms`);
898
- timeoutError.name = 'AbortError';
895
+ const timeoutError = createNamedError('AbortError', `Request timed out after ${timeoutMs}ms`);
899
896
  reject(timeoutError);
900
897
  ctrl.abort(timeoutError);
901
898
  }, timeoutMs);
@@ -1 +1 @@
1
- {"version":3,"file":"bot-detection.d.ts","sourceRoot":"","sources":["../../src/utils/bot-detection.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,uBAAuB,UA+FnC,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,WAAW,GAAa,IAAI,MAAM,GAAG,SAAS,EAAE,0BAAyB,MAAM,EAAO,KAAG,OAWrG,CAAA"}
1
+ {"version":3,"file":"bot-detection.d.ts","sourceRoot":"","sources":["../../src/utils/bot-detection.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,uBAAuB,UAmGnC,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,WAAW,GAAa,IAAI,MAAM,GAAG,SAAS,EAAE,0BAAyB,MAAM,EAAO,KAAG,OAWrG,CAAA"}
@@ -54,7 +54,7 @@ const DEFAULT_BLOCKED_UA_STRS = [
54
54
  'msnbot',
55
55
  'nessus',
56
56
  'petalbot',
57
- 'pinterest',
57
+ 'pinterestbot',
58
58
  'prerender',
59
59
  'rogerbot',
60
60
  'screaming frog',
@@ -25,7 +25,7 @@ const DEFAULT_BLOCKED_UA_STRS = [
25
25
  'msnbot',
26
26
  'nessus',
27
27
  'petalbot',
28
- 'pinterest',
28
+ 'pinterestbot',
29
29
  'prerender',
30
30
  'rogerbot',
31
31
  'screaming frog',
@@ -13,6 +13,18 @@ export declare const STRING_FORMAT = "utf8";
13
13
  export declare const UUID_REGEX: RegExp;
14
14
  export declare function isValidUUID(value: unknown): value is string;
15
15
  export declare function getEventUuid(uuid: unknown, generateUuid: () => string): string;
16
+ /**
17
+ * Creates an `Error` with the given `name`, in a way that also holds on pages where a browser
18
+ * extension has made `Error.prototype.name` non-writable. A plain `error.name = ...` throws
19
+ * there in strict mode, and swallowing that throw leaves the name as `Error`. Defining an own
20
+ * property on the instance shadows the prototype property instead. The descriptor matches what
21
+ * a plain assignment produces, so the resulting error is unchanged everywhere else.
22
+ *
23
+ * @param name the value for `error.name`, e.g. `'AbortError'`
24
+ * @param message the error message
25
+ * @internal Exposed for cross-package use within this SDK; not part of the stable public API.
26
+ */
27
+ export declare function createNamedError(name: string, message?: string): Error;
16
28
  export declare function assert(truthyValue: any, message: string): void;
17
29
  export declare function removeTrailingSlash(url: string): string;
18
30
  export declare function stripUrlHash<T extends string | undefined>(url: T): T extends string ? string : 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;AAGvC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,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,CAAA;AAE3F,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE3D;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,GAAG,MAAM,CAE9E;AAED,wBAAgB,MAAM,CAAC,WAAW,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAI9D;AASD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,GAAG,SAAS,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,SAAS,CAMxG;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAA;CACtC;AAED,wBAAsB,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,gBA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AAE,MAAM,EACjB,SAAS,CAAC,EAAE,MAAM,IAAI,GACrB,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAoBnB;AAGD,eAAO,MAAM,SAAS,GAAI,KAAK,GAAG,KAAG,GAAG,IAAI,OAAO,CAAC,GAAG,CAEtD,CAAA;AAED,wBAAgB,QAAQ,IAAI,SAAS,GAAG,SAAS,CAEhD;AAED,wBAAgB,UAAU,CAAC,CAAC,EAC1B,QAAQ,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,GAC1C,OAAO,CAAC,CAAC;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,GAAG,CAAA;CAAE,CAAC,EAAE,CAAC,CAStF"}
@@ -79,6 +79,7 @@ var __webpack_exports__ = {};
79
79
  UUID_REGEX: ()=>UUID_REGEX,
80
80
  allSettled: ()=>allSettled,
81
81
  assert: ()=>assert,
82
+ createNamedError: ()=>createNamedError,
82
83
  currentISOTime: ()=>currentISOTime,
83
84
  currentTimestamp: ()=>currentTimestamp,
84
85
  getEventUuid: ()=>getEventUuid,
@@ -111,6 +112,7 @@ var __webpack_exports__ = {};
111
112
  "raceWithTimeout",
112
113
  "getFetch",
113
114
  "getEventUuid",
115
+ "createNamedError",
114
116
  "isPromise"
115
117
  ].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
116
118
  return _bot_detection__WEBPACK_IMPORTED_MODULE_0__[key];
@@ -135,6 +137,7 @@ var __webpack_exports__ = {};
135
137
  "raceWithTimeout",
136
138
  "getFetch",
137
139
  "getEventUuid",
140
+ "createNamedError",
138
141
  "isPromise"
139
142
  ].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
140
143
  return _browser_utils__WEBPACK_IMPORTED_MODULE_1__[key];
@@ -159,6 +162,7 @@ var __webpack_exports__ = {};
159
162
  "raceWithTimeout",
160
163
  "getFetch",
161
164
  "getEventUuid",
165
+ "createNamedError",
162
166
  "isPromise"
163
167
  ].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
164
168
  return _bucketed_rate_limiter__WEBPACK_IMPORTED_MODULE_2__[key];
@@ -184,6 +188,7 @@ var __webpack_exports__ = {};
184
188
  "raceWithTimeout",
185
189
  "getFetch",
186
190
  "getEventUuid",
191
+ "createNamedError",
187
192
  "isPromise"
188
193
  ].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
189
194
  return _number_utils__WEBPACK_IMPORTED_MODULE_4__[key];
@@ -208,6 +213,7 @@ var __webpack_exports__ = {};
208
213
  "raceWithTimeout",
209
214
  "getFetch",
210
215
  "getEventUuid",
216
+ "createNamedError",
211
217
  "isPromise"
212
218
  ].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
213
219
  return _string_utils__WEBPACK_IMPORTED_MODULE_5__[key];
@@ -232,6 +238,7 @@ var __webpack_exports__ = {};
232
238
  "raceWithTimeout",
233
239
  "getFetch",
234
240
  "getEventUuid",
241
+ "createNamedError",
235
242
  "isPromise"
236
243
  ].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
237
244
  return _type_utils__WEBPACK_IMPORTED_MODULE_6__[key];
@@ -256,6 +263,7 @@ var __webpack_exports__ = {};
256
263
  "raceWithTimeout",
257
264
  "getFetch",
258
265
  "getEventUuid",
266
+ "createNamedError",
259
267
  "isPromise"
260
268
  ].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
261
269
  return _promise_queue__WEBPACK_IMPORTED_MODULE_7__[key];
@@ -280,6 +288,7 @@ var __webpack_exports__ = {};
280
288
  "raceWithTimeout",
281
289
  "getFetch",
282
290
  "getEventUuid",
291
+ "createNamedError",
283
292
  "isPromise"
284
293
  ].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
285
294
  return _logger__WEBPACK_IMPORTED_MODULE_8__[key];
@@ -304,6 +313,7 @@ var __webpack_exports__ = {};
304
313
  "raceWithTimeout",
305
314
  "getFetch",
306
315
  "getEventUuid",
316
+ "createNamedError",
307
317
  "isPromise"
308
318
  ].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
309
319
  return _user_agent_utils__WEBPACK_IMPORTED_MODULE_9__[key];
@@ -317,6 +327,18 @@ var __webpack_exports__ = {};
317
327
  function getEventUuid(uuid, generateUuid) {
318
328
  return isValidUUID(uuid) ? uuid : generateUuid();
319
329
  }
330
+ function createNamedError(name, message) {
331
+ const error = new Error(message);
332
+ try {
333
+ Object.defineProperty(error, 'name', {
334
+ value: name,
335
+ writable: true,
336
+ enumerable: true,
337
+ configurable: true
338
+ });
339
+ } catch {}
340
+ return error;
341
+ }
320
342
  function assert(truthyValue, message) {
321
343
  if (!truthyValue || 'string' != typeof truthyValue || isEmpty(truthyValue)) throw new Error(message);
322
344
  }
@@ -394,6 +416,7 @@ exports.STRING_FORMAT = __webpack_exports__.STRING_FORMAT;
394
416
  exports.UUID_REGEX = __webpack_exports__.UUID_REGEX;
395
417
  exports.allSettled = __webpack_exports__.allSettled;
396
418
  exports.assert = __webpack_exports__.assert;
419
+ exports.createNamedError = __webpack_exports__.createNamedError;
397
420
  exports.currentISOTime = __webpack_exports__.currentISOTime;
398
421
  exports.currentTimestamp = __webpack_exports__.currentTimestamp;
399
422
  exports.getEventUuid = __webpack_exports__.getEventUuid;
@@ -411,6 +434,7 @@ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
411
434
  "UUID_REGEX",
412
435
  "allSettled",
413
436
  "assert",
437
+ "createNamedError",
414
438
  "currentISOTime",
415
439
  "currentTimestamp",
416
440
  "getEventUuid",
@@ -16,6 +16,18 @@ function isValidUUID(value) {
16
16
  function getEventUuid(uuid, generateUuid) {
17
17
  return isValidUUID(uuid) ? uuid : generateUuid();
18
18
  }
19
+ function createNamedError(name, message) {
20
+ const error = new Error(message);
21
+ try {
22
+ Object.defineProperty(error, 'name', {
23
+ value: name,
24
+ writable: true,
25
+ enumerable: true,
26
+ configurable: true
27
+ });
28
+ } catch {}
29
+ return error;
30
+ }
19
31
  function assert(truthyValue, message) {
20
32
  if (!truthyValue || 'string' != typeof truthyValue || isEmpty(truthyValue)) throw new Error(message);
21
33
  }
@@ -88,4 +100,4 @@ function allSettled(promises) {
88
100
  reason
89
101
  }))));
90
102
  }
91
- export { STRING_FORMAT, UUID_REGEX, allSettled, assert, currentISOTime, currentTimestamp, getEventUuid, getFetch, isPromise, isValidUUID, raceWithTimeout, removeTrailingSlash, retriable, safeSetTimeout, stripUrlHash, toJsonSafeValue };
103
+ export { STRING_FORMAT, UUID_REGEX, allSettled, assert, createNamedError, currentISOTime, currentTimestamp, getEventUuid, getFetch, isPromise, isValidUUID, raceWithTimeout, removeTrailingSlash, retriable, safeSetTimeout, stripUrlHash, toJsonSafeValue };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/core",
3
- "version": "1.48.12",
3
+ "version": "1.49.1",
4
4
  "bugs": {
5
5
  "url": "https://github.com/PostHog/posthog-js/issues"
6
6
  },
package/src/gzip.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Compression } from './types'
2
+ import { createNamedError } from './utils'
2
3
 
3
4
  /**
4
5
  * Older browsers and some runtimes don't support this yet
@@ -88,9 +89,7 @@ const crc32 = (bytes: Uint8Array): number => {
88
89
  }
89
90
 
90
91
  const throwNativeGzipValidationError = (reason: NativeGzipValidationReason): never => {
91
- const error = new Error(`Native gzip produced invalid output: ${reason}`)
92
- error.name = NATIVE_GZIP_VALIDATION_ERROR
93
- throw error
92
+ throw createNamedError(NATIVE_GZIP_VALIDATION_ERROR, `Native gzip produced invalid output: ${reason}`)
94
93
  }
95
94
 
96
95
  const validateNativeGzip = async (compressed: Blob, inputBytes: Uint8Array): Promise<void> => {
@@ -171,6 +171,167 @@ describe('PostHogLogs', () => {
171
171
  expect(logs).toBeDefined()
172
172
  })
173
173
 
174
+ describe('clearQueue', () => {
175
+ it('does not let an in-flight batch drop records captured after the clear', async () => {
176
+ let releaseSend: (v: any) => void = () => {}
177
+ const mockInstance = createMockInstance({
178
+ _sendLogsBatch: jest.fn(() => new Promise((resolve) => (releaseSend = resolve))),
179
+ })
180
+ const logs = new PostHogLogs(
181
+ mockInstance,
182
+ resolveForTest(),
183
+ logger,
184
+ getContextFor(mockInstance),
185
+ immediateOnReady
186
+ )
187
+ logs.captureLog({ body: 'before the clear' })
188
+
189
+ const flushing = logs.flush()
190
+ logs.clearQueue()
191
+ logs.captureLog({ body: 'captured after the clear' })
192
+
193
+ releaseSend({ kind: 'ok' })
194
+ await flushing
195
+
196
+ expect(readQueue(mockInstance).map((e) => e.record.body)).toEqual([{ stringValue: 'captured after the clear' }])
197
+ })
198
+ })
199
+
200
+ describe('a 413 retry that lands after the queue is cleared', () => {
201
+ it('does not re-send records the clear purged', async () => {
202
+ const sentBodies: string[][] = []
203
+ let releaseSend: (v: any) => void = () => {}
204
+ const mockInstance = createMockInstance({
205
+ _sendLogsBatch: jest.fn((payload: any) => {
206
+ sentBodies.push(payload.resourceLogs[0].scopeLogs[0].logRecords.map((r: any) => r.body.stringValue))
207
+ // Only the first send is held open; any retry resolves at once so a
208
+ // regression fails on the assertion rather than by hanging the test.
209
+ return sentBodies.length === 1
210
+ ? new Promise((resolve) => (releaseSend = resolve))
211
+ : Promise.resolve({ kind: 'ok' })
212
+ }),
213
+ })
214
+ const logs = new PostHogLogs(
215
+ mockInstance,
216
+ resolveForTest(),
217
+ logger,
218
+ getContextFor(mockInstance),
219
+ immediateOnReady
220
+ )
221
+ logs.captureLog({ body: 'purged one' })
222
+ logs.captureLog({ body: 'purged two' })
223
+
224
+ const flushing = logs.flush()
225
+ logs.clearQueue()
226
+ // A 413 makes `_flushInner` retry the same records with a smaller batch cap.
227
+ releaseSend({ kind: 'too-large' })
228
+ await flushing
229
+
230
+ expect(sentBodies).toEqual([['purged one', 'purged two']])
231
+ })
232
+ })
233
+
234
+ describe('a clear that lands between two batches of one flush', () => {
235
+ it('still advances the batch assembled after the clear', async () => {
236
+ const sent: string[][] = []
237
+ let releasePersist: (() => void) | null = null
238
+ const mockInstance = createMockInstance({
239
+ _sendLogsBatch: jest.fn((payload: any) => {
240
+ sent.push(payload.resourceLogs[0].scopeLogs[0].logRecords.map((r: any) => r.body.stringValue))
241
+ return Promise.resolve({ kind: 'ok' })
242
+ }),
243
+ })
244
+ const logs = new PostHogLogs(
245
+ mockInstance,
246
+ resolveForTest({ maxBatchRecordsPerPost: 1 }),
247
+ logger,
248
+ getContextFor(mockInstance),
249
+ immediateOnReady,
250
+ () => new Promise<void>((resolve) => (releasePersist = resolve))
251
+ )
252
+ logs.captureLog({ body: 'a' })
253
+ logs.captureLog({ body: 'b' })
254
+
255
+ const flushing = logs.flush()
256
+ // Let batch ['a'] send and park inside the persist await between batches.
257
+ for (let i = 0; i < 10; i++) {
258
+ await Promise.resolve()
259
+ }
260
+ logs.clearQueue()
261
+ logs.captureLog({ body: 'c' })
262
+ // Each batch installs a fresh persist gate; release whichever is pending until
263
+ // the flush drains.
264
+ for (let i = 0; i < 20; i++) {
265
+ const pending = releasePersist
266
+ releasePersist = null
267
+ pending?.()
268
+ await Promise.resolve()
269
+ }
270
+ await flushing
271
+
272
+ expect({ sent, queue: readQueue(mockInstance).map((e) => e.record.body.stringValue) }).toEqual({
273
+ sent: [['a'], ['c']],
274
+ queue: [],
275
+ })
276
+ })
277
+ })
278
+
279
+ describe('reset during an in-flight flush', () => {
280
+ it('does not let an in-flight batch drop records captured after the reset', async () => {
281
+ let releaseSend: (v: any) => void = () => {}
282
+ const mockInstance = createMockInstance({
283
+ _sendLogsBatch: jest.fn(() => new Promise((resolve) => (releaseSend = resolve))),
284
+ })
285
+ const logs = new PostHogLogs(
286
+ mockInstance,
287
+ resolveForTest(),
288
+ logger,
289
+ getContextFor(mockInstance),
290
+ immediateOnReady
291
+ )
292
+ logs.captureLog({ body: 'before the reset' })
293
+
294
+ const flushing = logs.flush()
295
+ logs.clearQueue()
296
+ logs.reset()
297
+ logs.captureLog({ body: 'captured after the reset' })
298
+
299
+ releaseSend({ kind: 'ok' })
300
+ await flushing
301
+
302
+ expect(readQueue(mockInstance).map((e) => e.record.body)).toEqual([{ stringValue: 'captured after the reset' }])
303
+ })
304
+
305
+ it('does not let a flush started after the reset run alongside the in-flight one', async () => {
306
+ let releaseSend: (v: any) => void = () => {}
307
+ const mockInstance = createMockInstance({
308
+ _sendLogsBatch: jest.fn(() => new Promise((resolve) => (releaseSend = resolve))),
309
+ })
310
+ const logs = new PostHogLogs(
311
+ mockInstance,
312
+ resolveForTest(),
313
+ logger,
314
+ getContextFor(mockInstance),
315
+ immediateOnReady
316
+ )
317
+ logs.captureLog({ body: 'before the reset' })
318
+
319
+ const flushing = logs.flush()
320
+ logs.clearQueue()
321
+ logs.reset()
322
+ logs.captureLog({ body: 'captured after the reset' })
323
+ const second = logs.flush()
324
+
325
+ expect(mockInstance._sendLogsBatch).toHaveBeenCalledTimes(1)
326
+
327
+ releaseSend({ kind: 'ok' })
328
+ await flushing
329
+ await second
330
+
331
+ expect(readQueue(mockInstance).map((e) => e.record.body)).toEqual([{ stringValue: 'captured after the reset' }])
332
+ })
333
+ })
334
+
174
335
  describe('captureLog', () => {
175
336
  it('writes a record to the logs queue via setPersistedProperty', () => {
176
337
  const logs = new PostHogLogs(
@@ -191,6 +352,29 @@ describe('PostHogLogs', () => {
191
352
  )
192
353
  })
193
354
 
355
+ it('stamps a record from `capturedAt` rather than live state', () => {
356
+ const logs = new PostHogLogs(
357
+ mockInstance,
358
+ resolveForTest(),
359
+ logger,
360
+ getContextFor(mockInstance),
361
+ immediateOnReady
362
+ )
363
+ const occurredAtMs = Date.now() - 5000
364
+
365
+ logs.captureLog(
366
+ { body: 'buffered before identify' },
367
+ { context: { distinctId: 'anon-1', sessionId: 'session-1' }, occurredAtMs }
368
+ )
369
+
370
+ const [{ record }] = readQueue(mockInstance)
371
+ const attributes = Object.fromEntries(record.attributes.map((a: any) => [a.key, a.value.stringValue]))
372
+ expect(attributes.posthogDistinctId).toBe('anon-1')
373
+ expect(attributes.sessionId).toBe('session-1')
374
+ expect(record.timeUnixNano).toBe(String(occurredAtMs) + '000000')
375
+ expect(record.observedTimeUnixNano).toBe(record.timeUnixNano)
376
+ })
377
+
194
378
  it('maps severity levels correctly', () => {
195
379
  const logs = new PostHogLogs(
196
380
  mockInstance,
package/src/logs/index.ts CHANGED
@@ -24,6 +24,9 @@ export class PostHogLogs {
24
24
  // Head records evicted (FIFO) while a batch is in flight; the queue-advance
25
25
  // subtracts these so it drops the sent records, not ones captured mid-send.
26
26
  private _evictedSinceAdvance = 0
27
+ // A batch captures this when it is assembled, so it can tell that the records it is
28
+ // holding no longer correspond to anything queued.
29
+ private _queueGeneration = 0
27
30
  // Consecutive failed flushes; drives exponential backoff on the retry timer.
28
31
  // A successful flush resets it to 0.
29
32
  private _consecutiveFlushFailures = 0
@@ -65,17 +68,28 @@ export class PostHogLogs {
65
68
  this._maxLogsPerInterval = _config.maxLogsPerInterval
66
69
  }
67
70
 
71
+ /**
72
+ * Drops every queued record. A batch this instance has in flight is retired with
73
+ * them, so it can neither re-send what was just purged nor advance past records
74
+ * captured after this call.
75
+ */
76
+ clearQueue(): void {
77
+ this._queueGeneration++
78
+ this._instance.setPersistedProperty(PostHogPersistedProperty.LogsQueue, [])
79
+ }
80
+
68
81
  /**
69
82
  * Clears the flush timer and rate-cap state. The host owns the record queue
70
83
  * and clears it separately (the browser empties its in-memory store).
71
84
  */
72
85
  reset(): void {
73
86
  this._clearFlushTimer()
74
- this._flushPromise = null
87
+ // `_flushPromise` is deliberately left alone: clearing it would let a second flush
88
+ // run alongside the in-flight one. Retiring that flush is `clearQueue`'s job,
89
+ // because the queue it holds belongs to the host, not to this state.
75
90
  this._intervalWindowStart = 0
76
91
  this._intervalLogCount = 0
77
92
  this._droppedWarned = false
78
- this._evictedSinceAdvance = 0
79
93
  this._consecutiveFlushFailures = 0
80
94
  this._maxBatchRecordsPerPost = this._config.maxBatchRecordsPerPost
81
95
  }
@@ -88,7 +102,14 @@ export class PostHogLogs {
88
102
  this._flushInBackground()
89
103
  }
90
104
 
91
- captureLog(options: CaptureLogOptions): void {
105
+ /**
106
+ * Captures one log record.
107
+ *
108
+ * @param capturedAt State snapshotted when the event occurred, for a caller that
109
+ * observes an event earlier than it can build the record. Defaults to the identity,
110
+ * session and flags as of now.
111
+ */
112
+ captureLog(options: CaptureLogOptions, capturedAt?: { context?: LogSdkContext; occurredAtMs?: number }): void {
92
113
  if (this._instance.isDisabled) {
93
114
  return
94
115
  }
@@ -119,7 +140,12 @@ export class PostHogLogs {
119
140
  // Build before deferring so attributes reflect state at capture time, not
120
141
  // at drain time (identity/session changes between capture and drain must
121
142
  // not corrupt recorded attributes).
122
- const record = buildOtlpLogRecord(filtered, this._getContext(), this._logger)
143
+ const record = buildOtlpLogRecord(
144
+ filtered,
145
+ capturedAt?.context ?? this._getContext(),
146
+ this._logger,
147
+ capturedAt?.occurredAtMs
148
+ )
123
149
  const entry: BufferedLogEntry = { record }
124
150
 
125
151
  this._onReady(() => this._enqueue(entry))
@@ -233,6 +259,10 @@ export class PostHogLogs {
233
259
  let sentCount = 0
234
260
 
235
261
  while (queue.length > 0 && sentCount < originalQueueLength) {
262
+ // Captured per batch, not per flush: a clear that lands between batches leaves
263
+ // the next one assembled from an already-fresh queue, so that batch advances
264
+ // normally instead of being retired for a purge it never held.
265
+ const generation = this._queueGeneration
236
266
  // Reset per batch so the advance below counts only evictions during THIS
237
267
  // batch's send. Evictions during the persist await or between iterations
238
268
  // are already reflected in the next iteration's queue read, so they must
@@ -252,6 +282,13 @@ export class PostHogLogs {
252
282
 
253
283
  const outcome = await this._instance._sendLogsBatch(payload)
254
284
 
285
+ if (this._queueGeneration !== generation) {
286
+ // The queue was cleared while this batch was in flight. `queue` is a stale local
287
+ // copy, so retrying it would re-send purged records and advancing it would slice
288
+ // records captured since. Retire the batch instead.
289
+ return
290
+ }
291
+
255
292
  if (outcome.kind === 'too-large' && batch.length > 1) {
256
293
  this._maxBatchRecordsPerPost = Math.max(1, Math.floor(batch.length / 2))
257
294
  this._logger.warn(
@@ -467,6 +467,30 @@ describe('logs-utils', () => {
467
467
  expect(record.observedTimeUnixNano).toBe(record.timeUnixNano)
468
468
  })
469
469
 
470
+ it('stamps both timestamps from the event time when the record is built late', () => {
471
+ const occurredAtMs = Date.now() - 5000
472
+ const record = buildOtlpLogRecord({ body: 'buffered' }, minimalSdkContext, undefined, occurredAtMs)
473
+
474
+ expect(record.timeUnixNano).toBe(String(occurredAtMs) + '000000')
475
+ // The logs spec requires the client to keep the two equal.
476
+ expect(record.observedTimeUnixNano).toBe(record.timeUnixNano)
477
+ })
478
+
479
+ it.each([undefined, NaN, 'nope' as unknown as number])(
480
+ 'falls back to now when the event time is %p',
481
+ (occurredAtMs) => {
482
+ const before = Date.now()
483
+ const record = buildOtlpLogRecord({ body: 'x' }, minimalSdkContext, undefined, occurredAtMs)
484
+ // Divide and the 19-digit nanosecond value loses its last digits to float.
485
+ const stampedMs = Number(record.timeUnixNano.slice(0, -6))
486
+
487
+ expect(record.timeUnixNano).toMatch(/^\d+000000$/)
488
+ expect(stampedMs).toBeGreaterThanOrEqual(before)
489
+ expect(stampedMs).toBeLessThanOrEqual(Date.now())
490
+ expect(record.observedTimeUnixNano).toBe(record.timeUnixNano)
491
+ }
492
+ )
493
+
470
494
  it('maps severity levels correctly', () => {
471
495
  const record = buildOtlpLogRecord({ body: 'test', level: 'error' }, minimalSdkContext)
472
496
  expect(record.severityText).toBe('ERROR')
@@ -11,7 +11,7 @@ import type {
11
11
  } from '@posthog/types'
12
12
  import type { Logger } from '../types'
13
13
  import type { LogSdkContext, ResolvedPostHogLogsConfig } from './types'
14
- import { isArray, isBoolean, isNull, isNullish, isUndefined } from '../utils'
14
+ import { isArray, isBoolean, isNull, isNullish, isNumber, isUndefined } from '../utils'
15
15
  import {
16
16
  CIRCULAR_VALUE,
17
17
  FUNCTION_VALUE,
@@ -245,14 +245,14 @@ function encodeKeyValueList(
245
245
  // ============================================================================
246
246
 
247
247
  /**
248
- * Returns the current wall-clock time as a unix-nanos string.
248
+ * Returns `timestampMs` (default: now) as a unix-nanos string.
249
249
  *
250
250
  * OTLP requires nanoseconds as a string (uint64 doesn't fit in JS Number).
251
251
  * `Date.now() * 1_000_000` would exceed Number.MAX_SAFE_INTEGER, so we
252
252
  * concatenate instead of multiplying.
253
253
  */
254
- function timestampToUnixNano(): string {
255
- return String(Date.now()) + '000000'
254
+ function timestampToUnixNano(timestampMs: number = Date.now()): string {
255
+ return String(timestampMs) + '000000'
256
256
  }
257
257
 
258
258
  /**
@@ -264,6 +264,10 @@ function timestampToUnixNano(): string {
264
264
  * `screenName` / `appState`), so a missing field never adds a stray attribute.
265
265
  *
266
266
  * User-provided `options.attributes` always wins on conflicts.
267
+ *
268
+ * `occurredAtMs` is when the event happened, for a host that records an event earlier
269
+ * than it can build the record; it stamps both OTLP timestamps, which the logs spec
270
+ * requires to be equal.
267
271
  */
268
272
  // `body` is only typed as a string. An untyped caller — or a `beforeSend` that
269
273
  // rewrites it — can pass anything, and `String()` throws on a value whose
@@ -279,11 +283,12 @@ function encodeBody(body: string): string {
279
283
  export function buildOtlpLogRecord(
280
284
  options: CaptureLogOptions,
281
285
  sdkContext: LogSdkContext,
282
- logger?: Logger
286
+ logger?: Logger,
287
+ occurredAtMs?: number
283
288
  ): OtlpLogRecord {
284
289
  const level: LogSeverityLevel = options.level || 'info'
285
290
  const { text: severityText, number: severityNumber } = OTLP_SEVERITY_MAP[level] || DEFAULT_OTLP_SEVERITY
286
- const now = timestampToUnixNano()
291
+ const eventTimeNano = timestampToUnixNano(isNumber(occurredAtMs) ? occurredAtMs : undefined)
287
292
 
288
293
  const autoAttributes: Record<string, LogAttributeValue> = {}
289
294
 
@@ -340,8 +345,8 @@ export function buildOtlpLogRecord(
340
345
  }
341
346
 
342
347
  const record: OtlpLogRecord = {
343
- timeUnixNano: now,
344
- observedTimeUnixNano: now,
348
+ timeUnixNano: eventTimeNano,
349
+ observedTimeUnixNano: eventTimeNano,
345
350
  severityNumber,
346
351
  severityText,
347
352
  body: { stringValue: encodeBody(options.body) },
@@ -27,6 +27,7 @@ import {
27
27
  } from './types'
28
28
  import {
29
29
  allSettled,
30
+ createNamedError,
30
31
  currentISOTime,
31
32
  PromiseQueue,
32
33
  removeTrailingSlash,
@@ -76,16 +77,14 @@ class PostHogFetchHttpError extends Error {
76
77
  if (!this.responseBodyTextPromise) {
77
78
  if (Date.now() >= this.responseBodyDeadline) {
78
79
  this._bodyReadTimedOut = true
79
- const timeoutError = new Error('Response body read timed out')
80
- timeoutError.name = 'AbortError'
80
+ const timeoutError = createNamedError('AbortError', 'Response body read timed out')
81
81
  this.cancelResponseBody(timeoutError)
82
82
  this.responseBodyTextPromise = Promise.reject(timeoutError)
83
83
  } else {
84
84
  const responseBodyTimeout = new Promise<never>((_resolve, reject) => {
85
85
  this.responseBodyTimer = safeSetTimeout(() => {
86
86
  this._bodyReadTimedOut = true
87
- const timeoutError = new Error('Response body read timed out')
88
- timeoutError.name = 'AbortError'
87
+ const timeoutError = createNamedError('AbortError', 'Response body read timed out')
89
88
  // Reject first so the timeout remains the diagnostic if abort rejects the body read synchronously.
90
89
  reject(timeoutError)
91
90
  this.cancelResponseBody(timeoutError)
@@ -1768,8 +1767,7 @@ export abstract class PostHogCoreStateless {
1768
1767
  // relying only on standards-compliant AbortSignal behavior.
1769
1768
  const deadline = new Promise<never>((_resolve, reject) => {
1770
1769
  timer = safeSetTimeout(() => {
1771
- const timeoutError = new Error(`Request timed out after ${timeoutMs}ms`)
1772
- timeoutError.name = 'AbortError'
1770
+ const timeoutError = createNamedError('AbortError', `Request timed out after ${timeoutMs}ms`)
1773
1771
  // Reject first so this error wins if an abort-aware injected fetch rejects synchronously.
1774
1772
  reject(timeoutError)
1775
1773
  ctrl.abort(timeoutError)
@@ -28,7 +28,11 @@ export const DEFAULT_BLOCKED_UA_STRS = [
28
28
  'msnbot',
29
29
  'nessus',
30
30
  'petalbot',
31
- 'pinterest',
31
+ // not the bare 'pinterest' -- that also matches the Pinterest app's own in-app
32
+ // browser UA (e.g. "...Mobile/15D100 [Pinterest/iOS]"), which is a real user,
33
+ // not the crawler. The crawler's other UA variant ("...pinterest.com/bot.html")
34
+ // is still covered by the generic 'bot.htm' entry below.
35
+ 'pinterestbot',
32
36
  'prerender',
33
37
  'rogerbot',
34
38
  'screaming frog',
@@ -25,6 +25,27 @@ export function getEventUuid(uuid: unknown, generateUuid: () => string): string
25
25
  return isValidUUID(uuid) ? uuid : generateUuid()
26
26
  }
27
27
 
28
+ /**
29
+ * Creates an `Error` with the given `name`, in a way that also holds on pages where a browser
30
+ * extension has made `Error.prototype.name` non-writable. A plain `error.name = ...` throws
31
+ * there in strict mode, and swallowing that throw leaves the name as `Error`. Defining an own
32
+ * property on the instance shadows the prototype property instead. The descriptor matches what
33
+ * a plain assignment produces, so the resulting error is unchanged everywhere else.
34
+ *
35
+ * @param name the value for `error.name`, e.g. `'AbortError'`
36
+ * @param message the error message
37
+ * @internal Exposed for cross-package use within this SDK; not part of the stable public API.
38
+ */
39
+ export function createNamedError(name: string, message?: string): Error {
40
+ const error = new Error(message)
41
+ try {
42
+ Object.defineProperty(error, 'name', { value: name, writable: true, enumerable: true, configurable: true })
43
+ } catch {
44
+ // a page hostile enough to harden `Error.prototype` can also patch `Object.defineProperty`
45
+ }
46
+ return error
47
+ }
48
+
28
49
  export function assert(truthyValue: any, message: string): void {
29
50
  if (!truthyValue || typeof truthyValue !== 'string' || isEmpty(truthyValue)) {
30
51
  throw new Error(message)
@@ -0,0 +1,36 @@
1
+ import { createNamedError } from './index'
2
+
3
+ describe('createNamedError', () => {
4
+ it('sets the name and message', () => {
5
+ const error = createNamedError('AbortError', 'timed out')
6
+ expect(error.name).toBe('AbortError')
7
+ expect(error.message).toBe('timed out')
8
+ })
9
+
10
+ it('defines name with the same descriptor a plain assignment would produce', () => {
11
+ const error = createNamedError('AbortError', 'timed out')
12
+ expect(Object.getOwnPropertyDescriptor(error, 'name')).toEqual({
13
+ value: 'AbortError',
14
+ writable: true,
15
+ enumerable: true,
16
+ configurable: true,
17
+ })
18
+ })
19
+
20
+ it('preserves the name when Error.prototype.name is non-writable', () => {
21
+ const descriptor = Object.getOwnPropertyDescriptor(Error.prototype, 'name') ?? {
22
+ value: 'Error',
23
+ writable: true,
24
+ enumerable: false,
25
+ configurable: true,
26
+ }
27
+ Object.defineProperty(Error.prototype, 'name', { value: 'Error', writable: false, configurable: true })
28
+ try {
29
+ const error = createNamedError('AbortError', 'timed out')
30
+ expect(error.name).toBe('AbortError')
31
+ expect(error.message).toBe('timed out')
32
+ } finally {
33
+ Object.defineProperty(Error.prototype, 'name', descriptor)
34
+ }
35
+ })
36
+ })