@zuplo/cli 7.7.7 → 7.7.9
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/error-tracking/index.d.ts +1 -1
- package/node_modules/@posthog/core/dist/error-tracking/index.d.ts.map +1 -1
- package/node_modules/@posthog/core/dist/error-tracking/parsers/base.d.ts.map +1 -1
- package/node_modules/@posthog/core/dist/error-tracking/parsers/base.js +19 -2
- package/node_modules/@posthog/core/dist/error-tracking/parsers/base.mjs +19 -2
- package/node_modules/@posthog/core/dist/index.d.ts +7 -0
- package/node_modules/@posthog/core/dist/index.d.ts.map +1 -1
- package/node_modules/@posthog/core/dist/index.js +82 -21
- package/node_modules/@posthog/core/dist/index.mjs +4 -0
- package/node_modules/@posthog/core/dist/logs/index.d.ts +3 -2
- package/node_modules/@posthog/core/dist/logs/index.d.ts.map +1 -1
- package/node_modules/@posthog/core/dist/logs/index.js +28 -22
- package/node_modules/@posthog/core/dist/logs/index.mjs +29 -23
- package/node_modules/@posthog/core/dist/logs/logs-utils.js +1 -1
- package/node_modules/@posthog/core/dist/logs/logs-utils.mjs +2 -2
- package/node_modules/@posthog/core/dist/logs/types.d.ts +2 -2
- package/node_modules/@posthog/core/dist/metrics/index.d.ts +5 -2
- package/node_modules/@posthog/core/dist/metrics/index.d.ts.map +1 -1
- package/node_modules/@posthog/core/dist/metrics/index.js +28 -14
- package/node_modules/@posthog/core/dist/metrics/index.mjs +29 -15
- package/node_modules/@posthog/core/dist/metrics/metrics-utils.d.ts.map +1 -1
- package/node_modules/@posthog/core/dist/metrics/metrics-utils.js +1 -2
- package/node_modules/@posthog/core/dist/metrics/metrics-utils.mjs +2 -3
- package/node_modules/@posthog/core/dist/metrics/types.d.ts +7 -0
- package/node_modules/@posthog/core/dist/metrics/types.d.ts.map +1 -1
- package/node_modules/@posthog/core/dist/posthog-core-stateless.d.ts +32 -4
- package/node_modules/@posthog/core/dist/posthog-core-stateless.d.ts.map +1 -1
- package/node_modules/@posthog/core/dist/posthog-core-stateless.js +68 -20
- package/node_modules/@posthog/core/dist/posthog-core-stateless.mjs +68 -20
- package/node_modules/@posthog/core/dist/traces/config.d.ts +13 -0
- package/node_modules/@posthog/core/dist/traces/config.d.ts.map +1 -0
- package/node_modules/@posthog/core/dist/traces/config.js +101 -0
- package/node_modules/@posthog/core/dist/traces/config.mjs +63 -0
- package/node_modules/@posthog/core/dist/traces/context.d.ts +18 -0
- package/node_modules/@posthog/core/dist/traces/context.d.ts.map +1 -0
- package/node_modules/@posthog/core/dist/traces/context.js +53 -0
- package/node_modules/@posthog/core/dist/traces/context.mjs +15 -0
- package/node_modules/@posthog/core/dist/traces/ids.d.ts +12 -0
- package/node_modules/@posthog/core/dist/traces/ids.d.ts.map +1 -0
- package/node_modules/@posthog/core/dist/traces/ids.js +92 -0
- package/node_modules/@posthog/core/dist/traces/ids.mjs +42 -0
- package/node_modules/@posthog/core/dist/traces/index.d.ts +150 -0
- package/node_modules/@posthog/core/dist/traces/index.d.ts.map +1 -0
- package/node_modules/@posthog/core/dist/traces/index.js +551 -0
- package/node_modules/@posthog/core/dist/traces/index.mjs +513 -0
- package/node_modules/@posthog/core/dist/traces/otlp.d.ts +24 -0
- package/node_modules/@posthog/core/dist/traces/otlp.d.ts.map +1 -0
- package/node_modules/@posthog/core/dist/traces/otlp.js +158 -0
- package/node_modules/@posthog/core/dist/traces/otlp.mjs +108 -0
- package/node_modules/@posthog/core/dist/traces/sanitize.d.ts +32 -0
- package/node_modules/@posthog/core/dist/traces/sanitize.d.ts.map +1 -0
- package/node_modules/@posthog/core/dist/traces/sanitize.js +93 -0
- package/node_modules/@posthog/core/dist/traces/sanitize.mjs +43 -0
- package/node_modules/@posthog/core/dist/traces/span.d.ts +189 -0
- package/node_modules/@posthog/core/dist/traces/span.d.ts.map +1 -0
- package/node_modules/@posthog/core/dist/traces/span.js +533 -0
- package/node_modules/@posthog/core/dist/traces/span.mjs +462 -0
- package/node_modules/@posthog/core/dist/traces/traceparent.d.ts +51 -0
- package/node_modules/@posthog/core/dist/traces/traceparent.d.ts.map +1 -0
- package/node_modules/@posthog/core/dist/traces/traceparent.js +116 -0
- package/node_modules/@posthog/core/dist/traces/traceparent.mjs +63 -0
- package/node_modules/@posthog/core/dist/traces/types.d.ts +114 -0
- package/node_modules/@posthog/core/dist/traces/types.d.ts.map +1 -0
- package/node_modules/@posthog/core/dist/traces/types.js +18 -0
- package/node_modules/@posthog/core/dist/traces/types.mjs +1 -0
- package/node_modules/@posthog/core/dist/utils/backoff.d.ts +23 -0
- package/node_modules/@posthog/core/dist/utils/backoff.d.ts.map +1 -0
- package/node_modules/@posthog/core/dist/utils/backoff.js +65 -0
- package/node_modules/@posthog/core/dist/utils/backoff.mjs +14 -0
- package/node_modules/@posthog/core/dist/utils/flush-timer.d.ts +26 -0
- package/node_modules/@posthog/core/dist/utils/flush-timer.d.ts.map +1 -0
- package/node_modules/@posthog/core/dist/utils/flush-timer.js +67 -0
- package/node_modules/@posthog/core/dist/utils/flush-timer.mjs +29 -0
- package/node_modules/@posthog/core/dist/utils/json-utils.d.ts +7 -0
- package/node_modules/@posthog/core/dist/utils/json-utils.d.ts.map +1 -1
- package/node_modules/@posthog/core/dist/utils/json-utils.js +27 -0
- package/node_modules/@posthog/core/dist/utils/json-utils.mjs +25 -1
- package/node_modules/@posthog/core/dist/utils/otlp-resource.d.ts +13 -2
- package/node_modules/@posthog/core/dist/utils/otlp-resource.d.ts.map +1 -1
- package/node_modules/@posthog/core/dist/utils/otlp-resource.js +34 -7
- package/node_modules/@posthog/core/dist/utils/otlp-resource.mjs +26 -2
- package/node_modules/@posthog/core/dist/utils/retry-after.d.ts +55 -0
- package/node_modules/@posthog/core/dist/utils/retry-after.d.ts.map +1 -0
- package/node_modules/@posthog/core/dist/utils/retry-after.js +95 -0
- package/node_modules/@posthog/core/dist/utils/retry-after.mjs +50 -0
- package/node_modules/@posthog/core/package.json +3 -3
- package/node_modules/@posthog/core/src/error-tracking/index.ts +24 -1
- package/node_modules/@posthog/core/src/error-tracking/parsers/base.spec.ts +77 -7
- package/node_modules/@posthog/core/src/error-tracking/parsers/base.ts +42 -19
- package/node_modules/@posthog/core/src/index.ts +18 -0
- package/node_modules/@posthog/core/src/logs/index.spec.ts +490 -2
- package/node_modules/@posthog/core/src/logs/index.ts +63 -31
- package/node_modules/@posthog/core/src/logs/logs-utils.ts +2 -2
- package/node_modules/@posthog/core/src/logs/types.ts +2 -2
- package/node_modules/@posthog/core/src/metrics/index.spec.ts +304 -0
- package/node_modules/@posthog/core/src/metrics/index.ts +53 -16
- package/node_modules/@posthog/core/src/metrics/metrics-utils.ts +2 -3
- package/node_modules/@posthog/core/src/metrics/types.ts +10 -2
- package/node_modules/@posthog/core/src/posthog-core-stateless.ts +157 -38
- package/node_modules/@posthog/core/src/traces/config.spec.ts +271 -0
- package/node_modules/@posthog/core/src/traces/config.ts +142 -0
- package/node_modules/@posthog/core/src/traces/context.ts +30 -0
- package/node_modules/@posthog/core/src/traces/ids.spec.ts +115 -0
- package/node_modules/@posthog/core/src/traces/ids.ts +75 -0
- package/node_modules/@posthog/core/src/traces/index.spec.ts +3187 -0
- package/node_modules/@posthog/core/src/traces/index.ts +1060 -0
- package/node_modules/@posthog/core/src/traces/live-spans.spec.ts +69 -0
- package/node_modules/@posthog/core/src/traces/otlp.spec.ts +368 -0
- package/node_modules/@posthog/core/src/traces/otlp.ts +191 -0
- package/node_modules/@posthog/core/src/traces/sanitize.ts +116 -0
- package/node_modules/@posthog/core/src/traces/span.spec.ts +1122 -0
- package/node_modules/@posthog/core/src/traces/span.ts +822 -0
- package/node_modules/@posthog/core/src/traces/traceparent.spec.ts +184 -0
- package/node_modules/@posthog/core/src/traces/traceparent.ts +172 -0
- package/node_modules/@posthog/core/src/traces/types.ts +140 -0
- package/node_modules/@posthog/core/src/utils/backoff.ts +44 -0
- package/node_modules/@posthog/core/src/utils/flush-timer.ts +50 -0
- package/node_modules/@posthog/core/src/utils/json-utils.ts +33 -0
- package/node_modules/@posthog/core/src/utils/otlp-resource.spec.ts +55 -9
- package/node_modules/@posthog/core/src/utils/otlp-resource.ts +45 -4
- package/node_modules/@posthog/core/src/utils/retry-after.ts +135 -0
- package/node_modules/@posthog/types/dist/index.d.ts +1 -0
- package/node_modules/@posthog/types/dist/index.d.ts.map +1 -1
- package/node_modules/@posthog/types/dist/posthog-config.d.ts +10 -5
- package/node_modules/@posthog/types/dist/posthog-config.d.ts.map +1 -1
- package/node_modules/@posthog/types/dist/traces.d.ts +387 -0
- package/node_modules/@posthog/types/dist/traces.d.ts.map +1 -0
- package/node_modules/@posthog/types/dist/traces.js +18 -0
- package/node_modules/@posthog/types/dist/traces.mjs +1 -0
- package/node_modules/@posthog/types/package.json +1 -1
- package/node_modules/@posthog/types/src/index.ts +19 -0
- package/node_modules/@posthog/types/src/posthog-config.ts +10 -5
- package/node_modules/@posthog/types/src/traces.ts +429 -0
- 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/out/esm/{chunk-FEB2VFS7.js → chunk-KNAYKBEE.js} +96 -96
- package/node_modules/@zuplo/runtime/out/esm/chunk-KNAYKBEE.js.map +1 -0
- package/node_modules/@zuplo/runtime/out/esm/index.js +1 -1
- package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js +1 -1
- package/node_modules/@zuplo/runtime/out/esm/mocks/index.js +1 -1
- package/node_modules/@zuplo/runtime/package.json +1 -1
- package/package.json +11 -11
- package/node_modules/@zuplo/runtime/out/esm/chunk-FEB2VFS7.js.map +0 -1
- /package/node_modules/@zuplo/runtime/out/esm/{chunk-FEB2VFS7.js.LEGAL.txt → chunk-KNAYKBEE.js.LEGAL.txt} +0 -0
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
PostHogTraces: ()=>PostHogTraces
|
|
32
|
+
});
|
|
33
|
+
const external_span_js_namespaceObject = require("./span.js");
|
|
34
|
+
const external_ids_js_namespaceObject = require("./ids.js");
|
|
35
|
+
const external_traceparent_js_namespaceObject = require("./traceparent.js");
|
|
36
|
+
const external_sanitize_js_namespaceObject = require("./sanitize.js");
|
|
37
|
+
const json_utils_js_namespaceObject = require("../utils/json-utils.js");
|
|
38
|
+
const external_otlp_js_namespaceObject = require("./otlp.js");
|
|
39
|
+
const index_js_namespaceObject = require("../utils/index.js");
|
|
40
|
+
const flush_timer_js_namespaceObject = require("../utils/flush-timer.js");
|
|
41
|
+
const retry_after_js_namespaceObject = require("../utils/retry-after.js");
|
|
42
|
+
const backoff_js_namespaceObject = require("../utils/backoff.js");
|
|
43
|
+
const MAX_RETRIES_PER_BATCH = 8;
|
|
44
|
+
function clockNow() {
|
|
45
|
+
return (0, external_span_js_namespaceObject.monotonicNow)() ?? Date.now();
|
|
46
|
+
}
|
|
47
|
+
function isOwnSpan(value) {
|
|
48
|
+
try {
|
|
49
|
+
return value instanceof external_span_js_namespaceObject.PostHogSpan;
|
|
50
|
+
} catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function remoteContext(header, tracestate) {
|
|
55
|
+
const remote = (0, external_traceparent_js_namespaceObject.parseTraceparent)(header);
|
|
56
|
+
if (!remote) return;
|
|
57
|
+
return {
|
|
58
|
+
traceId: remote.traceId,
|
|
59
|
+
parentSpanId: remote.spanId,
|
|
60
|
+
traceState: (0, external_traceparent_js_namespaceObject.sanitizeTracestate)(tracestate),
|
|
61
|
+
traceFlags: remote.flags,
|
|
62
|
+
isRemote: true
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function looksLikeSpan(value) {
|
|
66
|
+
try {
|
|
67
|
+
return 'function' == typeof value.traceparent;
|
|
68
|
+
} catch {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function isSpanRecordShape(record) {
|
|
73
|
+
return !!record.attributes && 'object' == typeof record.attributes && !Array.isArray(record.attributes) && Array.isArray(record.events) && void 0 !== record.name && void 0 !== record.kind && void 0 !== record.startTime && void 0 !== record.endTime;
|
|
74
|
+
}
|
|
75
|
+
function restoreField(record, field, value) {
|
|
76
|
+
if (record[field] !== value) record[field] = value;
|
|
77
|
+
}
|
|
78
|
+
function withRestoredIdentity(hooked, original) {
|
|
79
|
+
try {
|
|
80
|
+
const descriptors = Object.getOwnPropertyDescriptors(hooked);
|
|
81
|
+
for (const field of [
|
|
82
|
+
'traceId',
|
|
83
|
+
'spanId',
|
|
84
|
+
'parentSpanId',
|
|
85
|
+
'traceState'
|
|
86
|
+
])descriptors[field] = {
|
|
87
|
+
value: original[field],
|
|
88
|
+
enumerable: true,
|
|
89
|
+
writable: true,
|
|
90
|
+
configurable: true
|
|
91
|
+
};
|
|
92
|
+
return Object.create(Object.getPrototypeOf(hooked), descriptors);
|
|
93
|
+
} catch {
|
|
94
|
+
return hooked;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
class PostHogTraces {
|
|
98
|
+
constructor(_instance, _config, _logger, _getContext, _contextManager, _onSpanQueued){
|
|
99
|
+
this._instance = _instance;
|
|
100
|
+
this._config = _config;
|
|
101
|
+
this._logger = _logger;
|
|
102
|
+
this._getContext = _getContext;
|
|
103
|
+
this._contextManager = _contextManager;
|
|
104
|
+
this._onSpanQueued = _onSpanQueued;
|
|
105
|
+
this._queue = [];
|
|
106
|
+
this._flushTimer = new flush_timer_js_namespaceObject.FlushTimer(()=>this._flushInBackground());
|
|
107
|
+
this._flushPromise = null;
|
|
108
|
+
this._droppedSinceWarning = 0;
|
|
109
|
+
this._lastDropWarningAt = 0;
|
|
110
|
+
this._dropReasons = new Set();
|
|
111
|
+
this._consecutiveFlushFailures = 0;
|
|
112
|
+
this._flushJitter = backoff_js_namespaceObject.NO_JITTER;
|
|
113
|
+
this._retryAfter = new retry_after_js_namespaceObject.RetryAfterWindow();
|
|
114
|
+
this._headBatchFailures = 0;
|
|
115
|
+
this._headBatchSize = 0;
|
|
116
|
+
this._headBatchChargeableAt = 0;
|
|
117
|
+
this._generation = 0;
|
|
118
|
+
this._liveSpans = new Map();
|
|
119
|
+
this._maxExportBatchSize = _config.maxExportBatchSize;
|
|
120
|
+
}
|
|
121
|
+
startSpan(name, options) {
|
|
122
|
+
if (this._instance.isDisabled || this._instance.optedOut) return (0, external_span_js_namespaceObject.inertSpan)(options, this._contextManager.active());
|
|
123
|
+
const explicitParent = (0, external_traceparent_js_namespaceObject.traceparentHeader)(options?.parent);
|
|
124
|
+
if (explicitParent && 'string' != typeof explicitParent && !isOwnSpan(explicitParent)) {
|
|
125
|
+
if (looksLikeSpan(explicitParent)) {
|
|
126
|
+
this._logger.debug('Span parent is not a span from this SDK; returning an inert span');
|
|
127
|
+
return (0, external_span_js_namespaceObject.inertSpan)(options, this._contextManager.active());
|
|
128
|
+
}
|
|
129
|
+
this._logger.debug('Ignoring an unusable span parent');
|
|
130
|
+
}
|
|
131
|
+
const parent = this._resolveParent(explicitParent, options);
|
|
132
|
+
this._evictAgedSpans();
|
|
133
|
+
if (this._liveSpans.size >= this._config.maxLiveSpans) {
|
|
134
|
+
this._recordDrop(1, `the live-span limit (${this._config.maxLiveSpans}) was reached — spans are being started and never ended`);
|
|
135
|
+
return (0, external_span_js_namespaceObject.inertSpan)(options, this._contextManager.active());
|
|
136
|
+
}
|
|
137
|
+
const now = Date.now();
|
|
138
|
+
const startTime = (0, external_sanitize_js_namespaceObject.resolveStartTime)(options?.startTime, now, this._logger);
|
|
139
|
+
const spanId = (0, external_ids_js_namespaceObject.newSpanId)();
|
|
140
|
+
this._liveSpans.set(spanId, clockNow());
|
|
141
|
+
const autoAttributes = this._autoContextAttributes();
|
|
142
|
+
return new external_span_js_namespaceObject.PostHogSpan({
|
|
143
|
+
traceId: parent?.traceId ?? (0, external_ids_js_namespaceObject.newTraceId)(),
|
|
144
|
+
spanId,
|
|
145
|
+
parentSpanId: parent?.parentSpanId,
|
|
146
|
+
traceState: parent?.traceState,
|
|
147
|
+
traceFlags: parent?.traceFlags,
|
|
148
|
+
parentIsRemote: parent?.isRemote,
|
|
149
|
+
name: (0, external_sanitize_js_namespaceObject.sanitizeName)(name, 'Span name', this._config.maxAttributeValueLength, this._logger),
|
|
150
|
+
kind: options?.kind ?? 'internal',
|
|
151
|
+
attributes: (0, json_utils_js_namespaceObject.assignUserAttributes)({
|
|
152
|
+
...autoAttributes
|
|
153
|
+
}, options?.attributes),
|
|
154
|
+
autoAttributeKeys: Object.keys(autoAttributes),
|
|
155
|
+
maxAttributes: this._config.maxAttributesPerSpan,
|
|
156
|
+
maxEvents: this._config.maxEventsPerSpan,
|
|
157
|
+
maxAttributesPerEvent: this._config.maxAttributesPerEvent,
|
|
158
|
+
maxAttributeValueLength: this._config.maxAttributeValueLength,
|
|
159
|
+
startTime,
|
|
160
|
+
backdated: startTime !== now
|
|
161
|
+
}, (record, autoKeys)=>this._onSpanEnd(record, autoKeys), this._logger);
|
|
162
|
+
}
|
|
163
|
+
withSpan(name, optionsOrFn, maybeFn) {
|
|
164
|
+
const options = 'function' == typeof optionsOrFn ? void 0 : optionsOrFn;
|
|
165
|
+
const fn = 'function' == typeof optionsOrFn ? optionsOrFn : maybeFn;
|
|
166
|
+
const span = this.startSpan(name, options);
|
|
167
|
+
try {
|
|
168
|
+
const result = (0, external_span_js_namespaceObject.runWithActiveSpan)(this._contextManager, span, fn);
|
|
169
|
+
if ((0, index_js_namespaceObject.isPromise)(result)) return result.then((value)=>{
|
|
170
|
+
span.end();
|
|
171
|
+
return value;
|
|
172
|
+
}, (error)=>{
|
|
173
|
+
this._recordCallbackError(span, error);
|
|
174
|
+
span.end();
|
|
175
|
+
throw error;
|
|
176
|
+
});
|
|
177
|
+
span.end();
|
|
178
|
+
return result;
|
|
179
|
+
} catch (error) {
|
|
180
|
+
this._recordCallbackError(span, error);
|
|
181
|
+
span.end();
|
|
182
|
+
throw error;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
getActiveSpan() {
|
|
186
|
+
return this._contextManager.active() ?? null;
|
|
187
|
+
}
|
|
188
|
+
get throttled() {
|
|
189
|
+
return this._retryAfter.isOpen();
|
|
190
|
+
}
|
|
191
|
+
async flush() {
|
|
192
|
+
for(;;){
|
|
193
|
+
if (!this._queue.length) return;
|
|
194
|
+
const inFlight = this._flushPromise;
|
|
195
|
+
const removed = await (inFlight ?? this._startFlush());
|
|
196
|
+
if (!removed) return;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
_startFlush() {
|
|
200
|
+
this._flushTimer.clear();
|
|
201
|
+
const startedAtGeneration = this._generation;
|
|
202
|
+
const promise = Promise.resolve().then(()=>startedAtGeneration === this._generation ? this._flushInner() : 0).finally(()=>{
|
|
203
|
+
if (this._flushPromise === promise) this._flushPromise = null;
|
|
204
|
+
this._armFlushTimerIfQueuedNoEarlierThan();
|
|
205
|
+
});
|
|
206
|
+
this._flushPromise = promise;
|
|
207
|
+
return promise;
|
|
208
|
+
}
|
|
209
|
+
reset() {
|
|
210
|
+
this._flushTimer.clear();
|
|
211
|
+
if (this._queue.length) this._logger.critical(`Discarding ${this._queue.length} span(s) that were still queued when tracing was shut down. Raise the shutdown timeout or flush earlier if they matter.`);
|
|
212
|
+
this._queue = [];
|
|
213
|
+
this._liveSpans.clear();
|
|
214
|
+
this._flushPromise = null;
|
|
215
|
+
this._generation++;
|
|
216
|
+
this._maxExportBatchSize = this._config.maxExportBatchSize;
|
|
217
|
+
this._droppedSinceWarning = 0;
|
|
218
|
+
this._dropReasons.clear();
|
|
219
|
+
this._lastDropWarningAt = 0;
|
|
220
|
+
this._consecutiveFlushFailures = 0;
|
|
221
|
+
this._flushJitter = backoff_js_namespaceObject.NO_JITTER;
|
|
222
|
+
this._retryAfter.reset();
|
|
223
|
+
this._resetHeadBatchBudget();
|
|
224
|
+
}
|
|
225
|
+
_resetHeadBatchBudget() {
|
|
226
|
+
this._headBatchFailures = 0;
|
|
227
|
+
this._headBatchChargeableAt = 0;
|
|
228
|
+
}
|
|
229
|
+
_resolveParent(explicit, options) {
|
|
230
|
+
if ('string' == typeof explicit) {
|
|
231
|
+
const remote = remoteContext(explicit, options?.tracestate);
|
|
232
|
+
if (!remote) this._logger.debug('Ignoring malformed traceparent; starting a new trace');
|
|
233
|
+
return remote;
|
|
234
|
+
}
|
|
235
|
+
if (isOwnSpan(explicit)) return explicit.childContext();
|
|
236
|
+
const active = this._contextManager.active();
|
|
237
|
+
if (isOwnSpan(active)) return active.childContext();
|
|
238
|
+
if (active instanceof external_span_js_namespaceObject.PassThroughSpan) return remoteContext(active.traceparent(), active.tracestate() ?? void 0);
|
|
239
|
+
}
|
|
240
|
+
_autoContextAttributes() {
|
|
241
|
+
let context;
|
|
242
|
+
try {
|
|
243
|
+
context = this._getContext();
|
|
244
|
+
} catch (error) {
|
|
245
|
+
this._logger.debug('Failed to read tracing context; span will carry no PostHog attributes', error);
|
|
246
|
+
return {};
|
|
247
|
+
}
|
|
248
|
+
const attributes = {};
|
|
249
|
+
if (context.distinctId) attributes.posthogDistinctId = context.distinctId;
|
|
250
|
+
if (context.sessionId) attributes.sessionId = context.sessionId;
|
|
251
|
+
if (context.currentUrl) attributes['url.full'] = context.currentUrl;
|
|
252
|
+
if (context.screenName) attributes['screen.name'] = context.screenName;
|
|
253
|
+
if (context.appState) attributes['app.state'] = context.appState;
|
|
254
|
+
return attributes;
|
|
255
|
+
}
|
|
256
|
+
_recordCallbackError(span, error) {
|
|
257
|
+
if (!(span instanceof external_span_js_namespaceObject.PostHogSpan)) return;
|
|
258
|
+
const { type, message, stack } = (0, external_span_js_namespaceObject.describeError)(error);
|
|
259
|
+
span.addEvent('exception', {
|
|
260
|
+
'exception.type': type,
|
|
261
|
+
'exception.message': message,
|
|
262
|
+
...stack && {
|
|
263
|
+
'exception.stacktrace': stack
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
if (!span.statusIsExplicitlyOk) span.setStatus('error', message);
|
|
267
|
+
}
|
|
268
|
+
_evictAgedSpans() {
|
|
269
|
+
const cutoff = clockNow() - this._config.maxSpanAgeMs;
|
|
270
|
+
let evicted = 0;
|
|
271
|
+
for (const [spanId, startedAt] of this._liveSpans){
|
|
272
|
+
if (startedAt > cutoff) break;
|
|
273
|
+
this._liveSpans.delete(spanId);
|
|
274
|
+
evicted++;
|
|
275
|
+
}
|
|
276
|
+
if (evicted) this._recordDrop(evicted, `they were still live after ${this._config.maxSpanAgeMs}ms`);
|
|
277
|
+
}
|
|
278
|
+
_onSpanEnd(incoming, autoKeys) {
|
|
279
|
+
if (!this._liveSpans.delete(incoming.spanId)) return;
|
|
280
|
+
if (this._instance.isDisabled || this._instance.optedOut) return void this._recordDrop(1, 'the user has opted out');
|
|
281
|
+
const record = this._runBeforeSpanSend(incoming, autoKeys);
|
|
282
|
+
if (!record) return;
|
|
283
|
+
this._reportLimitDrops(record);
|
|
284
|
+
if (this._queue.length >= this._config.maxQueueSize) return void this._recordDrop(1, `the queue is full (${this._config.maxQueueSize}) — raise the flush frequency or reduce span volume`);
|
|
285
|
+
this._queue.push(record);
|
|
286
|
+
try {
|
|
287
|
+
this._onSpanQueued?.();
|
|
288
|
+
} catch (error) {
|
|
289
|
+
this._logger.debug('Span queue notification failed', error);
|
|
290
|
+
}
|
|
291
|
+
if (!(this._queue.length >= this._maxExportBatchSize) || this._consecutiveFlushFailures || this._retryAfter.isOpen()) this._armFlushTimerIfQueued();
|
|
292
|
+
else this._flushInBackground();
|
|
293
|
+
}
|
|
294
|
+
_reportLimitDrops(record) {
|
|
295
|
+
const attributes = record.droppedAttributesCount ?? 0;
|
|
296
|
+
const events = record.droppedEventsCount ?? 0;
|
|
297
|
+
let eventAttributes = 0;
|
|
298
|
+
for (const event of record.events)eventAttributes += event.droppedAttributesCount ?? 0;
|
|
299
|
+
if (attributes || events || eventAttributes) this._logger.debug(`Span limits discarded data from "${record.name}": ${attributes} attributes, ${events} events, ${eventAttributes} event attributes`);
|
|
300
|
+
}
|
|
301
|
+
_runBeforeSpanSend(record, autoKeys) {
|
|
302
|
+
if (!this._config.beforeSpanSend.length) return record;
|
|
303
|
+
const identity = {
|
|
304
|
+
traceId: record.traceId,
|
|
305
|
+
spanId: record.spanId,
|
|
306
|
+
parentSpanId: record.parentSpanId,
|
|
307
|
+
traceState: record.traceState
|
|
308
|
+
};
|
|
309
|
+
const originalTimes = {
|
|
310
|
+
startTime: record.startTime,
|
|
311
|
+
endTime: record.endTime
|
|
312
|
+
};
|
|
313
|
+
const originalDropped = {
|
|
314
|
+
attributes: record.droppedAttributesCount,
|
|
315
|
+
events: record.droppedEventsCount
|
|
316
|
+
};
|
|
317
|
+
const keysBeforeHook = Object.keys(record.attributes);
|
|
318
|
+
const originalPropagation = {
|
|
319
|
+
traceFlags: record.traceFlags,
|
|
320
|
+
parentIsRemote: record.parentIsRemote
|
|
321
|
+
};
|
|
322
|
+
const originalStatus = record.status && {
|
|
323
|
+
...record.status
|
|
324
|
+
};
|
|
325
|
+
let hooked = record;
|
|
326
|
+
let current = record;
|
|
327
|
+
try {
|
|
328
|
+
for (const hook of this._config.beforeSpanSend){
|
|
329
|
+
const result = hook(hooked);
|
|
330
|
+
if (!result) {
|
|
331
|
+
this._recordDrop(1, 'beforeSpanSend dropped it');
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
334
|
+
hooked = this._keepSpanIdentity(result, identity);
|
|
335
|
+
}
|
|
336
|
+
const rebuilt = {
|
|
337
|
+
traceId: identity.traceId,
|
|
338
|
+
spanId: identity.spanId,
|
|
339
|
+
parentSpanId: identity.parentSpanId,
|
|
340
|
+
traceState: identity.traceState,
|
|
341
|
+
name: hooked.name,
|
|
342
|
+
kind: hooked.kind,
|
|
343
|
+
status: hooked.status,
|
|
344
|
+
attributes: hooked.attributes,
|
|
345
|
+
events: hooked.events,
|
|
346
|
+
startTime: hooked.startTime,
|
|
347
|
+
endTime: hooked.endTime,
|
|
348
|
+
traceFlags: originalPropagation.traceFlags,
|
|
349
|
+
parentIsRemote: originalPropagation.parentIsRemote,
|
|
350
|
+
droppedAttributesCount: originalDropped.attributes,
|
|
351
|
+
droppedEventsCount: originalDropped.events
|
|
352
|
+
};
|
|
353
|
+
current = rebuilt;
|
|
354
|
+
if (!isSpanRecordShape(current)) {
|
|
355
|
+
this._logger.debug('beforeSpanSend did not return a span record; dropping the span');
|
|
356
|
+
this._recordDrop(1, 'beforeSpanSend returned an unusable record');
|
|
357
|
+
return null;
|
|
358
|
+
}
|
|
359
|
+
current.name = (0, external_sanitize_js_namespaceObject.sanitizeName)(current.name, 'Span name', this._config.maxAttributeValueLength, this._logger);
|
|
360
|
+
if (current.status && 'ok' !== current.status.code && 'error' !== current.status.code) {
|
|
361
|
+
this._logger.debug('beforeSpanSend set an unknown span status; keeping the original');
|
|
362
|
+
current.status = originalStatus;
|
|
363
|
+
}
|
|
364
|
+
current.startTime = (0, external_sanitize_js_namespaceObject.toEpochMs)(current.startTime) ?? originalTimes.startTime;
|
|
365
|
+
current.endTime = (0, external_sanitize_js_namespaceObject.clampEndTime)((0, external_sanitize_js_namespaceObject.toEpochMs)(current.endTime) ?? originalTimes.endTime, current.startTime);
|
|
366
|
+
const sanitizedEvents = [];
|
|
367
|
+
for (const event of current.events)try {
|
|
368
|
+
sanitizedEvents.push({
|
|
369
|
+
...event,
|
|
370
|
+
name: (0, external_sanitize_js_namespaceObject.sanitizeName)(event.name, 'Span event name', this._config.maxAttributeValueLength, this._logger),
|
|
371
|
+
timestamp: (0, external_sanitize_js_namespaceObject.resolveSuppliedTime)(event.timestamp, current.startTime, 'event timestamp', this._logger)
|
|
372
|
+
});
|
|
373
|
+
} catch {
|
|
374
|
+
this._logger.debug('beforeSpanSend left an unreadable span event; dropping it');
|
|
375
|
+
}
|
|
376
|
+
current.events = sanitizedEvents;
|
|
377
|
+
(0, external_span_js_namespaceObject.applySpanLimits)(current, autoKeys, this._config.maxAttributesPerSpan, this._config.maxEventsPerSpan, this._config.maxAttributesPerEvent, this._config.maxAttributeValueLength, keysBeforeHook);
|
|
378
|
+
return current;
|
|
379
|
+
} catch (error) {
|
|
380
|
+
this._logger.debug('beforeSpanSend failed; dropping the span rather than exporting it unscrubbed', error);
|
|
381
|
+
this._recordDrop(1, 'beforeSpanSend failed');
|
|
382
|
+
return null;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
_keepSpanIdentity(hooked, original) {
|
|
386
|
+
if (hooked.traceId !== original.traceId || hooked.spanId !== original.spanId || hooked.parentSpanId !== original.parentSpanId) this._logger.debug('beforeSpanSend changed a span identity field; keeping the original ids');
|
|
387
|
+
try {
|
|
388
|
+
restoreField(hooked, 'traceId', original.traceId);
|
|
389
|
+
restoreField(hooked, 'spanId', original.spanId);
|
|
390
|
+
restoreField(hooked, 'parentSpanId', original.parentSpanId);
|
|
391
|
+
restoreField(hooked, 'traceState', original.traceState);
|
|
392
|
+
} catch {
|
|
393
|
+
return withRestoredIdentity(hooked, original);
|
|
394
|
+
}
|
|
395
|
+
return hooked;
|
|
396
|
+
}
|
|
397
|
+
_recordDrop(count, reason) {
|
|
398
|
+
this._droppedSinceWarning += count;
|
|
399
|
+
this._dropReasons.add(reason);
|
|
400
|
+
if (Date.now() - this._lastDropWarningAt >= this._config.flushIntervalMs) this._warnAboutDrops();
|
|
401
|
+
}
|
|
402
|
+
_warnAboutDrops() {
|
|
403
|
+
if (!this._droppedSinceWarning) return;
|
|
404
|
+
this._lastDropWarningAt = Date.now();
|
|
405
|
+
this._logger.warn(`Dropping ${this._droppedSinceWarning} span(s): ${[
|
|
406
|
+
...this._dropReasons
|
|
407
|
+
].join('; ')}`);
|
|
408
|
+
this._droppedSinceWarning = 0;
|
|
409
|
+
this._dropReasons.clear();
|
|
410
|
+
}
|
|
411
|
+
_encodeBatch(batch) {
|
|
412
|
+
const encoded = [];
|
|
413
|
+
for (const record of batch)try {
|
|
414
|
+
encoded.push((0, external_otlp_js_namespaceObject.buildOtlpSpan)(record, this._logger));
|
|
415
|
+
} catch (error) {
|
|
416
|
+
this._logger.debug('Failed to encode a span; dropping it', error);
|
|
417
|
+
this._recordDrop(1, 'its attributes could not be encoded');
|
|
418
|
+
}
|
|
419
|
+
return encoded;
|
|
420
|
+
}
|
|
421
|
+
_discardQueueIfConsentWithdrawn() {
|
|
422
|
+
if (!this._instance.isDisabled && !this._instance.optedOut) return 0;
|
|
423
|
+
const discarded = this._queue.length;
|
|
424
|
+
this._queue = [];
|
|
425
|
+
this._resetHeadBatchBudget();
|
|
426
|
+
this._recordDrop(discarded, 'the user has opted out');
|
|
427
|
+
this._warnAboutDrops();
|
|
428
|
+
return discarded;
|
|
429
|
+
}
|
|
430
|
+
async _flushInner() {
|
|
431
|
+
if (!this._queue.length) return 0;
|
|
432
|
+
const discardedBeforeDrain = this._discardQueueIfConsentWithdrawn();
|
|
433
|
+
if (discardedBeforeDrain) return discardedBeforeDrain;
|
|
434
|
+
const resourceAttributes = (0, external_span_js_namespaceObject.truncateAttributes)((0, external_otlp_js_namespaceObject.buildTracesResourceAttributes)(this._config, this._instance.getLibraryId(), this._instance.getLibraryVersion()), this._config.maxAttributeValueLength);
|
|
435
|
+
const scopeName = this._instance.getLibraryId();
|
|
436
|
+
const scopeVersion = this._instance.getLibraryVersion();
|
|
437
|
+
let remaining = this._queue.length;
|
|
438
|
+
let removed = 0;
|
|
439
|
+
let localCap = 1 / 0;
|
|
440
|
+
const generation = this._generation;
|
|
441
|
+
try {
|
|
442
|
+
while(remaining > 0 && this._queue.length > 0){
|
|
443
|
+
const discardedMidDrain = this._discardQueueIfConsentWithdrawn();
|
|
444
|
+
if (discardedMidDrain) return removed + discardedMidDrain;
|
|
445
|
+
const cap = this._headBatchFailures > 0 ? Math.min(this._maxExportBatchSize, this._headBatchSize) : this._maxExportBatchSize;
|
|
446
|
+
const size = Math.max(1, Math.min(cap, localCap, remaining, this._queue.length));
|
|
447
|
+
const batch = this._queue.slice(0, size);
|
|
448
|
+
const spans = this._encodeBatch(batch);
|
|
449
|
+
if (!spans.length) {
|
|
450
|
+
this._queue.splice(0, size);
|
|
451
|
+
remaining -= size;
|
|
452
|
+
removed += size;
|
|
453
|
+
this._resetHeadBatchBudget();
|
|
454
|
+
continue;
|
|
455
|
+
}
|
|
456
|
+
const chargeable = clockNow() >= this._headBatchChargeableAt && !this._retryAfter.isOpen();
|
|
457
|
+
const outcome = await this._instance._sendTracesBatch((0, external_otlp_js_namespaceObject.buildOtlpTracesPayload)(spans, resourceAttributes, scopeName, scopeVersion, this._logger));
|
|
458
|
+
if (generation !== this._generation) break;
|
|
459
|
+
this._retryAfter.record(outcome);
|
|
460
|
+
if ('ok' === outcome.kind) {
|
|
461
|
+
this._consecutiveFlushFailures = 0;
|
|
462
|
+
this._flushJitter = backoff_js_namespaceObject.NO_JITTER;
|
|
463
|
+
this._resetHeadBatchBudget();
|
|
464
|
+
this._queue.splice(0, size);
|
|
465
|
+
remaining -= size;
|
|
466
|
+
removed += size;
|
|
467
|
+
if (this._maxExportBatchSize < this._config.maxExportBatchSize) this._maxExportBatchSize++;
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
if ('too-large' === outcome.kind) {
|
|
471
|
+
if (1 === size) {
|
|
472
|
+
this._queue.splice(0, 1);
|
|
473
|
+
remaining -= 1;
|
|
474
|
+
removed += 1;
|
|
475
|
+
this._recordDrop(1, 'it is too large for the ingestion endpoint');
|
|
476
|
+
this._consecutiveFlushFailures = 0;
|
|
477
|
+
this._flushJitter = backoff_js_namespaceObject.NO_JITTER;
|
|
478
|
+
this._resetHeadBatchBudget();
|
|
479
|
+
continue;
|
|
480
|
+
}
|
|
481
|
+
const halved = Math.max(1, Math.floor(size / 2));
|
|
482
|
+
if (outcome.measuredLocally) localCap = halved;
|
|
483
|
+
else this._maxExportBatchSize = halved;
|
|
484
|
+
this._resetHeadBatchBudget();
|
|
485
|
+
this._logger.debug(`Batch too large; retrying the same spans in batches of ${halved}`);
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
if ('retry-later' === outcome.kind) {
|
|
489
|
+
this._consecutiveFlushFailures++;
|
|
490
|
+
this._flushJitter = (0, backoff_js_namespaceObject.drawJitter)();
|
|
491
|
+
this._headBatchSize = size;
|
|
492
|
+
if (chargeable) {
|
|
493
|
+
this._headBatchFailures++;
|
|
494
|
+
this._headBatchChargeableAt = clockNow() + this._nextFlushDelay();
|
|
495
|
+
}
|
|
496
|
+
if (this._headBatchFailures < MAX_RETRIES_PER_BATCH) {
|
|
497
|
+
this._logger.debug('Span export failed; retrying on the next flush', outcome.error);
|
|
498
|
+
return removed;
|
|
499
|
+
}
|
|
500
|
+
this._queue.splice(0, size);
|
|
501
|
+
remaining -= size;
|
|
502
|
+
removed += size;
|
|
503
|
+
this._consecutiveFlushFailures = 0;
|
|
504
|
+
this._flushJitter = backoff_js_namespaceObject.NO_JITTER;
|
|
505
|
+
this._resetHeadBatchBudget();
|
|
506
|
+
this._recordDrop(size, `the ingestion endpoint failed ${MAX_RETRIES_PER_BATCH} times in a row`);
|
|
507
|
+
if (this._retryAfter.isOpen()) return removed;
|
|
508
|
+
continue;
|
|
509
|
+
}
|
|
510
|
+
this._logger.debug('Dropping a span batch the ingestion endpoint rejected', outcome.error);
|
|
511
|
+
this._queue.splice(0, size);
|
|
512
|
+
remaining -= size;
|
|
513
|
+
removed += size;
|
|
514
|
+
this._consecutiveFlushFailures = 0;
|
|
515
|
+
this._flushJitter = backoff_js_namespaceObject.NO_JITTER;
|
|
516
|
+
this._resetHeadBatchBudget();
|
|
517
|
+
this._recordDrop(size, 'the ingestion endpoint rejected the batch');
|
|
518
|
+
}
|
|
519
|
+
return removed;
|
|
520
|
+
} finally{
|
|
521
|
+
this._warnAboutDrops();
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
_flushInBackground() {
|
|
525
|
+
if (this._backgroundFlush) return;
|
|
526
|
+
this._backgroundFlush = this.flush().catch((error)=>{
|
|
527
|
+
this._logger.debug('Background span flush failed', error);
|
|
528
|
+
}).finally(()=>{
|
|
529
|
+
this._backgroundFlush = void 0;
|
|
530
|
+
this._armFlushTimerIfQueuedNoEarlierThan();
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
_armFlushTimerIfQueued() {
|
|
534
|
+
if (this._flushTimer.pending || !this._queue.length) return;
|
|
535
|
+
this._flushTimer.arm(this._nextFlushDelay());
|
|
536
|
+
}
|
|
537
|
+
_armFlushTimerIfQueuedNoEarlierThan() {
|
|
538
|
+
if (!this._queue.length) return;
|
|
539
|
+
this._flushTimer.armNoEarlierThan(this._nextFlushDelay());
|
|
540
|
+
}
|
|
541
|
+
_nextFlushDelay() {
|
|
542
|
+
return Math.max((0, backoff_js_namespaceObject.backoffDelayMs)(this._config.flushIntervalMs, this._consecutiveFlushFailures, this._flushJitter, backoff_js_namespaceObject.MAX_FLUSH_BACKOFF_MS), this._retryAfter.remainingMs());
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
exports.PostHogTraces = __webpack_exports__.PostHogTraces;
|
|
546
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
547
|
+
"PostHogTraces"
|
|
548
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
549
|
+
Object.defineProperty(exports, '__esModule', {
|
|
550
|
+
value: true
|
|
551
|
+
});
|