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
|
@@ -4,170 +4,668 @@ var __export = (target, all) => {
|
|
|
4
4
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
-
// src/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
// src/global-instrumentation-hooks.ts
|
|
8
|
+
var GLOBAL_INSTRUMENTATION_HOOKS_KEY = "__braintrust_instrumentation_hooks";
|
|
9
|
+
var GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION = 1;
|
|
10
|
+
var GLOBAL_INSTRUMENTATION_HOOKS_REGISTRY_BRAND = "braintrust.global-instrumentation-hooks.registry";
|
|
11
|
+
var GLOBAL_INSTRUMENTATION_HOOK_BRAND = "braintrust.global-instrumentation-hooks.hook";
|
|
12
|
+
var GLOBAL_INVOCATION_HOOK_BRAND = "braintrust.global-instrumentation-hooks.invocation-hook";
|
|
13
|
+
var registryBrand = Symbol.for(GLOBAL_INSTRUMENTATION_HOOKS_REGISTRY_BRAND);
|
|
14
|
+
var hookBrand = Symbol.for(GLOBAL_INSTRUMENTATION_HOOK_BRAND);
|
|
15
|
+
var invocationHookBrand = Symbol.for(GLOBAL_INVOCATION_HOOK_BRAND);
|
|
16
|
+
var errorReporter;
|
|
17
|
+
function setGlobalHookErrorReporter(reporter) {
|
|
18
|
+
const previousReporter = errorReporter;
|
|
19
|
+
errorReporter = reporter;
|
|
20
|
+
return () => {
|
|
21
|
+
if (errorReporter === reporter) {
|
|
22
|
+
errorReporter = previousReporter;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function reportError(error) {
|
|
27
|
+
try {
|
|
28
|
+
errorReporter?.(error);
|
|
29
|
+
} catch {
|
|
13
30
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this.start?.hasSubscribers || this.end?.hasSubscribers || this.asyncStart?.hasSubscribers || this.asyncEnd?.hasSubscribers || this.error?.hasSubscribers
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
31
|
+
}
|
|
32
|
+
function setContextValue(context, key, value) {
|
|
33
|
+
try {
|
|
34
|
+
context[key] = value;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
reportError(error);
|
|
24
37
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
}
|
|
39
|
+
function wrapStoreRun(store, message, next, transform) {
|
|
40
|
+
return () => {
|
|
41
|
+
let context;
|
|
42
|
+
try {
|
|
43
|
+
context = transform ? transform(message) : message;
|
|
44
|
+
} catch (error) {
|
|
45
|
+
reportError(error);
|
|
46
|
+
return next();
|
|
47
|
+
}
|
|
48
|
+
let called = false;
|
|
49
|
+
let result;
|
|
50
|
+
let providerError;
|
|
51
|
+
let providerThrew = false;
|
|
52
|
+
const runNext = () => {
|
|
53
|
+
if (called) {
|
|
54
|
+
reportError(
|
|
55
|
+
new Error(
|
|
56
|
+
"Instrumentation store invoked its callback more than once"
|
|
57
|
+
)
|
|
58
|
+
);
|
|
59
|
+
if (providerThrew) {
|
|
60
|
+
throw providerError;
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
37
63
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
64
|
+
called = true;
|
|
65
|
+
try {
|
|
66
|
+
result = next();
|
|
67
|
+
return result;
|
|
68
|
+
} catch (error) {
|
|
69
|
+
providerThrew = true;
|
|
70
|
+
providerError = error;
|
|
71
|
+
throw error;
|
|
42
72
|
}
|
|
43
|
-
return start.runStores(context, () => {
|
|
44
|
-
try {
|
|
45
|
-
const result = Reflect.apply(fn, thisArg, args);
|
|
46
|
-
end?.publish(context);
|
|
47
|
-
if (result && (typeof result === "object" || typeof result === "function") && typeof result.then === "function") {
|
|
48
|
-
if (result.constructor === Promise) {
|
|
49
|
-
return result.then(
|
|
50
|
-
(res) => {
|
|
51
|
-
publishResolved(res);
|
|
52
|
-
return res;
|
|
53
|
-
},
|
|
54
|
-
(err) => {
|
|
55
|
-
publishRejected(err);
|
|
56
|
-
return Promise.reject(err);
|
|
57
|
-
}
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
void result.then(
|
|
61
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
62
|
-
(resolved) => {
|
|
63
|
-
try {
|
|
64
|
-
publishResolved(resolved);
|
|
65
|
-
} catch {
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
|
-
(err) => {
|
|
70
|
-
try {
|
|
71
|
-
publishRejected(err);
|
|
72
|
-
} catch {
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
);
|
|
76
|
-
return result;
|
|
77
|
-
}
|
|
78
|
-
context.result = result;
|
|
79
|
-
asyncStart?.publish(context);
|
|
80
|
-
asyncEnd?.publish(context);
|
|
81
|
-
return result;
|
|
82
|
-
} catch (err) {
|
|
83
|
-
context.error = err;
|
|
84
|
-
error?.publish(context);
|
|
85
|
-
end?.publish(context);
|
|
86
|
-
throw err;
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
73
|
};
|
|
90
|
-
|
|
74
|
+
try {
|
|
75
|
+
store.run(context, runNext);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
if (!providerThrew || error !== providerError) {
|
|
78
|
+
reportError(error);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (!called) {
|
|
82
|
+
reportError(
|
|
83
|
+
new Error("Instrumentation store did not invoke its callback")
|
|
84
|
+
);
|
|
85
|
+
return runNext();
|
|
86
|
+
}
|
|
87
|
+
if (providerThrew) {
|
|
88
|
+
throw providerError;
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
};
|
|
91
92
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
constructor() {
|
|
93
|
+
var HookChannel = class {
|
|
94
|
+
constructor(name) {
|
|
95
|
+
this.name = name;
|
|
96
96
|
}
|
|
97
|
-
|
|
97
|
+
name;
|
|
98
|
+
subscribers = [];
|
|
99
|
+
stores = /* @__PURE__ */ new Map();
|
|
100
|
+
get hasSubscribers() {
|
|
101
|
+
return this.subscribers.length > 0 || this.stores.size > 0;
|
|
98
102
|
}
|
|
99
|
-
|
|
100
|
-
|
|
103
|
+
subscribe(subscription) {
|
|
104
|
+
if (typeof subscription !== "function") {
|
|
105
|
+
throw new TypeError("subscription must be a function");
|
|
106
|
+
}
|
|
107
|
+
this.subscribers = [...this.subscribers, subscription];
|
|
101
108
|
}
|
|
102
|
-
|
|
103
|
-
|
|
109
|
+
unsubscribe(subscription) {
|
|
110
|
+
const index = this.subscribers.indexOf(subscription);
|
|
111
|
+
if (index === -1) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
this.subscribers = [
|
|
115
|
+
...this.subscribers.slice(0, index),
|
|
116
|
+
...this.subscribers.slice(index + 1)
|
|
117
|
+
];
|
|
118
|
+
return true;
|
|
104
119
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
120
|
+
bindStore(store, transform) {
|
|
121
|
+
if (!store || typeof store.run !== "function") {
|
|
122
|
+
throw new TypeError("store must have a run method");
|
|
123
|
+
}
|
|
124
|
+
this.stores.set(
|
|
125
|
+
store,
|
|
126
|
+
transform
|
|
127
|
+
);
|
|
109
128
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
subscribe(_subscription) {
|
|
129
|
+
unbindStore(store) {
|
|
130
|
+
return this.stores.delete(store);
|
|
113
131
|
}
|
|
114
|
-
|
|
115
|
-
|
|
132
|
+
publish(message) {
|
|
133
|
+
const subscribers = this.subscribers;
|
|
134
|
+
for (const subscriber of subscribers) {
|
|
135
|
+
try {
|
|
136
|
+
subscriber(message, this.name);
|
|
137
|
+
} catch (error) {
|
|
138
|
+
reportError(error);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
116
141
|
}
|
|
117
|
-
|
|
142
|
+
runStores(message, fn, thisArg, ...args) {
|
|
143
|
+
let run = () => {
|
|
144
|
+
this.publish(message);
|
|
145
|
+
return Reflect.apply(fn, thisArg, args);
|
|
146
|
+
};
|
|
147
|
+
for (const [store, transform] of this.stores.entries()) {
|
|
148
|
+
run = wrapStoreRun(store, message, run, transform);
|
|
149
|
+
}
|
|
150
|
+
return run();
|
|
118
151
|
}
|
|
119
|
-
|
|
120
|
-
|
|
152
|
+
};
|
|
153
|
+
var traceEvents = [
|
|
154
|
+
"start",
|
|
155
|
+
"end",
|
|
156
|
+
"asyncStart",
|
|
157
|
+
"asyncEnd",
|
|
158
|
+
"error"
|
|
159
|
+
];
|
|
160
|
+
function traceInvocation(hook, operator, target, thisArg, args, additional, callbackIndex = -1) {
|
|
161
|
+
const context = {
|
|
162
|
+
...additional,
|
|
163
|
+
arguments: args,
|
|
164
|
+
self: thisArg
|
|
165
|
+
};
|
|
166
|
+
const invoke = () => hook.invoke(target, thisArg, args, additional);
|
|
167
|
+
if (operator === "traceCallback") {
|
|
168
|
+
return hook.traceCallback(invoke, callbackIndex, context);
|
|
121
169
|
}
|
|
122
|
-
|
|
170
|
+
if (operator === "tracePromise") {
|
|
171
|
+
return hook.tracePromise(invoke, context);
|
|
123
172
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
173
|
+
return hook.traceSync(invoke, context);
|
|
174
|
+
}
|
|
175
|
+
var InvocationHook = class {
|
|
176
|
+
interceptors = [];
|
|
177
|
+
get hasInterceptors() {
|
|
178
|
+
return this.interceptors.length > 0;
|
|
179
|
+
}
|
|
180
|
+
intercept(interceptor) {
|
|
181
|
+
if (typeof interceptor !== "function") {
|
|
182
|
+
throw new TypeError("interceptor must be a function");
|
|
183
|
+
}
|
|
184
|
+
this.interceptors = [...this.interceptors, interceptor];
|
|
185
|
+
let active = true;
|
|
186
|
+
return () => {
|
|
187
|
+
if (!active) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
active = false;
|
|
191
|
+
const index = this.interceptors.indexOf(interceptor);
|
|
192
|
+
if (index !== -1) {
|
|
193
|
+
this.interceptors = [
|
|
194
|
+
...this.interceptors.slice(0, index),
|
|
195
|
+
...this.interceptors.slice(index + 1)
|
|
196
|
+
];
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
invoke(target, thisArg, args, additional) {
|
|
201
|
+
const interceptors = this.interceptors;
|
|
202
|
+
if (interceptors.length === 0) {
|
|
203
|
+
return Reflect.apply(target, thisArg, args);
|
|
204
|
+
}
|
|
205
|
+
let next = target;
|
|
206
|
+
for (let index = interceptors.length - 1; index >= 0; index -= 1) {
|
|
207
|
+
const interceptor = interceptors[index];
|
|
208
|
+
const downstream = next;
|
|
209
|
+
next = function(...nextArgs) {
|
|
210
|
+
return interceptor(downstream, this, nextArgs, additional);
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
return Reflect.apply(next, thisArg, args);
|
|
127
214
|
}
|
|
128
215
|
};
|
|
129
|
-
var
|
|
216
|
+
var TracingHook = class {
|
|
130
217
|
start;
|
|
131
218
|
end;
|
|
132
219
|
asyncStart;
|
|
133
220
|
asyncEnd;
|
|
134
221
|
error;
|
|
222
|
+
invocationHook = new InvocationHook();
|
|
135
223
|
constructor(nameOrChannels) {
|
|
224
|
+
Object.defineProperty(this, hookBrand, {
|
|
225
|
+
configurable: false,
|
|
226
|
+
enumerable: false,
|
|
227
|
+
value: GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
|
|
228
|
+
writable: false
|
|
229
|
+
});
|
|
230
|
+
Object.defineProperty(this, invocationHookBrand, {
|
|
231
|
+
configurable: false,
|
|
232
|
+
enumerable: false,
|
|
233
|
+
value: GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
|
|
234
|
+
writable: false
|
|
235
|
+
});
|
|
136
236
|
if (typeof nameOrChannels === "string") {
|
|
137
|
-
this.start = new
|
|
138
|
-
this.end = new
|
|
139
|
-
this.asyncStart = new
|
|
140
|
-
|
|
141
|
-
);
|
|
142
|
-
this.asyncEnd = new DefaultChannel(`tracing:${nameOrChannels}:asyncEnd`);
|
|
143
|
-
this.error = new DefaultChannel(`tracing:${nameOrChannels}:error`);
|
|
237
|
+
this.start = new HookChannel(`tracing:${nameOrChannels}:start`);
|
|
238
|
+
this.end = new HookChannel(`tracing:${nameOrChannels}:end`);
|
|
239
|
+
this.asyncStart = new HookChannel(`tracing:${nameOrChannels}:asyncStart`);
|
|
240
|
+
this.asyncEnd = new HookChannel(`tracing:${nameOrChannels}:asyncEnd`);
|
|
241
|
+
this.error = new HookChannel(`tracing:${nameOrChannels}:error`);
|
|
144
242
|
return;
|
|
145
243
|
}
|
|
146
|
-
this.start = nameOrChannels.start ?? new
|
|
147
|
-
this.end = nameOrChannels.end ?? new
|
|
148
|
-
this.asyncStart = nameOrChannels.asyncStart ?? new
|
|
149
|
-
this.asyncEnd = nameOrChannels.asyncEnd ?? new
|
|
150
|
-
this.error = nameOrChannels.error ?? new
|
|
244
|
+
this.start = nameOrChannels.start ?? new HookChannel("tracing:start");
|
|
245
|
+
this.end = nameOrChannels.end ?? new HookChannel("tracing:end");
|
|
246
|
+
this.asyncStart = nameOrChannels.asyncStart ?? new HookChannel("tracing:asyncStart");
|
|
247
|
+
this.asyncEnd = nameOrChannels.asyncEnd ?? new HookChannel("tracing:asyncEnd");
|
|
248
|
+
this.error = nameOrChannels.error ?? new HookChannel("tracing:error");
|
|
151
249
|
}
|
|
152
250
|
get hasSubscribers() {
|
|
153
251
|
return this.start.hasSubscribers || this.end.hasSubscribers || this.asyncStart.hasSubscribers || this.asyncEnd.hasSubscribers || this.error.hasSubscribers;
|
|
154
252
|
}
|
|
155
|
-
|
|
253
|
+
get hasInterceptors() {
|
|
254
|
+
return this.invocationHook.hasInterceptors;
|
|
255
|
+
}
|
|
256
|
+
intercept(interceptor) {
|
|
257
|
+
return this.invocationHook.intercept(interceptor);
|
|
258
|
+
}
|
|
259
|
+
invoke(target, thisArg, args, additional) {
|
|
260
|
+
return this.invocationHook.invoke(target, thisArg, args, additional);
|
|
261
|
+
}
|
|
262
|
+
traceInvocation(operator, target, thisArg, args, additional, callbackIndex = -1) {
|
|
263
|
+
return traceInvocation(
|
|
264
|
+
this,
|
|
265
|
+
operator,
|
|
266
|
+
target,
|
|
267
|
+
thisArg,
|
|
268
|
+
args,
|
|
269
|
+
additional,
|
|
270
|
+
callbackIndex
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
subscribe(handlers) {
|
|
274
|
+
for (const eventName of traceEvents) {
|
|
275
|
+
const handler = handlers[eventName];
|
|
276
|
+
if (handler) {
|
|
277
|
+
this[eventName].subscribe(handler);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
unsubscribe(handlers) {
|
|
282
|
+
let done = true;
|
|
283
|
+
for (const eventName of traceEvents) {
|
|
284
|
+
const handler = handlers[eventName];
|
|
285
|
+
if (handler && !this[eventName].unsubscribe(handler)) {
|
|
286
|
+
done = false;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return done;
|
|
290
|
+
}
|
|
291
|
+
traceSync(fn, message = {}, thisArg, ...args) {
|
|
292
|
+
if (!this.hasSubscribers) {
|
|
293
|
+
return Reflect.apply(fn, thisArg, args);
|
|
294
|
+
}
|
|
295
|
+
const context = message;
|
|
296
|
+
return this.start.runStores(message, () => {
|
|
297
|
+
try {
|
|
298
|
+
const result = Reflect.apply(fn, thisArg, args);
|
|
299
|
+
setContextValue(context, "result", result);
|
|
300
|
+
return result;
|
|
301
|
+
} catch (error) {
|
|
302
|
+
setContextValue(context, "error", error);
|
|
303
|
+
this.error.publish(message);
|
|
304
|
+
throw error;
|
|
305
|
+
} finally {
|
|
306
|
+
this.end.publish(message);
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
tracePromise(fn, message = {}, thisArg, ...args) {
|
|
311
|
+
if (!this.hasSubscribers) {
|
|
312
|
+
return Reflect.apply(fn, thisArg, args);
|
|
313
|
+
}
|
|
314
|
+
const context = message;
|
|
315
|
+
return this.start.runStores(message, () => {
|
|
316
|
+
let result;
|
|
317
|
+
try {
|
|
318
|
+
result = Reflect.apply(fn, thisArg, args);
|
|
319
|
+
} catch (error) {
|
|
320
|
+
setContextValue(context, "error", error);
|
|
321
|
+
this.error.publish(message);
|
|
322
|
+
this.end.publish(message);
|
|
323
|
+
throw error;
|
|
324
|
+
}
|
|
325
|
+
this.end.publish(message);
|
|
326
|
+
if (!result || typeof result !== "object" && typeof result !== "function") {
|
|
327
|
+
setContextValue(context, "result", result);
|
|
328
|
+
this.asyncStart.publish(message);
|
|
329
|
+
this.asyncEnd.publish(message);
|
|
330
|
+
return result;
|
|
331
|
+
}
|
|
332
|
+
let terminalPublished = false;
|
|
333
|
+
const finishUnobservedResult = (error) => {
|
|
334
|
+
reportError(error);
|
|
335
|
+
if (!terminalPublished) {
|
|
336
|
+
terminalPublished = true;
|
|
337
|
+
setContextValue(context, "result", result);
|
|
338
|
+
this.asyncStart.publish(message);
|
|
339
|
+
this.asyncEnd.publish(message);
|
|
340
|
+
}
|
|
341
|
+
return result;
|
|
342
|
+
};
|
|
343
|
+
let then;
|
|
344
|
+
try {
|
|
345
|
+
then = result.then;
|
|
346
|
+
} catch (error) {
|
|
347
|
+
return finishUnobservedResult(error);
|
|
348
|
+
}
|
|
349
|
+
if (typeof then !== "function") {
|
|
350
|
+
setContextValue(context, "result", result);
|
|
351
|
+
this.asyncStart.publish(message);
|
|
352
|
+
this.asyncEnd.publish(message);
|
|
353
|
+
return result;
|
|
354
|
+
}
|
|
355
|
+
const resolve = (resolved) => {
|
|
356
|
+
if (!terminalPublished) {
|
|
357
|
+
terminalPublished = true;
|
|
358
|
+
setContextValue(context, "result", resolved);
|
|
359
|
+
this.asyncStart.publish(message);
|
|
360
|
+
this.asyncEnd.publish(message);
|
|
361
|
+
}
|
|
362
|
+
return resolved;
|
|
363
|
+
};
|
|
364
|
+
let rejectionThrown = false;
|
|
365
|
+
let rejectionError;
|
|
366
|
+
const reject = (error) => {
|
|
367
|
+
if (!terminalPublished) {
|
|
368
|
+
terminalPublished = true;
|
|
369
|
+
setContextValue(context, "error", error);
|
|
370
|
+
this.error.publish(message);
|
|
371
|
+
this.asyncStart.publish(message);
|
|
372
|
+
this.asyncEnd.publish(message);
|
|
373
|
+
}
|
|
374
|
+
rejectionThrown = true;
|
|
375
|
+
rejectionError = error;
|
|
376
|
+
throw error;
|
|
377
|
+
};
|
|
378
|
+
let isPlainPromise;
|
|
379
|
+
try {
|
|
380
|
+
isPlainPromise = result instanceof Promise && result.constructor === Promise;
|
|
381
|
+
} catch (error) {
|
|
382
|
+
return finishUnobservedResult(error);
|
|
383
|
+
}
|
|
384
|
+
try {
|
|
385
|
+
if (isPlainPromise) {
|
|
386
|
+
return Reflect.apply(then, result, [resolve, reject]);
|
|
387
|
+
}
|
|
388
|
+
Reflect.apply(then, result, [
|
|
389
|
+
resolve,
|
|
390
|
+
(error) => {
|
|
391
|
+
try {
|
|
392
|
+
reject(error);
|
|
393
|
+
} catch {
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
]);
|
|
397
|
+
} catch (error) {
|
|
398
|
+
if (rejectionThrown && error === rejectionError) {
|
|
399
|
+
return result;
|
|
400
|
+
}
|
|
401
|
+
return finishUnobservedResult(error);
|
|
402
|
+
}
|
|
403
|
+
return result;
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
traceCallback(fn, position = -1, message = {}, thisArg, ...args) {
|
|
407
|
+
if (!this.hasSubscribers) {
|
|
408
|
+
return Reflect.apply(fn, thisArg, args);
|
|
409
|
+
}
|
|
410
|
+
const context = message;
|
|
411
|
+
const callArgs = args.length > 0 ? args : context.arguments ?? args;
|
|
412
|
+
const callback = Array.prototype.at.call(callArgs, position);
|
|
413
|
+
if (typeof callback !== "function") {
|
|
414
|
+
return Reflect.apply(fn, thisArg, args);
|
|
415
|
+
}
|
|
416
|
+
const { asyncStart, asyncEnd, error: errorChannel } = this;
|
|
417
|
+
function wrappedCallback(error, result) {
|
|
418
|
+
if (error) {
|
|
419
|
+
setContextValue(context, "error", error);
|
|
420
|
+
errorChannel.publish(message);
|
|
421
|
+
} else {
|
|
422
|
+
setContextValue(context, "result", result);
|
|
423
|
+
}
|
|
424
|
+
return asyncStart.runStores(message, () => {
|
|
425
|
+
try {
|
|
426
|
+
return Reflect.apply(callback, this, arguments);
|
|
427
|
+
} finally {
|
|
428
|
+
asyncEnd.publish(message);
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
Array.prototype.splice.call(callArgs, position, 1, wrappedCallback);
|
|
433
|
+
return this.start.runStores(message, () => {
|
|
434
|
+
try {
|
|
435
|
+
return Reflect.apply(fn, thisArg, args);
|
|
436
|
+
} catch (error) {
|
|
437
|
+
setContextValue(context, "error", error);
|
|
438
|
+
this.error.publish(message);
|
|
439
|
+
throw error;
|
|
440
|
+
} finally {
|
|
441
|
+
this.end.publish(message);
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
var inertChannel = Object.freeze({
|
|
447
|
+
name: "braintrust:inert",
|
|
448
|
+
hasSubscribers: false,
|
|
449
|
+
subscribe() {
|
|
450
|
+
},
|
|
451
|
+
unsubscribe() {
|
|
452
|
+
return false;
|
|
453
|
+
},
|
|
454
|
+
bindStore() {
|
|
455
|
+
},
|
|
456
|
+
unbindStore() {
|
|
457
|
+
return false;
|
|
458
|
+
},
|
|
459
|
+
publish() {
|
|
460
|
+
},
|
|
461
|
+
runStores(_message, fn, thisArg, ...args) {
|
|
462
|
+
return Reflect.apply(fn, thisArg, args);
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
var inertTracingHook = new TracingHook({
|
|
466
|
+
start: inertChannel,
|
|
467
|
+
end: inertChannel,
|
|
468
|
+
asyncStart: inertChannel,
|
|
469
|
+
asyncEnd: inertChannel,
|
|
470
|
+
error: inertChannel
|
|
471
|
+
});
|
|
472
|
+
function isHookChannel(value) {
|
|
473
|
+
if (typeof value !== "object" && typeof value !== "function" || value === null) {
|
|
474
|
+
return false;
|
|
156
475
|
}
|
|
157
|
-
|
|
476
|
+
try {
|
|
477
|
+
const channel2 = value;
|
|
478
|
+
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";
|
|
479
|
+
} catch {
|
|
158
480
|
return false;
|
|
159
481
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
482
|
+
}
|
|
483
|
+
function hasTracingHookShape(value) {
|
|
484
|
+
if (typeof value !== "object" && typeof value !== "function" || value === null) {
|
|
485
|
+
return false;
|
|
163
486
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
return
|
|
487
|
+
try {
|
|
488
|
+
const hook = value;
|
|
489
|
+
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);
|
|
490
|
+
} catch {
|
|
491
|
+
return false;
|
|
167
492
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
493
|
+
}
|
|
494
|
+
function hasInvocationHookShape(value) {
|
|
495
|
+
if (typeof value !== "object" && typeof value !== "function" || value === null) {
|
|
496
|
+
return false;
|
|
497
|
+
}
|
|
498
|
+
try {
|
|
499
|
+
const hook = value;
|
|
500
|
+
return value[invocationHookBrand] === GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION && typeof hook.hasInterceptors === "boolean" && typeof hook.intercept === "function" && typeof hook.invoke === "function";
|
|
501
|
+
} catch {
|
|
502
|
+
return false;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
function installInvocationHook(value) {
|
|
506
|
+
const hasInvocationHook = hasInvocationHookShape(value);
|
|
507
|
+
const invocationHook = new InvocationHook();
|
|
508
|
+
try {
|
|
509
|
+
if (!hasInvocationHook) {
|
|
510
|
+
Object.defineProperties(value, {
|
|
511
|
+
[invocationHookBrand]: {
|
|
512
|
+
configurable: false,
|
|
513
|
+
enumerable: false,
|
|
514
|
+
value: GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
|
|
515
|
+
writable: false
|
|
516
|
+
},
|
|
517
|
+
hasInterceptors: {
|
|
518
|
+
configurable: false,
|
|
519
|
+
enumerable: false,
|
|
520
|
+
get: () => invocationHook.hasInterceptors
|
|
521
|
+
},
|
|
522
|
+
intercept: {
|
|
523
|
+
configurable: false,
|
|
524
|
+
enumerable: false,
|
|
525
|
+
value: invocationHook.intercept.bind(invocationHook),
|
|
526
|
+
writable: false
|
|
527
|
+
},
|
|
528
|
+
invoke: {
|
|
529
|
+
configurable: false,
|
|
530
|
+
enumerable: false,
|
|
531
|
+
value: invocationHook.invoke.bind(invocationHook),
|
|
532
|
+
writable: false
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
if (typeof value.traceInvocation !== "function") {
|
|
537
|
+
Object.defineProperty(value, "traceInvocation", {
|
|
538
|
+
configurable: false,
|
|
539
|
+
enumerable: false,
|
|
540
|
+
value: traceInvocation.bind(void 0, value),
|
|
541
|
+
writable: false
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
} catch (error) {
|
|
545
|
+
reportError(error);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
function isCompatibleTracingHook(value) {
|
|
549
|
+
try {
|
|
550
|
+
return value[hookBrand] === GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION && hasTracingHookShape(value);
|
|
551
|
+
} catch {
|
|
552
|
+
return false;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
function isCompatibleHookRegistry(value) {
|
|
556
|
+
try {
|
|
557
|
+
return value instanceof Map && value[registryBrand] === GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION;
|
|
558
|
+
} catch {
|
|
559
|
+
return false;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
function getHookRegistry() {
|
|
563
|
+
let descriptor;
|
|
564
|
+
try {
|
|
565
|
+
descriptor = Object.getOwnPropertyDescriptor(
|
|
566
|
+
globalThis,
|
|
567
|
+
GLOBAL_INSTRUMENTATION_HOOKS_KEY
|
|
568
|
+
);
|
|
569
|
+
} catch (error) {
|
|
570
|
+
reportError(error);
|
|
571
|
+
return void 0;
|
|
572
|
+
}
|
|
573
|
+
if (descriptor && "value" in descriptor && isCompatibleHookRegistry(descriptor.value) && (descriptor.configurable || descriptor.enumerable === false)) {
|
|
574
|
+
if (descriptor.configurable || descriptor.writable) {
|
|
575
|
+
try {
|
|
576
|
+
Object.defineProperty(globalThis, GLOBAL_INSTRUMENTATION_HOOKS_KEY, {
|
|
577
|
+
configurable: false,
|
|
578
|
+
enumerable: false,
|
|
579
|
+
value: descriptor.value,
|
|
580
|
+
writable: false
|
|
581
|
+
});
|
|
582
|
+
} catch (error) {
|
|
583
|
+
reportError(error);
|
|
584
|
+
return void 0;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
return descriptor.value;
|
|
588
|
+
}
|
|
589
|
+
if (descriptor && !descriptor.configurable) {
|
|
590
|
+
reportError(new Error("Incompatible global instrumentation hook registry"));
|
|
591
|
+
return void 0;
|
|
592
|
+
}
|
|
593
|
+
const registry = /* @__PURE__ */ new Map();
|
|
594
|
+
try {
|
|
595
|
+
Object.defineProperty(registry, registryBrand, {
|
|
596
|
+
configurable: false,
|
|
597
|
+
enumerable: false,
|
|
598
|
+
value: GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
|
|
599
|
+
writable: false
|
|
600
|
+
});
|
|
601
|
+
} catch (error) {
|
|
602
|
+
reportError(error);
|
|
603
|
+
return void 0;
|
|
604
|
+
}
|
|
605
|
+
try {
|
|
606
|
+
Object.defineProperty(globalThis, GLOBAL_INSTRUMENTATION_HOOKS_KEY, {
|
|
607
|
+
configurable: false,
|
|
608
|
+
enumerable: false,
|
|
609
|
+
value: registry,
|
|
610
|
+
writable: false
|
|
611
|
+
});
|
|
612
|
+
return registry;
|
|
613
|
+
} catch (error) {
|
|
614
|
+
reportError(error);
|
|
615
|
+
return void 0;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
function newGlobalTracingChannel(nameOrChannels) {
|
|
619
|
+
if (typeof nameOrChannels !== "string") {
|
|
620
|
+
return new TracingHook(nameOrChannels);
|
|
621
|
+
}
|
|
622
|
+
const registry = getHookRegistry();
|
|
623
|
+
if (!registry) {
|
|
624
|
+
return inertTracingHook;
|
|
625
|
+
}
|
|
626
|
+
let existing;
|
|
627
|
+
try {
|
|
628
|
+
existing = Map.prototype.get.call(registry, nameOrChannels);
|
|
629
|
+
} catch (error) {
|
|
630
|
+
reportError(error);
|
|
631
|
+
return inertTracingHook;
|
|
632
|
+
}
|
|
633
|
+
if (isCompatibleTracingHook(existing)) {
|
|
634
|
+
installInvocationHook(existing);
|
|
635
|
+
return existing;
|
|
636
|
+
}
|
|
637
|
+
if (existing !== void 0) {
|
|
638
|
+
reportError(
|
|
639
|
+
new Error(`Invalid global instrumentation hook: ${nameOrChannels}`)
|
|
640
|
+
);
|
|
641
|
+
try {
|
|
642
|
+
Map.prototype.delete.call(registry, nameOrChannels);
|
|
643
|
+
} catch (error) {
|
|
644
|
+
reportError(error);
|
|
645
|
+
return inertTracingHook;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
const hook = new TracingHook(nameOrChannels);
|
|
649
|
+
try {
|
|
650
|
+
Map.prototype.set.call(registry, nameOrChannels, hook);
|
|
651
|
+
} catch (error) {
|
|
652
|
+
reportError(error);
|
|
653
|
+
return inertTracingHook;
|
|
654
|
+
}
|
|
655
|
+
return hook;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
// src/isomorph.ts
|
|
659
|
+
var DefaultAsyncLocalStorage = class {
|
|
660
|
+
constructor() {
|
|
661
|
+
}
|
|
662
|
+
enterWith(_) {
|
|
663
|
+
}
|
|
664
|
+
run(_, callback) {
|
|
665
|
+
return callback();
|
|
666
|
+
}
|
|
667
|
+
getStore() {
|
|
668
|
+
return void 0;
|
|
171
669
|
}
|
|
172
670
|
};
|
|
173
671
|
var iso = {
|
|
@@ -180,7 +678,7 @@ var iso = {
|
|
|
180
678
|
getCallerLocation: () => void 0,
|
|
181
679
|
newAsyncLocalStorage: () => new DefaultAsyncLocalStorage(),
|
|
182
680
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
183
|
-
newTracingChannel: (nameOrChannels) =>
|
|
681
|
+
newTracingChannel: (nameOrChannels) => newGlobalTracingChannel(nameOrChannels),
|
|
184
682
|
processOn: (_0, _1) => {
|
|
185
683
|
},
|
|
186
684
|
basename: (filepath) => filepath.split(/[\\/]/).pop() || filepath,
|
|
@@ -196,6 +694,9 @@ var INSTRUMENTATION_NAMES = {
|
|
|
196
694
|
BEDROCK_RUNTIME: "bedrock-runtime",
|
|
197
695
|
BRAINTRUST_JS_LOGGER: "braintrust-js-logger",
|
|
198
696
|
CLAUDE_AGENT_SDK: "claude-agent-sdk",
|
|
697
|
+
CLOUDFLARE_AI_CHAT: "cloudflare-ai-chat",
|
|
698
|
+
CLOUDFLARE_AGENTS: "cloudflare-agents",
|
|
699
|
+
CLOUDFLARE_THINK: "cloudflare-think",
|
|
199
700
|
COHERE: "cohere",
|
|
200
701
|
CURSOR_SDK: "cursor-sdk",
|
|
201
702
|
EVE: "eve",
|
|
@@ -210,6 +711,7 @@ var INSTRUMENTATION_NAMES = {
|
|
|
210
711
|
LANGSMITH: "langsmith",
|
|
211
712
|
MASTRA: "mastra",
|
|
212
713
|
MISTRAL: "mistral",
|
|
714
|
+
OLLAMA: "ollama",
|
|
213
715
|
OPENAI: "openai",
|
|
214
716
|
OPENAI_AGENTS: "openai-agents",
|
|
215
717
|
OPENAI_CODEX: "openai-codex",
|
|
@@ -221,7 +723,7 @@ var INSTRUMENTATION_NAMES = {
|
|
|
221
723
|
var INTERNAL_SPAN_INSTRUMENTATION_NAME = /* @__PURE__ */ Symbol.for(
|
|
222
724
|
"braintrust.spanInstrumentationName"
|
|
223
725
|
);
|
|
224
|
-
var SDK_VERSION = true ? "3.
|
|
726
|
+
var SDK_VERSION = true ? "3.27.0" : "0.0.0";
|
|
225
727
|
function withSpanInstrumentationName(args, instrumentationName) {
|
|
226
728
|
return {
|
|
227
729
|
...args,
|
|
@@ -341,11 +843,21 @@ function defineChannels(pkg, channels, options) {
|
|
|
341
843
|
const tracingChannel2 = () => isomorph_default.newTracingChannel(
|
|
342
844
|
fullChannelName
|
|
343
845
|
);
|
|
846
|
+
const intercept2 = (interceptor) => {
|
|
847
|
+
const hook = tracingChannel2();
|
|
848
|
+
return typeof hook.intercept === "function" ? hook.intercept(interceptor) : () => {
|
|
849
|
+
};
|
|
850
|
+
};
|
|
344
851
|
return [
|
|
345
852
|
key,
|
|
346
853
|
{
|
|
347
854
|
...asyncSpec,
|
|
348
855
|
instrumentationName,
|
|
856
|
+
intercept: intercept2,
|
|
857
|
+
invoke: (target, thisArg, args, additional) => {
|
|
858
|
+
const hook = tracingChannel2();
|
|
859
|
+
return typeof hook.invoke === "function" ? hook.invoke(target, thisArg, args, additional) : Reflect.apply(target, thisArg, args);
|
|
860
|
+
},
|
|
349
861
|
tracingChannel: tracingChannel2,
|
|
350
862
|
tracePromise: (fn, context) => tracingChannel2().tracePromise(
|
|
351
863
|
fn,
|
|
@@ -359,11 +871,21 @@ function defineChannels(pkg, channels, options) {
|
|
|
359
871
|
const tracingChannel = () => isomorph_default.newTracingChannel(
|
|
360
872
|
fullChannelName
|
|
361
873
|
);
|
|
874
|
+
const intercept = (interceptor) => {
|
|
875
|
+
const hook = tracingChannel();
|
|
876
|
+
return typeof hook.intercept === "function" ? hook.intercept(interceptor) : () => {
|
|
877
|
+
};
|
|
878
|
+
};
|
|
362
879
|
return [
|
|
363
880
|
key,
|
|
364
881
|
{
|
|
365
882
|
...syncSpec,
|
|
366
883
|
instrumentationName,
|
|
884
|
+
intercept,
|
|
885
|
+
invoke: (target, thisArg, args, additional) => {
|
|
886
|
+
const hook = tracingChannel();
|
|
887
|
+
return typeof hook.invoke === "function" ? hook.invoke(target, thisArg, args, additional) : Reflect.apply(target, thisArg, args);
|
|
888
|
+
},
|
|
367
889
|
tracingChannel,
|
|
368
890
|
traceSync: (fn, context) => tracingChannel().traceSync(
|
|
369
891
|
fn,
|
|
@@ -451,6 +973,14 @@ var anthropicChannels = defineChannels(
|
|
|
451
973
|
betaMessagesToolRunner: channel({
|
|
452
974
|
channelName: "beta.messages.toolRunner",
|
|
453
975
|
kind: "sync-stream"
|
|
976
|
+
}),
|
|
977
|
+
betaSessionsEventsStream: channel({
|
|
978
|
+
channelName: "beta.sessions.events.stream",
|
|
979
|
+
kind: "async"
|
|
980
|
+
}),
|
|
981
|
+
betaSessionsThreadsEventsStream: channel({
|
|
982
|
+
channelName: "beta.sessions.threads.events.stream",
|
|
983
|
+
kind: "async"
|
|
454
984
|
})
|
|
455
985
|
},
|
|
456
986
|
{ instrumentationName: INSTRUMENTATION_NAMES.ANTHROPIC }
|
|
@@ -566,6 +1096,18 @@ var claudeAgentSDKChannels = defineChannels(
|
|
|
566
1096
|
{ instrumentationName: INSTRUMENTATION_NAMES.CLAUDE_AGENT_SDK }
|
|
567
1097
|
);
|
|
568
1098
|
|
|
1099
|
+
// src/instrumentation/plugins/cloudflare-think-channels.ts
|
|
1100
|
+
var cloudflareThinkChannels = defineChannels(
|
|
1101
|
+
"@cloudflare/think",
|
|
1102
|
+
{
|
|
1103
|
+
runInferenceLoop: channel({
|
|
1104
|
+
channelName: "Think.runInferenceLoop",
|
|
1105
|
+
kind: "async"
|
|
1106
|
+
})
|
|
1107
|
+
},
|
|
1108
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.CLOUDFLARE_THINK }
|
|
1109
|
+
);
|
|
1110
|
+
|
|
569
1111
|
// src/instrumentation/plugins/cursor-sdk-channels.ts
|
|
570
1112
|
var cursorSDKChannels = defineChannels(
|
|
571
1113
|
"@cursor/sdk",
|
|
@@ -642,6 +1184,46 @@ var huggingFaceChannels = defineChannels(
|
|
|
642
1184
|
{ instrumentationName: INSTRUMENTATION_NAMES.HUGGINGFACE }
|
|
643
1185
|
);
|
|
644
1186
|
|
|
1187
|
+
// src/instrumentation/plugins/huggingface-transformers-channels.ts
|
|
1188
|
+
var SUPPORTED_TASKS = /* @__PURE__ */ new Set([
|
|
1189
|
+
"text-generation",
|
|
1190
|
+
"text2text-generation",
|
|
1191
|
+
"summarization",
|
|
1192
|
+
"feature-extraction",
|
|
1193
|
+
"question-answering"
|
|
1194
|
+
]);
|
|
1195
|
+
var pipelineInfo = /* @__PURE__ */ new WeakMap();
|
|
1196
|
+
function isSupportedHuggingFaceTransformersTask(task) {
|
|
1197
|
+
return typeof task === "string" && SUPPORTED_TASKS.has(task);
|
|
1198
|
+
}
|
|
1199
|
+
function registerHuggingFaceTransformersPipeline(pipeline, task, model) {
|
|
1200
|
+
if (typeof task !== "string") {
|
|
1201
|
+
return;
|
|
1202
|
+
}
|
|
1203
|
+
const info = { task };
|
|
1204
|
+
if (typeof model === "string") {
|
|
1205
|
+
info.model = model;
|
|
1206
|
+
}
|
|
1207
|
+
pipelineInfo.set(pipeline, info);
|
|
1208
|
+
}
|
|
1209
|
+
function getHuggingFaceTransformersPipelineInfo(pipeline) {
|
|
1210
|
+
return pipeline ? pipelineInfo.get(pipeline) : void 0;
|
|
1211
|
+
}
|
|
1212
|
+
var huggingFaceTransformersChannels = defineChannels(
|
|
1213
|
+
"@huggingface/transformers",
|
|
1214
|
+
{
|
|
1215
|
+
pipeline: channel({
|
|
1216
|
+
channelName: "pipeline",
|
|
1217
|
+
kind: "async"
|
|
1218
|
+
}),
|
|
1219
|
+
pipelineCall: channel({
|
|
1220
|
+
channelName: "pipeline.call",
|
|
1221
|
+
kind: "async"
|
|
1222
|
+
})
|
|
1223
|
+
},
|
|
1224
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.HUGGINGFACE }
|
|
1225
|
+
);
|
|
1226
|
+
|
|
645
1227
|
// src/instrumentation/plugins/openrouter-agent-channels.ts
|
|
646
1228
|
var openRouterAgentChannels = defineChannels(
|
|
647
1229
|
"@openrouter/agent",
|
|
@@ -750,6 +1332,26 @@ var mistralChannels = defineChannels(
|
|
|
750
1332
|
{ instrumentationName: INSTRUMENTATION_NAMES.MISTRAL }
|
|
751
1333
|
);
|
|
752
1334
|
|
|
1335
|
+
// src/instrumentation/plugins/ollama-channels.ts
|
|
1336
|
+
var ollamaChannels = defineChannels(
|
|
1337
|
+
"ollama",
|
|
1338
|
+
{
|
|
1339
|
+
chat: channel({
|
|
1340
|
+
channelName: "chat",
|
|
1341
|
+
kind: "async"
|
|
1342
|
+
}),
|
|
1343
|
+
generate: channel({
|
|
1344
|
+
channelName: "generate",
|
|
1345
|
+
kind: "async"
|
|
1346
|
+
}),
|
|
1347
|
+
embed: channel({
|
|
1348
|
+
channelName: "embed",
|
|
1349
|
+
kind: "async"
|
|
1350
|
+
})
|
|
1351
|
+
},
|
|
1352
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.OLLAMA }
|
|
1353
|
+
);
|
|
1354
|
+
|
|
753
1355
|
// src/instrumentation/plugins/google-adk-channels.ts
|
|
754
1356
|
var googleADKChannels = defineChannels(
|
|
755
1357
|
"@google/adk",
|
|
@@ -963,6 +1565,18 @@ var strandsAgentSDKChannels = defineChannels(
|
|
|
963
1565
|
{ instrumentationName: INSTRUMENTATION_NAMES.STRANDS_AGENT_SDK }
|
|
964
1566
|
);
|
|
965
1567
|
|
|
1568
|
+
// src/instrumentation/plugins/cloudflare-agents-channels.ts
|
|
1569
|
+
var cloudflareAgentsChannels = defineChannels(
|
|
1570
|
+
"agents",
|
|
1571
|
+
{
|
|
1572
|
+
runAgentTool: channel({
|
|
1573
|
+
channelName: "Agent.runAgentTool",
|
|
1574
|
+
kind: "async"
|
|
1575
|
+
})
|
|
1576
|
+
},
|
|
1577
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.CLOUDFLARE_AGENTS }
|
|
1578
|
+
);
|
|
1579
|
+
|
|
966
1580
|
// src/instrumentation/config.ts
|
|
967
1581
|
var envIntegrationAliases = {
|
|
968
1582
|
openai: "openai",
|
|
@@ -980,6 +1594,9 @@ var envIntegrationAliases = {
|
|
|
980
1594
|
strandsagentsdk: "strandsAgentSDK",
|
|
981
1595
|
"strands-agent-sdk": "strandsAgentSDK",
|
|
982
1596
|
"@strands-agents/sdk": "strandsAgentSDK",
|
|
1597
|
+
agents: "cloudflareAgents",
|
|
1598
|
+
"cloudflare-agents": "cloudflareAgents",
|
|
1599
|
+
cloudflareagents: "cloudflareAgents",
|
|
983
1600
|
anthropic: "anthropic",
|
|
984
1601
|
aisdk: "aisdk",
|
|
985
1602
|
"ai-sdk": "aisdk",
|
|
@@ -987,6 +1604,10 @@ var envIntegrationAliases = {
|
|
|
987
1604
|
vercel: "vercel",
|
|
988
1605
|
claudeagentsdk: "claudeAgentSDK",
|
|
989
1606
|
"claude-agent-sdk": "claudeAgentSDK",
|
|
1607
|
+
cloudflareaichat: "cloudflareAIChat",
|
|
1608
|
+
"cloudflare-ai-chat": "cloudflareAIChat",
|
|
1609
|
+
"@cloudflare/ai-chat": "cloudflareAIChat",
|
|
1610
|
+
cloudflarethink: "cloudflareThink",
|
|
990
1611
|
cursor: "cursor",
|
|
991
1612
|
"cursor-sdk": "cursorSDK",
|
|
992
1613
|
cursorsdk: "cursorSDK",
|
|
@@ -1001,10 +1622,13 @@ var envIntegrationAliases = {
|
|
|
1001
1622
|
"google-genai": "googleGenAI",
|
|
1002
1623
|
googlegenai: "googleGenAI",
|
|
1003
1624
|
huggingface: "huggingface",
|
|
1625
|
+
"@huggingface/transformers": "huggingface",
|
|
1626
|
+
transformers: "huggingface",
|
|
1004
1627
|
openrouter: "openrouter",
|
|
1005
1628
|
openrouteragent: "openrouterAgent",
|
|
1006
1629
|
"openrouter-agent": "openrouterAgent",
|
|
1007
1630
|
mistral: "mistral",
|
|
1631
|
+
ollama: "ollama",
|
|
1008
1632
|
googleadk: "googleADK",
|
|
1009
1633
|
"google-adk": "googleADK",
|
|
1010
1634
|
cohere: "cohere",
|
|
@@ -1039,6 +1663,8 @@ function getDefaultInstrumentationIntegrations() {
|
|
|
1039
1663
|
googleADK: true,
|
|
1040
1664
|
huggingface: true,
|
|
1041
1665
|
claudeAgentSDK: true,
|
|
1666
|
+
cloudflareAIChat: true,
|
|
1667
|
+
cloudflareThink: true,
|
|
1042
1668
|
cursor: true,
|
|
1043
1669
|
cursorSDK: true,
|
|
1044
1670
|
flue: true,
|
|
@@ -1047,6 +1673,7 @@ function getDefaultInstrumentationIntegrations() {
|
|
|
1047
1673
|
openrouter: true,
|
|
1048
1674
|
openrouterAgent: true,
|
|
1049
1675
|
mistral: true,
|
|
1676
|
+
ollama: true,
|
|
1050
1677
|
cohere: true,
|
|
1051
1678
|
groq: true,
|
|
1052
1679
|
bedrock: true,
|
|
@@ -1058,7 +1685,8 @@ function getDefaultInstrumentationIntegrations() {
|
|
|
1058
1685
|
langgraph: true,
|
|
1059
1686
|
langsmith: true,
|
|
1060
1687
|
piCodingAgent: true,
|
|
1061
|
-
strandsAgentSDK: true
|
|
1688
|
+
strandsAgentSDK: true,
|
|
1689
|
+
cloudflareAgents: true
|
|
1062
1690
|
};
|
|
1063
1691
|
}
|
|
1064
1692
|
function readDisabledInstrumentationEnvConfig(disabledList) {
|
|
@@ -1291,9 +1919,29 @@ var langChainChannels = defineChannels(
|
|
|
1291
1919
|
{ instrumentationName: INSTRUMENTATION_NAMES.LANGCHAIN }
|
|
1292
1920
|
);
|
|
1293
1921
|
|
|
1922
|
+
// src/instrumentation/plugins/cloudflare-ai-chat-channels.ts
|
|
1923
|
+
var cloudflareAIChatChannels = defineChannels(
|
|
1924
|
+
"@cloudflare/ai-chat",
|
|
1925
|
+
{
|
|
1926
|
+
runExclusiveChatTurn: channel({
|
|
1927
|
+
channelName: "AIChatAgent._runExclusiveChatTurn",
|
|
1928
|
+
kind: "async"
|
|
1929
|
+
}),
|
|
1930
|
+
onChatResponse: channel({
|
|
1931
|
+
channelName: "AIChatAgent.onChatResponse",
|
|
1932
|
+
kind: "sync-stream"
|
|
1933
|
+
})
|
|
1934
|
+
},
|
|
1935
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.CLOUDFLARE_AI_CHAT }
|
|
1936
|
+
);
|
|
1937
|
+
|
|
1294
1938
|
export {
|
|
1295
1939
|
__export,
|
|
1296
|
-
|
|
1940
|
+
GLOBAL_INSTRUMENTATION_HOOKS_KEY,
|
|
1941
|
+
GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
|
|
1942
|
+
GLOBAL_INSTRUMENTATION_HOOKS_REGISTRY_BRAND,
|
|
1943
|
+
GLOBAL_INSTRUMENTATION_HOOK_BRAND,
|
|
1944
|
+
setGlobalHookErrorReporter,
|
|
1297
1945
|
isomorph_default,
|
|
1298
1946
|
INSTRUMENTATION_NAMES,
|
|
1299
1947
|
withSpanInstrumentationName,
|
|
@@ -1306,13 +1954,19 @@ export {
|
|
|
1306
1954
|
aiSDKChannels,
|
|
1307
1955
|
harnessAgentChannels,
|
|
1308
1956
|
claudeAgentSDKChannels,
|
|
1957
|
+
cloudflareThinkChannels,
|
|
1309
1958
|
cursorSDKChannels,
|
|
1310
1959
|
openAIAgentsCoreChannels,
|
|
1311
1960
|
googleGenAIChannels,
|
|
1312
1961
|
huggingFaceChannels,
|
|
1962
|
+
isSupportedHuggingFaceTransformersTask,
|
|
1963
|
+
registerHuggingFaceTransformersPipeline,
|
|
1964
|
+
getHuggingFaceTransformersPipelineInfo,
|
|
1965
|
+
huggingFaceTransformersChannels,
|
|
1313
1966
|
openRouterAgentChannels,
|
|
1314
1967
|
openRouterChannels,
|
|
1315
1968
|
mistralChannels,
|
|
1969
|
+
ollamaChannels,
|
|
1316
1970
|
googleADKChannels,
|
|
1317
1971
|
cohereChannels,
|
|
1318
1972
|
groqChannels,
|
|
@@ -1327,6 +1981,8 @@ export {
|
|
|
1327
1981
|
langSmithChannels,
|
|
1328
1982
|
piCodingAgentChannels,
|
|
1329
1983
|
strandsAgentSDKChannels,
|
|
1984
|
+
cloudflareAIChatChannels,
|
|
1985
|
+
cloudflareAgentsChannels,
|
|
1330
1986
|
getDefaultInstrumentationIntegrations,
|
|
1331
1987
|
readDisabledInstrumentationEnvConfig,
|
|
1332
1988
|
isInstrumentationIntegrationDisabled,
|