braintrust 3.24.0 → 3.26.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/NOTICE +6 -0
- package/dev/dist/index.d.mts +135 -2
- package/dev/dist/index.d.ts +135 -2
- package/dev/dist/index.js +4426 -2040
- package/dev/dist/index.mjs +3594 -1208
- package/dist/apply-auto-instrumentation.js +445 -403
- package/dist/apply-auto-instrumentation.mjs +249 -207
- package/dist/auto-instrumentations/bundler/esbuild.cjs +1449 -799
- package/dist/auto-instrumentations/bundler/esbuild.d.mts +4 -4
- package/dist/auto-instrumentations/bundler/esbuild.d.ts +4 -4
- package/dist/auto-instrumentations/bundler/esbuild.mjs +5 -8
- package/dist/auto-instrumentations/bundler/next.cjs +1448 -818
- package/dist/auto-instrumentations/bundler/next.mjs +6 -29
- package/dist/auto-instrumentations/bundler/rollup.cjs +1449 -799
- package/dist/auto-instrumentations/bundler/rollup.d.mts +4 -4
- package/dist/auto-instrumentations/bundler/rollup.d.ts +4 -4
- package/dist/auto-instrumentations/bundler/rollup.mjs +5 -8
- package/dist/auto-instrumentations/bundler/vite.cjs +1449 -799
- package/dist/auto-instrumentations/bundler/vite.d.mts +4 -4
- package/dist/auto-instrumentations/bundler/vite.d.ts +4 -4
- package/dist/auto-instrumentations/bundler/vite.mjs +5 -8
- package/dist/auto-instrumentations/bundler/webpack-loader.cjs +1602 -728
- package/dist/auto-instrumentations/bundler/webpack-loader.d.ts +20 -12
- package/dist/auto-instrumentations/bundler/webpack.cjs +1449 -799
- package/dist/auto-instrumentations/bundler/webpack.d.mts +4 -4
- package/dist/auto-instrumentations/bundler/webpack.d.ts +4 -4
- package/dist/auto-instrumentations/bundler/webpack.mjs +5 -4
- package/dist/auto-instrumentations/{chunk-GSZHTAQW.mjs → chunk-6E22MYSW.mjs} +194 -93
- package/dist/auto-instrumentations/{chunk-VT6DDNKM.mjs → chunk-AKKPLXTP.mjs} +631 -194
- package/dist/auto-instrumentations/chunk-NRE4QUQR.mjs +509 -0
- package/dist/auto-instrumentations/{chunk-BURMPO7L.mjs → chunk-V5LEODRX.mjs} +2 -6
- package/dist/auto-instrumentations/{chunk-M6DLIJ2Z.mjs → chunk-XYN63IG5.mjs} +124 -194
- package/dist/auto-instrumentations/{chunk-F43DNLPD.mjs → chunk-XZHHE4Y3.mjs} +646 -510
- package/dist/auto-instrumentations/hook.mjs +894 -657
- package/dist/auto-instrumentations/index.cjs +1125 -490
- package/dist/auto-instrumentations/index.d.mts +6 -2
- package/dist/auto-instrumentations/index.d.ts +6 -2
- package/dist/auto-instrumentations/index.mjs +6 -1
- package/dist/auto-instrumentations/loader/cjs-patch.cjs +492 -195
- package/dist/auto-instrumentations/loader/cjs-patch.d.mts +2 -2
- package/dist/auto-instrumentations/loader/cjs-patch.d.ts +2 -2
- package/dist/auto-instrumentations/loader/cjs-patch.mjs +3 -2
- package/dist/auto-instrumentations/loader/esm-hook.mjs +1 -1
- package/dist/auto-instrumentations/plugin-B-aZh7EP.d.ts +30 -0
- package/dist/auto-instrumentations/plugin-Bnj4E_6B.d.mts +30 -0
- package/dist/auto-instrumentations/{types-RNPaKi9o.d.mts → types-C1fVeiCp.d.mts} +1 -1
- package/dist/auto-instrumentations/{types-RNPaKi9o.d.ts → types-C1fVeiCp.d.ts} +1 -1
- package/dist/browser.d.mts +824 -197
- package/dist/browser.d.ts +824 -197
- package/dist/browser.js +3897 -1228
- package/dist/browser.mjs +3897 -1228
- package/dist/chunk-PN7EWK66.mjs +1784 -0
- package/dist/{chunk-SU6EHKJV.js → chunk-VRZZQPAA.js} +3289 -1577
- package/dist/chunk-VYNNEKSA.js +1784 -0
- package/dist/{chunk-XE5FS7QY.mjs → chunk-XIZOM2HO.mjs} +2470 -758
- package/dist/cli.js +3596 -1211
- package/dist/edge-light.d.mts +1 -1
- package/dist/edge-light.d.ts +1 -1
- package/dist/edge-light.js +3897 -1231
- package/dist/edge-light.mjs +3897 -1231
- package/dist/index.d.mts +824 -197
- package/dist/index.d.ts +824 -197
- package/dist/index.js +750 -445
- package/dist/index.mjs +334 -29
- package/dist/instrumentation/index.d.mts +135 -6
- package/dist/instrumentation/index.d.ts +135 -6
- package/dist/instrumentation/index.js +3696 -1257
- package/dist/instrumentation/index.mjs +3696 -1257
- package/dist/vitest-evals-reporter.js +16 -16
- package/dist/vitest-evals-reporter.mjs +2 -2
- package/dist/workerd.d.mts +1 -1
- package/dist/workerd.d.ts +1 -1
- package/dist/workerd.js +3897 -1231
- package/dist/workerd.mjs +3897 -1231
- package/licenses/node-diagnostics-channel/LICENSE +19 -0
- package/package.json +34 -35
- package/dist/auto-instrumentations/plugin-D0KHwSJv.d.mts +0 -44
- package/dist/auto-instrumentations/plugin-G6fgxk1b.d.ts +0 -44
- package/dist/chunk-7AUY2XWX.js +0 -1090
- package/dist/chunk-7F6GCRHH.mjs +0 -1090
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
// src/global-instrumentation-hooks.ts
|
|
2
|
+
var GLOBAL_INSTRUMENTATION_HOOKS_KEY = "__braintrust_instrumentation_hooks";
|
|
3
|
+
var GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION = 1;
|
|
4
|
+
var GLOBAL_INSTRUMENTATION_HOOKS_REGISTRY_BRAND = "braintrust.global-instrumentation-hooks.registry";
|
|
5
|
+
var GLOBAL_INSTRUMENTATION_HOOK_BRAND = "braintrust.global-instrumentation-hooks.hook";
|
|
6
|
+
var registryBrand = Symbol.for(GLOBAL_INSTRUMENTATION_HOOKS_REGISTRY_BRAND);
|
|
7
|
+
var hookBrand = Symbol.for(GLOBAL_INSTRUMENTATION_HOOK_BRAND);
|
|
8
|
+
var errorReporter;
|
|
9
|
+
function reportError(error) {
|
|
10
|
+
try {
|
|
11
|
+
errorReporter?.(error);
|
|
12
|
+
} catch {
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function setContextValue(context, key, value) {
|
|
16
|
+
try {
|
|
17
|
+
context[key] = value;
|
|
18
|
+
} catch (error) {
|
|
19
|
+
reportError(error);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function wrapStoreRun(store, message, next, transform) {
|
|
23
|
+
return () => {
|
|
24
|
+
let context;
|
|
25
|
+
try {
|
|
26
|
+
context = transform ? transform(message) : message;
|
|
27
|
+
} catch (error) {
|
|
28
|
+
reportError(error);
|
|
29
|
+
return next();
|
|
30
|
+
}
|
|
31
|
+
let called = false;
|
|
32
|
+
let result;
|
|
33
|
+
let providerError;
|
|
34
|
+
let providerThrew = false;
|
|
35
|
+
const runNext = () => {
|
|
36
|
+
if (called) {
|
|
37
|
+
reportError(
|
|
38
|
+
new Error(
|
|
39
|
+
"Instrumentation store invoked its callback more than once"
|
|
40
|
+
)
|
|
41
|
+
);
|
|
42
|
+
if (providerThrew) {
|
|
43
|
+
throw providerError;
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
called = true;
|
|
48
|
+
try {
|
|
49
|
+
result = next();
|
|
50
|
+
return result;
|
|
51
|
+
} catch (error) {
|
|
52
|
+
providerThrew = true;
|
|
53
|
+
providerError = error;
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
try {
|
|
58
|
+
store.run(context, runNext);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (!providerThrew || error !== providerError) {
|
|
61
|
+
reportError(error);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (!called) {
|
|
65
|
+
reportError(
|
|
66
|
+
new Error("Instrumentation store did not invoke its callback")
|
|
67
|
+
);
|
|
68
|
+
return runNext();
|
|
69
|
+
}
|
|
70
|
+
if (providerThrew) {
|
|
71
|
+
throw providerError;
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
var HookChannel = class {
|
|
77
|
+
constructor(name) {
|
|
78
|
+
this.name = name;
|
|
79
|
+
}
|
|
80
|
+
name;
|
|
81
|
+
subscribers = [];
|
|
82
|
+
stores = /* @__PURE__ */ new Map();
|
|
83
|
+
get hasSubscribers() {
|
|
84
|
+
return this.subscribers.length > 0 || this.stores.size > 0;
|
|
85
|
+
}
|
|
86
|
+
subscribe(subscription) {
|
|
87
|
+
if (typeof subscription !== "function") {
|
|
88
|
+
throw new TypeError("subscription must be a function");
|
|
89
|
+
}
|
|
90
|
+
this.subscribers = [...this.subscribers, subscription];
|
|
91
|
+
}
|
|
92
|
+
unsubscribe(subscription) {
|
|
93
|
+
const index = this.subscribers.indexOf(subscription);
|
|
94
|
+
if (index === -1) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
this.subscribers = [
|
|
98
|
+
...this.subscribers.slice(0, index),
|
|
99
|
+
...this.subscribers.slice(index + 1)
|
|
100
|
+
];
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
bindStore(store, transform) {
|
|
104
|
+
if (!store || typeof store.run !== "function") {
|
|
105
|
+
throw new TypeError("store must have a run method");
|
|
106
|
+
}
|
|
107
|
+
this.stores.set(
|
|
108
|
+
store,
|
|
109
|
+
transform
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
unbindStore(store) {
|
|
113
|
+
return this.stores.delete(store);
|
|
114
|
+
}
|
|
115
|
+
publish(message) {
|
|
116
|
+
const subscribers = this.subscribers;
|
|
117
|
+
for (const subscriber of subscribers) {
|
|
118
|
+
try {
|
|
119
|
+
subscriber(message, this.name);
|
|
120
|
+
} catch (error) {
|
|
121
|
+
reportError(error);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
runStores(message, fn, thisArg, ...args) {
|
|
126
|
+
let run = () => {
|
|
127
|
+
this.publish(message);
|
|
128
|
+
return Reflect.apply(fn, thisArg, args);
|
|
129
|
+
};
|
|
130
|
+
for (const [store, transform] of this.stores.entries()) {
|
|
131
|
+
run = wrapStoreRun(store, message, run, transform);
|
|
132
|
+
}
|
|
133
|
+
return run();
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
var traceEvents = [
|
|
137
|
+
"start",
|
|
138
|
+
"end",
|
|
139
|
+
"asyncStart",
|
|
140
|
+
"asyncEnd",
|
|
141
|
+
"error"
|
|
142
|
+
];
|
|
143
|
+
var TracingHook = class {
|
|
144
|
+
start;
|
|
145
|
+
end;
|
|
146
|
+
asyncStart;
|
|
147
|
+
asyncEnd;
|
|
148
|
+
error;
|
|
149
|
+
constructor(nameOrChannels) {
|
|
150
|
+
Object.defineProperty(this, hookBrand, {
|
|
151
|
+
configurable: false,
|
|
152
|
+
enumerable: false,
|
|
153
|
+
value: GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
|
|
154
|
+
writable: false
|
|
155
|
+
});
|
|
156
|
+
if (typeof nameOrChannels === "string") {
|
|
157
|
+
this.start = new HookChannel(`tracing:${nameOrChannels}:start`);
|
|
158
|
+
this.end = new HookChannel(`tracing:${nameOrChannels}:end`);
|
|
159
|
+
this.asyncStart = new HookChannel(`tracing:${nameOrChannels}:asyncStart`);
|
|
160
|
+
this.asyncEnd = new HookChannel(`tracing:${nameOrChannels}:asyncEnd`);
|
|
161
|
+
this.error = new HookChannel(`tracing:${nameOrChannels}:error`);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
this.start = nameOrChannels.start ?? new HookChannel("tracing:start");
|
|
165
|
+
this.end = nameOrChannels.end ?? new HookChannel("tracing:end");
|
|
166
|
+
this.asyncStart = nameOrChannels.asyncStart ?? new HookChannel("tracing:asyncStart");
|
|
167
|
+
this.asyncEnd = nameOrChannels.asyncEnd ?? new HookChannel("tracing:asyncEnd");
|
|
168
|
+
this.error = nameOrChannels.error ?? new HookChannel("tracing:error");
|
|
169
|
+
}
|
|
170
|
+
get hasSubscribers() {
|
|
171
|
+
return this.start.hasSubscribers || this.end.hasSubscribers || this.asyncStart.hasSubscribers || this.asyncEnd.hasSubscribers || this.error.hasSubscribers;
|
|
172
|
+
}
|
|
173
|
+
subscribe(handlers) {
|
|
174
|
+
for (const eventName of traceEvents) {
|
|
175
|
+
const handler = handlers[eventName];
|
|
176
|
+
if (handler) {
|
|
177
|
+
this[eventName].subscribe(handler);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
unsubscribe(handlers) {
|
|
182
|
+
let done = true;
|
|
183
|
+
for (const eventName of traceEvents) {
|
|
184
|
+
const handler = handlers[eventName];
|
|
185
|
+
if (handler && !this[eventName].unsubscribe(handler)) {
|
|
186
|
+
done = false;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return done;
|
|
190
|
+
}
|
|
191
|
+
traceSync(fn, message = {}, thisArg, ...args) {
|
|
192
|
+
if (!this.hasSubscribers) {
|
|
193
|
+
return Reflect.apply(fn, thisArg, args);
|
|
194
|
+
}
|
|
195
|
+
const context = message;
|
|
196
|
+
return this.start.runStores(message, () => {
|
|
197
|
+
try {
|
|
198
|
+
const result = Reflect.apply(fn, thisArg, args);
|
|
199
|
+
setContextValue(context, "result", result);
|
|
200
|
+
return result;
|
|
201
|
+
} catch (error) {
|
|
202
|
+
setContextValue(context, "error", error);
|
|
203
|
+
this.error.publish(message);
|
|
204
|
+
throw error;
|
|
205
|
+
} finally {
|
|
206
|
+
this.end.publish(message);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
tracePromise(fn, message = {}, thisArg, ...args) {
|
|
211
|
+
if (!this.hasSubscribers) {
|
|
212
|
+
return Reflect.apply(fn, thisArg, args);
|
|
213
|
+
}
|
|
214
|
+
const context = message;
|
|
215
|
+
return this.start.runStores(message, () => {
|
|
216
|
+
let result;
|
|
217
|
+
try {
|
|
218
|
+
result = Reflect.apply(fn, thisArg, args);
|
|
219
|
+
} catch (error) {
|
|
220
|
+
setContextValue(context, "error", error);
|
|
221
|
+
this.error.publish(message);
|
|
222
|
+
this.end.publish(message);
|
|
223
|
+
throw error;
|
|
224
|
+
}
|
|
225
|
+
this.end.publish(message);
|
|
226
|
+
if (!result || typeof result !== "object" && typeof result !== "function") {
|
|
227
|
+
setContextValue(context, "result", result);
|
|
228
|
+
this.asyncStart.publish(message);
|
|
229
|
+
this.asyncEnd.publish(message);
|
|
230
|
+
return result;
|
|
231
|
+
}
|
|
232
|
+
let terminalPublished = false;
|
|
233
|
+
const finishUnobservedResult = (error) => {
|
|
234
|
+
reportError(error);
|
|
235
|
+
if (!terminalPublished) {
|
|
236
|
+
terminalPublished = true;
|
|
237
|
+
setContextValue(context, "result", result);
|
|
238
|
+
this.asyncStart.publish(message);
|
|
239
|
+
this.asyncEnd.publish(message);
|
|
240
|
+
}
|
|
241
|
+
return result;
|
|
242
|
+
};
|
|
243
|
+
let then;
|
|
244
|
+
try {
|
|
245
|
+
then = result.then;
|
|
246
|
+
} catch (error) {
|
|
247
|
+
return finishUnobservedResult(error);
|
|
248
|
+
}
|
|
249
|
+
if (typeof then !== "function") {
|
|
250
|
+
setContextValue(context, "result", result);
|
|
251
|
+
this.asyncStart.publish(message);
|
|
252
|
+
this.asyncEnd.publish(message);
|
|
253
|
+
return result;
|
|
254
|
+
}
|
|
255
|
+
const resolve = (resolved) => {
|
|
256
|
+
if (!terminalPublished) {
|
|
257
|
+
terminalPublished = true;
|
|
258
|
+
setContextValue(context, "result", resolved);
|
|
259
|
+
this.asyncStart.publish(message);
|
|
260
|
+
this.asyncEnd.publish(message);
|
|
261
|
+
}
|
|
262
|
+
return resolved;
|
|
263
|
+
};
|
|
264
|
+
let rejectionThrown = false;
|
|
265
|
+
let rejectionError;
|
|
266
|
+
const reject = (error) => {
|
|
267
|
+
if (!terminalPublished) {
|
|
268
|
+
terminalPublished = true;
|
|
269
|
+
setContextValue(context, "error", error);
|
|
270
|
+
this.error.publish(message);
|
|
271
|
+
this.asyncStart.publish(message);
|
|
272
|
+
this.asyncEnd.publish(message);
|
|
273
|
+
}
|
|
274
|
+
rejectionThrown = true;
|
|
275
|
+
rejectionError = error;
|
|
276
|
+
throw error;
|
|
277
|
+
};
|
|
278
|
+
let isPlainPromise;
|
|
279
|
+
try {
|
|
280
|
+
isPlainPromise = result instanceof Promise && result.constructor === Promise;
|
|
281
|
+
} catch (error) {
|
|
282
|
+
return finishUnobservedResult(error);
|
|
283
|
+
}
|
|
284
|
+
try {
|
|
285
|
+
if (isPlainPromise) {
|
|
286
|
+
return Reflect.apply(then, result, [resolve, reject]);
|
|
287
|
+
}
|
|
288
|
+
Reflect.apply(then, result, [
|
|
289
|
+
resolve,
|
|
290
|
+
(error) => {
|
|
291
|
+
try {
|
|
292
|
+
reject(error);
|
|
293
|
+
} catch {
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
]);
|
|
297
|
+
} catch (error) {
|
|
298
|
+
if (rejectionThrown && error === rejectionError) {
|
|
299
|
+
return result;
|
|
300
|
+
}
|
|
301
|
+
return finishUnobservedResult(error);
|
|
302
|
+
}
|
|
303
|
+
return result;
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
traceCallback(fn, position = -1, message = {}, thisArg, ...args) {
|
|
307
|
+
if (!this.hasSubscribers) {
|
|
308
|
+
return Reflect.apply(fn, thisArg, args);
|
|
309
|
+
}
|
|
310
|
+
const context = message;
|
|
311
|
+
const callArgs = args.length > 0 ? args : context.arguments ?? args;
|
|
312
|
+
const callback = Array.prototype.at.call(callArgs, position);
|
|
313
|
+
if (typeof callback !== "function") {
|
|
314
|
+
return Reflect.apply(fn, thisArg, args);
|
|
315
|
+
}
|
|
316
|
+
const { asyncStart, asyncEnd, error: errorChannel } = this;
|
|
317
|
+
function wrappedCallback(error, result) {
|
|
318
|
+
if (error) {
|
|
319
|
+
setContextValue(context, "error", error);
|
|
320
|
+
errorChannel.publish(message);
|
|
321
|
+
} else {
|
|
322
|
+
setContextValue(context, "result", result);
|
|
323
|
+
}
|
|
324
|
+
return asyncStart.runStores(message, () => {
|
|
325
|
+
try {
|
|
326
|
+
return Reflect.apply(callback, this, arguments);
|
|
327
|
+
} finally {
|
|
328
|
+
asyncEnd.publish(message);
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
Array.prototype.splice.call(callArgs, position, 1, wrappedCallback);
|
|
333
|
+
return this.start.runStores(message, () => {
|
|
334
|
+
try {
|
|
335
|
+
return Reflect.apply(fn, thisArg, args);
|
|
336
|
+
} catch (error) {
|
|
337
|
+
setContextValue(context, "error", error);
|
|
338
|
+
this.error.publish(message);
|
|
339
|
+
throw error;
|
|
340
|
+
} finally {
|
|
341
|
+
this.end.publish(message);
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
var inertChannel = Object.freeze({
|
|
347
|
+
name: "braintrust:inert",
|
|
348
|
+
hasSubscribers: false,
|
|
349
|
+
subscribe() {
|
|
350
|
+
},
|
|
351
|
+
unsubscribe() {
|
|
352
|
+
return false;
|
|
353
|
+
},
|
|
354
|
+
bindStore() {
|
|
355
|
+
},
|
|
356
|
+
unbindStore() {
|
|
357
|
+
return false;
|
|
358
|
+
},
|
|
359
|
+
publish() {
|
|
360
|
+
},
|
|
361
|
+
runStores(_message, fn, thisArg, ...args) {
|
|
362
|
+
return Reflect.apply(fn, thisArg, args);
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
var inertTracingHook = new TracingHook({
|
|
366
|
+
start: inertChannel,
|
|
367
|
+
end: inertChannel,
|
|
368
|
+
asyncStart: inertChannel,
|
|
369
|
+
asyncEnd: inertChannel,
|
|
370
|
+
error: inertChannel
|
|
371
|
+
});
|
|
372
|
+
function isHookChannel(value) {
|
|
373
|
+
if (typeof value !== "object" && typeof value !== "function" || value === null) {
|
|
374
|
+
return false;
|
|
375
|
+
}
|
|
376
|
+
try {
|
|
377
|
+
const channel = value;
|
|
378
|
+
return typeof channel.hasSubscribers === "boolean" && typeof channel.subscribe === "function" && typeof channel.unsubscribe === "function" && typeof channel.bindStore === "function" && typeof channel.unbindStore === "function" && typeof channel.publish === "function" && typeof channel.runStores === "function";
|
|
379
|
+
} catch {
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
function hasTracingHookShape(value) {
|
|
384
|
+
if (typeof value !== "object" && typeof value !== "function" || value === null) {
|
|
385
|
+
return false;
|
|
386
|
+
}
|
|
387
|
+
try {
|
|
388
|
+
const hook = value;
|
|
389
|
+
return typeof hook.hasSubscribers === "boolean" && typeof hook.subscribe === "function" && typeof hook.unsubscribe === "function" && typeof hook.traceSync === "function" && typeof hook.tracePromise === "function" && typeof hook.traceCallback === "function" && isHookChannel(hook.start) && isHookChannel(hook.end) && isHookChannel(hook.asyncStart) && isHookChannel(hook.asyncEnd) && isHookChannel(hook.error);
|
|
390
|
+
} catch {
|
|
391
|
+
return false;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
function isCompatibleTracingHook(value) {
|
|
395
|
+
try {
|
|
396
|
+
return value[hookBrand] === GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION && hasTracingHookShape(value);
|
|
397
|
+
} catch {
|
|
398
|
+
return false;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
function isCompatibleHookRegistry(value) {
|
|
402
|
+
try {
|
|
403
|
+
return value instanceof Map && value[registryBrand] === GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION;
|
|
404
|
+
} catch {
|
|
405
|
+
return false;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
function getHookRegistry() {
|
|
409
|
+
let descriptor;
|
|
410
|
+
try {
|
|
411
|
+
descriptor = Object.getOwnPropertyDescriptor(
|
|
412
|
+
globalThis,
|
|
413
|
+
GLOBAL_INSTRUMENTATION_HOOKS_KEY
|
|
414
|
+
);
|
|
415
|
+
} catch (error) {
|
|
416
|
+
reportError(error);
|
|
417
|
+
return void 0;
|
|
418
|
+
}
|
|
419
|
+
if (descriptor && "value" in descriptor && isCompatibleHookRegistry(descriptor.value) && (descriptor.configurable || descriptor.enumerable === false)) {
|
|
420
|
+
if (descriptor.configurable || descriptor.writable) {
|
|
421
|
+
try {
|
|
422
|
+
Object.defineProperty(globalThis, GLOBAL_INSTRUMENTATION_HOOKS_KEY, {
|
|
423
|
+
configurable: false,
|
|
424
|
+
enumerable: false,
|
|
425
|
+
value: descriptor.value,
|
|
426
|
+
writable: false
|
|
427
|
+
});
|
|
428
|
+
} catch (error) {
|
|
429
|
+
reportError(error);
|
|
430
|
+
return void 0;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
return descriptor.value;
|
|
434
|
+
}
|
|
435
|
+
if (descriptor && !descriptor.configurable) {
|
|
436
|
+
reportError(new Error("Incompatible global instrumentation hook registry"));
|
|
437
|
+
return void 0;
|
|
438
|
+
}
|
|
439
|
+
const registry = /* @__PURE__ */ new Map();
|
|
440
|
+
try {
|
|
441
|
+
Object.defineProperty(registry, registryBrand, {
|
|
442
|
+
configurable: false,
|
|
443
|
+
enumerable: false,
|
|
444
|
+
value: GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
|
|
445
|
+
writable: false
|
|
446
|
+
});
|
|
447
|
+
} catch (error) {
|
|
448
|
+
reportError(error);
|
|
449
|
+
return void 0;
|
|
450
|
+
}
|
|
451
|
+
try {
|
|
452
|
+
Object.defineProperty(globalThis, GLOBAL_INSTRUMENTATION_HOOKS_KEY, {
|
|
453
|
+
configurable: false,
|
|
454
|
+
enumerable: false,
|
|
455
|
+
value: registry,
|
|
456
|
+
writable: false
|
|
457
|
+
});
|
|
458
|
+
return registry;
|
|
459
|
+
} catch (error) {
|
|
460
|
+
reportError(error);
|
|
461
|
+
return void 0;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
function newGlobalTracingChannel(nameOrChannels) {
|
|
465
|
+
if (typeof nameOrChannels !== "string") {
|
|
466
|
+
return new TracingHook(nameOrChannels);
|
|
467
|
+
}
|
|
468
|
+
const registry = getHookRegistry();
|
|
469
|
+
if (!registry) {
|
|
470
|
+
return inertTracingHook;
|
|
471
|
+
}
|
|
472
|
+
let existing;
|
|
473
|
+
try {
|
|
474
|
+
existing = Map.prototype.get.call(registry, nameOrChannels);
|
|
475
|
+
} catch (error) {
|
|
476
|
+
reportError(error);
|
|
477
|
+
return inertTracingHook;
|
|
478
|
+
}
|
|
479
|
+
if (isCompatibleTracingHook(existing)) {
|
|
480
|
+
return existing;
|
|
481
|
+
}
|
|
482
|
+
if (existing !== void 0) {
|
|
483
|
+
reportError(
|
|
484
|
+
new Error(`Invalid global instrumentation hook: ${nameOrChannels}`)
|
|
485
|
+
);
|
|
486
|
+
try {
|
|
487
|
+
Map.prototype.delete.call(registry, nameOrChannels);
|
|
488
|
+
} catch (error) {
|
|
489
|
+
reportError(error);
|
|
490
|
+
return inertTracingHook;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
const hook = new TracingHook(nameOrChannels);
|
|
494
|
+
try {
|
|
495
|
+
Map.prototype.set.call(registry, nameOrChannels, hook);
|
|
496
|
+
} catch (error) {
|
|
497
|
+
reportError(error);
|
|
498
|
+
return inertTracingHook;
|
|
499
|
+
}
|
|
500
|
+
return hook;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
export {
|
|
504
|
+
GLOBAL_INSTRUMENTATION_HOOKS_KEY,
|
|
505
|
+
GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
|
|
506
|
+
GLOBAL_INSTRUMENTATION_HOOKS_REGISTRY_BRAND,
|
|
507
|
+
GLOBAL_INSTRUMENTATION_HOOK_BRAND,
|
|
508
|
+
newGlobalTracingChannel
|
|
509
|
+
};
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
unplugin
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-6E22MYSW.mjs";
|
|
4
4
|
|
|
5
5
|
// src/auto-instrumentations/bundler/webpack.ts
|
|
6
6
|
function braintrustWebpackPlugin(options = {}) {
|
|
7
|
-
|
|
8
|
-
return unplugin.webpack({
|
|
9
|
-
...pluginOptions,
|
|
10
|
-
browser: useDiagnosticChannelCompatShim
|
|
11
|
-
});
|
|
7
|
+
return unplugin.webpack(options);
|
|
12
8
|
}
|
|
13
9
|
var webpackPlugin = unplugin.webpack;
|
|
14
10
|
|