@posthog/core 1.69.9 → 1.71.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/capture-v1/package.json +6 -0
- package/dist/capture-v1/compression.d.ts +18 -0
- package/dist/capture-v1/compression.d.ts.map +1 -0
- package/dist/capture-v1/compression.js +70 -0
- package/dist/capture-v1/compression.mjs +26 -0
- package/dist/capture-v1/errors.d.ts +48 -0
- package/dist/capture-v1/errors.d.ts.map +1 -0
- package/dist/capture-v1/errors.js +82 -0
- package/dist/capture-v1/errors.mjs +38 -0
- package/dist/capture-v1/index.d.ts +15 -0
- package/dist/capture-v1/index.d.ts.map +1 -0
- package/dist/capture-v1/index.js +88 -0
- package/dist/capture-v1/index.mjs +7 -0
- package/dist/capture-v1/sender.d.ts +150 -0
- package/dist/capture-v1/sender.d.ts.map +1 -0
- package/dist/capture-v1/sender.js +554 -0
- package/dist/capture-v1/sender.mjs +507 -0
- package/dist/capture-v1/serialize.d.ts +30 -0
- package/dist/capture-v1/serialize.d.ts.map +1 -0
- package/dist/capture-v1/serialize.js +106 -0
- package/dist/capture-v1/serialize.mjs +59 -0
- package/dist/capture-v1/transform.d.ts +19 -0
- package/dist/capture-v1/transform.d.ts.map +1 -0
- package/dist/capture-v1/transform.js +118 -0
- package/dist/capture-v1/transform.mjs +77 -0
- package/dist/capture-v1/types.d.ts +52 -0
- package/dist/capture-v1/types.d.ts.map +1 -0
- package/dist/capture-v1/types.js +44 -0
- package/dist/capture-v1/types.mjs +3 -0
- package/dist/capture-v1/uuid.d.ts +9 -0
- package/dist/capture-v1/uuid.d.ts.map +1 -0
- package/dist/capture-v1/uuid.js +75 -0
- package/dist/capture-v1/uuid.mjs +34 -0
- package/dist/featureFlagLocalEvaluation.d.ts +2 -0
- package/dist/featureFlagLocalEvaluation.d.ts.map +1 -1
- package/dist/featureFlagLocalEvaluation.js +38 -0
- package/dist/featureFlagLocalEvaluation.mjs +38 -0
- package/dist/featureFlagUtils.d.ts +7 -5
- package/dist/featureFlagUtils.d.ts.map +1 -1
- package/dist/featureFlagUtils.js +17 -11
- package/dist/featureFlagUtils.mjs +14 -11
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -16
- package/dist/index.mjs +1 -1
- package/dist/posthog-core-stateless.d.ts +44 -7
- package/dist/posthog-core-stateless.d.ts.map +1 -1
- package/dist/posthog-core-stateless.js +103 -24
- package/dist/posthog-core-stateless.mjs +103 -24
- package/dist/posthog-core.d.ts +138 -53
- package/dist/posthog-core.d.ts.map +1 -1
- package/dist/posthog-core.js +341 -115
- package/dist/posthog-core.mjs +338 -115
- package/dist/types.d.ts +33 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +25 -12
- package/dist/utils/index.mjs +1 -1
- package/dist/utils/json-utils.d.ts +11 -1
- package/dist/utils/json-utils.d.ts.map +1 -1
- package/dist/utils/json-utils.js +50 -2
- package/dist/utils/json-utils.mjs +46 -1
- package/package.json +13 -3
- package/src/capture-v1/compression.ts +50 -0
- package/src/capture-v1/errors.ts +91 -0
- package/src/capture-v1/index.ts +34 -0
- package/src/capture-v1/sender.ts +779 -0
- package/src/capture-v1/serialize.ts +113 -0
- package/src/capture-v1/transform.ts +135 -0
- package/src/capture-v1/types.ts +59 -0
- package/src/capture-v1/uuid.ts +53 -0
- package/src/featureFlagLocalEvaluation.ts +51 -0
- package/src/featureFlagUtils.ts +22 -10
- package/src/index.ts +1 -0
- package/src/posthog-core-stateless.ts +190 -35
- package/src/posthog-core.ts +615 -178
- package/src/types.ts +31 -1
- package/src/utils/index.ts +1 -1
- package/src/utils/json-utils.ts +64 -1
- package/src/error-tracking/chunk-ids.spec.ts +0 -77
- package/src/error-tracking/coercers/error-event-coercer.spec.ts +0 -142
- package/src/error-tracking/coercers/promise-rejection-event.spec.ts +0 -77
- package/src/error-tracking/coercers/string-coercer.spec.ts +0 -26
- package/src/error-tracking/error-properties-builder.aggregate-errors.spec.ts +0 -412
- package/src/error-tracking/error-properties-builder.coerce.spec.ts +0 -337
- package/src/error-tracking/error-properties-builder.metadata.spec.ts +0 -318
- package/src/error-tracking/error-properties-builder.parse.spec.ts +0 -37
- package/src/error-tracking/exception-steps.spec.ts +0 -115
- package/src/error-tracking/parsers/base.spec.ts +0 -156
- package/src/error-tracking/parsers/index.spec.ts +0 -270
- package/src/error-tracking/parsers/node.spec.ts +0 -34
- package/src/error-tracking/release.spec.ts +0 -34
- package/src/logs/index.spec.ts +0 -2421
- package/src/logs/logs-utils.spec.ts +0 -266
- package/src/metrics/index.spec.ts +0 -1249
- package/src/surveys/activation.spec.ts +0 -61
- package/src/surveys/events.spec.ts +0 -183
- package/src/surveys/keys.spec.ts +0 -29
- package/src/surveys/property-matching.spec.ts +0 -539
- package/src/surveys/shuffling.spec.ts +0 -51
- package/src/surveys/translations.spec.ts +0 -274
- package/src/surveys/validation.spec.ts +0 -168
- package/src/traces/config.spec.ts +0 -271
- package/src/traces/ids.spec.ts +0 -115
- package/src/traces/index.spec.ts +0 -3287
- package/src/traces/live-spans.spec.ts +0 -69
- package/src/traces/otlp.spec.ts +0 -368
- package/src/traces/span.spec.ts +0 -1137
- package/src/traces/traceparent.spec.ts +0 -184
- package/src/utils/bot-detection.spec.ts +0 -107
- package/src/utils/bucketed-rate-limiter.spec.ts +0 -327
- package/src/utils/json-utils.spec.ts +0 -115
- package/src/utils/named-error.spec.ts +0 -36
- package/src/utils/number-utils.spec.ts +0 -212
- package/src/utils/otlp-any-value.spec.ts +0 -376
- package/src/utils/otlp-resource.spec.ts +0 -171
- package/src/utils/promise-queue.spec.ts +0 -55
- package/src/utils/string-utils.spec.ts +0 -158
- package/src/utils/type-utils.spec.ts +0 -38
- package/src/utils/webview-app-utils.spec.ts +0 -118
- package/src/vendor/uuidv7.spec.ts +0 -26
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { CaptureEndpoint } from './types'
|
|
2
|
+
|
|
3
|
+
/** A single event the server explicitly rejected (`drop`). */
|
|
4
|
+
export interface CaptureDroppedEvent {
|
|
5
|
+
uuid: string
|
|
6
|
+
details?: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface CaptureErrorParams {
|
|
10
|
+
/** The capture lane the batch was sent to. */
|
|
11
|
+
endpoint: CaptureEndpoint
|
|
12
|
+
requestId: string
|
|
13
|
+
/** Events the server rejected outright (billing/validation). */
|
|
14
|
+
drops: CaptureDroppedEvent[]
|
|
15
|
+
/** UUIDs of events still pending `retry` after the attempt budget was exhausted, or lost to a batch-level failure. */
|
|
16
|
+
retryExhausted: string[]
|
|
17
|
+
/** The underlying transport/HTTP/parse failure, when the whole batch failed. */
|
|
18
|
+
cause?: unknown
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Surfaced on the client error channel whenever a capture batch did not
|
|
23
|
+
* fully deliver: some events were `drop`ped, some `retry` events outlived the
|
|
24
|
+
* attempt budget, or the batch hit a terminal transport/HTTP/parse failure.
|
|
25
|
+
*
|
|
26
|
+
* A 2xx with drops is still a partial failure and is reported here — a
|
|
27
|
+
* successful HTTP status does not mean every event was accepted.
|
|
28
|
+
*/
|
|
29
|
+
export class CaptureError extends Error {
|
|
30
|
+
name = 'CaptureError'
|
|
31
|
+
readonly endpoint: CaptureEndpoint
|
|
32
|
+
readonly requestId: string
|
|
33
|
+
readonly drops: CaptureDroppedEvent[]
|
|
34
|
+
readonly retryExhausted: string[]
|
|
35
|
+
cause?: unknown
|
|
36
|
+
|
|
37
|
+
constructor({ endpoint, requestId, drops, retryExhausted, cause }: CaptureErrorParams) {
|
|
38
|
+
super(CaptureError.buildMessage(endpoint, requestId, drops, retryExhausted, cause))
|
|
39
|
+
this.endpoint = endpoint
|
|
40
|
+
this.requestId = requestId
|
|
41
|
+
this.drops = drops
|
|
42
|
+
this.retryExhausted = retryExhausted
|
|
43
|
+
this.cause = cause
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private static buildMessage(
|
|
47
|
+
endpoint: CaptureEndpoint,
|
|
48
|
+
requestId: string,
|
|
49
|
+
drops: CaptureDroppedEvent[],
|
|
50
|
+
retryExhausted: string[],
|
|
51
|
+
cause: unknown
|
|
52
|
+
): string {
|
|
53
|
+
let message = `Capture batch ${requestId} to ${endpoint} did not fully deliver: ${drops.length} dropped, ${retryExhausted.length} undelivered`
|
|
54
|
+
if (cause instanceof Error) {
|
|
55
|
+
message += ` (${cause.message})`
|
|
56
|
+
}
|
|
57
|
+
return message
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Counts of undelivered events by cause, in the order the causes first occurred. */
|
|
62
|
+
export class CaptureLossTally {
|
|
63
|
+
private readonly counts = new Map<string, number>()
|
|
64
|
+
|
|
65
|
+
add(cause: string, count: number): void {
|
|
66
|
+
if (count > 0) {
|
|
67
|
+
this.counts.set(cause, (this.counts.get(cause) ?? 0) + count)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
get total(): number {
|
|
72
|
+
let total = 0
|
|
73
|
+
for (const count of this.counts.values()) {
|
|
74
|
+
total += count
|
|
75
|
+
}
|
|
76
|
+
return total
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
entries(): [cause: string, count: number][] {
|
|
80
|
+
return [...this.counts]
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The one line logged for a capture loss when nothing listens for `'error'`. It holds the lane,
|
|
86
|
+
* counts and causes only: never server response text, event content or uuids.
|
|
87
|
+
*/
|
|
88
|
+
export function describeCaptureLoss(endpoint: CaptureEndpoint, loss: CaptureLossTally): string {
|
|
89
|
+
const causes = loss.entries().map(([cause, count]) => `${count} ${cause}`)
|
|
90
|
+
return `${loss.total} event(s) were not delivered to ${endpoint}: ${causes.join(', ')}`
|
|
91
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capture V1 transport shared by the PostHog SDKs. It follows semver, because the SDKs depend on
|
|
3
|
+
* core with a caret range. `CaptureError`, `CaptureDroppedEvent`, `CaptureErrorParams` and
|
|
4
|
+
* `CaptureEndpoint` are also public through posthog-node.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
export {
|
|
9
|
+
CAPTURE_COMPRESSIONS,
|
|
10
|
+
resolveCaptureCodec,
|
|
11
|
+
webCompressor,
|
|
12
|
+
type CaptureCodec,
|
|
13
|
+
type CaptureCompression,
|
|
14
|
+
type CaptureCompressor,
|
|
15
|
+
} from './compression'
|
|
16
|
+
export {
|
|
17
|
+
CaptureError,
|
|
18
|
+
CaptureLossTally,
|
|
19
|
+
describeCaptureLoss,
|
|
20
|
+
type CaptureDroppedEvent,
|
|
21
|
+
type CaptureErrorParams,
|
|
22
|
+
} from './errors'
|
|
23
|
+
export {
|
|
24
|
+
V1CaptureSender,
|
|
25
|
+
type V1CaptureSenderConfig,
|
|
26
|
+
type V1CaptureSenderHooks,
|
|
27
|
+
type V1RequestIdentity,
|
|
28
|
+
type V1SendDeferral,
|
|
29
|
+
type V1SendOptions,
|
|
30
|
+
} from './sender'
|
|
31
|
+
export { serializeV1Event, utf8Length, wireProblem, type SerializedV1Event } from './serialize'
|
|
32
|
+
export { readEventOptions } from './transform'
|
|
33
|
+
export { AI_CAPTURE_ENDPOINT, ANALYTICS_CAPTURE_ENDPOINT, type CaptureEndpoint, type V1EventOptions } from './types'
|
|
34
|
+
export { canonicalizeUuid, eventUuidv7 } from './uuid'
|