braintrust 3.26.0 → 3.28.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/dev/dist/index.d.mts +519 -186
- package/dev/dist/index.d.ts +519 -186
- package/dev/dist/index.js +3727 -1526
- package/dev/dist/index.mjs +2815 -614
- package/dist/apply-auto-instrumentation.js +372 -261
- package/dist/apply-auto-instrumentation.mjs +171 -60
- package/dist/auto-instrumentations/bundler/esbuild.cjs +458 -61
- package/dist/auto-instrumentations/bundler/esbuild.mjs +5 -4
- package/dist/auto-instrumentations/bundler/next.cjs +460 -63
- package/dist/auto-instrumentations/bundler/next.mjs +6 -5
- package/dist/auto-instrumentations/bundler/rollup.cjs +458 -61
- package/dist/auto-instrumentations/bundler/rollup.mjs +5 -4
- package/dist/auto-instrumentations/bundler/vite.cjs +487 -62
- package/dist/auto-instrumentations/bundler/vite.mjs +34 -5
- package/dist/auto-instrumentations/bundler/webpack-loader.cjs +444 -61
- package/dist/auto-instrumentations/bundler/webpack.cjs +458 -61
- package/dist/auto-instrumentations/bundler/webpack.mjs +6 -5
- package/dist/auto-instrumentations/{chunk-6E22MYSW.mjs → chunk-26PKVUKB.mjs} +109 -5
- package/dist/auto-instrumentations/{chunk-AKKPLXTP.mjs → chunk-2AMDGD65.mjs} +160 -57
- package/dist/auto-instrumentations/{chunk-V5LEODRX.mjs → chunk-HD35AM3M.mjs} +1 -1
- package/dist/auto-instrumentations/{chunk-XYN63IG5.mjs → chunk-I55G56ZL.mjs} +21 -58
- package/dist/auto-instrumentations/{chunk-NRE4QUQR.mjs → chunk-JPUFNW7X.mjs} +140 -0
- package/dist/auto-instrumentations/{chunk-XZHHE4Y3.mjs → chunk-NP7V4XB2.mjs} +157 -3
- package/dist/auto-instrumentations/hook.mjs +396 -32
- package/dist/auto-instrumentations/index.cjs +298 -2
- package/dist/auto-instrumentations/index.d.mts +5 -1
- package/dist/auto-instrumentations/index.d.ts +5 -1
- package/dist/auto-instrumentations/index.mjs +6 -2
- package/dist/auto-instrumentations/loader/cjs-patch.cjs +105 -57
- package/dist/auto-instrumentations/loader/cjs-patch.mjs +2 -2
- package/dist/auto-instrumentations/loader/esm-hook.mjs +1 -1
- package/dist/browser.d.mts +683 -56
- package/dist/browser.d.ts +683 -56
- package/dist/browser.js +4242 -655
- package/dist/browser.mjs +4242 -655
- package/dist/{chunk-VYNNEKSA.js → chunk-BBE7SNRV.js} +248 -10
- package/dist/{chunk-VRZZQPAA.js → chunk-OBBWQW6K.js} +3351 -1392
- package/dist/{chunk-XIZOM2HO.mjs → chunk-UPFNQCGB.mjs} +2419 -460
- package/dist/{chunk-PN7EWK66.mjs → chunk-ZHUHZWFY.mjs} +241 -3
- package/dist/cli.js +2867 -668
- package/dist/edge-light.d.mts +1 -1
- package/dist/edge-light.d.ts +1 -1
- package/dist/edge-light.js +4242 -655
- package/dist/edge-light.mjs +4242 -655
- package/dist/index.d.mts +1267 -640
- package/dist/index.d.ts +1267 -640
- package/dist/index.js +2107 -630
- package/dist/index.mjs +1649 -172
- package/dist/instrumentation/index.d.mts +198 -6
- package/dist/instrumentation/index.d.ts +198 -6
- package/dist/instrumentation/index.js +2661 -581
- package/dist/instrumentation/index.mjs +2661 -581
- package/dist/vitest-evals-reporter.js +45 -43
- package/dist/vitest-evals-reporter.mjs +5 -3
- package/dist/workerd.d.mts +1 -1
- package/dist/workerd.d.ts +1 -1
- package/dist/workerd.js +4242 -655
- package/dist/workerd.mjs +4242 -655
- package/package.json +2 -3
- package/util/dist/index.d.mts +1545 -100
- package/util/dist/index.d.ts +1545 -100
|
@@ -52,8 +52,10 @@ var GLOBAL_INSTRUMENTATION_HOOKS_KEY = "__braintrust_instrumentation_hooks";
|
|
|
52
52
|
var GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION = 1;
|
|
53
53
|
var GLOBAL_INSTRUMENTATION_HOOKS_REGISTRY_BRAND = "braintrust.global-instrumentation-hooks.registry";
|
|
54
54
|
var GLOBAL_INSTRUMENTATION_HOOK_BRAND = "braintrust.global-instrumentation-hooks.hook";
|
|
55
|
+
var GLOBAL_INVOCATION_HOOK_BRAND = "braintrust.global-instrumentation-hooks.invocation-hook";
|
|
55
56
|
var registryBrand = Symbol.for(GLOBAL_INSTRUMENTATION_HOOKS_REGISTRY_BRAND);
|
|
56
57
|
var hookBrand = Symbol.for(GLOBAL_INSTRUMENTATION_HOOK_BRAND);
|
|
58
|
+
var invocationHookBrand = Symbol.for(GLOBAL_INVOCATION_HOOK_BRAND);
|
|
57
59
|
var errorReporter;
|
|
58
60
|
function reportError(error) {
|
|
59
61
|
try {
|
|
@@ -189,12 +191,69 @@ var traceEvents = [
|
|
|
189
191
|
"asyncEnd",
|
|
190
192
|
"error"
|
|
191
193
|
];
|
|
194
|
+
function traceInvocation(hook, operator, target, thisArg, args, additional, callbackIndex = -1) {
|
|
195
|
+
const context = {
|
|
196
|
+
...additional,
|
|
197
|
+
arguments: args,
|
|
198
|
+
self: thisArg
|
|
199
|
+
};
|
|
200
|
+
const invoke = () => hook.invoke(target, thisArg, args, additional);
|
|
201
|
+
if (operator === "traceCallback") {
|
|
202
|
+
return hook.traceCallback(invoke, callbackIndex, context);
|
|
203
|
+
}
|
|
204
|
+
if (operator === "tracePromise") {
|
|
205
|
+
return hook.tracePromise(invoke, context);
|
|
206
|
+
}
|
|
207
|
+
return hook.traceSync(invoke, context);
|
|
208
|
+
}
|
|
209
|
+
var InvocationHook = class {
|
|
210
|
+
interceptors = [];
|
|
211
|
+
get hasInterceptors() {
|
|
212
|
+
return this.interceptors.length > 0;
|
|
213
|
+
}
|
|
214
|
+
intercept(interceptor) {
|
|
215
|
+
if (typeof interceptor !== "function") {
|
|
216
|
+
throw new TypeError("interceptor must be a function");
|
|
217
|
+
}
|
|
218
|
+
this.interceptors = [...this.interceptors, interceptor];
|
|
219
|
+
let active = true;
|
|
220
|
+
return () => {
|
|
221
|
+
if (!active) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
active = false;
|
|
225
|
+
const index = this.interceptors.indexOf(interceptor);
|
|
226
|
+
if (index !== -1) {
|
|
227
|
+
this.interceptors = [
|
|
228
|
+
...this.interceptors.slice(0, index),
|
|
229
|
+
...this.interceptors.slice(index + 1)
|
|
230
|
+
];
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
invoke(target, thisArg, args, additional) {
|
|
235
|
+
const interceptors = this.interceptors;
|
|
236
|
+
if (interceptors.length === 0) {
|
|
237
|
+
return Reflect.apply(target, thisArg, args);
|
|
238
|
+
}
|
|
239
|
+
let next = target;
|
|
240
|
+
for (let index = interceptors.length - 1; index >= 0; index -= 1) {
|
|
241
|
+
const interceptor = interceptors[index];
|
|
242
|
+
const downstream = next;
|
|
243
|
+
next = function(...nextArgs) {
|
|
244
|
+
return interceptor(downstream, this, nextArgs, additional);
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
return Reflect.apply(next, thisArg, args);
|
|
248
|
+
}
|
|
249
|
+
};
|
|
192
250
|
var TracingHook = class {
|
|
193
251
|
start;
|
|
194
252
|
end;
|
|
195
253
|
asyncStart;
|
|
196
254
|
asyncEnd;
|
|
197
255
|
error;
|
|
256
|
+
invocationHook = new InvocationHook();
|
|
198
257
|
constructor(nameOrChannels) {
|
|
199
258
|
Object.defineProperty(this, hookBrand, {
|
|
200
259
|
configurable: false,
|
|
@@ -202,6 +261,12 @@ var TracingHook = class {
|
|
|
202
261
|
value: GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
|
|
203
262
|
writable: false
|
|
204
263
|
});
|
|
264
|
+
Object.defineProperty(this, invocationHookBrand, {
|
|
265
|
+
configurable: false,
|
|
266
|
+
enumerable: false,
|
|
267
|
+
value: GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
|
|
268
|
+
writable: false
|
|
269
|
+
});
|
|
205
270
|
if (typeof nameOrChannels === "string") {
|
|
206
271
|
this.start = new HookChannel(`tracing:${nameOrChannels}:start`);
|
|
207
272
|
this.end = new HookChannel(`tracing:${nameOrChannels}:end`);
|
|
@@ -219,6 +284,26 @@ var TracingHook = class {
|
|
|
219
284
|
get hasSubscribers() {
|
|
220
285
|
return this.start.hasSubscribers || this.end.hasSubscribers || this.asyncStart.hasSubscribers || this.asyncEnd.hasSubscribers || this.error.hasSubscribers;
|
|
221
286
|
}
|
|
287
|
+
get hasInterceptors() {
|
|
288
|
+
return this.invocationHook.hasInterceptors;
|
|
289
|
+
}
|
|
290
|
+
intercept(interceptor) {
|
|
291
|
+
return this.invocationHook.intercept(interceptor);
|
|
292
|
+
}
|
|
293
|
+
invoke(target, thisArg, args, additional) {
|
|
294
|
+
return this.invocationHook.invoke(target, thisArg, args, additional);
|
|
295
|
+
}
|
|
296
|
+
traceInvocation(operator, target, thisArg, args, additional, callbackIndex = -1) {
|
|
297
|
+
return traceInvocation(
|
|
298
|
+
this,
|
|
299
|
+
operator,
|
|
300
|
+
target,
|
|
301
|
+
thisArg,
|
|
302
|
+
args,
|
|
303
|
+
additional,
|
|
304
|
+
callbackIndex
|
|
305
|
+
);
|
|
306
|
+
}
|
|
222
307
|
subscribe(handlers) {
|
|
223
308
|
for (const eventName of traceEvents) {
|
|
224
309
|
const handler = handlers[eventName];
|
|
@@ -432,8 +517,7 @@ var transforms = {
|
|
|
432
517
|
tracingHookDeclaration(state, node) {
|
|
433
518
|
const {
|
|
434
519
|
channelName,
|
|
435
|
-
module: { name }
|
|
436
|
-
operator
|
|
520
|
+
module: { name }
|
|
437
521
|
} = state;
|
|
438
522
|
const channelVariable = formatChannelVariable(channelName);
|
|
439
523
|
const channelGetter = formatChannelGetter(channelName);
|
|
@@ -446,7 +530,7 @@ var transforms = {
|
|
|
446
530
|
return;
|
|
447
531
|
}
|
|
448
532
|
const sharedHookLookup = hasSharedHookLookup ? "" : `
|
|
449
|
-
const ${SHARED_HOOK_LOOKUP} = (__bt$hookName
|
|
533
|
+
const ${SHARED_HOOK_LOOKUP} = (__bt$hookName) => {
|
|
450
534
|
try {
|
|
451
535
|
const __bt$hooks = globalThis[${JSON.stringify(
|
|
452
536
|
GLOBAL_INSTRUMENTATION_HOOKS_KEY
|
|
@@ -468,8 +552,7 @@ var transforms = {
|
|
|
468
552
|
__bt$hook[Symbol.for(${JSON.stringify(
|
|
469
553
|
GLOBAL_INSTRUMENTATION_HOOK_BRAND
|
|
470
554
|
)})] !== ${GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION} ||
|
|
471
|
-
typeof __bt$hook.
|
|
472
|
-
typeof __bt$hook[__bt$operator] !== "function"
|
|
555
|
+
typeof __bt$hook.traceInvocation !== "function"
|
|
473
556
|
) return undefined;
|
|
474
557
|
return __bt$hook;
|
|
475
558
|
} catch {
|
|
@@ -482,8 +565,7 @@ var transforms = {
|
|
|
482
565
|
let ${channelVariable};
|
|
483
566
|
const ${channelGetter} = () =>
|
|
484
567
|
${channelVariable} ??= ${SHARED_HOOK_LOOKUP}(
|
|
485
|
-
${JSON.stringify(`orchestrion:${name}:${channelName}`)}
|
|
486
|
-
${JSON.stringify(operator)}
|
|
568
|
+
${JSON.stringify(`orchestrion:${name}:${channelName}`)}
|
|
487
569
|
);
|
|
488
570
|
`;
|
|
489
571
|
const sharedHookLookupIndex = node.body.findIndex(
|
|
@@ -558,28 +640,18 @@ function traceInstanceMethod(state, node, program) {
|
|
|
558
640
|
ctor.value.body.body.push(...ctorBody);
|
|
559
641
|
}
|
|
560
642
|
function wrap(state, node) {
|
|
561
|
-
const
|
|
562
|
-
const wrapper = operator === "traceCallback" ? wrapCallback(state) : operator === "tracePromise" ? wrapPromise(state) : wrapSync(state);
|
|
643
|
+
const wrapper = wrapInvocation(state);
|
|
563
644
|
const block = wrapper.body[0].body;
|
|
564
645
|
const common = (0, import_meriyah.parse)(
|
|
565
646
|
node.type === "ArrowFunctionExpression" ? `
|
|
566
|
-
const __bt$
|
|
567
|
-
arguments,
|
|
568
|
-
moduleVersion: ${JSON.stringify(moduleVersion)}
|
|
569
|
-
};
|
|
570
|
-
const __bt$traced = () => {
|
|
647
|
+
const __bt$target = (...__bt$args) => {
|
|
571
648
|
const __bt$wrapped = () => {};
|
|
572
|
-
return __bt$wrapped(...
|
|
649
|
+
return __bt$wrapped(...__bt$args);
|
|
573
650
|
};
|
|
574
651
|
` : `
|
|
575
|
-
const __bt$
|
|
576
|
-
arguments,
|
|
577
|
-
self: this,
|
|
578
|
-
moduleVersion: ${JSON.stringify(moduleVersion)}
|
|
579
|
-
};
|
|
580
|
-
const __bt$traced = () => {
|
|
652
|
+
const __bt$target = function (...__bt$args) {
|
|
581
653
|
const __bt$wrapped = () => {};
|
|
582
|
-
return __bt$wrapped.apply(this,
|
|
654
|
+
return __bt$wrapped.apply(this, __bt$args);
|
|
583
655
|
};
|
|
584
656
|
`
|
|
585
657
|
).body;
|
|
@@ -621,49 +693,25 @@ function wrapSuper(node) {
|
|
|
621
693
|
node.body.body.unshift((0, import_meriyah.parse)("const __bt$super = {}").body[0]);
|
|
622
694
|
}
|
|
623
695
|
}
|
|
624
|
-
function
|
|
625
|
-
const {
|
|
626
|
-
channelName,
|
|
627
|
-
functionQuery: { callbackIndex = -1 }
|
|
628
|
-
} = state;
|
|
696
|
+
function wrapInvocation(state) {
|
|
697
|
+
const { channelName, moduleVersion, operator, functionQuery } = state;
|
|
629
698
|
const channelGetter = formatChannelGetter(channelName);
|
|
699
|
+
const callbackIndex = functionQuery.callbackIndex ?? -1;
|
|
630
700
|
return (0, import_meriyah.parse)(`
|
|
631
701
|
function wrapper () {
|
|
632
702
|
const __bt$hook = ${channelGetter}();
|
|
633
|
-
if (!__bt$hook
|
|
634
|
-
__bt$
|
|
635
|
-
|
|
636
|
-
__bt$
|
|
637
|
-
|
|
638
|
-
|
|
703
|
+
if (!__bt$hook) return __bt$target.apply(this, arguments);
|
|
704
|
+
return __bt$hook.traceInvocation(
|
|
705
|
+
${JSON.stringify(operator)},
|
|
706
|
+
__bt$target,
|
|
707
|
+
this,
|
|
708
|
+
arguments,
|
|
709
|
+
{ moduleVersion: ${JSON.stringify(moduleVersion)} },
|
|
710
|
+
${callbackIndex}
|
|
639
711
|
);
|
|
640
712
|
}
|
|
641
713
|
`);
|
|
642
714
|
}
|
|
643
|
-
function wrapPromise(state) {
|
|
644
|
-
const { channelName } = state;
|
|
645
|
-
const channelGetter = formatChannelGetter(channelName);
|
|
646
|
-
return (0, import_meriyah.parse)(`
|
|
647
|
-
function wrapper () {
|
|
648
|
-
const __bt$hook = ${channelGetter}();
|
|
649
|
-
if (!__bt$hook?.hasSubscribers) return __bt$traced();
|
|
650
|
-
__bt$ctx.self ??= this;
|
|
651
|
-
return __bt$hook.tracePromise(__bt$traced, __bt$ctx);
|
|
652
|
-
}
|
|
653
|
-
`);
|
|
654
|
-
}
|
|
655
|
-
function wrapSync(state) {
|
|
656
|
-
const { channelName } = state;
|
|
657
|
-
const channelGetter = formatChannelGetter(channelName);
|
|
658
|
-
return (0, import_meriyah.parse)(`
|
|
659
|
-
function wrapper () {
|
|
660
|
-
const __bt$hook = ${channelGetter}();
|
|
661
|
-
if (!__bt$hook?.hasSubscribers) return __bt$traced();
|
|
662
|
-
__bt$ctx.self ??= this;
|
|
663
|
-
return __bt$hook.traceSync(__bt$traced, __bt$ctx);
|
|
664
|
-
}
|
|
665
|
-
`);
|
|
666
|
-
}
|
|
667
715
|
|
|
668
716
|
// src/auto-instrumentations/orchestrion-js/transformer.ts
|
|
669
717
|
var Transformer = class {
|