braintrust 3.25.0 → 3.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +6 -0
- package/dev/dist/index.d.mts +130 -2
- package/dev/dist/index.d.ts +130 -2
- package/dev/dist/index.js +2455 -1116
- package/dev/dist/index.mjs +1599 -260
- package/dist/apply-auto-instrumentation.js +439 -398
- package/dist/apply-auto-instrumentation.mjs +242 -201
- package/dist/auto-instrumentations/bundler/esbuild.cjs +853 -337
- package/dist/auto-instrumentations/bundler/esbuild.d.mts +4 -4
- package/dist/auto-instrumentations/bundler/esbuild.d.ts +4 -4
- package/dist/auto-instrumentations/bundler/esbuild.mjs +5 -8
- package/dist/auto-instrumentations/bundler/next.cjs +852 -356
- package/dist/auto-instrumentations/bundler/next.mjs +6 -29
- package/dist/auto-instrumentations/bundler/rollup.cjs +853 -337
- package/dist/auto-instrumentations/bundler/rollup.d.mts +4 -4
- package/dist/auto-instrumentations/bundler/rollup.d.ts +4 -4
- package/dist/auto-instrumentations/bundler/rollup.mjs +5 -8
- package/dist/auto-instrumentations/bundler/vite.cjs +853 -337
- package/dist/auto-instrumentations/bundler/vite.d.mts +4 -4
- package/dist/auto-instrumentations/bundler/vite.d.ts +4 -4
- package/dist/auto-instrumentations/bundler/vite.mjs +5 -8
- package/dist/auto-instrumentations/bundler/webpack-loader.cjs +1006 -266
- package/dist/auto-instrumentations/bundler/webpack-loader.d.ts +20 -12
- package/dist/auto-instrumentations/bundler/webpack.cjs +853 -337
- package/dist/auto-instrumentations/bundler/webpack.d.mts +4 -4
- package/dist/auto-instrumentations/bundler/webpack.d.ts +4 -4
- package/dist/auto-instrumentations/bundler/webpack.mjs +5 -4
- package/dist/auto-instrumentations/{chunk-JPVCUKTY.mjs → chunk-6E22MYSW.mjs} +165 -73
- package/dist/auto-instrumentations/{chunk-VT6DDNKM.mjs → chunk-AKKPLXTP.mjs} +631 -194
- package/dist/auto-instrumentations/chunk-NRE4QUQR.mjs +509 -0
- package/dist/auto-instrumentations/{chunk-7P6563SW.mjs → chunk-V5LEODRX.mjs} +2 -6
- package/dist/auto-instrumentations/{chunk-M6DLIJ2Z.mjs → chunk-XYN63IG5.mjs} +124 -194
- package/dist/auto-instrumentations/{chunk-CZ24KNHT.mjs → chunk-XZHHE4Y3.mjs} +77 -68
- package/dist/auto-instrumentations/hook.mjs +247 -182
- package/dist/auto-instrumentations/index.cjs +557 -48
- package/dist/auto-instrumentations/index.d.mts +6 -2
- package/dist/auto-instrumentations/index.d.ts +6 -2
- package/dist/auto-instrumentations/index.mjs +6 -1
- package/dist/auto-instrumentations/loader/cjs-patch.cjs +492 -195
- package/dist/auto-instrumentations/loader/cjs-patch.d.mts +2 -2
- package/dist/auto-instrumentations/loader/cjs-patch.d.ts +2 -2
- package/dist/auto-instrumentations/loader/cjs-patch.mjs +3 -2
- package/dist/auto-instrumentations/loader/esm-hook.mjs +1 -1
- package/dist/auto-instrumentations/plugin-B-aZh7EP.d.ts +30 -0
- package/dist/auto-instrumentations/plugin-Bnj4E_6B.d.mts +30 -0
- package/dist/auto-instrumentations/{types-RNPaKi9o.d.mts → types-C1fVeiCp.d.mts} +1 -1
- package/dist/auto-instrumentations/{types-RNPaKi9o.d.ts → types-C1fVeiCp.d.ts} +1 -1
- package/dist/browser.d.mts +817 -197
- package/dist/browser.d.ts +817 -197
- package/dist/browser.js +1883 -265
- package/dist/browser.mjs +1883 -265
- package/dist/{chunk-ABR2QWDP.mjs → chunk-PN7EWK66.mjs} +581 -133
- package/dist/{chunk-GSIDVFE6.js → chunk-VRZZQPAA.js} +1670 -736
- package/dist/{chunk-P25IOOU4.js → chunk-VYNNEKSA.js} +586 -138
- package/dist/{chunk-2SANLSWX.mjs → chunk-XIZOM2HO.mjs} +1052 -118
- package/dist/cli.js +1601 -263
- package/dist/edge-light.d.mts +1 -1
- package/dist/edge-light.d.ts +1 -1
- package/dist/edge-light.js +1883 -268
- package/dist/edge-light.mjs +1883 -268
- package/dist/index.d.mts +817 -197
- package/dist/index.d.ts +817 -197
- package/dist/index.js +695 -435
- package/dist/index.mjs +264 -4
- package/dist/instrumentation/index.d.mts +130 -6
- package/dist/instrumentation/index.d.ts +130 -6
- package/dist/instrumentation/index.js +1510 -80
- package/dist/instrumentation/index.mjs +1510 -80
- package/dist/vitest-evals-reporter.js +16 -16
- package/dist/vitest-evals-reporter.mjs +2 -2
- package/dist/workerd.d.mts +1 -1
- package/dist/workerd.d.ts +1 -1
- package/dist/workerd.js +1883 -268
- package/dist/workerd.mjs +1883 -268
- package/licenses/node-diagnostics-channel/LICENSE +19 -0
- package/package.json +34 -35
- package/dist/auto-instrumentations/plugin-D0KHwSJv.d.mts +0 -44
- package/dist/auto-instrumentations/plugin-G6fgxk1b.d.ts +0 -44
|
@@ -24,6 +24,8 @@ __export(index_exports, {
|
|
|
24
24
|
anthropicConfigs: () => anthropicConfigs,
|
|
25
25
|
bedrockRuntimeConfigs: () => bedrockRuntimeConfigs,
|
|
26
26
|
claudeAgentSDKConfigs: () => claudeAgentSDKConfigs,
|
|
27
|
+
cloudflareAIChatConfigs: () => cloudflareAIChatConfigs,
|
|
28
|
+
cloudflareAgentsConfigs: () => cloudflareAgentsConfigs,
|
|
27
29
|
cohereConfigs: () => cohereConfigs,
|
|
28
30
|
cursorSDKConfigs: () => cursorSDKConfigs,
|
|
29
31
|
genkitConfigs: () => genkitConfigs,
|
|
@@ -44,84 +46,519 @@ __export(index_exports, {
|
|
|
44
46
|
});
|
|
45
47
|
module.exports = __toCommonJS(index_exports);
|
|
46
48
|
|
|
47
|
-
// src/
|
|
48
|
-
var
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
// src/global-instrumentation-hooks.ts
|
|
50
|
+
var GLOBAL_INSTRUMENTATION_HOOKS_KEY = "__braintrust_instrumentation_hooks";
|
|
51
|
+
var GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION = 1;
|
|
52
|
+
var GLOBAL_INSTRUMENTATION_HOOKS_REGISTRY_BRAND = "braintrust.global-instrumentation-hooks.registry";
|
|
53
|
+
var GLOBAL_INSTRUMENTATION_HOOK_BRAND = "braintrust.global-instrumentation-hooks.hook";
|
|
54
|
+
var registryBrand = Symbol.for(GLOBAL_INSTRUMENTATION_HOOKS_REGISTRY_BRAND);
|
|
55
|
+
var hookBrand = Symbol.for(GLOBAL_INSTRUMENTATION_HOOK_BRAND);
|
|
56
|
+
var errorReporter;
|
|
57
|
+
function reportError(error) {
|
|
58
|
+
try {
|
|
59
|
+
errorReporter?.(error);
|
|
60
|
+
} catch {
|
|
52
61
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
62
|
+
}
|
|
63
|
+
function setContextValue(context, key, value) {
|
|
64
|
+
try {
|
|
65
|
+
context[key] = value;
|
|
66
|
+
} catch (error) {
|
|
67
|
+
reportError(error);
|
|
58
68
|
}
|
|
59
|
-
}
|
|
60
|
-
|
|
69
|
+
}
|
|
70
|
+
function wrapStoreRun(store, message, next, transform) {
|
|
71
|
+
return () => {
|
|
72
|
+
let context;
|
|
73
|
+
try {
|
|
74
|
+
context = transform ? transform(message) : message;
|
|
75
|
+
} catch (error) {
|
|
76
|
+
reportError(error);
|
|
77
|
+
return next();
|
|
78
|
+
}
|
|
79
|
+
let called = false;
|
|
80
|
+
let result;
|
|
81
|
+
let providerError;
|
|
82
|
+
let providerThrew = false;
|
|
83
|
+
const runNext = () => {
|
|
84
|
+
if (called) {
|
|
85
|
+
reportError(
|
|
86
|
+
new Error(
|
|
87
|
+
"Instrumentation store invoked its callback more than once"
|
|
88
|
+
)
|
|
89
|
+
);
|
|
90
|
+
if (providerThrew) {
|
|
91
|
+
throw providerError;
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
called = true;
|
|
96
|
+
try {
|
|
97
|
+
result = next();
|
|
98
|
+
return result;
|
|
99
|
+
} catch (error) {
|
|
100
|
+
providerThrew = true;
|
|
101
|
+
providerError = error;
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
try {
|
|
106
|
+
store.run(context, runNext);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
if (!providerThrew || error !== providerError) {
|
|
109
|
+
reportError(error);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (!called) {
|
|
113
|
+
reportError(
|
|
114
|
+
new Error("Instrumentation store did not invoke its callback")
|
|
115
|
+
);
|
|
116
|
+
return runNext();
|
|
117
|
+
}
|
|
118
|
+
if (providerThrew) {
|
|
119
|
+
throw providerError;
|
|
120
|
+
}
|
|
121
|
+
return result;
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
var HookChannel = class {
|
|
61
125
|
constructor(name) {
|
|
62
126
|
this.name = name;
|
|
63
127
|
}
|
|
64
128
|
name;
|
|
65
|
-
|
|
66
|
-
|
|
129
|
+
subscribers = [];
|
|
130
|
+
stores = /* @__PURE__ */ new Map();
|
|
131
|
+
get hasSubscribers() {
|
|
132
|
+
return this.subscribers.length > 0 || this.stores.size > 0;
|
|
67
133
|
}
|
|
68
|
-
|
|
69
|
-
|
|
134
|
+
subscribe(subscription) {
|
|
135
|
+
if (typeof subscription !== "function") {
|
|
136
|
+
throw new TypeError("subscription must be a function");
|
|
137
|
+
}
|
|
138
|
+
this.subscribers = [...this.subscribers, subscription];
|
|
70
139
|
}
|
|
71
|
-
|
|
140
|
+
unsubscribe(subscription) {
|
|
141
|
+
const index = this.subscribers.indexOf(subscription);
|
|
142
|
+
if (index === -1) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
this.subscribers = [
|
|
146
|
+
...this.subscribers.slice(0, index),
|
|
147
|
+
...this.subscribers.slice(index + 1)
|
|
148
|
+
];
|
|
149
|
+
return true;
|
|
72
150
|
}
|
|
73
|
-
|
|
74
|
-
|
|
151
|
+
bindStore(store, transform) {
|
|
152
|
+
if (!store || typeof store.run !== "function") {
|
|
153
|
+
throw new TypeError("store must have a run method");
|
|
154
|
+
}
|
|
155
|
+
this.stores.set(
|
|
156
|
+
store,
|
|
157
|
+
transform
|
|
158
|
+
);
|
|
75
159
|
}
|
|
76
|
-
|
|
160
|
+
unbindStore(store) {
|
|
161
|
+
return this.stores.delete(store);
|
|
77
162
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
163
|
+
publish(message) {
|
|
164
|
+
const subscribers = this.subscribers;
|
|
165
|
+
for (const subscriber of subscribers) {
|
|
166
|
+
try {
|
|
167
|
+
subscriber(message, this.name);
|
|
168
|
+
} catch (error) {
|
|
169
|
+
reportError(error);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
runStores(message, fn, thisArg, ...args) {
|
|
174
|
+
let run = () => {
|
|
175
|
+
this.publish(message);
|
|
176
|
+
return Reflect.apply(fn, thisArg, args);
|
|
177
|
+
};
|
|
178
|
+
for (const [store, transform] of this.stores.entries()) {
|
|
179
|
+
run = wrapStoreRun(store, message, run, transform);
|
|
180
|
+
}
|
|
181
|
+
return run();
|
|
81
182
|
}
|
|
82
183
|
};
|
|
83
|
-
var
|
|
184
|
+
var traceEvents = [
|
|
185
|
+
"start",
|
|
186
|
+
"end",
|
|
187
|
+
"asyncStart",
|
|
188
|
+
"asyncEnd",
|
|
189
|
+
"error"
|
|
190
|
+
];
|
|
191
|
+
var TracingHook = class {
|
|
84
192
|
start;
|
|
85
193
|
end;
|
|
86
194
|
asyncStart;
|
|
87
195
|
asyncEnd;
|
|
88
196
|
error;
|
|
89
197
|
constructor(nameOrChannels) {
|
|
198
|
+
Object.defineProperty(this, hookBrand, {
|
|
199
|
+
configurable: false,
|
|
200
|
+
enumerable: false,
|
|
201
|
+
value: GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
|
|
202
|
+
writable: false
|
|
203
|
+
});
|
|
90
204
|
if (typeof nameOrChannels === "string") {
|
|
91
|
-
this.start = new
|
|
92
|
-
this.end = new
|
|
93
|
-
this.asyncStart = new
|
|
94
|
-
|
|
95
|
-
);
|
|
96
|
-
this.asyncEnd = new DefaultChannel(`tracing:${nameOrChannels}:asyncEnd`);
|
|
97
|
-
this.error = new DefaultChannel(`tracing:${nameOrChannels}:error`);
|
|
205
|
+
this.start = new HookChannel(`tracing:${nameOrChannels}:start`);
|
|
206
|
+
this.end = new HookChannel(`tracing:${nameOrChannels}:end`);
|
|
207
|
+
this.asyncStart = new HookChannel(`tracing:${nameOrChannels}:asyncStart`);
|
|
208
|
+
this.asyncEnd = new HookChannel(`tracing:${nameOrChannels}:asyncEnd`);
|
|
209
|
+
this.error = new HookChannel(`tracing:${nameOrChannels}:error`);
|
|
98
210
|
return;
|
|
99
211
|
}
|
|
100
|
-
this.start = nameOrChannels.start ?? new
|
|
101
|
-
this.end = nameOrChannels.end ?? new
|
|
102
|
-
this.asyncStart = nameOrChannels.asyncStart ?? new
|
|
103
|
-
this.asyncEnd = nameOrChannels.asyncEnd ?? new
|
|
104
|
-
this.error = nameOrChannels.error ?? new
|
|
212
|
+
this.start = nameOrChannels.start ?? new HookChannel("tracing:start");
|
|
213
|
+
this.end = nameOrChannels.end ?? new HookChannel("tracing:end");
|
|
214
|
+
this.asyncStart = nameOrChannels.asyncStart ?? new HookChannel("tracing:asyncStart");
|
|
215
|
+
this.asyncEnd = nameOrChannels.asyncEnd ?? new HookChannel("tracing:asyncEnd");
|
|
216
|
+
this.error = nameOrChannels.error ?? new HookChannel("tracing:error");
|
|
105
217
|
}
|
|
106
218
|
get hasSubscribers() {
|
|
107
219
|
return this.start.hasSubscribers || this.end.hasSubscribers || this.asyncStart.hasSubscribers || this.asyncEnd.hasSubscribers || this.error.hasSubscribers;
|
|
108
220
|
}
|
|
109
|
-
subscribe(
|
|
221
|
+
subscribe(handlers) {
|
|
222
|
+
for (const eventName of traceEvents) {
|
|
223
|
+
const handler = handlers[eventName];
|
|
224
|
+
if (handler) {
|
|
225
|
+
this[eventName].subscribe(handler);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
unsubscribe(handlers) {
|
|
230
|
+
let done = true;
|
|
231
|
+
for (const eventName of traceEvents) {
|
|
232
|
+
const handler = handlers[eventName];
|
|
233
|
+
if (handler && !this[eventName].unsubscribe(handler)) {
|
|
234
|
+
done = false;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return done;
|
|
238
|
+
}
|
|
239
|
+
traceSync(fn, message = {}, thisArg, ...args) {
|
|
240
|
+
if (!this.hasSubscribers) {
|
|
241
|
+
return Reflect.apply(fn, thisArg, args);
|
|
242
|
+
}
|
|
243
|
+
const context = message;
|
|
244
|
+
return this.start.runStores(message, () => {
|
|
245
|
+
try {
|
|
246
|
+
const result = Reflect.apply(fn, thisArg, args);
|
|
247
|
+
setContextValue(context, "result", result);
|
|
248
|
+
return result;
|
|
249
|
+
} catch (error) {
|
|
250
|
+
setContextValue(context, "error", error);
|
|
251
|
+
this.error.publish(message);
|
|
252
|
+
throw error;
|
|
253
|
+
} finally {
|
|
254
|
+
this.end.publish(message);
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
tracePromise(fn, message = {}, thisArg, ...args) {
|
|
259
|
+
if (!this.hasSubscribers) {
|
|
260
|
+
return Reflect.apply(fn, thisArg, args);
|
|
261
|
+
}
|
|
262
|
+
const context = message;
|
|
263
|
+
return this.start.runStores(message, () => {
|
|
264
|
+
let result;
|
|
265
|
+
try {
|
|
266
|
+
result = Reflect.apply(fn, thisArg, args);
|
|
267
|
+
} catch (error) {
|
|
268
|
+
setContextValue(context, "error", error);
|
|
269
|
+
this.error.publish(message);
|
|
270
|
+
this.end.publish(message);
|
|
271
|
+
throw error;
|
|
272
|
+
}
|
|
273
|
+
this.end.publish(message);
|
|
274
|
+
if (!result || typeof result !== "object" && typeof result !== "function") {
|
|
275
|
+
setContextValue(context, "result", result);
|
|
276
|
+
this.asyncStart.publish(message);
|
|
277
|
+
this.asyncEnd.publish(message);
|
|
278
|
+
return result;
|
|
279
|
+
}
|
|
280
|
+
let terminalPublished = false;
|
|
281
|
+
const finishUnobservedResult = (error) => {
|
|
282
|
+
reportError(error);
|
|
283
|
+
if (!terminalPublished) {
|
|
284
|
+
terminalPublished = true;
|
|
285
|
+
setContextValue(context, "result", result);
|
|
286
|
+
this.asyncStart.publish(message);
|
|
287
|
+
this.asyncEnd.publish(message);
|
|
288
|
+
}
|
|
289
|
+
return result;
|
|
290
|
+
};
|
|
291
|
+
let then;
|
|
292
|
+
try {
|
|
293
|
+
then = result.then;
|
|
294
|
+
} catch (error) {
|
|
295
|
+
return finishUnobservedResult(error);
|
|
296
|
+
}
|
|
297
|
+
if (typeof then !== "function") {
|
|
298
|
+
setContextValue(context, "result", result);
|
|
299
|
+
this.asyncStart.publish(message);
|
|
300
|
+
this.asyncEnd.publish(message);
|
|
301
|
+
return result;
|
|
302
|
+
}
|
|
303
|
+
const resolve = (resolved) => {
|
|
304
|
+
if (!terminalPublished) {
|
|
305
|
+
terminalPublished = true;
|
|
306
|
+
setContextValue(context, "result", resolved);
|
|
307
|
+
this.asyncStart.publish(message);
|
|
308
|
+
this.asyncEnd.publish(message);
|
|
309
|
+
}
|
|
310
|
+
return resolved;
|
|
311
|
+
};
|
|
312
|
+
let rejectionThrown = false;
|
|
313
|
+
let rejectionError;
|
|
314
|
+
const reject = (error) => {
|
|
315
|
+
if (!terminalPublished) {
|
|
316
|
+
terminalPublished = true;
|
|
317
|
+
setContextValue(context, "error", error);
|
|
318
|
+
this.error.publish(message);
|
|
319
|
+
this.asyncStart.publish(message);
|
|
320
|
+
this.asyncEnd.publish(message);
|
|
321
|
+
}
|
|
322
|
+
rejectionThrown = true;
|
|
323
|
+
rejectionError = error;
|
|
324
|
+
throw error;
|
|
325
|
+
};
|
|
326
|
+
let isPlainPromise;
|
|
327
|
+
try {
|
|
328
|
+
isPlainPromise = result instanceof Promise && result.constructor === Promise;
|
|
329
|
+
} catch (error) {
|
|
330
|
+
return finishUnobservedResult(error);
|
|
331
|
+
}
|
|
332
|
+
try {
|
|
333
|
+
if (isPlainPromise) {
|
|
334
|
+
return Reflect.apply(then, result, [resolve, reject]);
|
|
335
|
+
}
|
|
336
|
+
Reflect.apply(then, result, [
|
|
337
|
+
resolve,
|
|
338
|
+
(error) => {
|
|
339
|
+
try {
|
|
340
|
+
reject(error);
|
|
341
|
+
} catch {
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
]);
|
|
345
|
+
} catch (error) {
|
|
346
|
+
if (rejectionThrown && error === rejectionError) {
|
|
347
|
+
return result;
|
|
348
|
+
}
|
|
349
|
+
return finishUnobservedResult(error);
|
|
350
|
+
}
|
|
351
|
+
return result;
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
traceCallback(fn, position = -1, message = {}, thisArg, ...args) {
|
|
355
|
+
if (!this.hasSubscribers) {
|
|
356
|
+
return Reflect.apply(fn, thisArg, args);
|
|
357
|
+
}
|
|
358
|
+
const context = message;
|
|
359
|
+
const callArgs = args.length > 0 ? args : context.arguments ?? args;
|
|
360
|
+
const callback = Array.prototype.at.call(callArgs, position);
|
|
361
|
+
if (typeof callback !== "function") {
|
|
362
|
+
return Reflect.apply(fn, thisArg, args);
|
|
363
|
+
}
|
|
364
|
+
const { asyncStart, asyncEnd, error: errorChannel } = this;
|
|
365
|
+
function wrappedCallback(error, result) {
|
|
366
|
+
if (error) {
|
|
367
|
+
setContextValue(context, "error", error);
|
|
368
|
+
errorChannel.publish(message);
|
|
369
|
+
} else {
|
|
370
|
+
setContextValue(context, "result", result);
|
|
371
|
+
}
|
|
372
|
+
return asyncStart.runStores(message, () => {
|
|
373
|
+
try {
|
|
374
|
+
return Reflect.apply(callback, this, arguments);
|
|
375
|
+
} finally {
|
|
376
|
+
asyncEnd.publish(message);
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
Array.prototype.splice.call(callArgs, position, 1, wrappedCallback);
|
|
381
|
+
return this.start.runStores(message, () => {
|
|
382
|
+
try {
|
|
383
|
+
return Reflect.apply(fn, thisArg, args);
|
|
384
|
+
} catch (error) {
|
|
385
|
+
setContextValue(context, "error", error);
|
|
386
|
+
this.error.publish(message);
|
|
387
|
+
throw error;
|
|
388
|
+
} finally {
|
|
389
|
+
this.end.publish(message);
|
|
390
|
+
}
|
|
391
|
+
});
|
|
110
392
|
}
|
|
111
|
-
|
|
393
|
+
};
|
|
394
|
+
var inertChannel = Object.freeze({
|
|
395
|
+
name: "braintrust:inert",
|
|
396
|
+
hasSubscribers: false,
|
|
397
|
+
subscribe() {
|
|
398
|
+
},
|
|
399
|
+
unsubscribe() {
|
|
400
|
+
return false;
|
|
401
|
+
},
|
|
402
|
+
bindStore() {
|
|
403
|
+
},
|
|
404
|
+
unbindStore() {
|
|
112
405
|
return false;
|
|
406
|
+
},
|
|
407
|
+
publish() {
|
|
408
|
+
},
|
|
409
|
+
runStores(_message, fn, thisArg, ...args) {
|
|
410
|
+
return Reflect.apply(fn, thisArg, args);
|
|
113
411
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
412
|
+
});
|
|
413
|
+
var inertTracingHook = new TracingHook({
|
|
414
|
+
start: inertChannel,
|
|
415
|
+
end: inertChannel,
|
|
416
|
+
asyncStart: inertChannel,
|
|
417
|
+
asyncEnd: inertChannel,
|
|
418
|
+
error: inertChannel
|
|
419
|
+
});
|
|
420
|
+
function isHookChannel(value) {
|
|
421
|
+
if (typeof value !== "object" && typeof value !== "function" || value === null) {
|
|
422
|
+
return false;
|
|
117
423
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
return
|
|
424
|
+
try {
|
|
425
|
+
const channel2 = value;
|
|
426
|
+
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";
|
|
427
|
+
} catch {
|
|
428
|
+
return false;
|
|
121
429
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
430
|
+
}
|
|
431
|
+
function hasTracingHookShape(value) {
|
|
432
|
+
if (typeof value !== "object" && typeof value !== "function" || value === null) {
|
|
433
|
+
return false;
|
|
434
|
+
}
|
|
435
|
+
try {
|
|
436
|
+
const hook = value;
|
|
437
|
+
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);
|
|
438
|
+
} catch {
|
|
439
|
+
return false;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
function isCompatibleTracingHook(value) {
|
|
443
|
+
try {
|
|
444
|
+
return value[hookBrand] === GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION && hasTracingHookShape(value);
|
|
445
|
+
} catch {
|
|
446
|
+
return false;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
function isCompatibleHookRegistry(value) {
|
|
450
|
+
try {
|
|
451
|
+
return value instanceof Map && value[registryBrand] === GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION;
|
|
452
|
+
} catch {
|
|
453
|
+
return false;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
function getHookRegistry() {
|
|
457
|
+
let descriptor;
|
|
458
|
+
try {
|
|
459
|
+
descriptor = Object.getOwnPropertyDescriptor(
|
|
460
|
+
globalThis,
|
|
461
|
+
GLOBAL_INSTRUMENTATION_HOOKS_KEY
|
|
462
|
+
);
|
|
463
|
+
} catch (error) {
|
|
464
|
+
reportError(error);
|
|
465
|
+
return void 0;
|
|
466
|
+
}
|
|
467
|
+
if (descriptor && "value" in descriptor && isCompatibleHookRegistry(descriptor.value) && (descriptor.configurable || descriptor.enumerable === false)) {
|
|
468
|
+
if (descriptor.configurable || descriptor.writable) {
|
|
469
|
+
try {
|
|
470
|
+
Object.defineProperty(globalThis, GLOBAL_INSTRUMENTATION_HOOKS_KEY, {
|
|
471
|
+
configurable: false,
|
|
472
|
+
enumerable: false,
|
|
473
|
+
value: descriptor.value,
|
|
474
|
+
writable: false
|
|
475
|
+
});
|
|
476
|
+
} catch (error) {
|
|
477
|
+
reportError(error);
|
|
478
|
+
return void 0;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
return descriptor.value;
|
|
482
|
+
}
|
|
483
|
+
if (descriptor && !descriptor.configurable) {
|
|
484
|
+
reportError(new Error("Incompatible global instrumentation hook registry"));
|
|
485
|
+
return void 0;
|
|
486
|
+
}
|
|
487
|
+
const registry = /* @__PURE__ */ new Map();
|
|
488
|
+
try {
|
|
489
|
+
Object.defineProperty(registry, registryBrand, {
|
|
490
|
+
configurable: false,
|
|
491
|
+
enumerable: false,
|
|
492
|
+
value: GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
|
|
493
|
+
writable: false
|
|
494
|
+
});
|
|
495
|
+
} catch (error) {
|
|
496
|
+
reportError(error);
|
|
497
|
+
return void 0;
|
|
498
|
+
}
|
|
499
|
+
try {
|
|
500
|
+
Object.defineProperty(globalThis, GLOBAL_INSTRUMENTATION_HOOKS_KEY, {
|
|
501
|
+
configurable: false,
|
|
502
|
+
enumerable: false,
|
|
503
|
+
value: registry,
|
|
504
|
+
writable: false
|
|
505
|
+
});
|
|
506
|
+
return registry;
|
|
507
|
+
} catch (error) {
|
|
508
|
+
reportError(error);
|
|
509
|
+
return void 0;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
function newGlobalTracingChannel(nameOrChannels) {
|
|
513
|
+
if (typeof nameOrChannels !== "string") {
|
|
514
|
+
return new TracingHook(nameOrChannels);
|
|
515
|
+
}
|
|
516
|
+
const registry = getHookRegistry();
|
|
517
|
+
if (!registry) {
|
|
518
|
+
return inertTracingHook;
|
|
519
|
+
}
|
|
520
|
+
let existing;
|
|
521
|
+
try {
|
|
522
|
+
existing = Map.prototype.get.call(registry, nameOrChannels);
|
|
523
|
+
} catch (error) {
|
|
524
|
+
reportError(error);
|
|
525
|
+
return inertTracingHook;
|
|
526
|
+
}
|
|
527
|
+
if (isCompatibleTracingHook(existing)) {
|
|
528
|
+
return existing;
|
|
529
|
+
}
|
|
530
|
+
if (existing !== void 0) {
|
|
531
|
+
reportError(
|
|
532
|
+
new Error(`Invalid global instrumentation hook: ${nameOrChannels}`)
|
|
533
|
+
);
|
|
534
|
+
try {
|
|
535
|
+
Map.prototype.delete.call(registry, nameOrChannels);
|
|
536
|
+
} catch (error) {
|
|
537
|
+
reportError(error);
|
|
538
|
+
return inertTracingHook;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
const hook = new TracingHook(nameOrChannels);
|
|
542
|
+
try {
|
|
543
|
+
Map.prototype.set.call(registry, nameOrChannels, hook);
|
|
544
|
+
} catch (error) {
|
|
545
|
+
reportError(error);
|
|
546
|
+
return inertTracingHook;
|
|
547
|
+
}
|
|
548
|
+
return hook;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
// src/isomorph.ts
|
|
552
|
+
var DefaultAsyncLocalStorage = class {
|
|
553
|
+
constructor() {
|
|
554
|
+
}
|
|
555
|
+
enterWith(_) {
|
|
556
|
+
}
|
|
557
|
+
run(_, callback) {
|
|
558
|
+
return callback();
|
|
559
|
+
}
|
|
560
|
+
getStore() {
|
|
561
|
+
return void 0;
|
|
125
562
|
}
|
|
126
563
|
};
|
|
127
564
|
var iso = {
|
|
@@ -134,7 +571,7 @@ var iso = {
|
|
|
134
571
|
getCallerLocation: () => void 0,
|
|
135
572
|
newAsyncLocalStorage: () => new DefaultAsyncLocalStorage(),
|
|
136
573
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
137
|
-
newTracingChannel: (nameOrChannels) =>
|
|
574
|
+
newTracingChannel: (nameOrChannels) => newGlobalTracingChannel(nameOrChannels),
|
|
138
575
|
processOn: (_0, _1) => {
|
|
139
576
|
},
|
|
140
577
|
basename: (filepath) => filepath.split(/[\\/]/).pop() || filepath,
|
|
@@ -199,6 +636,8 @@ var INSTRUMENTATION_NAMES = {
|
|
|
199
636
|
BEDROCK_RUNTIME: "bedrock-runtime",
|
|
200
637
|
BRAINTRUST_JS_LOGGER: "braintrust-js-logger",
|
|
201
638
|
CLAUDE_AGENT_SDK: "claude-agent-sdk",
|
|
639
|
+
CLOUDFLARE_AI_CHAT: "cloudflare-ai-chat",
|
|
640
|
+
CLOUDFLARE_AGENTS: "cloudflare-agents",
|
|
202
641
|
COHERE: "cohere",
|
|
203
642
|
CURSOR_SDK: "cursor-sdk",
|
|
204
643
|
EVE: "eve",
|
|
@@ -1246,6 +1685,36 @@ var claudeAgentSDKConfigs = [
|
|
|
1246
1685
|
}
|
|
1247
1686
|
];
|
|
1248
1687
|
|
|
1688
|
+
// src/instrumentation/plugins/cloudflare-agents-channels.ts
|
|
1689
|
+
var cloudflareAgentsChannels = defineChannels(
|
|
1690
|
+
"agents",
|
|
1691
|
+
{
|
|
1692
|
+
runAgentTool: channel({
|
|
1693
|
+
channelName: "Agent.runAgentTool",
|
|
1694
|
+
kind: "async"
|
|
1695
|
+
})
|
|
1696
|
+
},
|
|
1697
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.CLOUDFLARE_AGENTS }
|
|
1698
|
+
);
|
|
1699
|
+
|
|
1700
|
+
// src/auto-instrumentations/configs/cloudflare-agents.ts
|
|
1701
|
+
var cloudflareAgentsVersionRange = ">=0.17.0 <0.18.0";
|
|
1702
|
+
var cloudflareAgentsConfigs = [
|
|
1703
|
+
{
|
|
1704
|
+
channelName: cloudflareAgentsChannels.runAgentTool.channelName,
|
|
1705
|
+
module: {
|
|
1706
|
+
name: "agents",
|
|
1707
|
+
versionRange: cloudflareAgentsVersionRange,
|
|
1708
|
+
filePath: "dist/index.js"
|
|
1709
|
+
},
|
|
1710
|
+
functionQuery: {
|
|
1711
|
+
className: "Agent",
|
|
1712
|
+
methodName: "runAgentTool",
|
|
1713
|
+
kind: "Async"
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
];
|
|
1717
|
+
|
|
1249
1718
|
// src/instrumentation/plugins/cursor-sdk-channels.ts
|
|
1250
1719
|
var cursorSDKChannels = defineChannels(
|
|
1251
1720
|
"@cursor/sdk",
|
|
@@ -2468,6 +2937,44 @@ var googleADKConfigs = [
|
|
|
2468
2937
|
}
|
|
2469
2938
|
];
|
|
2470
2939
|
|
|
2940
|
+
// src/instrumentation/plugins/cloudflare-ai-chat-channels.ts
|
|
2941
|
+
var cloudflareAIChatChannels = defineChannels(
|
|
2942
|
+
"@cloudflare/ai-chat",
|
|
2943
|
+
{
|
|
2944
|
+
runExclusiveChatTurn: channel({
|
|
2945
|
+
channelName: "AIChatAgent._runExclusiveChatTurn",
|
|
2946
|
+
kind: "async"
|
|
2947
|
+
}),
|
|
2948
|
+
onChatResponse: channel({
|
|
2949
|
+
channelName: "AIChatAgent.onChatResponse",
|
|
2950
|
+
kind: "sync-stream"
|
|
2951
|
+
})
|
|
2952
|
+
},
|
|
2953
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.CLOUDFLARE_AI_CHAT }
|
|
2954
|
+
);
|
|
2955
|
+
|
|
2956
|
+
// src/auto-instrumentations/configs/cloudflare-ai-chat.ts
|
|
2957
|
+
var cloudflareAIChatVersionRange = ">=0.9.0 <0.10.0";
|
|
2958
|
+
var cloudflareAIChatConfigs = [
|
|
2959
|
+
{
|
|
2960
|
+
// AIChatAgent subclasses replace onChatMessage, so there is no stable
|
|
2961
|
+
// public implementation for the transformer to target. This runner is
|
|
2962
|
+
// the narrowest shared boundary around every chat turn; keep the version
|
|
2963
|
+
// range tight because it is an internal method.
|
|
2964
|
+
channelName: cloudflareAIChatChannels.runExclusiveChatTurn.channelName,
|
|
2965
|
+
module: {
|
|
2966
|
+
name: "@cloudflare/ai-chat",
|
|
2967
|
+
versionRange: cloudflareAIChatVersionRange,
|
|
2968
|
+
filePath: "dist/index.js"
|
|
2969
|
+
},
|
|
2970
|
+
functionQuery: {
|
|
2971
|
+
className: "AIChatAgent",
|
|
2972
|
+
methodName: "_runExclusiveChatTurn",
|
|
2973
|
+
kind: "Async"
|
|
2974
|
+
}
|
|
2975
|
+
}
|
|
2976
|
+
];
|
|
2977
|
+
|
|
2471
2978
|
// src/instrumentation/plugins/cohere-channels.ts
|
|
2472
2979
|
var cohereChannels = defineChannels(
|
|
2473
2980
|
"cohere-ai",
|
|
@@ -3248,6 +3755,8 @@ var piCodingAgentConfigs = [
|
|
|
3248
3755
|
anthropicConfigs,
|
|
3249
3756
|
bedrockRuntimeConfigs,
|
|
3250
3757
|
claudeAgentSDKConfigs,
|
|
3758
|
+
cloudflareAIChatConfigs,
|
|
3759
|
+
cloudflareAgentsConfigs,
|
|
3251
3760
|
cohereConfigs,
|
|
3252
3761
|
cursorSDKConfigs,
|
|
3253
3762
|
genkitConfigs,
|