braintrust 3.25.0 → 3.27.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 +130 -2
- package/dev/dist/index.d.ts +130 -2
- package/dev/dist/index.js +4133 -1421
- package/dev/dist/index.mjs +3242 -530
- package/dist/apply-auto-instrumentation.js +526 -426
- package/dist/apply-auto-instrumentation.mjs +329 -229
- package/dist/auto-instrumentations/bundler/esbuild.cjs +1198 -364
- 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 +6 -8
- package/dist/auto-instrumentations/bundler/next.cjs +1227 -413
- package/dist/auto-instrumentations/bundler/next.mjs +7 -29
- package/dist/auto-instrumentations/bundler/rollup.cjs +1198 -364
- 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 +6 -8
- package/dist/auto-instrumentations/bundler/vite.cjs +1249 -387
- 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 +34 -8
- package/dist/auto-instrumentations/bundler/webpack-loader.cjs +1368 -324
- package/dist/auto-instrumentations/bundler/webpack-loader.d.ts +20 -12
- package/dist/auto-instrumentations/bundler/webpack.cjs +1198 -364
- 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 +6 -4
- package/dist/auto-instrumentations/chunk-2AMDGD65.mjs +1396 -0
- package/dist/auto-instrumentations/{chunk-7P6563SW.mjs → chunk-BW33ULMW.mjs} +2 -6
- package/dist/auto-instrumentations/{chunk-M6DLIJ2Z.mjs → chunk-I55G56ZL.mjs} +114 -221
- package/dist/auto-instrumentations/chunk-JPUFNW7X.mjs +649 -0
- package/dist/auto-instrumentations/{chunk-JPVCUKTY.mjs → chunk-XEYKUBLY.mjs} +191 -73
- package/dist/auto-instrumentations/{chunk-CZ24KNHT.mjs → chunk-ZNHTSSGI.mjs} +231 -69
- package/dist/auto-instrumentations/hook.mjs +406 -183
- package/dist/auto-instrumentations/index.cjs +853 -49
- package/dist/auto-instrumentations/index.d.mts +10 -2
- package/dist/auto-instrumentations/index.d.ts +10 -2
- package/dist/auto-instrumentations/index.mjs +10 -1
- package/dist/auto-instrumentations/loader/cjs-patch.cjs +566 -221
- 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 +871 -199
- package/dist/browser.d.ts +871 -199
- package/dist/browser.js +3737 -549
- package/dist/browser.mjs +3737 -549
- package/dist/{chunk-ABR2QWDP.mjs → chunk-CZM5JIQL.mjs} +788 -132
- package/dist/{chunk-P25IOOU4.js → chunk-MF7NU6BT.js} +795 -139
- package/dist/{chunk-GSIDVFE6.js → chunk-QRHGVBKU.js} +3580 -1463
- package/dist/{chunk-2SANLSWX.mjs → chunk-YKD22IMR.mjs} +2505 -388
- package/dist/cli.js +3244 -533
- package/dist/edge-light.d.mts +1 -1
- package/dist/edge-light.d.ts +1 -1
- package/dist/edge-light.js +3737 -552
- package/dist/edge-light.mjs +3737 -552
- package/dist/index.d.mts +871 -199
- package/dist/index.d.ts +871 -199
- package/dist/index.js +893 -446
- package/dist/index.mjs +463 -16
- package/dist/instrumentation/index.d.mts +138 -6
- package/dist/instrumentation/index.d.ts +138 -6
- package/dist/instrumentation/index.js +3362 -559
- package/dist/instrumentation/index.mjs +3362 -559
- 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 +3737 -552
- package/dist/workerd.mjs +3737 -552
- package/licenses/node-diagnostics-channel/LICENSE +19 -0
- package/package.json +34 -35
- package/dist/auto-instrumentations/chunk-VT6DDNKM.mjs +0 -856
- package/dist/auto-instrumentations/plugin-D0KHwSJv.d.mts +0 -44
- package/dist/auto-instrumentations/plugin-G6fgxk1b.d.ts +0 -44
|
@@ -34,52 +34,720 @@ var import_source_map = require("source-map");
|
|
|
34
34
|
// src/auto-instrumentations/orchestrion-js/transforms.ts
|
|
35
35
|
var import_esquery = __toESM(require("esquery"));
|
|
36
36
|
var import_meriyah = require("meriyah");
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
|
|
38
|
+
// src/global-instrumentation-hooks.ts
|
|
39
|
+
var GLOBAL_INSTRUMENTATION_HOOKS_KEY = "__braintrust_instrumentation_hooks";
|
|
40
|
+
var GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION = 1;
|
|
41
|
+
var GLOBAL_INSTRUMENTATION_HOOKS_REGISTRY_BRAND = "braintrust.global-instrumentation-hooks.registry";
|
|
42
|
+
var GLOBAL_INSTRUMENTATION_HOOK_BRAND = "braintrust.global-instrumentation-hooks.hook";
|
|
43
|
+
var GLOBAL_INVOCATION_HOOK_BRAND = "braintrust.global-instrumentation-hooks.invocation-hook";
|
|
44
|
+
var registryBrand = Symbol.for(GLOBAL_INSTRUMENTATION_HOOKS_REGISTRY_BRAND);
|
|
45
|
+
var hookBrand = Symbol.for(GLOBAL_INSTRUMENTATION_HOOK_BRAND);
|
|
46
|
+
var invocationHookBrand = Symbol.for(GLOBAL_INVOCATION_HOOK_BRAND);
|
|
47
|
+
var errorReporter;
|
|
48
|
+
function reportError(error) {
|
|
49
|
+
try {
|
|
50
|
+
errorReporter?.(error);
|
|
51
|
+
} catch {
|
|
52
|
+
}
|
|
41
53
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
54
|
+
function setContextValue(context, key, value) {
|
|
55
|
+
try {
|
|
56
|
+
context[key] = value;
|
|
57
|
+
} catch (error) {
|
|
58
|
+
reportError(error);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function wrapStoreRun(store, message, next, transform) {
|
|
62
|
+
return () => {
|
|
63
|
+
let context;
|
|
64
|
+
try {
|
|
65
|
+
context = transform ? transform(message) : message;
|
|
66
|
+
} catch (error) {
|
|
67
|
+
reportError(error);
|
|
68
|
+
return next();
|
|
69
|
+
}
|
|
70
|
+
let called = false;
|
|
71
|
+
let result;
|
|
72
|
+
let providerError;
|
|
73
|
+
let providerThrew = false;
|
|
74
|
+
const runNext = () => {
|
|
75
|
+
if (called) {
|
|
76
|
+
reportError(
|
|
77
|
+
new Error(
|
|
78
|
+
"Instrumentation store invoked its callback more than once"
|
|
79
|
+
)
|
|
80
|
+
);
|
|
81
|
+
if (providerThrew) {
|
|
82
|
+
throw providerError;
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
called = true;
|
|
87
|
+
try {
|
|
88
|
+
result = next();
|
|
89
|
+
return result;
|
|
90
|
+
} catch (error) {
|
|
91
|
+
providerThrew = true;
|
|
92
|
+
providerError = error;
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
try {
|
|
97
|
+
store.run(context, runNext);
|
|
98
|
+
} catch (error) {
|
|
99
|
+
if (!providerThrew || error !== providerError) {
|
|
100
|
+
reportError(error);
|
|
101
|
+
}
|
|
46
102
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
103
|
+
if (!called) {
|
|
104
|
+
reportError(
|
|
105
|
+
new Error("Instrumentation store did not invoke its callback")
|
|
106
|
+
);
|
|
107
|
+
return runNext();
|
|
108
|
+
}
|
|
109
|
+
if (providerThrew) {
|
|
110
|
+
throw providerError;
|
|
111
|
+
}
|
|
112
|
+
return result;
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
var HookChannel = class {
|
|
116
|
+
constructor(name) {
|
|
117
|
+
this.name = name;
|
|
118
|
+
}
|
|
119
|
+
name;
|
|
120
|
+
subscribers = [];
|
|
121
|
+
stores = /* @__PURE__ */ new Map();
|
|
122
|
+
get hasSubscribers() {
|
|
123
|
+
return this.subscribers.length > 0 || this.stores.size > 0;
|
|
124
|
+
}
|
|
125
|
+
subscribe(subscription) {
|
|
126
|
+
if (typeof subscription !== "function") {
|
|
127
|
+
throw new TypeError("subscription must be a function");
|
|
128
|
+
}
|
|
129
|
+
this.subscribers = [...this.subscribers, subscription];
|
|
130
|
+
}
|
|
131
|
+
unsubscribe(subscription) {
|
|
132
|
+
const index = this.subscribers.indexOf(subscription);
|
|
133
|
+
if (index === -1) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
this.subscribers = [
|
|
137
|
+
...this.subscribers.slice(0, index),
|
|
138
|
+
...this.subscribers.slice(index + 1)
|
|
139
|
+
];
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
bindStore(store, transform) {
|
|
143
|
+
if (!store || typeof store.run !== "function") {
|
|
144
|
+
throw new TypeError("store must have a run method");
|
|
145
|
+
}
|
|
146
|
+
this.stores.set(
|
|
147
|
+
store,
|
|
148
|
+
transform
|
|
50
149
|
);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
150
|
+
}
|
|
151
|
+
unbindStore(store) {
|
|
152
|
+
return this.stores.delete(store);
|
|
153
|
+
}
|
|
154
|
+
publish(message) {
|
|
155
|
+
const subscribers = this.subscribers;
|
|
156
|
+
for (const subscriber of subscribers) {
|
|
157
|
+
try {
|
|
158
|
+
subscriber(message, this.name);
|
|
159
|
+
} catch (error) {
|
|
160
|
+
reportError(error);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
runStores(message, fn, thisArg, ...args) {
|
|
165
|
+
let run = () => {
|
|
166
|
+
this.publish(message);
|
|
167
|
+
return Reflect.apply(fn, thisArg, args);
|
|
168
|
+
};
|
|
169
|
+
for (const [store, transform] of this.stores.entries()) {
|
|
170
|
+
run = wrapStoreRun(store, message, run, transform);
|
|
171
|
+
}
|
|
172
|
+
return run();
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
var traceEvents = [
|
|
176
|
+
"start",
|
|
177
|
+
"end",
|
|
178
|
+
"asyncStart",
|
|
179
|
+
"asyncEnd",
|
|
180
|
+
"error"
|
|
181
|
+
];
|
|
182
|
+
function traceInvocation(hook, operator, target, thisArg, args, additional, callbackIndex = -1) {
|
|
183
|
+
const context = {
|
|
184
|
+
...additional,
|
|
185
|
+
arguments: args,
|
|
186
|
+
self: thisArg
|
|
187
|
+
};
|
|
188
|
+
const invoke = () => hook.invoke(target, thisArg, args, additional);
|
|
189
|
+
if (operator === "traceCallback") {
|
|
190
|
+
return hook.traceCallback(invoke, callbackIndex, context);
|
|
191
|
+
}
|
|
192
|
+
if (operator === "tracePromise") {
|
|
193
|
+
return hook.tracePromise(invoke, context);
|
|
194
|
+
}
|
|
195
|
+
return hook.traceSync(invoke, context);
|
|
196
|
+
}
|
|
197
|
+
var InvocationHook = class {
|
|
198
|
+
interceptors = [];
|
|
199
|
+
get hasInterceptors() {
|
|
200
|
+
return this.interceptors.length > 0;
|
|
201
|
+
}
|
|
202
|
+
intercept(interceptor) {
|
|
203
|
+
if (typeof interceptor !== "function") {
|
|
204
|
+
throw new TypeError("interceptor must be a function");
|
|
205
|
+
}
|
|
206
|
+
this.interceptors = [...this.interceptors, interceptor];
|
|
207
|
+
let active = true;
|
|
208
|
+
return () => {
|
|
209
|
+
if (!active) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
active = false;
|
|
213
|
+
const index = this.interceptors.indexOf(interceptor);
|
|
214
|
+
if (index !== -1) {
|
|
215
|
+
this.interceptors = [
|
|
216
|
+
...this.interceptors.slice(0, index),
|
|
217
|
+
...this.interceptors.slice(index + 1)
|
|
218
|
+
];
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
invoke(target, thisArg, args, additional) {
|
|
223
|
+
const interceptors = this.interceptors;
|
|
224
|
+
if (interceptors.length === 0) {
|
|
225
|
+
return Reflect.apply(target, thisArg, args);
|
|
226
|
+
}
|
|
227
|
+
let next = target;
|
|
228
|
+
for (let index = interceptors.length - 1; index >= 0; index -= 1) {
|
|
229
|
+
const interceptor = interceptors[index];
|
|
230
|
+
const downstream = next;
|
|
231
|
+
next = function(...nextArgs) {
|
|
232
|
+
return interceptor(downstream, this, nextArgs, additional);
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
return Reflect.apply(next, thisArg, args);
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
var TracingHook = class {
|
|
239
|
+
start;
|
|
240
|
+
end;
|
|
241
|
+
asyncStart;
|
|
242
|
+
asyncEnd;
|
|
243
|
+
error;
|
|
244
|
+
invocationHook = new InvocationHook();
|
|
245
|
+
constructor(nameOrChannels) {
|
|
246
|
+
Object.defineProperty(this, hookBrand, {
|
|
247
|
+
configurable: false,
|
|
248
|
+
enumerable: false,
|
|
249
|
+
value: GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
|
|
250
|
+
writable: false
|
|
251
|
+
});
|
|
252
|
+
Object.defineProperty(this, invocationHookBrand, {
|
|
253
|
+
configurable: false,
|
|
254
|
+
enumerable: false,
|
|
255
|
+
value: GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
|
|
256
|
+
writable: false
|
|
257
|
+
});
|
|
258
|
+
if (typeof nameOrChannels === "string") {
|
|
259
|
+
this.start = new HookChannel(`tracing:${nameOrChannels}:start`);
|
|
260
|
+
this.end = new HookChannel(`tracing:${nameOrChannels}:end`);
|
|
261
|
+
this.asyncStart = new HookChannel(`tracing:${nameOrChannels}:asyncStart`);
|
|
262
|
+
this.asyncEnd = new HookChannel(`tracing:${nameOrChannels}:asyncEnd`);
|
|
263
|
+
this.error = new HookChannel(`tracing:${nameOrChannels}:error`);
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
this.start = nameOrChannels.start ?? new HookChannel("tracing:start");
|
|
267
|
+
this.end = nameOrChannels.end ?? new HookChannel("tracing:end");
|
|
268
|
+
this.asyncStart = nameOrChannels.asyncStart ?? new HookChannel("tracing:asyncStart");
|
|
269
|
+
this.asyncEnd = nameOrChannels.asyncEnd ?? new HookChannel("tracing:asyncEnd");
|
|
270
|
+
this.error = nameOrChannels.error ?? new HookChannel("tracing:error");
|
|
271
|
+
}
|
|
272
|
+
get hasSubscribers() {
|
|
273
|
+
return this.start.hasSubscribers || this.end.hasSubscribers || this.asyncStart.hasSubscribers || this.asyncEnd.hasSubscribers || this.error.hasSubscribers;
|
|
274
|
+
}
|
|
275
|
+
get hasInterceptors() {
|
|
276
|
+
return this.invocationHook.hasInterceptors;
|
|
277
|
+
}
|
|
278
|
+
intercept(interceptor) {
|
|
279
|
+
return this.invocationHook.intercept(interceptor);
|
|
280
|
+
}
|
|
281
|
+
invoke(target, thisArg, args, additional) {
|
|
282
|
+
return this.invocationHook.invoke(target, thisArg, args, additional);
|
|
283
|
+
}
|
|
284
|
+
traceInvocation(operator, target, thisArg, args, additional, callbackIndex = -1) {
|
|
285
|
+
return traceInvocation(
|
|
286
|
+
this,
|
|
287
|
+
operator,
|
|
288
|
+
target,
|
|
289
|
+
thisArg,
|
|
290
|
+
args,
|
|
291
|
+
additional,
|
|
292
|
+
callbackIndex
|
|
64
293
|
);
|
|
294
|
+
}
|
|
295
|
+
subscribe(handlers) {
|
|
296
|
+
for (const eventName of traceEvents) {
|
|
297
|
+
const handler = handlers[eventName];
|
|
298
|
+
if (handler) {
|
|
299
|
+
this[eventName].subscribe(handler);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
unsubscribe(handlers) {
|
|
304
|
+
let done = true;
|
|
305
|
+
for (const eventName of traceEvents) {
|
|
306
|
+
const handler = handlers[eventName];
|
|
307
|
+
if (handler && !this[eventName].unsubscribe(handler)) {
|
|
308
|
+
done = false;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return done;
|
|
312
|
+
}
|
|
313
|
+
traceSync(fn, message = {}, thisArg, ...args) {
|
|
314
|
+
if (!this.hasSubscribers) {
|
|
315
|
+
return Reflect.apply(fn, thisArg, args);
|
|
316
|
+
}
|
|
317
|
+
const context = message;
|
|
318
|
+
return this.start.runStores(message, () => {
|
|
319
|
+
try {
|
|
320
|
+
const result = Reflect.apply(fn, thisArg, args);
|
|
321
|
+
setContextValue(context, "result", result);
|
|
322
|
+
return result;
|
|
323
|
+
} catch (error) {
|
|
324
|
+
setContextValue(context, "error", error);
|
|
325
|
+
this.error.publish(message);
|
|
326
|
+
throw error;
|
|
327
|
+
} finally {
|
|
328
|
+
this.end.publish(message);
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
tracePromise(fn, message = {}, thisArg, ...args) {
|
|
333
|
+
if (!this.hasSubscribers) {
|
|
334
|
+
return Reflect.apply(fn, thisArg, args);
|
|
335
|
+
}
|
|
336
|
+
const context = message;
|
|
337
|
+
return this.start.runStores(message, () => {
|
|
338
|
+
let result;
|
|
339
|
+
try {
|
|
340
|
+
result = Reflect.apply(fn, thisArg, args);
|
|
341
|
+
} catch (error) {
|
|
342
|
+
setContextValue(context, "error", error);
|
|
343
|
+
this.error.publish(message);
|
|
344
|
+
this.end.publish(message);
|
|
345
|
+
throw error;
|
|
346
|
+
}
|
|
347
|
+
this.end.publish(message);
|
|
348
|
+
if (!result || typeof result !== "object" && typeof result !== "function") {
|
|
349
|
+
setContextValue(context, "result", result);
|
|
350
|
+
this.asyncStart.publish(message);
|
|
351
|
+
this.asyncEnd.publish(message);
|
|
352
|
+
return result;
|
|
353
|
+
}
|
|
354
|
+
let terminalPublished = false;
|
|
355
|
+
const finishUnobservedResult = (error) => {
|
|
356
|
+
reportError(error);
|
|
357
|
+
if (!terminalPublished) {
|
|
358
|
+
terminalPublished = true;
|
|
359
|
+
setContextValue(context, "result", result);
|
|
360
|
+
this.asyncStart.publish(message);
|
|
361
|
+
this.asyncEnd.publish(message);
|
|
362
|
+
}
|
|
363
|
+
return result;
|
|
364
|
+
};
|
|
365
|
+
let then;
|
|
366
|
+
try {
|
|
367
|
+
then = result.then;
|
|
368
|
+
} catch (error) {
|
|
369
|
+
return finishUnobservedResult(error);
|
|
370
|
+
}
|
|
371
|
+
if (typeof then !== "function") {
|
|
372
|
+
setContextValue(context, "result", result);
|
|
373
|
+
this.asyncStart.publish(message);
|
|
374
|
+
this.asyncEnd.publish(message);
|
|
375
|
+
return result;
|
|
376
|
+
}
|
|
377
|
+
const resolve = (resolved) => {
|
|
378
|
+
if (!terminalPublished) {
|
|
379
|
+
terminalPublished = true;
|
|
380
|
+
setContextValue(context, "result", resolved);
|
|
381
|
+
this.asyncStart.publish(message);
|
|
382
|
+
this.asyncEnd.publish(message);
|
|
383
|
+
}
|
|
384
|
+
return resolved;
|
|
385
|
+
};
|
|
386
|
+
let rejectionThrown = false;
|
|
387
|
+
let rejectionError;
|
|
388
|
+
const reject = (error) => {
|
|
389
|
+
if (!terminalPublished) {
|
|
390
|
+
terminalPublished = true;
|
|
391
|
+
setContextValue(context, "error", error);
|
|
392
|
+
this.error.publish(message);
|
|
393
|
+
this.asyncStart.publish(message);
|
|
394
|
+
this.asyncEnd.publish(message);
|
|
395
|
+
}
|
|
396
|
+
rejectionThrown = true;
|
|
397
|
+
rejectionError = error;
|
|
398
|
+
throw error;
|
|
399
|
+
};
|
|
400
|
+
let isPlainPromise;
|
|
401
|
+
try {
|
|
402
|
+
isPlainPromise = result instanceof Promise && result.constructor === Promise;
|
|
403
|
+
} catch (error) {
|
|
404
|
+
return finishUnobservedResult(error);
|
|
405
|
+
}
|
|
406
|
+
try {
|
|
407
|
+
if (isPlainPromise) {
|
|
408
|
+
return Reflect.apply(then, result, [resolve, reject]);
|
|
409
|
+
}
|
|
410
|
+
Reflect.apply(then, result, [
|
|
411
|
+
resolve,
|
|
412
|
+
(error) => {
|
|
413
|
+
try {
|
|
414
|
+
reject(error);
|
|
415
|
+
} catch {
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
]);
|
|
419
|
+
} catch (error) {
|
|
420
|
+
if (rejectionThrown && error === rejectionError) {
|
|
421
|
+
return result;
|
|
422
|
+
}
|
|
423
|
+
return finishUnobservedResult(error);
|
|
424
|
+
}
|
|
425
|
+
return result;
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
traceCallback(fn, position = -1, message = {}, thisArg, ...args) {
|
|
429
|
+
if (!this.hasSubscribers) {
|
|
430
|
+
return Reflect.apply(fn, thisArg, args);
|
|
431
|
+
}
|
|
432
|
+
const context = message;
|
|
433
|
+
const callArgs = args.length > 0 ? args : context.arguments ?? args;
|
|
434
|
+
const callback = Array.prototype.at.call(callArgs, position);
|
|
435
|
+
if (typeof callback !== "function") {
|
|
436
|
+
return Reflect.apply(fn, thisArg, args);
|
|
437
|
+
}
|
|
438
|
+
const { asyncStart, asyncEnd, error: errorChannel } = this;
|
|
439
|
+
function wrappedCallback(error, result) {
|
|
440
|
+
if (error) {
|
|
441
|
+
setContextValue(context, "error", error);
|
|
442
|
+
errorChannel.publish(message);
|
|
443
|
+
} else {
|
|
444
|
+
setContextValue(context, "result", result);
|
|
445
|
+
}
|
|
446
|
+
return asyncStart.runStores(message, () => {
|
|
447
|
+
try {
|
|
448
|
+
return Reflect.apply(callback, this, arguments);
|
|
449
|
+
} finally {
|
|
450
|
+
asyncEnd.publish(message);
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
Array.prototype.splice.call(callArgs, position, 1, wrappedCallback);
|
|
455
|
+
return this.start.runStores(message, () => {
|
|
456
|
+
try {
|
|
457
|
+
return Reflect.apply(fn, thisArg, args);
|
|
458
|
+
} catch (error) {
|
|
459
|
+
setContextValue(context, "error", error);
|
|
460
|
+
this.error.publish(message);
|
|
461
|
+
throw error;
|
|
462
|
+
} finally {
|
|
463
|
+
this.end.publish(message);
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
var inertChannel = Object.freeze({
|
|
469
|
+
name: "braintrust:inert",
|
|
470
|
+
hasSubscribers: false,
|
|
471
|
+
subscribe() {
|
|
472
|
+
},
|
|
473
|
+
unsubscribe() {
|
|
474
|
+
return false;
|
|
475
|
+
},
|
|
476
|
+
bindStore() {
|
|
477
|
+
},
|
|
478
|
+
unbindStore() {
|
|
479
|
+
return false;
|
|
480
|
+
},
|
|
481
|
+
publish() {
|
|
65
482
|
},
|
|
66
|
-
|
|
483
|
+
runStores(_message, fn, thisArg, ...args) {
|
|
484
|
+
return Reflect.apply(fn, thisArg, args);
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
var inertTracingHook = new TracingHook({
|
|
488
|
+
start: inertChannel,
|
|
489
|
+
end: inertChannel,
|
|
490
|
+
asyncStart: inertChannel,
|
|
491
|
+
asyncEnd: inertChannel,
|
|
492
|
+
error: inertChannel
|
|
493
|
+
});
|
|
494
|
+
function isHookChannel(value) {
|
|
495
|
+
if (typeof value !== "object" && typeof value !== "function" || value === null) {
|
|
496
|
+
return false;
|
|
497
|
+
}
|
|
498
|
+
try {
|
|
499
|
+
const channel2 = value;
|
|
500
|
+
return typeof channel2.hasSubscribers === "boolean" && typeof channel2.subscribe === "function" && typeof channel2.unsubscribe === "function" && typeof channel2.bindStore === "function" && typeof channel2.unbindStore === "function" && typeof channel2.publish === "function" && typeof channel2.runStores === "function";
|
|
501
|
+
} catch {
|
|
502
|
+
return false;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
function hasTracingHookShape(value) {
|
|
506
|
+
if (typeof value !== "object" && typeof value !== "function" || value === null) {
|
|
507
|
+
return false;
|
|
508
|
+
}
|
|
509
|
+
try {
|
|
510
|
+
const hook = value;
|
|
511
|
+
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);
|
|
512
|
+
} catch {
|
|
513
|
+
return false;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
function hasInvocationHookShape(value) {
|
|
517
|
+
if (typeof value !== "object" && typeof value !== "function" || value === null) {
|
|
518
|
+
return false;
|
|
519
|
+
}
|
|
520
|
+
try {
|
|
521
|
+
const hook = value;
|
|
522
|
+
return value[invocationHookBrand] === GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION && typeof hook.hasInterceptors === "boolean" && typeof hook.intercept === "function" && typeof hook.invoke === "function";
|
|
523
|
+
} catch {
|
|
524
|
+
return false;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
function installInvocationHook(value) {
|
|
528
|
+
const hasInvocationHook = hasInvocationHookShape(value);
|
|
529
|
+
const invocationHook = new InvocationHook();
|
|
530
|
+
try {
|
|
531
|
+
if (!hasInvocationHook) {
|
|
532
|
+
Object.defineProperties(value, {
|
|
533
|
+
[invocationHookBrand]: {
|
|
534
|
+
configurable: false,
|
|
535
|
+
enumerable: false,
|
|
536
|
+
value: GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
|
|
537
|
+
writable: false
|
|
538
|
+
},
|
|
539
|
+
hasInterceptors: {
|
|
540
|
+
configurable: false,
|
|
541
|
+
enumerable: false,
|
|
542
|
+
get: () => invocationHook.hasInterceptors
|
|
543
|
+
},
|
|
544
|
+
intercept: {
|
|
545
|
+
configurable: false,
|
|
546
|
+
enumerable: false,
|
|
547
|
+
value: invocationHook.intercept.bind(invocationHook),
|
|
548
|
+
writable: false
|
|
549
|
+
},
|
|
550
|
+
invoke: {
|
|
551
|
+
configurable: false,
|
|
552
|
+
enumerable: false,
|
|
553
|
+
value: invocationHook.invoke.bind(invocationHook),
|
|
554
|
+
writable: false
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
if (typeof value.traceInvocation !== "function") {
|
|
559
|
+
Object.defineProperty(value, "traceInvocation", {
|
|
560
|
+
configurable: false,
|
|
561
|
+
enumerable: false,
|
|
562
|
+
value: traceInvocation.bind(void 0, value),
|
|
563
|
+
writable: false
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
} catch (error) {
|
|
567
|
+
reportError(error);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
function isCompatibleTracingHook(value) {
|
|
571
|
+
try {
|
|
572
|
+
return value[hookBrand] === GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION && hasTracingHookShape(value);
|
|
573
|
+
} catch {
|
|
574
|
+
return false;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
function isCompatibleHookRegistry(value) {
|
|
578
|
+
try {
|
|
579
|
+
return value instanceof Map && value[registryBrand] === GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION;
|
|
580
|
+
} catch {
|
|
581
|
+
return false;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
function getHookRegistry() {
|
|
585
|
+
let descriptor;
|
|
586
|
+
try {
|
|
587
|
+
descriptor = Object.getOwnPropertyDescriptor(
|
|
588
|
+
globalThis,
|
|
589
|
+
GLOBAL_INSTRUMENTATION_HOOKS_KEY
|
|
590
|
+
);
|
|
591
|
+
} catch (error) {
|
|
592
|
+
reportError(error);
|
|
593
|
+
return void 0;
|
|
594
|
+
}
|
|
595
|
+
if (descriptor && "value" in descriptor && isCompatibleHookRegistry(descriptor.value) && (descriptor.configurable || descriptor.enumerable === false)) {
|
|
596
|
+
if (descriptor.configurable || descriptor.writable) {
|
|
597
|
+
try {
|
|
598
|
+
Object.defineProperty(globalThis, GLOBAL_INSTRUMENTATION_HOOKS_KEY, {
|
|
599
|
+
configurable: false,
|
|
600
|
+
enumerable: false,
|
|
601
|
+
value: descriptor.value,
|
|
602
|
+
writable: false
|
|
603
|
+
});
|
|
604
|
+
} catch (error) {
|
|
605
|
+
reportError(error);
|
|
606
|
+
return void 0;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
return descriptor.value;
|
|
610
|
+
}
|
|
611
|
+
if (descriptor && !descriptor.configurable) {
|
|
612
|
+
reportError(new Error("Incompatible global instrumentation hook registry"));
|
|
613
|
+
return void 0;
|
|
614
|
+
}
|
|
615
|
+
const registry = /* @__PURE__ */ new Map();
|
|
616
|
+
try {
|
|
617
|
+
Object.defineProperty(registry, registryBrand, {
|
|
618
|
+
configurable: false,
|
|
619
|
+
enumerable: false,
|
|
620
|
+
value: GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
|
|
621
|
+
writable: false
|
|
622
|
+
});
|
|
623
|
+
} catch (error) {
|
|
624
|
+
reportError(error);
|
|
625
|
+
return void 0;
|
|
626
|
+
}
|
|
627
|
+
try {
|
|
628
|
+
Object.defineProperty(globalThis, GLOBAL_INSTRUMENTATION_HOOKS_KEY, {
|
|
629
|
+
configurable: false,
|
|
630
|
+
enumerable: false,
|
|
631
|
+
value: registry,
|
|
632
|
+
writable: false
|
|
633
|
+
});
|
|
634
|
+
return registry;
|
|
635
|
+
} catch (error) {
|
|
636
|
+
reportError(error);
|
|
637
|
+
return void 0;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
function newGlobalTracingChannel(nameOrChannels) {
|
|
641
|
+
if (typeof nameOrChannels !== "string") {
|
|
642
|
+
return new TracingHook(nameOrChannels);
|
|
643
|
+
}
|
|
644
|
+
const registry = getHookRegistry();
|
|
645
|
+
if (!registry) {
|
|
646
|
+
return inertTracingHook;
|
|
647
|
+
}
|
|
648
|
+
let existing;
|
|
649
|
+
try {
|
|
650
|
+
existing = Map.prototype.get.call(registry, nameOrChannels);
|
|
651
|
+
} catch (error) {
|
|
652
|
+
reportError(error);
|
|
653
|
+
return inertTracingHook;
|
|
654
|
+
}
|
|
655
|
+
if (isCompatibleTracingHook(existing)) {
|
|
656
|
+
installInvocationHook(existing);
|
|
657
|
+
return existing;
|
|
658
|
+
}
|
|
659
|
+
if (existing !== void 0) {
|
|
660
|
+
reportError(
|
|
661
|
+
new Error(`Invalid global instrumentation hook: ${nameOrChannels}`)
|
|
662
|
+
);
|
|
663
|
+
try {
|
|
664
|
+
Map.prototype.delete.call(registry, nameOrChannels);
|
|
665
|
+
} catch (error) {
|
|
666
|
+
reportError(error);
|
|
667
|
+
return inertTracingHook;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
const hook = new TracingHook(nameOrChannels);
|
|
671
|
+
try {
|
|
672
|
+
Map.prototype.set.call(registry, nameOrChannels, hook);
|
|
673
|
+
} catch (error) {
|
|
674
|
+
reportError(error);
|
|
675
|
+
return inertTracingHook;
|
|
676
|
+
}
|
|
677
|
+
return hook;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
// src/auto-instrumentations/orchestrion-js/transforms.ts
|
|
681
|
+
var CHANNEL_REGEX = /[^\w]/g;
|
|
682
|
+
var SHARED_HOOK_LOOKUP = "tr_ch_bt$get_hook";
|
|
683
|
+
function formatChannelVariable(channelName) {
|
|
684
|
+
return `tr_ch_bt$${channelName.replace(CHANNEL_REGEX, "_")}`;
|
|
685
|
+
}
|
|
686
|
+
function formatChannelGetter(channelName) {
|
|
687
|
+
return `tr_ch_bt$get_${channelName.replace(CHANNEL_REGEX, "_")}`;
|
|
688
|
+
}
|
|
689
|
+
var transforms = {
|
|
690
|
+
tracingHookDeclaration(state, node) {
|
|
67
691
|
const {
|
|
68
692
|
channelName,
|
|
69
693
|
module: { name }
|
|
70
694
|
} = state;
|
|
71
695
|
const channelVariable = formatChannelVariable(channelName);
|
|
696
|
+
const channelGetter = formatChannelGetter(channelName);
|
|
697
|
+
const hasSharedHookLookup = node.body.some(
|
|
698
|
+
(child) => child.declarations?.[0]?.id?.name === SHARED_HOOK_LOOKUP
|
|
699
|
+
);
|
|
72
700
|
if (node.body.some(
|
|
73
|
-
(child) => child.declarations?.[0]?.id?.name ===
|
|
701
|
+
(child) => child.declarations?.[0]?.id?.name === channelGetter
|
|
74
702
|
)) {
|
|
75
703
|
return;
|
|
76
704
|
}
|
|
77
|
-
|
|
78
|
-
|
|
705
|
+
const sharedHookLookup = hasSharedHookLookup ? "" : `
|
|
706
|
+
const ${SHARED_HOOK_LOOKUP} = (__bt$hookName) => {
|
|
707
|
+
try {
|
|
708
|
+
const __bt$hooks = globalThis[${JSON.stringify(
|
|
709
|
+
GLOBAL_INSTRUMENTATION_HOOKS_KEY
|
|
710
|
+
)}];
|
|
711
|
+
if (
|
|
712
|
+
!(__bt$hooks instanceof Map) ||
|
|
713
|
+
__bt$hooks[Symbol.for(${JSON.stringify(
|
|
714
|
+
GLOBAL_INSTRUMENTATION_HOOKS_REGISTRY_BRAND
|
|
715
|
+
)})] !== ${GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION}
|
|
716
|
+
) return undefined;
|
|
717
|
+
const __bt$hook = Map.prototype.get.call(
|
|
718
|
+
__bt$hooks,
|
|
719
|
+
__bt$hookName
|
|
720
|
+
);
|
|
721
|
+
if (
|
|
722
|
+
(__bt$hook === null ||
|
|
723
|
+
(typeof __bt$hook !== "object" &&
|
|
724
|
+
typeof __bt$hook !== "function")) ||
|
|
725
|
+
__bt$hook[Symbol.for(${JSON.stringify(
|
|
726
|
+
GLOBAL_INSTRUMENTATION_HOOK_BRAND
|
|
727
|
+
)})] !== ${GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION} ||
|
|
728
|
+
typeof __bt$hook.traceInvocation !== "function"
|
|
729
|
+
) return undefined;
|
|
730
|
+
return __bt$hook;
|
|
731
|
+
} catch {
|
|
732
|
+
return undefined;
|
|
733
|
+
}
|
|
734
|
+
};
|
|
735
|
+
`;
|
|
79
736
|
const code = `
|
|
80
|
-
|
|
737
|
+
${sharedHookLookup}
|
|
738
|
+
let ${channelVariable};
|
|
739
|
+
const ${channelGetter} = () =>
|
|
740
|
+
${channelVariable} ??= ${SHARED_HOOK_LOOKUP}(
|
|
741
|
+
${JSON.stringify(`orchestrion:${name}:${channelName}`)}
|
|
742
|
+
);
|
|
81
743
|
`;
|
|
82
|
-
node.body.
|
|
744
|
+
const sharedHookLookupIndex = node.body.findIndex(
|
|
745
|
+
(child) => child.declarations?.[0]?.id?.name === SHARED_HOOK_LOOKUP
|
|
746
|
+
);
|
|
747
|
+
const index = sharedHookLookupIndex === -1 ? node.body.findIndex(
|
|
748
|
+
(child) => child.directive === "use strict"
|
|
749
|
+
) : sharedHookLookupIndex;
|
|
750
|
+
node.body.splice(index + 1, 0, ...(0, import_meriyah.parse)(code).body);
|
|
83
751
|
},
|
|
84
752
|
traceCallback: traceAny,
|
|
85
753
|
tracePromise: traceAny,
|
|
@@ -94,25 +762,21 @@ function traceAny(state, node, _parent, ancestry) {
|
|
|
94
762
|
}
|
|
95
763
|
}
|
|
96
764
|
function traceFunction(state, node, program) {
|
|
97
|
-
transforms.
|
|
765
|
+
transforms.tracingHookDeclaration(state, program, null, []);
|
|
98
766
|
const { functionQuery } = state;
|
|
99
767
|
const methodName = "methodName" in functionQuery ? functionQuery.methodName : void 0;
|
|
100
768
|
const privateMethodName = "privateMethodName" in functionQuery ? functionQuery.privateMethodName : void 0;
|
|
101
769
|
const functionName = "functionName" in functionQuery ? functionQuery.functionName : void 0;
|
|
102
770
|
const isConstructor = methodName === "constructor" || !methodName && !privateMethodName && !functionName;
|
|
103
771
|
const type = isConstructor ? "ArrowFunctionExpression" : "FunctionExpression";
|
|
104
|
-
node.body = wrap(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
generator: node.generator
|
|
113
|
-
},
|
|
114
|
-
program
|
|
115
|
-
);
|
|
772
|
+
node.body = wrap(state, {
|
|
773
|
+
type,
|
|
774
|
+
params: node.params,
|
|
775
|
+
body: node.body,
|
|
776
|
+
async: node.async,
|
|
777
|
+
expression: false,
|
|
778
|
+
generator: node.generator
|
|
779
|
+
});
|
|
116
780
|
node.generator = false;
|
|
117
781
|
node.async = false;
|
|
118
782
|
wrapSuper(node);
|
|
@@ -124,11 +788,11 @@ function traceInstanceMethod(state, node, program) {
|
|
|
124
788
|
return;
|
|
125
789
|
}
|
|
126
790
|
const classBody = node.body;
|
|
127
|
-
if (classBody.body.some(({ key }) => key
|
|
791
|
+
if (classBody.body.some(({ key }) => key?.name === methodName)) {
|
|
128
792
|
return;
|
|
129
793
|
}
|
|
130
794
|
let ctor = classBody.body.find(({ kind }) => kind === "constructor");
|
|
131
|
-
transforms.
|
|
795
|
+
transforms.tracingHookDeclaration(state, program, null, []);
|
|
132
796
|
if (!ctor) {
|
|
133
797
|
ctor = (0, import_meriyah.parse)(
|
|
134
798
|
node.superClass ? "class A extends Object { constructor (...args) { super(...args) } }" : "class A { constructor () {} }"
|
|
@@ -136,47 +800,36 @@ function traceInstanceMethod(state, node, program) {
|
|
|
136
800
|
classBody.body.unshift(ctor);
|
|
137
801
|
}
|
|
138
802
|
const ctorBody = (0, import_meriyah.parse)(`
|
|
139
|
-
const
|
|
803
|
+
const __bt$${methodName} = this["${methodName}"]
|
|
140
804
|
this["${methodName}"] = function () {}
|
|
141
805
|
`).body;
|
|
142
806
|
const fn = ctorBody[1].expression.right;
|
|
143
807
|
fn.async = operator === "tracePromise";
|
|
144
|
-
fn.body = wrap(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
);
|
|
808
|
+
fn.body = wrap(state, {
|
|
809
|
+
type: "Identifier",
|
|
810
|
+
name: `__bt$${methodName}`
|
|
811
|
+
});
|
|
149
812
|
wrapSuper(fn);
|
|
150
813
|
ctor.value.body.body.push(...ctorBody);
|
|
151
814
|
}
|
|
152
|
-
function wrap(state, node
|
|
153
|
-
const
|
|
154
|
-
const wrapper = operator === "traceCallback" ? wrapCallback(state) : operator === "tracePromise" ? wrapPromise(state) : wrapSync(state);
|
|
815
|
+
function wrap(state, node) {
|
|
816
|
+
const wrapper = wrapInvocation(state);
|
|
155
817
|
const block = wrapper.body[0].body;
|
|
156
818
|
const common = (0, import_meriyah.parse)(
|
|
157
819
|
node.type === "ArrowFunctionExpression" ? `
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
};
|
|
162
|
-
const __apm$traced = () => {
|
|
163
|
-
const __apm$wrapped = () => {};
|
|
164
|
-
return __apm$wrapped(...arguments);
|
|
820
|
+
const __bt$target = (...__bt$args) => {
|
|
821
|
+
const __bt$wrapped = () => {};
|
|
822
|
+
return __bt$wrapped(...__bt$args);
|
|
165
823
|
};
|
|
166
824
|
` : `
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
moduleVersion: ${JSON.stringify(moduleVersion)}
|
|
171
|
-
};
|
|
172
|
-
const __apm$traced = () => {
|
|
173
|
-
const __apm$wrapped = () => {};
|
|
174
|
-
return __apm$wrapped.apply(this, arguments);
|
|
825
|
+
const __bt$target = function (...__bt$args) {
|
|
826
|
+
const __bt$wrapped = () => {};
|
|
827
|
+
return __bt$wrapped.apply(this, __bt$args);
|
|
175
828
|
};
|
|
176
829
|
`
|
|
177
830
|
).body;
|
|
178
831
|
block.body.unshift(...common);
|
|
179
|
-
import_esquery.default.query(block, "[id.name=
|
|
832
|
+
import_esquery.default.query(block, "[id.name=__bt$wrapped]")[0].init = node;
|
|
180
833
|
return block;
|
|
181
834
|
}
|
|
182
835
|
function wrapSuper(node) {
|
|
@@ -188,11 +841,11 @@ function wrapSuper(node) {
|
|
|
188
841
|
const { name } = node2.property;
|
|
189
842
|
let child;
|
|
190
843
|
if (parent.callee) {
|
|
191
|
-
const { expression } = (0, import_meriyah.parse)(`
|
|
844
|
+
const { expression } = (0, import_meriyah.parse)(`__bt$super['${name}'].call(this)`).body[0];
|
|
192
845
|
parent.callee = child = expression.callee;
|
|
193
846
|
parent.arguments.unshift(...expression.arguments);
|
|
194
847
|
} else {
|
|
195
|
-
parent.expression = child = (0, import_meriyah.parse)(`
|
|
848
|
+
parent.expression = child = (0, import_meriyah.parse)(`__bt$super['${name}']`).body[0];
|
|
196
849
|
}
|
|
197
850
|
child.computed = parent.callee.computed;
|
|
198
851
|
child.optional = parent.callee.optional;
|
|
@@ -203,151 +856,32 @@ function wrapSuper(node) {
|
|
|
203
856
|
const member = (0, import_meriyah.parse)(`
|
|
204
857
|
class Wrapper {
|
|
205
858
|
wrapper () {
|
|
206
|
-
|
|
859
|
+
__bt$super['${name}'] = super['${name}']
|
|
207
860
|
}
|
|
208
861
|
}
|
|
209
862
|
`).body[0].body.body[0].value.body.body[0];
|
|
210
863
|
node.body.body.unshift(member);
|
|
211
864
|
}
|
|
212
865
|
if (members.size > 0) {
|
|
213
|
-
node.body.body.unshift((0, import_meriyah.parse)("const
|
|
866
|
+
node.body.body.unshift((0, import_meriyah.parse)("const __bt$super = {}").body[0]);
|
|
214
867
|
}
|
|
215
868
|
}
|
|
216
|
-
function
|
|
217
|
-
const {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
} = state;
|
|
221
|
-
const channelVariable = formatChannelVariable(channelName);
|
|
869
|
+
function wrapInvocation(state) {
|
|
870
|
+
const { channelName, moduleVersion, operator, functionQuery } = state;
|
|
871
|
+
const channelGetter = formatChannelGetter(channelName);
|
|
872
|
+
const callbackIndex = functionQuery.callbackIndex ?? -1;
|
|
222
873
|
return (0, import_meriyah.parse)(`
|
|
223
874
|
function wrapper () {
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
${channelVariable}.asyncStart.runStores(__apm$ctx, () => {
|
|
237
|
-
try {
|
|
238
|
-
if (__apm$cb) {
|
|
239
|
-
return __apm$cb.apply(this, arguments);
|
|
240
|
-
}
|
|
241
|
-
} finally {
|
|
242
|
-
${channelVariable}.asyncEnd.publish(__apm$ctx);
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (typeof __apm$cb !== 'function') {
|
|
248
|
-
return __apm$traced();
|
|
249
|
-
}
|
|
250
|
-
Array.prototype.splice.call(arguments, ${callbackIndex}, 1, __apm$wrappedCb);
|
|
251
|
-
|
|
252
|
-
return ${channelVariable}.start.runStores(__apm$ctx, () => {
|
|
253
|
-
try {
|
|
254
|
-
return __apm$traced();
|
|
255
|
-
} catch (err) {
|
|
256
|
-
__apm$ctx.error = err;
|
|
257
|
-
${channelVariable}.error.publish(__apm$ctx);
|
|
258
|
-
throw err;
|
|
259
|
-
} finally {
|
|
260
|
-
__apm$ctx.self ??= this;
|
|
261
|
-
${channelVariable}.end.publish(__apm$ctx);
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
`);
|
|
266
|
-
}
|
|
267
|
-
function wrapPromise(state) {
|
|
268
|
-
const { channelName } = state;
|
|
269
|
-
const channelVariable = formatChannelVariable(channelName);
|
|
270
|
-
return (0, import_meriyah.parse)(`
|
|
271
|
-
function wrapper () {
|
|
272
|
-
if (!tr_ch_apm_hasSubscribers(${channelVariable})) return __apm$traced();
|
|
273
|
-
|
|
274
|
-
return ${channelVariable}.start.runStores(__apm$ctx, () => {
|
|
275
|
-
try {
|
|
276
|
-
let promise = __apm$traced();
|
|
277
|
-
if (typeof promise?.then !== 'function') {
|
|
278
|
-
__apm$ctx.result = promise;
|
|
279
|
-
return promise;
|
|
280
|
-
}
|
|
281
|
-
// Mirror Node.js core diagnostics_channel behaviour: for native Promise
|
|
282
|
-
// instances, chain normally (safe since there is no subclass API to
|
|
283
|
-
// preserve). For Promise subclasses and other thenables, side-chain the
|
|
284
|
-
// callbacks for event publishing and return the original so that any
|
|
285
|
-
// subclass-specific methods (e.g. APIPromise.withResponse()) remain
|
|
286
|
-
// accessible to the caller.
|
|
287
|
-
if (promise instanceof Promise && promise.constructor === Promise) {
|
|
288
|
-
return promise.then(
|
|
289
|
-
result => {
|
|
290
|
-
__apm$ctx.result = result;
|
|
291
|
-
${channelVariable}.asyncStart.publish(__apm$ctx);
|
|
292
|
-
${channelVariable}.asyncEnd.publish(__apm$ctx);
|
|
293
|
-
return result;
|
|
294
|
-
},
|
|
295
|
-
err => {
|
|
296
|
-
__apm$ctx.error = err;
|
|
297
|
-
${channelVariable}.error.publish(__apm$ctx);
|
|
298
|
-
${channelVariable}.asyncStart.publish(__apm$ctx);
|
|
299
|
-
${channelVariable}.asyncEnd.publish(__apm$ctx);
|
|
300
|
-
throw err;
|
|
301
|
-
}
|
|
302
|
-
);
|
|
303
|
-
}
|
|
304
|
-
promise.then(
|
|
305
|
-
result => {
|
|
306
|
-
__apm$ctx.result = result;
|
|
307
|
-
${channelVariable}.asyncStart.publish(__apm$ctx);
|
|
308
|
-
${channelVariable}.asyncEnd.publish(__apm$ctx);
|
|
309
|
-
},
|
|
310
|
-
err => {
|
|
311
|
-
__apm$ctx.error = err;
|
|
312
|
-
${channelVariable}.error.publish(__apm$ctx);
|
|
313
|
-
${channelVariable}.asyncStart.publish(__apm$ctx);
|
|
314
|
-
${channelVariable}.asyncEnd.publish(__apm$ctx);
|
|
315
|
-
}
|
|
316
|
-
);
|
|
317
|
-
return promise;
|
|
318
|
-
} catch (err) {
|
|
319
|
-
__apm$ctx.error = err;
|
|
320
|
-
${channelVariable}.error.publish(__apm$ctx);
|
|
321
|
-
throw err;
|
|
322
|
-
} finally {
|
|
323
|
-
__apm$ctx.self ??= this;
|
|
324
|
-
${channelVariable}.end.publish(__apm$ctx);
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
`);
|
|
329
|
-
}
|
|
330
|
-
function wrapSync(state) {
|
|
331
|
-
const { channelName } = state;
|
|
332
|
-
const channelVariable = formatChannelVariable(channelName);
|
|
333
|
-
return (0, import_meriyah.parse)(`
|
|
334
|
-
function wrapper () {
|
|
335
|
-
if (!tr_ch_apm_hasSubscribers(${channelVariable})) return __apm$traced();
|
|
336
|
-
|
|
337
|
-
return ${channelVariable}.start.runStores(__apm$ctx, () => {
|
|
338
|
-
try {
|
|
339
|
-
const result = __apm$traced();
|
|
340
|
-
__apm$ctx.result = result;
|
|
341
|
-
return result;
|
|
342
|
-
} catch (err) {
|
|
343
|
-
__apm$ctx.error = err;
|
|
344
|
-
${channelVariable}.error.publish(__apm$ctx);
|
|
345
|
-
throw err;
|
|
346
|
-
} finally {
|
|
347
|
-
__apm$ctx.self ??= this;
|
|
348
|
-
${channelVariable}.end.publish(__apm$ctx);
|
|
349
|
-
}
|
|
350
|
-
});
|
|
875
|
+
const __bt$hook = ${channelGetter}();
|
|
876
|
+
if (!__bt$hook) return __bt$target.apply(this, arguments);
|
|
877
|
+
return __bt$hook.traceInvocation(
|
|
878
|
+
${JSON.stringify(operator)},
|
|
879
|
+
__bt$target,
|
|
880
|
+
this,
|
|
881
|
+
arguments,
|
|
882
|
+
{ moduleVersion: ${JSON.stringify(moduleVersion)} },
|
|
883
|
+
${callbackIndex}
|
|
884
|
+
);
|
|
351
885
|
}
|
|
352
886
|
`);
|
|
353
887
|
}
|
|
@@ -358,16 +892,14 @@ var Transformer = class {
|
|
|
358
892
|
version;
|
|
359
893
|
filePath;
|
|
360
894
|
configs = [];
|
|
361
|
-
|
|
362
|
-
constructor(moduleName, version, filePath, configs, dcModule) {
|
|
895
|
+
constructor(moduleName, version, filePath, configs) {
|
|
363
896
|
this.moduleName = moduleName;
|
|
364
897
|
this.version = version;
|
|
365
898
|
this.filePath = filePath;
|
|
366
899
|
this.configs = configs;
|
|
367
|
-
this.dcModule = dcModule;
|
|
368
900
|
}
|
|
369
901
|
/**
|
|
370
|
-
* Instruments `code` by injecting
|
|
902
|
+
* Instruments `code` by injecting global tracing hooks around the
|
|
371
903
|
* target functions defined by this transformer's configs.
|
|
372
904
|
*/
|
|
373
905
|
transform(code, moduleType) {
|
|
@@ -405,8 +937,6 @@ var Transformer = class {
|
|
|
405
937
|
const query = astQuery || this.fromFunctionQuery(resolvedFunctionQuery);
|
|
406
938
|
const state = {
|
|
407
939
|
...config,
|
|
408
|
-
dcModule: this.dcModule,
|
|
409
|
-
moduleType,
|
|
410
940
|
moduleVersion: this.version,
|
|
411
941
|
functionQuery: resolvedFunctionQuery,
|
|
412
942
|
operator: this.getOperator(resolvedFunctionQuery.kind)
|
|
@@ -556,11 +1086,9 @@ var Transformer = class {
|
|
|
556
1086
|
// src/auto-instrumentations/orchestrion-js/matcher.ts
|
|
557
1087
|
var InstrumentationMatcher = class {
|
|
558
1088
|
configs = [];
|
|
559
|
-
dcModule;
|
|
560
1089
|
transformers = {};
|
|
561
|
-
constructor(configs
|
|
1090
|
+
constructor(configs) {
|
|
562
1091
|
this.configs = configs;
|
|
563
|
-
this.dcModule = dcModule || "diagnostics_channel";
|
|
564
1092
|
}
|
|
565
1093
|
/**
|
|
566
1094
|
* Returns a Transformer for the given module/file/version, or undefined if no
|
|
@@ -582,8 +1110,7 @@ var InstrumentationMatcher = class {
|
|
|
582
1110
|
moduleName,
|
|
583
1111
|
version,
|
|
584
1112
|
filePath,
|
|
585
|
-
configs
|
|
586
|
-
this.dcModule
|
|
1113
|
+
configs
|
|
587
1114
|
);
|
|
588
1115
|
return this.transformers[id];
|
|
589
1116
|
}
|
|
@@ -593,8 +1120,8 @@ var InstrumentationMatcher = class {
|
|
|
593
1120
|
};
|
|
594
1121
|
|
|
595
1122
|
// src/auto-instrumentations/orchestrion-js/index.ts
|
|
596
|
-
function create(configs
|
|
597
|
-
return new InstrumentationMatcher(configs
|
|
1123
|
+
function create(configs) {
|
|
1124
|
+
return new InstrumentationMatcher(configs);
|
|
598
1125
|
}
|
|
599
1126
|
|
|
600
1127
|
// src/auto-instrumentations/bundler/webpack-loader.ts
|
|
@@ -619,6 +1146,9 @@ var envIntegrationAliases = {
|
|
|
619
1146
|
strandsagentsdk: "strandsAgentSDK",
|
|
620
1147
|
"strands-agent-sdk": "strandsAgentSDK",
|
|
621
1148
|
"@strands-agents/sdk": "strandsAgentSDK",
|
|
1149
|
+
agents: "cloudflareAgents",
|
|
1150
|
+
"cloudflare-agents": "cloudflareAgents",
|
|
1151
|
+
cloudflareagents: "cloudflareAgents",
|
|
622
1152
|
anthropic: "anthropic",
|
|
623
1153
|
aisdk: "aisdk",
|
|
624
1154
|
"ai-sdk": "aisdk",
|
|
@@ -626,6 +1156,10 @@ var envIntegrationAliases = {
|
|
|
626
1156
|
vercel: "vercel",
|
|
627
1157
|
claudeagentsdk: "claudeAgentSDK",
|
|
628
1158
|
"claude-agent-sdk": "claudeAgentSDK",
|
|
1159
|
+
cloudflareaichat: "cloudflareAIChat",
|
|
1160
|
+
"cloudflare-ai-chat": "cloudflareAIChat",
|
|
1161
|
+
"@cloudflare/ai-chat": "cloudflareAIChat",
|
|
1162
|
+
cloudflarethink: "cloudflareThink",
|
|
629
1163
|
cursor: "cursor",
|
|
630
1164
|
"cursor-sdk": "cursorSDK",
|
|
631
1165
|
cursorsdk: "cursorSDK",
|
|
@@ -640,10 +1174,13 @@ var envIntegrationAliases = {
|
|
|
640
1174
|
"google-genai": "googleGenAI",
|
|
641
1175
|
googlegenai: "googleGenAI",
|
|
642
1176
|
huggingface: "huggingface",
|
|
1177
|
+
"@huggingface/transformers": "huggingface",
|
|
1178
|
+
transformers: "huggingface",
|
|
643
1179
|
openrouter: "openrouter",
|
|
644
1180
|
openrouteragent: "openrouterAgent",
|
|
645
1181
|
"openrouter-agent": "openrouterAgent",
|
|
646
1182
|
mistral: "mistral",
|
|
1183
|
+
ollama: "ollama",
|
|
647
1184
|
googleadk: "googleADK",
|
|
648
1185
|
"google-adk": "googleADK",
|
|
649
1186
|
cohere: "cohere",
|
|
@@ -660,107 +1197,40 @@ var envIntegrationAliases = {
|
|
|
660
1197
|
githubcopilot: "gitHubCopilot",
|
|
661
1198
|
"github-copilot": "gitHubCopilot",
|
|
662
1199
|
"copilot-sdk": "gitHubCopilot",
|
|
663
|
-
langchain: "langchain",
|
|
664
|
-
"langchain-js": "langchain",
|
|
665
|
-
"@langchain": "langchain",
|
|
666
|
-
langgraph: "langgraph",
|
|
667
|
-
langsmith: "langsmith"
|
|
668
|
-
};
|
|
669
|
-
function readDisabledInstrumentationEnvConfig(disabledList) {
|
|
670
|
-
const integrations = {};
|
|
671
|
-
if (disabledList) {
|
|
672
|
-
for (const value of disabledList.split(",")) {
|
|
673
|
-
const rawSdk = value.trim();
|
|
674
|
-
const sdk = rawSdk.toLowerCase();
|
|
675
|
-
if (sdk.length > 0) {
|
|
676
|
-
integrations[envIntegrationAliases[rawSdk] ?? envIntegrationAliases[sdk] ?? sdk] = false;
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
return { integrations };
|
|
681
|
-
}
|
|
682
|
-
function isInstrumentationIntegrationDisabled(integrations, ...names) {
|
|
683
|
-
return names.some((name) => integrations?.[name] === false);
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
// src/isomorph.ts
|
|
687
|
-
var DefaultAsyncLocalStorage = class {
|
|
688
|
-
constructor() {
|
|
689
|
-
}
|
|
690
|
-
enterWith(_) {
|
|
691
|
-
}
|
|
692
|
-
run(_, callback) {
|
|
693
|
-
return callback();
|
|
694
|
-
}
|
|
695
|
-
getStore() {
|
|
696
|
-
return void 0;
|
|
697
|
-
}
|
|
698
|
-
};
|
|
699
|
-
var DefaultChannel = class {
|
|
700
|
-
constructor(name) {
|
|
701
|
-
this.name = name;
|
|
702
|
-
}
|
|
703
|
-
name;
|
|
704
|
-
hasSubscribers = false;
|
|
705
|
-
subscribe(_subscription) {
|
|
706
|
-
}
|
|
707
|
-
unsubscribe(_subscription) {
|
|
708
|
-
return false;
|
|
709
|
-
}
|
|
710
|
-
bindStore(_store, _transform) {
|
|
711
|
-
}
|
|
712
|
-
unbindStore(_store) {
|
|
713
|
-
return false;
|
|
714
|
-
}
|
|
715
|
-
publish(_message) {
|
|
716
|
-
}
|
|
717
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
718
|
-
runStores(_message, fn, thisArg, ...args) {
|
|
719
|
-
return fn.apply(thisArg, args);
|
|
720
|
-
}
|
|
721
|
-
};
|
|
722
|
-
var DefaultTracingChannel = class {
|
|
723
|
-
start;
|
|
724
|
-
end;
|
|
725
|
-
asyncStart;
|
|
726
|
-
asyncEnd;
|
|
727
|
-
error;
|
|
728
|
-
constructor(nameOrChannels) {
|
|
729
|
-
if (typeof nameOrChannels === "string") {
|
|
730
|
-
this.start = new DefaultChannel(`tracing:${nameOrChannels}:start`);
|
|
731
|
-
this.end = new DefaultChannel(`tracing:${nameOrChannels}:end`);
|
|
732
|
-
this.asyncStart = new DefaultChannel(
|
|
733
|
-
`tracing:${nameOrChannels}:asyncStart`
|
|
734
|
-
);
|
|
735
|
-
this.asyncEnd = new DefaultChannel(`tracing:${nameOrChannels}:asyncEnd`);
|
|
736
|
-
this.error = new DefaultChannel(`tracing:${nameOrChannels}:error`);
|
|
737
|
-
return;
|
|
1200
|
+
langchain: "langchain",
|
|
1201
|
+
"langchain-js": "langchain",
|
|
1202
|
+
"@langchain": "langchain",
|
|
1203
|
+
langgraph: "langgraph",
|
|
1204
|
+
langsmith: "langsmith"
|
|
1205
|
+
};
|
|
1206
|
+
function readDisabledInstrumentationEnvConfig(disabledList) {
|
|
1207
|
+
const integrations = {};
|
|
1208
|
+
if (disabledList) {
|
|
1209
|
+
for (const value of disabledList.split(",")) {
|
|
1210
|
+
const rawSdk = value.trim();
|
|
1211
|
+
const sdk = rawSdk.toLowerCase();
|
|
1212
|
+
if (sdk.length > 0) {
|
|
1213
|
+
integrations[envIntegrationAliases[rawSdk] ?? envIntegrationAliases[sdk] ?? sdk] = false;
|
|
1214
|
+
}
|
|
738
1215
|
}
|
|
739
|
-
this.start = nameOrChannels.start ?? new DefaultChannel("tracing:start");
|
|
740
|
-
this.end = nameOrChannels.end ?? new DefaultChannel("tracing:end");
|
|
741
|
-
this.asyncStart = nameOrChannels.asyncStart ?? new DefaultChannel("tracing:asyncStart");
|
|
742
|
-
this.asyncEnd = nameOrChannels.asyncEnd ?? new DefaultChannel("tracing:asyncEnd");
|
|
743
|
-
this.error = nameOrChannels.error ?? new DefaultChannel("tracing:error");
|
|
744
|
-
}
|
|
745
|
-
get hasSubscribers() {
|
|
746
|
-
return this.start.hasSubscribers || this.end.hasSubscribers || this.asyncStart.hasSubscribers || this.asyncEnd.hasSubscribers || this.error.hasSubscribers;
|
|
747
1216
|
}
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
1217
|
+
return { integrations };
|
|
1218
|
+
}
|
|
1219
|
+
function isInstrumentationIntegrationDisabled(integrations, ...names) {
|
|
1220
|
+
return names.some((name) => integrations?.[name] === false);
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
// src/isomorph.ts
|
|
1224
|
+
var DefaultAsyncLocalStorage = class {
|
|
1225
|
+
constructor() {
|
|
752
1226
|
}
|
|
753
|
-
|
|
754
|
-
traceSync(fn, _message, thisArg, ...args) {
|
|
755
|
-
return fn.apply(thisArg, args);
|
|
1227
|
+
enterWith(_) {
|
|
756
1228
|
}
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
return fn.apply(thisArg, args);
|
|
1229
|
+
run(_, callback) {
|
|
1230
|
+
return callback();
|
|
760
1231
|
}
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
return fn.apply(thisArg, args);
|
|
1232
|
+
getStore() {
|
|
1233
|
+
return void 0;
|
|
764
1234
|
}
|
|
765
1235
|
};
|
|
766
1236
|
var iso = {
|
|
@@ -773,7 +1243,7 @@ var iso = {
|
|
|
773
1243
|
getCallerLocation: () => void 0,
|
|
774
1244
|
newAsyncLocalStorage: () => new DefaultAsyncLocalStorage(),
|
|
775
1245
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
776
|
-
newTracingChannel: (nameOrChannels) =>
|
|
1246
|
+
newTracingChannel: (nameOrChannels) => newGlobalTracingChannel(nameOrChannels),
|
|
777
1247
|
processOn: (_0, _1) => {
|
|
778
1248
|
},
|
|
779
1249
|
basename: (filepath) => filepath.split(/[\\/]/).pop() || filepath,
|
|
@@ -796,11 +1266,21 @@ function defineChannels(pkg, channels, options) {
|
|
|
796
1266
|
const tracingChannel2 = () => isomorph_default.newTracingChannel(
|
|
797
1267
|
fullChannelName
|
|
798
1268
|
);
|
|
1269
|
+
const intercept2 = (interceptor) => {
|
|
1270
|
+
const hook = tracingChannel2();
|
|
1271
|
+
return typeof hook.intercept === "function" ? hook.intercept(interceptor) : () => {
|
|
1272
|
+
};
|
|
1273
|
+
};
|
|
799
1274
|
return [
|
|
800
1275
|
key,
|
|
801
1276
|
{
|
|
802
1277
|
...asyncSpec,
|
|
803
1278
|
instrumentationName,
|
|
1279
|
+
intercept: intercept2,
|
|
1280
|
+
invoke: (target, thisArg, args, additional) => {
|
|
1281
|
+
const hook = tracingChannel2();
|
|
1282
|
+
return typeof hook.invoke === "function" ? hook.invoke(target, thisArg, args, additional) : Reflect.apply(target, thisArg, args);
|
|
1283
|
+
},
|
|
804
1284
|
tracingChannel: tracingChannel2,
|
|
805
1285
|
tracePromise: (fn, context) => tracingChannel2().tracePromise(
|
|
806
1286
|
fn,
|
|
@@ -814,11 +1294,21 @@ function defineChannels(pkg, channels, options) {
|
|
|
814
1294
|
const tracingChannel = () => isomorph_default.newTracingChannel(
|
|
815
1295
|
fullChannelName
|
|
816
1296
|
);
|
|
1297
|
+
const intercept = (interceptor) => {
|
|
1298
|
+
const hook = tracingChannel();
|
|
1299
|
+
return typeof hook.intercept === "function" ? hook.intercept(interceptor) : () => {
|
|
1300
|
+
};
|
|
1301
|
+
};
|
|
817
1302
|
return [
|
|
818
1303
|
key,
|
|
819
1304
|
{
|
|
820
1305
|
...syncSpec,
|
|
821
1306
|
instrumentationName,
|
|
1307
|
+
intercept,
|
|
1308
|
+
invoke: (target, thisArg, args, additional) => {
|
|
1309
|
+
const hook = tracingChannel();
|
|
1310
|
+
return typeof hook.invoke === "function" ? hook.invoke(target, thisArg, args, additional) : Reflect.apply(target, thisArg, args);
|
|
1311
|
+
},
|
|
822
1312
|
tracingChannel,
|
|
823
1313
|
traceSync: (fn, context) => tracingChannel().traceSync(
|
|
824
1314
|
fn,
|
|
@@ -838,6 +1328,9 @@ var INSTRUMENTATION_NAMES = {
|
|
|
838
1328
|
BEDROCK_RUNTIME: "bedrock-runtime",
|
|
839
1329
|
BRAINTRUST_JS_LOGGER: "braintrust-js-logger",
|
|
840
1330
|
CLAUDE_AGENT_SDK: "claude-agent-sdk",
|
|
1331
|
+
CLOUDFLARE_AI_CHAT: "cloudflare-ai-chat",
|
|
1332
|
+
CLOUDFLARE_AGENTS: "cloudflare-agents",
|
|
1333
|
+
CLOUDFLARE_THINK: "cloudflare-think",
|
|
841
1334
|
COHERE: "cohere",
|
|
842
1335
|
CURSOR_SDK: "cursor-sdk",
|
|
843
1336
|
EVE: "eve",
|
|
@@ -852,6 +1345,7 @@ var INSTRUMENTATION_NAMES = {
|
|
|
852
1345
|
LANGSMITH: "langsmith",
|
|
853
1346
|
MASTRA: "mastra",
|
|
854
1347
|
MISTRAL: "mistral",
|
|
1348
|
+
OLLAMA: "ollama",
|
|
855
1349
|
OPENAI: "openai",
|
|
856
1350
|
OPENAI_AGENTS: "openai-agents",
|
|
857
1351
|
OPENAI_CODEX: "openai-codex",
|
|
@@ -1368,6 +1862,14 @@ var anthropicChannels = defineChannels(
|
|
|
1368
1862
|
betaMessagesToolRunner: channel({
|
|
1369
1863
|
channelName: "beta.messages.toolRunner",
|
|
1370
1864
|
kind: "sync-stream"
|
|
1865
|
+
}),
|
|
1866
|
+
betaSessionsEventsStream: channel({
|
|
1867
|
+
channelName: "beta.sessions.events.stream",
|
|
1868
|
+
kind: "async"
|
|
1869
|
+
}),
|
|
1870
|
+
betaSessionsThreadsEventsStream: channel({
|
|
1871
|
+
channelName: "beta.sessions.threads.events.stream",
|
|
1872
|
+
kind: "async"
|
|
1371
1873
|
})
|
|
1372
1874
|
},
|
|
1373
1875
|
{ instrumentationName: INSTRUMENTATION_NAMES.ANTHROPIC }
|
|
@@ -1486,7 +1988,40 @@ var anthropicConfigs = [
|
|
|
1486
1988
|
methodName: "toolRunner",
|
|
1487
1989
|
kind: "Sync"
|
|
1488
1990
|
}
|
|
1489
|
-
}
|
|
1991
|
+
},
|
|
1992
|
+
// Managed Agents Sessions event streams are discovered automatically, but
|
|
1993
|
+
// remain passive until the user calls collectAnthropicSession() on the
|
|
1994
|
+
// returned stream.
|
|
1995
|
+
...["mjs", "js"].map(
|
|
1996
|
+
(extension) => ({
|
|
1997
|
+
channelName: anthropicChannels.betaSessionsEventsStream.channelName,
|
|
1998
|
+
module: {
|
|
1999
|
+
name: "@anthropic-ai/sdk",
|
|
2000
|
+
versionRange: ">=0.86.0",
|
|
2001
|
+
filePath: `resources/beta/sessions/events.${extension}`
|
|
2002
|
+
},
|
|
2003
|
+
functionQuery: {
|
|
2004
|
+
className: "Events",
|
|
2005
|
+
methodName: "stream",
|
|
2006
|
+
kind: "Async"
|
|
2007
|
+
}
|
|
2008
|
+
})
|
|
2009
|
+
),
|
|
2010
|
+
...["mjs", "js"].map(
|
|
2011
|
+
(extension) => ({
|
|
2012
|
+
channelName: anthropicChannels.betaSessionsThreadsEventsStream.channelName,
|
|
2013
|
+
module: {
|
|
2014
|
+
name: "@anthropic-ai/sdk",
|
|
2015
|
+
versionRange: ">=0.86.0",
|
|
2016
|
+
filePath: `resources/beta/sessions/threads/events.${extension}`
|
|
2017
|
+
},
|
|
2018
|
+
functionQuery: {
|
|
2019
|
+
className: "Events",
|
|
2020
|
+
methodName: "stream",
|
|
2021
|
+
kind: "Async"
|
|
2022
|
+
}
|
|
2023
|
+
})
|
|
2024
|
+
)
|
|
1490
2025
|
];
|
|
1491
2026
|
|
|
1492
2027
|
// src/instrumentation/plugins/bedrock-runtime-channels.ts
|
|
@@ -1615,6 +2150,104 @@ var claudeAgentSDKConfigs = [
|
|
|
1615
2150
|
}
|
|
1616
2151
|
];
|
|
1617
2152
|
|
|
2153
|
+
// src/instrumentation/plugins/cloudflare-ai-chat-channels.ts
|
|
2154
|
+
var cloudflareAIChatChannels = defineChannels(
|
|
2155
|
+
"@cloudflare/ai-chat",
|
|
2156
|
+
{
|
|
2157
|
+
runExclusiveChatTurn: channel({
|
|
2158
|
+
channelName: "AIChatAgent._runExclusiveChatTurn",
|
|
2159
|
+
kind: "async"
|
|
2160
|
+
}),
|
|
2161
|
+
onChatResponse: channel({
|
|
2162
|
+
channelName: "AIChatAgent.onChatResponse",
|
|
2163
|
+
kind: "sync-stream"
|
|
2164
|
+
})
|
|
2165
|
+
},
|
|
2166
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.CLOUDFLARE_AI_CHAT }
|
|
2167
|
+
);
|
|
2168
|
+
|
|
2169
|
+
// src/auto-instrumentations/configs/cloudflare-ai-chat.ts
|
|
2170
|
+
var cloudflareAIChatVersionRange = ">=0.9.0 <0.10.0";
|
|
2171
|
+
var cloudflareAIChatConfigs = [
|
|
2172
|
+
{
|
|
2173
|
+
// AIChatAgent subclasses replace onChatMessage, so there is no stable
|
|
2174
|
+
// public implementation for the transformer to target. This runner is
|
|
2175
|
+
// the narrowest shared boundary around every chat turn; keep the version
|
|
2176
|
+
// range tight because it is an internal method.
|
|
2177
|
+
channelName: cloudflareAIChatChannels.runExclusiveChatTurn.channelName,
|
|
2178
|
+
module: {
|
|
2179
|
+
name: "@cloudflare/ai-chat",
|
|
2180
|
+
versionRange: cloudflareAIChatVersionRange,
|
|
2181
|
+
filePath: "dist/index.js"
|
|
2182
|
+
},
|
|
2183
|
+
functionQuery: {
|
|
2184
|
+
className: "AIChatAgent",
|
|
2185
|
+
methodName: "_runExclusiveChatTurn",
|
|
2186
|
+
kind: "Async"
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
];
|
|
2190
|
+
|
|
2191
|
+
// src/instrumentation/plugins/cloudflare-agents-channels.ts
|
|
2192
|
+
var cloudflareAgentsChannels = defineChannels(
|
|
2193
|
+
"agents",
|
|
2194
|
+
{
|
|
2195
|
+
runAgentTool: channel({
|
|
2196
|
+
channelName: "Agent.runAgentTool",
|
|
2197
|
+
kind: "async"
|
|
2198
|
+
})
|
|
2199
|
+
},
|
|
2200
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.CLOUDFLARE_AGENTS }
|
|
2201
|
+
);
|
|
2202
|
+
|
|
2203
|
+
// src/auto-instrumentations/configs/cloudflare-agents.ts
|
|
2204
|
+
var cloudflareAgentsVersionRange = ">=0.17.0 <0.18.0";
|
|
2205
|
+
var cloudflareAgentsConfigs = [
|
|
2206
|
+
{
|
|
2207
|
+
channelName: cloudflareAgentsChannels.runAgentTool.channelName,
|
|
2208
|
+
module: {
|
|
2209
|
+
name: "agents",
|
|
2210
|
+
versionRange: cloudflareAgentsVersionRange,
|
|
2211
|
+
filePath: "dist/index.js"
|
|
2212
|
+
},
|
|
2213
|
+
functionQuery: {
|
|
2214
|
+
className: "Agent",
|
|
2215
|
+
methodName: "runAgentTool",
|
|
2216
|
+
kind: "Async"
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2219
|
+
];
|
|
2220
|
+
|
|
2221
|
+
// src/instrumentation/plugins/cloudflare-think-channels.ts
|
|
2222
|
+
var cloudflareThinkChannels = defineChannels(
|
|
2223
|
+
"@cloudflare/think",
|
|
2224
|
+
{
|
|
2225
|
+
runInferenceLoop: channel({
|
|
2226
|
+
channelName: "Think.runInferenceLoop",
|
|
2227
|
+
kind: "async"
|
|
2228
|
+
})
|
|
2229
|
+
},
|
|
2230
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.CLOUDFLARE_THINK }
|
|
2231
|
+
);
|
|
2232
|
+
|
|
2233
|
+
// src/auto-instrumentations/configs/cloudflare-think.ts
|
|
2234
|
+
var cloudflareThinkVersionRange = ">=0.13.0 <0.14.0";
|
|
2235
|
+
var cloudflareThinkConfigs = [
|
|
2236
|
+
{
|
|
2237
|
+
channelName: cloudflareThinkChannels.runInferenceLoop.channelName,
|
|
2238
|
+
module: {
|
|
2239
|
+
name: "@cloudflare/think",
|
|
2240
|
+
versionRange: cloudflareThinkVersionRange,
|
|
2241
|
+
filePath: "dist/think.js"
|
|
2242
|
+
},
|
|
2243
|
+
functionQuery: {
|
|
2244
|
+
className: "Think",
|
|
2245
|
+
methodName: "_runInferenceLoop",
|
|
2246
|
+
kind: "Async"
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
];
|
|
2250
|
+
|
|
1618
2251
|
// src/instrumentation/plugins/cohere-channels.ts
|
|
1619
2252
|
var cohereChannels = defineChannels(
|
|
1620
2253
|
"cohere-ai",
|
|
@@ -2977,6 +3610,83 @@ var huggingFaceConfigs = [
|
|
|
2977
3610
|
}
|
|
2978
3611
|
];
|
|
2979
3612
|
|
|
3613
|
+
// src/instrumentation/plugins/huggingface-transformers-channels.ts
|
|
3614
|
+
var huggingFaceTransformersChannels = defineChannels(
|
|
3615
|
+
"@huggingface/transformers",
|
|
3616
|
+
{
|
|
3617
|
+
pipeline: channel({
|
|
3618
|
+
channelName: "pipeline",
|
|
3619
|
+
kind: "async"
|
|
3620
|
+
}),
|
|
3621
|
+
pipelineCall: channel({
|
|
3622
|
+
channelName: "pipeline.call",
|
|
3623
|
+
kind: "async"
|
|
3624
|
+
})
|
|
3625
|
+
},
|
|
3626
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.HUGGINGFACE }
|
|
3627
|
+
);
|
|
3628
|
+
|
|
3629
|
+
// src/auto-instrumentations/configs/huggingface-transformers.ts
|
|
3630
|
+
var moduleFiles = [
|
|
3631
|
+
{
|
|
3632
|
+
filePath: "dist/transformers.mjs",
|
|
3633
|
+
versionRange: ">=3.0.0 <3.4.0"
|
|
3634
|
+
},
|
|
3635
|
+
{
|
|
3636
|
+
filePath: "dist/transformers.cjs",
|
|
3637
|
+
versionRange: ">=3.0.0 <3.4.0"
|
|
3638
|
+
},
|
|
3639
|
+
{
|
|
3640
|
+
filePath: "dist/transformers.js",
|
|
3641
|
+
versionRange: ">=3.0.0 <3.4.0"
|
|
3642
|
+
},
|
|
3643
|
+
{
|
|
3644
|
+
filePath: "dist/transformers.node.mjs",
|
|
3645
|
+
versionRange: ">=3.4.0 <5.0.0"
|
|
3646
|
+
},
|
|
3647
|
+
{
|
|
3648
|
+
filePath: "dist/transformers.node.cjs",
|
|
3649
|
+
versionRange: ">=3.4.0 <5.0.0"
|
|
3650
|
+
},
|
|
3651
|
+
{
|
|
3652
|
+
filePath: "dist/transformers.web.js",
|
|
3653
|
+
versionRange: ">=3.4.0 <5.0.0"
|
|
3654
|
+
}
|
|
3655
|
+
];
|
|
3656
|
+
var pipelineClasses = [
|
|
3657
|
+
"TextGenerationPipeline",
|
|
3658
|
+
"Text2TextGenerationPipeline",
|
|
3659
|
+
"FeatureExtractionPipeline",
|
|
3660
|
+
"QuestionAnsweringPipeline"
|
|
3661
|
+
];
|
|
3662
|
+
var huggingFaceTransformersConfigs = moduleFiles.flatMap(({ filePath, versionRange: versionRange2 }) => [
|
|
3663
|
+
{
|
|
3664
|
+
channelName: huggingFaceTransformersChannels.pipeline.channelName,
|
|
3665
|
+
module: {
|
|
3666
|
+
name: "@huggingface/transformers",
|
|
3667
|
+
versionRange: versionRange2,
|
|
3668
|
+
filePath
|
|
3669
|
+
},
|
|
3670
|
+
functionQuery: {
|
|
3671
|
+
functionName: "pipeline",
|
|
3672
|
+
kind: "Async"
|
|
3673
|
+
}
|
|
3674
|
+
},
|
|
3675
|
+
...pipelineClasses.map((className) => ({
|
|
3676
|
+
channelName: huggingFaceTransformersChannels.pipelineCall.channelName,
|
|
3677
|
+
module: {
|
|
3678
|
+
name: "@huggingface/transformers",
|
|
3679
|
+
versionRange: versionRange2,
|
|
3680
|
+
filePath
|
|
3681
|
+
},
|
|
3682
|
+
functionQuery: {
|
|
3683
|
+
className,
|
|
3684
|
+
methodName: "_call",
|
|
3685
|
+
kind: "Async"
|
|
3686
|
+
}
|
|
3687
|
+
}))
|
|
3688
|
+
]);
|
|
3689
|
+
|
|
2980
3690
|
// src/instrumentation/plugins/langchain-channels.ts
|
|
2981
3691
|
var langChainChannels = defineChannels(
|
|
2982
3692
|
"@langchain/core",
|
|
@@ -3421,6 +4131,51 @@ var mistralConfigs = [
|
|
|
3421
4131
|
}
|
|
3422
4132
|
];
|
|
3423
4133
|
|
|
4134
|
+
// src/instrumentation/plugins/ollama-channels.ts
|
|
4135
|
+
var ollamaChannels = defineChannels(
|
|
4136
|
+
"ollama",
|
|
4137
|
+
{
|
|
4138
|
+
chat: channel({
|
|
4139
|
+
channelName: "chat",
|
|
4140
|
+
kind: "async"
|
|
4141
|
+
}),
|
|
4142
|
+
generate: channel({
|
|
4143
|
+
channelName: "generate",
|
|
4144
|
+
kind: "async"
|
|
4145
|
+
}),
|
|
4146
|
+
embed: channel({
|
|
4147
|
+
channelName: "embed",
|
|
4148
|
+
kind: "async"
|
|
4149
|
+
})
|
|
4150
|
+
},
|
|
4151
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.OLLAMA }
|
|
4152
|
+
);
|
|
4153
|
+
|
|
4154
|
+
// src/auto-instrumentations/configs/ollama.ts
|
|
4155
|
+
var methods = [
|
|
4156
|
+
["chat", ollamaChannels.chat.channelName],
|
|
4157
|
+
["generate", ollamaChannels.generate.channelName],
|
|
4158
|
+
["embed", ollamaChannels.embed.channelName]
|
|
4159
|
+
];
|
|
4160
|
+
var implementationFiles = ["dist/browser.mjs", "dist/browser.cjs"];
|
|
4161
|
+
var ollamaConfigs = [
|
|
4162
|
+
...implementationFiles.flatMap(
|
|
4163
|
+
(filePath) => methods.map(([methodName, channelName]) => ({
|
|
4164
|
+
channelName,
|
|
4165
|
+
module: {
|
|
4166
|
+
name: "ollama",
|
|
4167
|
+
versionRange: ">=0.6.0 <0.7.0",
|
|
4168
|
+
filePath
|
|
4169
|
+
},
|
|
4170
|
+
functionQuery: {
|
|
4171
|
+
className: "Ollama",
|
|
4172
|
+
methodName,
|
|
4173
|
+
kind: "Async"
|
|
4174
|
+
}
|
|
4175
|
+
}))
|
|
4176
|
+
)
|
|
4177
|
+
];
|
|
4178
|
+
|
|
3424
4179
|
// src/instrumentation/plugins/openai-agents-channels.ts
|
|
3425
4180
|
var openAIAgentsCoreChannels = defineChannels(
|
|
3426
4181
|
"@openai/agents-core",
|
|
@@ -3830,6 +4585,19 @@ var openRouterConfigs = [
|
|
|
3830
4585
|
kind: "Async"
|
|
3831
4586
|
}
|
|
3832
4587
|
},
|
|
4588
|
+
{
|
|
4589
|
+
channelName: openRouterChannels.betaResponsesSend.channelName,
|
|
4590
|
+
module: {
|
|
4591
|
+
name: "@openrouter/sdk",
|
|
4592
|
+
versionRange: ">=1.1.2 <2.0.0",
|
|
4593
|
+
filePath: "esm/sdk/betaresponses.js"
|
|
4594
|
+
},
|
|
4595
|
+
functionQuery: {
|
|
4596
|
+
className: "BetaResponses",
|
|
4597
|
+
methodName: "send",
|
|
4598
|
+
kind: "Async"
|
|
4599
|
+
}
|
|
4600
|
+
},
|
|
3833
4601
|
{
|
|
3834
4602
|
channelName: openRouterChannels.callModel.channelName,
|
|
3835
4603
|
module: {
|
|
@@ -3995,6 +4763,18 @@ var defaultInstrumentationConfigGroups = [
|
|
|
3995
4763
|
integrations: ["claudeAgentSDK"],
|
|
3996
4764
|
configs: claudeAgentSDKConfigs
|
|
3997
4765
|
},
|
|
4766
|
+
{
|
|
4767
|
+
integrations: ["cloudflareAIChat"],
|
|
4768
|
+
configs: cloudflareAIChatConfigs
|
|
4769
|
+
},
|
|
4770
|
+
{
|
|
4771
|
+
integrations: ["cloudflareAgents"],
|
|
4772
|
+
configs: cloudflareAgentsConfigs
|
|
4773
|
+
},
|
|
4774
|
+
{
|
|
4775
|
+
integrations: ["cloudflareThink"],
|
|
4776
|
+
configs: cloudflareThinkConfigs
|
|
4777
|
+
},
|
|
3998
4778
|
{ integrations: ["cursor", "cursorSDK"], configs: cursorSDKConfigs },
|
|
3999
4779
|
{
|
|
4000
4780
|
integrations: ["openAIAgents"],
|
|
@@ -4004,7 +4784,10 @@ var defaultInstrumentationConfigGroups = [
|
|
|
4004
4784
|
integrations: ["google", "googleGenAI"],
|
|
4005
4785
|
configs: googleGenAIConfigs
|
|
4006
4786
|
},
|
|
4007
|
-
{
|
|
4787
|
+
{
|
|
4788
|
+
integrations: ["huggingface"],
|
|
4789
|
+
configs: [...huggingFaceConfigs, ...huggingFaceTransformersConfigs]
|
|
4790
|
+
},
|
|
4008
4791
|
{
|
|
4009
4792
|
integrations: ["langchain", "langgraph"],
|
|
4010
4793
|
configs: langchainConfigs
|
|
@@ -4016,6 +4799,7 @@ var defaultInstrumentationConfigGroups = [
|
|
|
4016
4799
|
configs: openRouterAgentConfigs
|
|
4017
4800
|
},
|
|
4018
4801
|
{ integrations: ["mistral"], configs: mistralConfigs },
|
|
4802
|
+
{ integrations: ["ollama"], configs: ollamaConfigs },
|
|
4019
4803
|
{ integrations: ["googleADK"], configs: googleADKConfigs },
|
|
4020
4804
|
{ integrations: ["cohere"], configs: cohereConfigs },
|
|
4021
4805
|
{ integrations: ["groq"], configs: groqConfigs },
|
|
@@ -4063,6 +4847,257 @@ function getDefaultInstrumentationConfigs({
|
|
|
4063
4847
|
];
|
|
4064
4848
|
}
|
|
4065
4849
|
|
|
4850
|
+
// src/auto-instrumentations/loader/mastra-observability-patch.ts
|
|
4851
|
+
var MASTRA_EXPORTER_FACTORY_GLOBAL = "__braintrustMastraExporterFactory";
|
|
4852
|
+
var MASTRA_CORE_PACKAGE = "@mastra/core";
|
|
4853
|
+
var MASTRA_OBSERVABILITY_PACKAGE = "@mastra/observability";
|
|
4854
|
+
var MASTRA_CORE_ENTRY_PATHS = /* @__PURE__ */ new Set([
|
|
4855
|
+
"dist/index.js",
|
|
4856
|
+
"dist/index.cjs",
|
|
4857
|
+
"dist/mastra/index.js",
|
|
4858
|
+
"dist/mastra/index.cjs"
|
|
4859
|
+
]);
|
|
4860
|
+
var MASTRA_OBSERVABILITY_ENTRY_PATHS = /* @__PURE__ */ new Set([
|
|
4861
|
+
"dist/index.js",
|
|
4862
|
+
"dist/index.cjs"
|
|
4863
|
+
]);
|
|
4864
|
+
function classifyMastraTarget(packageName, modulePath) {
|
|
4865
|
+
if (packageName === MASTRA_CORE_PACKAGE && MASTRA_CORE_ENTRY_PATHS.has(modulePath)) {
|
|
4866
|
+
return "core";
|
|
4867
|
+
}
|
|
4868
|
+
if (packageName === MASTRA_OBSERVABILITY_PACKAGE && MASTRA_OBSERVABILITY_ENTRY_PATHS.has(modulePath)) {
|
|
4869
|
+
return "observability";
|
|
4870
|
+
}
|
|
4871
|
+
return null;
|
|
4872
|
+
}
|
|
4873
|
+
function extractChunkPath(source) {
|
|
4874
|
+
const esmMatch = source.match(
|
|
4875
|
+
/export\s*\{\s*Mastra(?:\s+as\s+\w+)?\s*\}\s*from\s*['"]([^'"]+)['"]/
|
|
4876
|
+
);
|
|
4877
|
+
if (esmMatch) return esmMatch[1];
|
|
4878
|
+
const cjsMatch = source.match(
|
|
4879
|
+
/require\s*\(\s*['"]([^'"]+chunk-[^'"]+)['"]\s*\)/
|
|
4880
|
+
);
|
|
4881
|
+
if (cjsMatch) return cjsMatch[1];
|
|
4882
|
+
return null;
|
|
4883
|
+
}
|
|
4884
|
+
var EXPORTER_FACTORY_KEY = JSON.stringify(MASTRA_EXPORTER_FACTORY_GLOBAL);
|
|
4885
|
+
var MASTRA_PROXY_HANDLER_BODY = `
|
|
4886
|
+
{
|
|
4887
|
+
construct(target, args, newTarget) {
|
|
4888
|
+
var firstArg = args[0];
|
|
4889
|
+
if (
|
|
4890
|
+
(!firstArg || typeof firstArg !== "object" || !firstArg.observability) &&
|
|
4891
|
+
__braintrustObservabilityClass
|
|
4892
|
+
) {
|
|
4893
|
+
try {
|
|
4894
|
+
// serviceName is required by Mastra's Observability validator; pass
|
|
4895
|
+
// something sensible by default. Users who want a different name
|
|
4896
|
+
// should construct Observability themselves.
|
|
4897
|
+
var observability = new __braintrustObservabilityClass({
|
|
4898
|
+
configs: { default: { serviceName: "mastra" } },
|
|
4899
|
+
});
|
|
4900
|
+
args = args.slice();
|
|
4901
|
+
args[0] = Object.assign({}, firstArg, { observability: observability });
|
|
4902
|
+
} catch (e) {
|
|
4903
|
+
// Fall through. Mastra will use its own NoOp; user code still works,
|
|
4904
|
+
// just without auto-instrumentation.
|
|
4905
|
+
}
|
|
4906
|
+
}
|
|
4907
|
+
return Reflect.construct(target, args, newTarget);
|
|
4908
|
+
},
|
|
4909
|
+
}`;
|
|
4910
|
+
function buildMastraEsmWrapper(chunkPath) {
|
|
4911
|
+
const chunk = JSON.stringify(chunkPath);
|
|
4912
|
+
return `import { Mastra as __braintrustOrigMastra } from ${chunk};
|
|
4913
|
+
import { createRequire as __braintrustCreateRequire } from "node:module";
|
|
4914
|
+
|
|
4915
|
+
let __braintrustObservabilityClass = null;
|
|
4916
|
+
try {
|
|
4917
|
+
// Resolve @mastra/observability relative to this module (the Mastra entry),
|
|
4918
|
+
// so it's looked up from the user's node_modules tree.
|
|
4919
|
+
const __braintrustRequire = __braintrustCreateRequire(import.meta.url);
|
|
4920
|
+
__braintrustObservabilityClass =
|
|
4921
|
+
__braintrustRequire("@mastra/observability").Observability;
|
|
4922
|
+
} catch (e) {
|
|
4923
|
+
// @mastra/observability isn't installed; the construct trap will skip the
|
|
4924
|
+
// auto-construct branch and Mastra falls back to its own NoOp.
|
|
4925
|
+
}
|
|
4926
|
+
const Mastra = new Proxy(__braintrustOrigMastra, ${MASTRA_PROXY_HANDLER_BODY});
|
|
4927
|
+
export { Mastra };
|
|
4928
|
+
`;
|
|
4929
|
+
}
|
|
4930
|
+
function buildMastraCjsWrapper(chunkPath) {
|
|
4931
|
+
const chunk = JSON.stringify(chunkPath);
|
|
4932
|
+
return `'use strict';
|
|
4933
|
+
const __braintrustChunk = require(${chunk});
|
|
4934
|
+
|
|
4935
|
+
let __braintrustObservabilityClass = null;
|
|
4936
|
+
try {
|
|
4937
|
+
__braintrustObservabilityClass = require("@mastra/observability").Observability;
|
|
4938
|
+
} catch (e) {
|
|
4939
|
+
// @mastra/observability isn't installed; same fallback as the ESM wrapper.
|
|
4940
|
+
}
|
|
4941
|
+
|
|
4942
|
+
const __braintrustWrappedMastra = new Proxy(
|
|
4943
|
+
__braintrustChunk.Mastra,
|
|
4944
|
+
${MASTRA_PROXY_HANDLER_BODY},
|
|
4945
|
+
);
|
|
4946
|
+
Object.defineProperty(exports, "Mastra", {
|
|
4947
|
+
enumerable: true,
|
|
4948
|
+
configurable: true,
|
|
4949
|
+
get: function () { return __braintrustWrappedMastra; }
|
|
4950
|
+
});
|
|
4951
|
+
`;
|
|
4952
|
+
}
|
|
4953
|
+
var OBSERVABILITY_APPEND_BODY = `
|
|
4954
|
+
;(function __braintrustWrapObservability() {
|
|
4955
|
+
// Top-level so we can both read and reassign the var binding the original
|
|
4956
|
+
// entry declared.
|
|
4957
|
+
if (typeof Observability === "undefined") return;
|
|
4958
|
+
if (Observability.__braintrustWrapped) return;
|
|
4959
|
+
function __braintrustEnsureExporter(rawConfig) {
|
|
4960
|
+
try {
|
|
4961
|
+
var factory = globalThis[${EXPORTER_FACTORY_KEY}];
|
|
4962
|
+
if (typeof factory !== "function") return rawConfig;
|
|
4963
|
+
var config = rawConfig && typeof rawConfig === "object" ? rawConfig : {};
|
|
4964
|
+
var configsIn = config.configs && typeof config.configs === "object" ? config.configs : null;
|
|
4965
|
+
var configsOut = {};
|
|
4966
|
+
var hadEntries = false;
|
|
4967
|
+
if (configsIn) {
|
|
4968
|
+
for (var name in configsIn) {
|
|
4969
|
+
if (!Object.prototype.hasOwnProperty.call(configsIn, name)) continue;
|
|
4970
|
+
hadEntries = true;
|
|
4971
|
+
var inst = configsIn[name] || {};
|
|
4972
|
+
var existing = Array.isArray(inst.exporters) ? inst.exporters : [];
|
|
4973
|
+
var hasOurs = existing.some(function (e) { return e && e.name === "braintrust"; });
|
|
4974
|
+
configsOut[name] = Object.assign({}, inst, {
|
|
4975
|
+
exporters: hasOurs ? existing : existing.concat([factory()]),
|
|
4976
|
+
});
|
|
4977
|
+
}
|
|
4978
|
+
}
|
|
4979
|
+
if (!hadEntries) {
|
|
4980
|
+
configsOut.default = {
|
|
4981
|
+
serviceName: "mastra",
|
|
4982
|
+
exporters: [factory()],
|
|
4983
|
+
};
|
|
4984
|
+
}
|
|
4985
|
+
return Object.assign({}, config, { configs: configsOut });
|
|
4986
|
+
} catch (e) {
|
|
4987
|
+
return rawConfig;
|
|
4988
|
+
}
|
|
4989
|
+
}
|
|
4990
|
+
var __OriginalObservability = Observability;
|
|
4991
|
+
Observability = new Proxy(__OriginalObservability, {
|
|
4992
|
+
construct: function (target, args, newTarget) {
|
|
4993
|
+
var nextArgs = args.slice();
|
|
4994
|
+
nextArgs[0] = __braintrustEnsureExporter(nextArgs[0]);
|
|
4995
|
+
return Reflect.construct(target, nextArgs, newTarget);
|
|
4996
|
+
},
|
|
4997
|
+
});
|
|
4998
|
+
Observability.__braintrustWrapped = true;
|
|
4999
|
+
if (typeof exports !== "undefined" && exports && typeof exports === "object") {
|
|
5000
|
+
try {
|
|
5001
|
+
Object.defineProperty(exports, "Observability", {
|
|
5002
|
+
enumerable: true,
|
|
5003
|
+
configurable: true,
|
|
5004
|
+
get: function () { return Observability; },
|
|
5005
|
+
});
|
|
5006
|
+
} catch (e) {}
|
|
5007
|
+
}
|
|
5008
|
+
})();
|
|
5009
|
+
`;
|
|
5010
|
+
function patchMastraSource(source, target, format) {
|
|
5011
|
+
if (target === "core") {
|
|
5012
|
+
const chunkPath = extractChunkPath(source);
|
|
5013
|
+
if (!chunkPath) return source;
|
|
5014
|
+
return format === "esm" ? buildMastraEsmWrapper(chunkPath) : buildMastraCjsWrapper(chunkPath);
|
|
5015
|
+
}
|
|
5016
|
+
return source + OBSERVABILITY_APPEND_BODY;
|
|
5017
|
+
}
|
|
5018
|
+
|
|
5019
|
+
// src/auto-instrumentations/loader/openai-api-promise-patch.ts
|
|
5020
|
+
var OPENAI_API_PROMISE_PATCH = `
|
|
5021
|
+
;(function __btPatchAPIPromise() {
|
|
5022
|
+
if (typeof APIPromise === "undefined" || APIPromise.prototype.__btParsePatched) return;
|
|
5023
|
+
APIPromise.prototype.__btParsePatched = true;
|
|
5024
|
+
var _origThen = APIPromise.prototype.then;
|
|
5025
|
+
APIPromise.prototype.then = function __btThen(onfulfilled, onrejected) {
|
|
5026
|
+
if (!this.__btParseWrapped && Object.prototype.hasOwnProperty.call(this, "parseResponse")) {
|
|
5027
|
+
this.__btParseWrapped = true;
|
|
5028
|
+
var _origParse = this.parseResponse;
|
|
5029
|
+
var _cached;
|
|
5030
|
+
this.parseResponse = function() {
|
|
5031
|
+
if (!_cached) _cached = _origParse.apply(this, arguments);
|
|
5032
|
+
return _cached;
|
|
5033
|
+
};
|
|
5034
|
+
}
|
|
5035
|
+
return _origThen.call(this, onfulfilled, onrejected);
|
|
5036
|
+
};
|
|
5037
|
+
})();
|
|
5038
|
+
`;
|
|
5039
|
+
|
|
5040
|
+
// src/auto-instrumentations/loader/special-case-patches.ts
|
|
5041
|
+
function applySpecialCasePatch(input) {
|
|
5042
|
+
if (input.packageName === "openai" && input.modulePath.includes("api-promise")) {
|
|
5043
|
+
return input.source + OPENAI_API_PROMISE_PATCH;
|
|
5044
|
+
}
|
|
5045
|
+
if (input.browser) {
|
|
5046
|
+
return null;
|
|
5047
|
+
}
|
|
5048
|
+
const mastraTarget = classifyMastraTarget(
|
|
5049
|
+
input.packageName,
|
|
5050
|
+
input.modulePath
|
|
5051
|
+
);
|
|
5052
|
+
if (mastraTarget) {
|
|
5053
|
+
return patchMastraSource(input.source, mastraTarget, input.format);
|
|
5054
|
+
}
|
|
5055
|
+
return null;
|
|
5056
|
+
}
|
|
5057
|
+
|
|
5058
|
+
// src/auto-instrumentations/loader/get-package-version.ts
|
|
5059
|
+
var import_node_fs = require("fs");
|
|
5060
|
+
var import_node_path = require("path");
|
|
5061
|
+
var packageNames = /* @__PURE__ */ new Map();
|
|
5062
|
+
function readPackageJson(baseDir) {
|
|
5063
|
+
try {
|
|
5064
|
+
const packageJsonPath = (0, import_node_path.join)(baseDir, "package.json");
|
|
5065
|
+
const jsonFile = (0, import_node_fs.readFileSync)(packageJsonPath, "utf8");
|
|
5066
|
+
return JSON.parse(jsonFile);
|
|
5067
|
+
} catch {
|
|
5068
|
+
return void 0;
|
|
5069
|
+
}
|
|
5070
|
+
}
|
|
5071
|
+
function resolvePackageBaseDir(baseDir) {
|
|
5072
|
+
try {
|
|
5073
|
+
return (0, import_node_fs.realpathSync)(baseDir);
|
|
5074
|
+
} catch {
|
|
5075
|
+
return baseDir;
|
|
5076
|
+
}
|
|
5077
|
+
}
|
|
5078
|
+
function readPackageJsonWithFallback(baseDir) {
|
|
5079
|
+
const packageJson = readPackageJson(baseDir);
|
|
5080
|
+
if (packageJson) {
|
|
5081
|
+
return packageJson;
|
|
5082
|
+
}
|
|
5083
|
+
const resolvedBaseDir = resolvePackageBaseDir(baseDir);
|
|
5084
|
+
if (resolvedBaseDir === baseDir) {
|
|
5085
|
+
return void 0;
|
|
5086
|
+
}
|
|
5087
|
+
return readPackageJson(resolvedBaseDir);
|
|
5088
|
+
}
|
|
5089
|
+
function getPackageName(baseDir) {
|
|
5090
|
+
if (packageNames.has(baseDir)) {
|
|
5091
|
+
return packageNames.get(baseDir);
|
|
5092
|
+
}
|
|
5093
|
+
const packageJson = readPackageJsonWithFallback(baseDir);
|
|
5094
|
+
if (typeof packageJson?.name === "string") {
|
|
5095
|
+
packageNames.set(baseDir, packageJson.name);
|
|
5096
|
+
return packageJson.name;
|
|
5097
|
+
}
|
|
5098
|
+
return void 0;
|
|
5099
|
+
}
|
|
5100
|
+
|
|
4066
5101
|
// src/auto-instrumentations/bundler/webpack-loader.ts
|
|
4067
5102
|
function getModuleVersion(basedir) {
|
|
4068
5103
|
try {
|
|
@@ -4080,8 +5115,7 @@ function getMatcher(options) {
|
|
|
4080
5115
|
const allInstrumentations = getDefaultInstrumentationConfigs({
|
|
4081
5116
|
additionalInstrumentations: options.instrumentations
|
|
4082
5117
|
});
|
|
4083
|
-
const
|
|
4084
|
-
const configHash = JSON.stringify({ allInstrumentations, dcModule });
|
|
5118
|
+
const configHash = JSON.stringify({ allInstrumentations });
|
|
4085
5119
|
if (matcherCache.has(configHash)) {
|
|
4086
5120
|
return matcherCache.get(configHash);
|
|
4087
5121
|
}
|
|
@@ -4090,7 +5124,7 @@ function getMatcher(options) {
|
|
|
4090
5124
|
matcherCache.delete(hash);
|
|
4091
5125
|
}
|
|
4092
5126
|
}
|
|
4093
|
-
const matcher = create(allInstrumentations
|
|
5127
|
+
const matcher = create(allInstrumentations);
|
|
4094
5128
|
matcherCache.set(configHash, matcher);
|
|
4095
5129
|
return matcher;
|
|
4096
5130
|
}
|
|
@@ -4114,12 +5148,22 @@ function codeTransformerLoader(code, inputSourceMap) {
|
|
|
4114
5148
|
if (!moduleDetails) {
|
|
4115
5149
|
return callback(null, code, inputSourceMap);
|
|
4116
5150
|
}
|
|
4117
|
-
const moduleName = moduleDetails.name;
|
|
5151
|
+
const moduleName = getPackageName(moduleDetails.basedir) ?? moduleDetails.name;
|
|
5152
|
+
const normalizedModulePath = moduleDetails.path.replace(/\\/g, "/");
|
|
5153
|
+
const patched = applySpecialCasePatch({
|
|
5154
|
+
packageName: moduleName,
|
|
5155
|
+
modulePath: normalizedModulePath,
|
|
5156
|
+
source: code,
|
|
5157
|
+
format: isModule ? "esm" : "cjs",
|
|
5158
|
+
browser: options.browser ?? options.useDiagnosticChannelCompatShim ?? false
|
|
5159
|
+
});
|
|
5160
|
+
if (patched !== null) {
|
|
5161
|
+
return callback(null, patched);
|
|
5162
|
+
}
|
|
4118
5163
|
const moduleVersion = getModuleVersion(moduleDetails.basedir);
|
|
4119
5164
|
if (!moduleVersion) {
|
|
4120
5165
|
return callback(null, code, inputSourceMap);
|
|
4121
5166
|
}
|
|
4122
|
-
const normalizedModulePath = moduleDetails.path.replace(/\\/g, "/");
|
|
4123
5167
|
const matcher = getMatcher(options);
|
|
4124
5168
|
const transformer = matcher.getTransformer(
|
|
4125
5169
|
moduleName,
|