@posthog/core 1.52.1 → 1.53.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/error-tracking/parsers/base.d.ts.map +1 -1
- package/dist/error-tracking/parsers/base.js +19 -2
- package/dist/error-tracking/parsers/base.mjs +19 -2
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +82 -21
- package/dist/index.mjs +4 -0
- package/dist/logs/index.d.ts +3 -2
- package/dist/logs/index.d.ts.map +1 -1
- package/dist/logs/index.js +28 -22
- package/dist/logs/index.mjs +29 -23
- package/dist/logs/logs-utils.js +1 -1
- package/dist/logs/logs-utils.mjs +2 -2
- package/dist/logs/types.d.ts +2 -2
- package/dist/metrics/index.d.ts +5 -2
- package/dist/metrics/index.d.ts.map +1 -1
- package/dist/metrics/index.js +28 -14
- package/dist/metrics/index.mjs +29 -15
- package/dist/metrics/metrics-utils.d.ts.map +1 -1
- package/dist/metrics/metrics-utils.js +1 -2
- package/dist/metrics/metrics-utils.mjs +2 -3
- package/dist/metrics/types.d.ts +7 -0
- package/dist/metrics/types.d.ts.map +1 -1
- package/dist/posthog-core-stateless.d.ts +32 -4
- package/dist/posthog-core-stateless.d.ts.map +1 -1
- package/dist/posthog-core-stateless.js +68 -20
- package/dist/posthog-core-stateless.mjs +68 -20
- package/dist/traces/config.d.ts +13 -0
- package/dist/traces/config.d.ts.map +1 -0
- package/dist/traces/config.js +101 -0
- package/dist/traces/config.mjs +63 -0
- package/dist/traces/context.d.ts +18 -0
- package/dist/traces/context.d.ts.map +1 -0
- package/dist/traces/context.js +53 -0
- package/dist/traces/context.mjs +15 -0
- package/dist/traces/ids.d.ts +12 -0
- package/dist/traces/ids.d.ts.map +1 -0
- package/dist/traces/ids.js +92 -0
- package/dist/traces/ids.mjs +42 -0
- package/dist/traces/index.d.ts +150 -0
- package/dist/traces/index.d.ts.map +1 -0
- package/dist/traces/index.js +551 -0
- package/dist/traces/index.mjs +513 -0
- package/dist/traces/otlp.d.ts +24 -0
- package/dist/traces/otlp.d.ts.map +1 -0
- package/dist/traces/otlp.js +158 -0
- package/dist/traces/otlp.mjs +108 -0
- package/dist/traces/sanitize.d.ts +32 -0
- package/dist/traces/sanitize.d.ts.map +1 -0
- package/dist/traces/sanitize.js +93 -0
- package/dist/traces/sanitize.mjs +43 -0
- package/dist/traces/span.d.ts +189 -0
- package/dist/traces/span.d.ts.map +1 -0
- package/dist/traces/span.js +533 -0
- package/dist/traces/span.mjs +462 -0
- package/dist/traces/traceparent.d.ts +51 -0
- package/dist/traces/traceparent.d.ts.map +1 -0
- package/dist/traces/traceparent.js +116 -0
- package/dist/traces/traceparent.mjs +63 -0
- package/dist/traces/types.d.ts +114 -0
- package/dist/traces/types.d.ts.map +1 -0
- package/dist/traces/types.js +18 -0
- package/dist/traces/types.mjs +1 -0
- package/dist/utils/backoff.d.ts +23 -0
- package/dist/utils/backoff.d.ts.map +1 -0
- package/dist/utils/backoff.js +65 -0
- package/dist/utils/backoff.mjs +14 -0
- package/dist/utils/flush-timer.d.ts +26 -0
- package/dist/utils/flush-timer.d.ts.map +1 -0
- package/dist/utils/flush-timer.js +67 -0
- package/dist/utils/flush-timer.mjs +29 -0
- package/dist/utils/json-utils.d.ts +7 -0
- package/dist/utils/json-utils.d.ts.map +1 -1
- package/dist/utils/json-utils.js +27 -0
- package/dist/utils/json-utils.mjs +25 -1
- package/dist/utils/otlp-resource.d.ts +13 -2
- package/dist/utils/otlp-resource.d.ts.map +1 -1
- package/dist/utils/otlp-resource.js +34 -7
- package/dist/utils/otlp-resource.mjs +26 -2
- package/dist/utils/retry-after.d.ts +55 -0
- package/dist/utils/retry-after.d.ts.map +1 -0
- package/dist/utils/retry-after.js +95 -0
- package/dist/utils/retry-after.mjs +50 -0
- package/package.json +3 -3
- package/src/error-tracking/parsers/base.spec.ts +77 -7
- package/src/error-tracking/parsers/base.ts +42 -19
- package/src/index.ts +18 -0
- package/src/logs/index.spec.ts +490 -2
- package/src/logs/index.ts +63 -31
- package/src/logs/logs-utils.ts +2 -2
- package/src/logs/types.ts +2 -2
- package/src/metrics/index.spec.ts +304 -0
- package/src/metrics/index.ts +53 -16
- package/src/metrics/metrics-utils.ts +2 -3
- package/src/metrics/types.ts +10 -2
- package/src/posthog-core-stateless.ts +157 -38
- package/src/traces/config.spec.ts +271 -0
- package/src/traces/config.ts +142 -0
- package/src/traces/context.ts +30 -0
- package/src/traces/ids.spec.ts +115 -0
- package/src/traces/ids.ts +75 -0
- package/src/traces/index.spec.ts +3187 -0
- package/src/traces/index.ts +1060 -0
- package/src/traces/live-spans.spec.ts +69 -0
- package/src/traces/otlp.spec.ts +368 -0
- package/src/traces/otlp.ts +191 -0
- package/src/traces/sanitize.ts +116 -0
- package/src/traces/span.spec.ts +1122 -0
- package/src/traces/span.ts +822 -0
- package/src/traces/traceparent.spec.ts +184 -0
- package/src/traces/traceparent.ts +172 -0
- package/src/traces/types.ts +140 -0
- package/src/utils/backoff.ts +44 -0
- package/src/utils/flush-timer.ts +50 -0
- package/src/utils/json-utils.ts +33 -0
- package/src/utils/otlp-resource.spec.ts +55 -9
- package/src/utils/otlp-resource.ts +45 -4
- package/src/utils/retry-after.ts +135 -0
|
@@ -0,0 +1,533 @@
|
|
|
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
|
+
NOOP_SPAN: ()=>NOOP_SPAN,
|
|
32
|
+
NoopSpan: ()=>NoopSpan,
|
|
33
|
+
PassThroughSpan: ()=>PassThroughSpan,
|
|
34
|
+
PostHogSpan: ()=>PostHogSpan,
|
|
35
|
+
applySpanLimits: ()=>applySpanLimits,
|
|
36
|
+
describeError: ()=>describeError,
|
|
37
|
+
inertSpan: ()=>inertSpan,
|
|
38
|
+
monotonicNow: ()=>monotonicNow,
|
|
39
|
+
nonNegativeCount: ()=>nonNegativeCount,
|
|
40
|
+
runWithActiveSpan: ()=>runWithActiveSpan,
|
|
41
|
+
truncateAttributeValue: ()=>truncateAttributeValue,
|
|
42
|
+
truncateAttributes: ()=>truncateAttributes
|
|
43
|
+
});
|
|
44
|
+
const external_traceparent_js_namespaceObject = require("./traceparent.js");
|
|
45
|
+
const external_sanitize_js_namespaceObject = require("./sanitize.js");
|
|
46
|
+
const index_js_namespaceObject = require("../utils/index.js");
|
|
47
|
+
const json_utils_js_namespaceObject = require("../utils/json-utils.js");
|
|
48
|
+
function monotonicNow() {
|
|
49
|
+
const perf = globalThis.performance;
|
|
50
|
+
return 'function' == typeof perf?.now ? perf.now() : void 0;
|
|
51
|
+
}
|
|
52
|
+
class PostHogSpan {
|
|
53
|
+
constructor(init, _onEnd, _logger){
|
|
54
|
+
this._onEnd = _onEnd;
|
|
55
|
+
this._logger = _logger;
|
|
56
|
+
this._events = [];
|
|
57
|
+
this._ended = false;
|
|
58
|
+
this._userAttributeCount = 0;
|
|
59
|
+
this._userEventCount = 0;
|
|
60
|
+
this._droppedAttributes = 0;
|
|
61
|
+
this._droppedEvents = 0;
|
|
62
|
+
this._traceId = init.traceId;
|
|
63
|
+
this._spanId = init.spanId;
|
|
64
|
+
this._parentSpanId = init.parentSpanId;
|
|
65
|
+
this._traceState = init.traceState;
|
|
66
|
+
this._traceFlags = init.traceFlags ?? external_traceparent_js_namespaceObject.TRACE_FLAGS_SAMPLED;
|
|
67
|
+
this._parentIsRemote = init.parentIsRemote ?? false;
|
|
68
|
+
this._name = init.name;
|
|
69
|
+
this._kind = init.kind;
|
|
70
|
+
this._autoKeys = new Set(init.autoAttributeKeys);
|
|
71
|
+
this._maxAttributes = init.maxAttributes;
|
|
72
|
+
this._maxEvents = init.maxEvents;
|
|
73
|
+
this._maxAttributesPerEvent = init.maxAttributesPerEvent;
|
|
74
|
+
this._maxAttributeValueLength = init.maxAttributeValueLength;
|
|
75
|
+
this._attributes = Object.create(null);
|
|
76
|
+
for (const key of Object.keys(init.attributes))this._writeAttribute(key, init.attributes[key]);
|
|
77
|
+
this._startTime = init.startTime;
|
|
78
|
+
this._startMono = init.backdated ? void 0 : monotonicNow();
|
|
79
|
+
}
|
|
80
|
+
_now() {
|
|
81
|
+
if (void 0 !== this._startMono) {
|
|
82
|
+
const mono = monotonicNow();
|
|
83
|
+
if (void 0 !== mono) return this._startTime + Math.max(0, mono - this._startMono);
|
|
84
|
+
}
|
|
85
|
+
return Date.now();
|
|
86
|
+
}
|
|
87
|
+
_mutable(operation) {
|
|
88
|
+
if (this._ended) {
|
|
89
|
+
this._logger?.debug(`Ignoring ${operation} on a span that has already ended`);
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
_writeAttribute(key, value) {
|
|
95
|
+
if ((0, index_js_namespaceObject.isNullish)(value)) {
|
|
96
|
+
if (key in this._attributes && !this._autoKeys.has(key)) this._userAttributeCount--;
|
|
97
|
+
delete this._attributes[key];
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (!this._autoKeys.has(key) && !(key in this._attributes)) {
|
|
101
|
+
if (this._userAttributeCount >= this._maxAttributes) return void this._droppedAttributes++;
|
|
102
|
+
this._userAttributeCount++;
|
|
103
|
+
}
|
|
104
|
+
this._attributes[key] = truncateAttributeValue(value, this._maxAttributeValueLength);
|
|
105
|
+
}
|
|
106
|
+
setAttribute(key, value) {
|
|
107
|
+
if (this._mutable('setAttribute')) this._writeAttribute(key, value);
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
setAttributes(attributes) {
|
|
111
|
+
if (this._mutable('setAttributes')) {
|
|
112
|
+
const safe = (0, json_utils_js_namespaceObject.assignUserAttributes)({}, attributes);
|
|
113
|
+
for (const key of Object.keys(safe))this._writeAttribute(key, safe[key]);
|
|
114
|
+
}
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
addEvent(name, attributes, timestamp) {
|
|
118
|
+
if (this._mutable('addEvent')) {
|
|
119
|
+
if (this._userEventCount >= this._maxEvents) {
|
|
120
|
+
this._droppedEvents++;
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
this._userEventCount++;
|
|
124
|
+
const bounded = attributes && boundAttributes(attributes, this._maxAttributesPerEvent, this._maxAttributeValueLength);
|
|
125
|
+
this._events.push({
|
|
126
|
+
name: (0, external_sanitize_js_namespaceObject.sanitizeName)(name, 'Span event name', this._maxAttributeValueLength, this._logger),
|
|
127
|
+
timestamp: (0, external_sanitize_js_namespaceObject.resolveSuppliedTime)(timestamp, this._now(), 'event timestamp', this._logger),
|
|
128
|
+
...bounded && {
|
|
129
|
+
attributes: bounded.attributes,
|
|
130
|
+
...bounded.dropped && {
|
|
131
|
+
droppedAttributesCount: bounded.dropped
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
setStatus(status, message) {
|
|
139
|
+
if (this._mutable('setStatus')) {
|
|
140
|
+
if ('ok' !== status && 'error' !== status) {
|
|
141
|
+
this._logger?.debug(`Ignoring unknown span status "${String(status)}"; expected "ok" or "error"`);
|
|
142
|
+
return this;
|
|
143
|
+
}
|
|
144
|
+
this._status = {
|
|
145
|
+
code: status,
|
|
146
|
+
...message && {
|
|
147
|
+
message: truncateString(message, this._maxAttributeValueLength)
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
153
|
+
get statusIsExplicitlyOk() {
|
|
154
|
+
return this._status?.code === 'ok';
|
|
155
|
+
}
|
|
156
|
+
recordException(error) {
|
|
157
|
+
if (!this._mutable('recordException')) return this;
|
|
158
|
+
const { type, message, stack } = describeError(error);
|
|
159
|
+
this.addEvent(EXCEPTION_EVENT_NAME, {
|
|
160
|
+
'exception.type': type,
|
|
161
|
+
'exception.message': message,
|
|
162
|
+
...stack && {
|
|
163
|
+
'exception.stacktrace': stack
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
return this.setStatus('error', message);
|
|
167
|
+
}
|
|
168
|
+
updateName(name) {
|
|
169
|
+
if (this._mutable('updateName')) this._name = (0, external_sanitize_js_namespaceObject.sanitizeName)(name, 'Span name', this._maxAttributeValueLength, this._logger);
|
|
170
|
+
return this;
|
|
171
|
+
}
|
|
172
|
+
traceparent() {
|
|
173
|
+
return (0, external_traceparent_js_namespaceObject.formatTraceparent)(this._traceId, this._spanId, this._traceFlags);
|
|
174
|
+
}
|
|
175
|
+
tracestate() {
|
|
176
|
+
return this._traceState ?? null;
|
|
177
|
+
}
|
|
178
|
+
childContext() {
|
|
179
|
+
return {
|
|
180
|
+
traceId: this._traceId,
|
|
181
|
+
parentSpanId: this._spanId,
|
|
182
|
+
traceState: this._traceState,
|
|
183
|
+
traceFlags: this._traceFlags
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
end(endTime) {
|
|
187
|
+
if (this._ended) return void this._logger?.debug('Ignoring end() on a span that has already ended');
|
|
188
|
+
this._ended = true;
|
|
189
|
+
const derived = this._now();
|
|
190
|
+
const resolved = (0, external_sanitize_js_namespaceObject.resolveSuppliedTime)(endTime, derived, 'end time', this._logger);
|
|
191
|
+
this._onEnd({
|
|
192
|
+
traceId: this._traceId,
|
|
193
|
+
spanId: this._spanId,
|
|
194
|
+
...this._parentSpanId && {
|
|
195
|
+
parentSpanId: this._parentSpanId
|
|
196
|
+
},
|
|
197
|
+
...this._traceState && {
|
|
198
|
+
traceState: this._traceState
|
|
199
|
+
},
|
|
200
|
+
traceFlags: this._traceFlags,
|
|
201
|
+
parentIsRemote: this._parentIsRemote,
|
|
202
|
+
name: this._name,
|
|
203
|
+
kind: this._kind,
|
|
204
|
+
...this._status && {
|
|
205
|
+
status: this._status
|
|
206
|
+
},
|
|
207
|
+
attributes: {
|
|
208
|
+
...this._attributes
|
|
209
|
+
},
|
|
210
|
+
events: this._events,
|
|
211
|
+
startTime: this._startTime,
|
|
212
|
+
endTime: (0, external_sanitize_js_namespaceObject.clampEndTime)(resolved, this._startTime),
|
|
213
|
+
...this._droppedAttributes && {
|
|
214
|
+
droppedAttributesCount: this._droppedAttributes
|
|
215
|
+
},
|
|
216
|
+
...this._droppedEvents && {
|
|
217
|
+
droppedEventsCount: this._droppedEvents
|
|
218
|
+
}
|
|
219
|
+
}, this._autoKeys);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
const EXCEPTION_EVENT_NAME = 'exception';
|
|
223
|
+
const MAX_UINT32 = 0xffffffff;
|
|
224
|
+
function safeString(value) {
|
|
225
|
+
try {
|
|
226
|
+
return 'string' == typeof value ? value : String(value);
|
|
227
|
+
} catch {
|
|
228
|
+
return json_utils_js_namespaceObject.UNSERIALIZABLE_VALUE;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
function nonNegativeCount(value) {
|
|
232
|
+
if ('number' != typeof value || !Number.isFinite(value) || value <= 0) return 0;
|
|
233
|
+
return Math.min(Math.floor(value), MAX_UINT32);
|
|
234
|
+
}
|
|
235
|
+
function orderedKeys(attributes, keysBeforeHook) {
|
|
236
|
+
if (!keysBeforeHook.length) return Object.keys(attributes);
|
|
237
|
+
const beforeHook = keysBeforeHook.filter((key)=>Object.prototype.propertyIsEnumerable.call(attributes, key));
|
|
238
|
+
const seen = new Set(beforeHook);
|
|
239
|
+
return [
|
|
240
|
+
...beforeHook,
|
|
241
|
+
...Object.keys(attributes).filter((key)=>!seen.has(key))
|
|
242
|
+
];
|
|
243
|
+
}
|
|
244
|
+
function applySpanLimits(record, autoKeys, maxAttributes, maxEvents, maxAttributesPerEvent, maxAttributeValueLength, keysBeforeHook = []) {
|
|
245
|
+
let kept = 0;
|
|
246
|
+
let droppedAttributes = 0;
|
|
247
|
+
const attributes = {};
|
|
248
|
+
for (const key of orderedKeys(record.attributes, keysBeforeHook)){
|
|
249
|
+
const value = record.attributes[key];
|
|
250
|
+
if (!(0, index_js_namespaceObject.isNullish)(value)) {
|
|
251
|
+
if (!autoKeys.has(key)) {
|
|
252
|
+
if (kept >= maxAttributes) {
|
|
253
|
+
droppedAttributes++;
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
kept++;
|
|
257
|
+
}
|
|
258
|
+
Object.defineProperty(attributes, key, {
|
|
259
|
+
value: truncateAttributeValue(value, maxAttributeValueLength),
|
|
260
|
+
enumerable: true,
|
|
261
|
+
writable: true,
|
|
262
|
+
configurable: true
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
record.attributes = attributes;
|
|
267
|
+
if (droppedAttributes) record.droppedAttributesCount = nonNegativeCount(record.droppedAttributesCount) + droppedAttributes;
|
|
268
|
+
let keptEvents = 0;
|
|
269
|
+
let droppedEvents = 0;
|
|
270
|
+
const events = [];
|
|
271
|
+
for (const event of record.events){
|
|
272
|
+
if (keptEvents >= maxEvents) {
|
|
273
|
+
droppedEvents++;
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
keptEvents++;
|
|
277
|
+
if (event.attributes) {
|
|
278
|
+
const bounded = boundAttributes(event.attributes, maxAttributesPerEvent, maxAttributeValueLength);
|
|
279
|
+
event.attributes = bounded.attributes;
|
|
280
|
+
if (bounded.dropped) event.droppedAttributesCount = nonNegativeCount(event.droppedAttributesCount) + bounded.dropped;
|
|
281
|
+
}
|
|
282
|
+
events.push(event);
|
|
283
|
+
}
|
|
284
|
+
record.events = events;
|
|
285
|
+
if (droppedEvents) record.droppedEventsCount = nonNegativeCount(record.droppedEventsCount) + droppedEvents;
|
|
286
|
+
if (record.status?.message) record.status = {
|
|
287
|
+
...record.status,
|
|
288
|
+
message: truncateString(safeString(record.status.message), maxAttributeValueLength)
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
class NoopSpan {
|
|
292
|
+
setAttribute() {
|
|
293
|
+
return this;
|
|
294
|
+
}
|
|
295
|
+
setAttributes() {
|
|
296
|
+
return this;
|
|
297
|
+
}
|
|
298
|
+
addEvent() {
|
|
299
|
+
return this;
|
|
300
|
+
}
|
|
301
|
+
setStatus() {
|
|
302
|
+
return this;
|
|
303
|
+
}
|
|
304
|
+
recordException() {
|
|
305
|
+
return this;
|
|
306
|
+
}
|
|
307
|
+
updateName() {
|
|
308
|
+
return this;
|
|
309
|
+
}
|
|
310
|
+
traceparent() {
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
tracestate() {
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
end() {}
|
|
317
|
+
}
|
|
318
|
+
const NOOP_SPAN = /* @__PURE__ */ new NoopSpan();
|
|
319
|
+
class PassThroughSpan extends NoopSpan {
|
|
320
|
+
constructor(_traceparent, _tracestate){
|
|
321
|
+
super(), this._traceparent = _traceparent, this._tracestate = _tracestate;
|
|
322
|
+
}
|
|
323
|
+
traceparent() {
|
|
324
|
+
return this._traceparent;
|
|
325
|
+
}
|
|
326
|
+
tracestate() {
|
|
327
|
+
return this._tracestate ?? null;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
function readStack(error) {
|
|
331
|
+
try {
|
|
332
|
+
const stack = error.stack;
|
|
333
|
+
return 'string' == typeof stack && stack ? {
|
|
334
|
+
stack
|
|
335
|
+
} : {};
|
|
336
|
+
} catch {
|
|
337
|
+
return {};
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
function inertSpan(options, active) {
|
|
341
|
+
const parent = (0, external_traceparent_js_namespaceObject.traceparentHeader)(options?.parent) ?? active;
|
|
342
|
+
const inbound = 'string' == typeof parent || null == parent ? parent : readHandle(parent, 'traceparent');
|
|
343
|
+
const traceparent = (0, external_traceparent_js_namespaceObject.normalizeTraceparent)(inbound);
|
|
344
|
+
if (!traceparent) return NOOP_SPAN;
|
|
345
|
+
const tracestate = 'string' == typeof parent || null == parent ? options?.tracestate : readHandle(parent, 'tracestate');
|
|
346
|
+
return new PassThroughSpan(traceparent, (0, external_traceparent_js_namespaceObject.sanitizeTracestate)(tracestate));
|
|
347
|
+
}
|
|
348
|
+
function readHandle(parent, method) {
|
|
349
|
+
try {
|
|
350
|
+
const fn = parent[method];
|
|
351
|
+
return 'function' == typeof fn ? fn.call(parent) : void 0;
|
|
352
|
+
} catch {
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
function truncateString(value, maxLength) {
|
|
357
|
+
return value.length > maxLength ? value.slice(0, maxLength) : value;
|
|
358
|
+
}
|
|
359
|
+
function truncateAttributeValue(value, maxLength) {
|
|
360
|
+
return truncateValue(value, maxLength, {
|
|
361
|
+
ancestors: new WeakSet(),
|
|
362
|
+
remainingNodes: json_utils_js_namespaceObject.MAX_JSON_SAFE_VALUE_NODES
|
|
363
|
+
}, 0);
|
|
364
|
+
}
|
|
365
|
+
function truncateValue(value, maxLength, state, depth) {
|
|
366
|
+
if (null === value || 'object' != typeof value) {
|
|
367
|
+
if ((0, index_js_namespaceObject.isNullish)(value)) return value;
|
|
368
|
+
if (state.remainingNodes <= 0) return value;
|
|
369
|
+
state.remainingNodes--;
|
|
370
|
+
return 'string' == typeof value ? truncateString(value, maxLength) : value;
|
|
371
|
+
}
|
|
372
|
+
if (state.ancestors.has(value)) return json_utils_js_namespaceObject.CIRCULAR_VALUE;
|
|
373
|
+
if (state.remainingNodes <= 0 || depth >= json_utils_js_namespaceObject.MAX_JSON_SAFE_VALUE_DEPTH) return value;
|
|
374
|
+
state.remainingNodes--;
|
|
375
|
+
state.ancestors.add(value);
|
|
376
|
+
try {
|
|
377
|
+
if (value instanceof Date) return value;
|
|
378
|
+
const resolved = resolveToJson(value);
|
|
379
|
+
if (resolved.selfDescribed) return (0, index_js_namespaceObject.isNullish)(resolved.value) ? String(resolved.value) : truncateValue(resolved.value, maxLength, state, depth + 1);
|
|
380
|
+
if ((0, index_js_namespaceObject.isArray)(value)) {
|
|
381
|
+
const walked = Math.min(value.length, json_utils_js_namespaceObject.MAX_JSON_SAFE_VALUE_ITEMS);
|
|
382
|
+
const boundedItems = [];
|
|
383
|
+
for(let index = 0; index < walked; index++)try {
|
|
384
|
+
boundedItems.push(truncateValue(value[index], maxLength, state, depth + 1));
|
|
385
|
+
} catch {
|
|
386
|
+
boundedItems.push(json_utils_js_namespaceObject.UNSERIALIZABLE_VALUE);
|
|
387
|
+
}
|
|
388
|
+
if (value.length > walked) boundedItems.length = value.length;
|
|
389
|
+
return boundedItems;
|
|
390
|
+
}
|
|
391
|
+
const bounded = {};
|
|
392
|
+
let emittable = 0;
|
|
393
|
+
for (const key of Object.keys(value)){
|
|
394
|
+
if (emittable >= json_utils_js_namespaceObject.MAX_JSON_SAFE_VALUE_ITEMS) break;
|
|
395
|
+
let boundedItem;
|
|
396
|
+
try {
|
|
397
|
+
boundedItem = truncateValue(value[key], maxLength, state, depth + 1);
|
|
398
|
+
} catch {
|
|
399
|
+
boundedItem = json_utils_js_namespaceObject.UNSERIALIZABLE_VALUE;
|
|
400
|
+
}
|
|
401
|
+
if (key && !(0, index_js_namespaceObject.isNullish)(boundedItem)) emittable++;
|
|
402
|
+
Object.defineProperty(bounded, key, {
|
|
403
|
+
value: boundedItem,
|
|
404
|
+
enumerable: true,
|
|
405
|
+
writable: true,
|
|
406
|
+
configurable: true
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
return bounded;
|
|
410
|
+
} catch {
|
|
411
|
+
return value;
|
|
412
|
+
} finally{
|
|
413
|
+
state.ancestors.delete(value);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
function resolveToJson(value) {
|
|
417
|
+
try {
|
|
418
|
+
const toJSON = value.toJSON;
|
|
419
|
+
if ('function' == typeof toJSON) return {
|
|
420
|
+
selfDescribed: true,
|
|
421
|
+
value: toJSON.call(value)
|
|
422
|
+
};
|
|
423
|
+
} catch {}
|
|
424
|
+
return {
|
|
425
|
+
selfDescribed: false
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
function boundAttributes(source, max, maxLength) {
|
|
429
|
+
let keys;
|
|
430
|
+
try {
|
|
431
|
+
keys = Object.keys(source);
|
|
432
|
+
} catch {
|
|
433
|
+
return {
|
|
434
|
+
attributes: {},
|
|
435
|
+
dropped: 0
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
const attributes = {};
|
|
439
|
+
let kept = 0;
|
|
440
|
+
let dropped = 0;
|
|
441
|
+
for (const key of keys){
|
|
442
|
+
if (kept >= max) {
|
|
443
|
+
dropped++;
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
let value;
|
|
447
|
+
try {
|
|
448
|
+
value = truncateAttributeValue(source[key], maxLength);
|
|
449
|
+
} catch {
|
|
450
|
+
value = json_utils_js_namespaceObject.UNSERIALIZABLE_VALUE;
|
|
451
|
+
}
|
|
452
|
+
if (!(0, index_js_namespaceObject.isNullish)(value)) {
|
|
453
|
+
kept++;
|
|
454
|
+
Object.defineProperty(attributes, key, {
|
|
455
|
+
value,
|
|
456
|
+
enumerable: true,
|
|
457
|
+
writable: true,
|
|
458
|
+
configurable: true
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
return {
|
|
463
|
+
attributes,
|
|
464
|
+
dropped
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
function truncateAttributes(attributes, maxLength) {
|
|
468
|
+
for (const key of Object.keys(attributes))attributes[key] = truncateAttributeValue(attributes[key], maxLength);
|
|
469
|
+
return attributes;
|
|
470
|
+
}
|
|
471
|
+
function runWithActiveSpan(contextManager, span, fn) {
|
|
472
|
+
return span === NOOP_SPAN ? fn(span) : contextManager.with(span, ()=>fn(span));
|
|
473
|
+
}
|
|
474
|
+
function describeError(error) {
|
|
475
|
+
try {
|
|
476
|
+
const stack = readStack(error);
|
|
477
|
+
if ((0, index_js_namespaceObject.isError)(error)) return {
|
|
478
|
+
type: error.name || 'Error',
|
|
479
|
+
message: error.message || '',
|
|
480
|
+
...stack
|
|
481
|
+
};
|
|
482
|
+
if ('string' == typeof error) return {
|
|
483
|
+
type: 'string',
|
|
484
|
+
message: error
|
|
485
|
+
};
|
|
486
|
+
if (error && 'object' == typeof error) {
|
|
487
|
+
const maybe = error;
|
|
488
|
+
if ('string' == typeof maybe.message) return {
|
|
489
|
+
type: 'string' == typeof maybe.name ? maybe.name : 'Object',
|
|
490
|
+
message: maybe.message,
|
|
491
|
+
...stack
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
return {
|
|
495
|
+
type: typeof error,
|
|
496
|
+
message: String(error)
|
|
497
|
+
};
|
|
498
|
+
} catch {
|
|
499
|
+
return {
|
|
500
|
+
type: typeof error,
|
|
501
|
+
message: ''
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
exports.NOOP_SPAN = __webpack_exports__.NOOP_SPAN;
|
|
506
|
+
exports.NoopSpan = __webpack_exports__.NoopSpan;
|
|
507
|
+
exports.PassThroughSpan = __webpack_exports__.PassThroughSpan;
|
|
508
|
+
exports.PostHogSpan = __webpack_exports__.PostHogSpan;
|
|
509
|
+
exports.applySpanLimits = __webpack_exports__.applySpanLimits;
|
|
510
|
+
exports.describeError = __webpack_exports__.describeError;
|
|
511
|
+
exports.inertSpan = __webpack_exports__.inertSpan;
|
|
512
|
+
exports.monotonicNow = __webpack_exports__.monotonicNow;
|
|
513
|
+
exports.nonNegativeCount = __webpack_exports__.nonNegativeCount;
|
|
514
|
+
exports.runWithActiveSpan = __webpack_exports__.runWithActiveSpan;
|
|
515
|
+
exports.truncateAttributeValue = __webpack_exports__.truncateAttributeValue;
|
|
516
|
+
exports.truncateAttributes = __webpack_exports__.truncateAttributes;
|
|
517
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
518
|
+
"NOOP_SPAN",
|
|
519
|
+
"NoopSpan",
|
|
520
|
+
"PassThroughSpan",
|
|
521
|
+
"PostHogSpan",
|
|
522
|
+
"applySpanLimits",
|
|
523
|
+
"describeError",
|
|
524
|
+
"inertSpan",
|
|
525
|
+
"monotonicNow",
|
|
526
|
+
"nonNegativeCount",
|
|
527
|
+
"runWithActiveSpan",
|
|
528
|
+
"truncateAttributeValue",
|
|
529
|
+
"truncateAttributes"
|
|
530
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
531
|
+
Object.defineProperty(exports, '__esModule', {
|
|
532
|
+
value: true
|
|
533
|
+
});
|