braintrust 3.20.0 → 3.22.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 +20 -0
- package/README.md +6 -0
- package/dev/dist/index.d.mts +1338 -199
- package/dev/dist/index.d.ts +1338 -199
- package/dev/dist/index.js +2904 -997
- package/dev/dist/index.mjs +2418 -511
- package/dist/apply-auto-instrumentation.js +781 -199
- package/dist/apply-auto-instrumentation.mjs +588 -6
- package/dist/auto-instrumentations/bundler/esbuild.cjs +594 -2
- package/dist/auto-instrumentations/bundler/esbuild.d.mts +2 -2
- package/dist/auto-instrumentations/bundler/esbuild.d.ts +2 -2
- package/dist/auto-instrumentations/bundler/esbuild.mjs +3 -3
- package/dist/auto-instrumentations/bundler/next.cjs +594 -2
- package/dist/auto-instrumentations/bundler/next.mjs +4 -4
- package/dist/auto-instrumentations/bundler/rollup.cjs +594 -2
- package/dist/auto-instrumentations/bundler/rollup.d.mts +2 -2
- package/dist/auto-instrumentations/bundler/rollup.d.ts +2 -2
- package/dist/auto-instrumentations/bundler/rollup.mjs +3 -3
- package/dist/auto-instrumentations/bundler/vite.cjs +594 -2
- package/dist/auto-instrumentations/bundler/vite.d.mts +2 -2
- package/dist/auto-instrumentations/bundler/vite.d.ts +2 -2
- package/dist/auto-instrumentations/bundler/vite.mjs +3 -3
- package/dist/auto-instrumentations/bundler/webpack-loader.cjs +593 -9
- package/dist/auto-instrumentations/bundler/webpack-loader.d.ts +68 -1
- package/dist/auto-instrumentations/bundler/webpack.cjs +594 -2
- package/dist/auto-instrumentations/bundler/webpack.d.mts +2 -2
- package/dist/auto-instrumentations/bundler/webpack.d.ts +2 -2
- package/dist/auto-instrumentations/bundler/webpack.mjs +4 -4
- package/dist/auto-instrumentations/{chunk-W4E36GIW.mjs → chunk-BRQX23KL.mjs} +16 -0
- package/dist/auto-instrumentations/chunk-M6DLIJ2Z.mjs +784 -0
- package/dist/auto-instrumentations/{chunk-K74TZGGM.mjs → chunk-T6J4C7LX.mjs} +1 -1
- package/dist/auto-instrumentations/{chunk-S4374IP6.mjs → chunk-TKRPRPGD.mjs} +4 -6
- package/dist/auto-instrumentations/chunk-VT6DDNKM.mjs +856 -0
- package/dist/auto-instrumentations/hook.mjs +824 -56
- package/dist/auto-instrumentations/index.cjs +16 -0
- package/dist/auto-instrumentations/index.d.mts +2 -3
- package/dist/auto-instrumentations/index.d.ts +2 -3
- package/dist/auto-instrumentations/index.mjs +1 -1
- package/dist/auto-instrumentations/loader/cjs-patch.cjs +578 -4
- package/dist/auto-instrumentations/loader/cjs-patch.d.mts +1 -1
- package/dist/auto-instrumentations/loader/cjs-patch.d.ts +1 -1
- package/dist/auto-instrumentations/loader/cjs-patch.mjs +3 -7
- package/dist/auto-instrumentations/loader/esm-hook.mjs +2 -6
- package/dist/auto-instrumentations/{plugin-D7nDswtC.d.mts → plugin-D0KHwSJv.d.mts} +1 -1
- package/dist/auto-instrumentations/{plugin-D7nDswtC.d.ts → plugin-G6fgxk1b.d.ts} +1 -1
- package/dist/auto-instrumentations/types-RNPaKi9o.d.mts +70 -0
- package/dist/auto-instrumentations/types-RNPaKi9o.d.ts +70 -0
- package/dist/browser.d.mts +4411 -719
- package/dist/browser.d.ts +4411 -719
- package/dist/browser.js +4274 -480
- package/dist/browser.mjs +4274 -480
- package/dist/{chunk-LPC4W2WX.js → chunk-BFGIH2ZJ.js} +4 -0
- package/dist/{chunk-Y7W7WP6H.mjs → chunk-KMGUTPB7.mjs} +4 -0
- package/dist/{chunk-POCCIJAL.js → chunk-MWVVR5LR.js} +3278 -1334
- package/dist/{chunk-F73OMF66.mjs → chunk-ZG2O3XVF.mjs} +2542 -598
- package/dist/cli.js +2338 -419
- package/dist/edge-light.d.mts +1 -1
- package/dist/edge-light.d.ts +1 -1
- package/dist/edge-light.js +4274 -480
- package/dist/edge-light.mjs +4274 -480
- package/dist/index.d.mts +4926 -1234
- package/dist/index.d.ts +4926 -1234
- package/dist/index.js +2303 -435
- package/dist/index.mjs +1914 -46
- package/dist/instrumentation/index.d.mts +1026 -20
- package/dist/instrumentation/index.d.ts +1026 -20
- package/dist/instrumentation/index.js +3864 -483
- package/dist/instrumentation/index.mjs +3862 -483
- 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 +4274 -480
- package/dist/workerd.mjs +4274 -480
- package/licenses/import-in-the-middle/LICENSE +201 -0
- package/licenses/import-in-the-middle/LICENSE-3rdparty.csv +4 -0
- package/licenses/import-in-the-middle/NOTICE +34 -0
- package/licenses/orchestrion-js/LICENSE +202 -0
- package/licenses/orchestrion-js/LICENSE-3rdparty.csv +8 -0
- package/licenses/orchestrion-js/NOTICE +3 -0
- package/licenses/require-in-the-middle/LICENSE +23 -0
- package/package.json +16 -4
- package/util/dist/index.d.mts +1 -0
- package/util/dist/index.d.ts +1 -0
- package/util/dist/index.js +4 -4
- package/util/dist/index.mjs +2 -2
- package/dist/auto-instrumentations/chunk-J57YF7WS.mjs +0 -208
- package/dist/auto-instrumentations/chunk-QFMACSOL.mjs +0 -280
|
@@ -38,7 +38,583 @@ var import_node_path = require("path");
|
|
|
38
38
|
|
|
39
39
|
// src/auto-instrumentations/bundler/plugin.ts
|
|
40
40
|
var import_unplugin = require("unplugin");
|
|
41
|
-
|
|
41
|
+
|
|
42
|
+
// src/auto-instrumentations/orchestrion-js/matcher.ts
|
|
43
|
+
var import_semifies = __toESM(require("semifies"));
|
|
44
|
+
|
|
45
|
+
// src/auto-instrumentations/orchestrion-js/transformer.ts
|
|
46
|
+
var import_esquery2 = __toESM(require("esquery"));
|
|
47
|
+
var import_astring = require("astring");
|
|
48
|
+
var import_meriyah2 = require("meriyah");
|
|
49
|
+
var import_source_map = require("source-map");
|
|
50
|
+
|
|
51
|
+
// src/auto-instrumentations/orchestrion-js/transforms.ts
|
|
52
|
+
var import_esquery = __toESM(require("esquery"));
|
|
53
|
+
var import_meriyah = require("meriyah");
|
|
54
|
+
var tracingChannelPredicate = (node) => node.declarations?.[0]?.id?.properties?.[0]?.value?.name === "tr_ch_apm_tracingChannel";
|
|
55
|
+
var CHANNEL_REGEX = /[^\w]/g;
|
|
56
|
+
function formatChannelVariable(channelName) {
|
|
57
|
+
return `tr_ch_apm$${channelName.replace(CHANNEL_REGEX, "_")}`;
|
|
58
|
+
}
|
|
59
|
+
var transforms = {
|
|
60
|
+
tracingChannelImport({ dcModule, moduleType }, node) {
|
|
61
|
+
if (node.body.some(tracingChannelPredicate)) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const options = { module: moduleType === "esm" };
|
|
65
|
+
const index = node.body.findIndex(
|
|
66
|
+
(child) => child.directive === "use strict"
|
|
67
|
+
);
|
|
68
|
+
const dc = moduleType === "esm" ? `import tr_ch_apm_dc from "${dcModule}"` : `const tr_ch_apm_dc = ${"require"}("${dcModule}")`;
|
|
69
|
+
const tracingChannel = "const { tracingChannel: tr_ch_apm_tracingChannel } = tr_ch_apm_dc";
|
|
70
|
+
const hasSubscribers = `const tr_ch_apm_hasSubscribers = ch => ch.start.hasSubscribers
|
|
71
|
+
|| ch.end.hasSubscribers
|
|
72
|
+
|| ch.asyncStart.hasSubscribers
|
|
73
|
+
|| ch.asyncEnd.hasSubscribers
|
|
74
|
+
|| ch.error.hasSubscribers`;
|
|
75
|
+
node.body.splice(
|
|
76
|
+
index + 1,
|
|
77
|
+
0,
|
|
78
|
+
(0, import_meriyah.parse)(dc, options).body[0],
|
|
79
|
+
(0, import_meriyah.parse)(tracingChannel, options).body[0],
|
|
80
|
+
(0, import_meriyah.parse)(hasSubscribers, options).body[0]
|
|
81
|
+
);
|
|
82
|
+
},
|
|
83
|
+
tracingChannelDeclaration(state, node) {
|
|
84
|
+
const {
|
|
85
|
+
channelName,
|
|
86
|
+
module: { name }
|
|
87
|
+
} = state;
|
|
88
|
+
const channelVariable = formatChannelVariable(channelName);
|
|
89
|
+
if (node.body.some(
|
|
90
|
+
(child) => child.declarations?.[0]?.id?.name === channelVariable
|
|
91
|
+
)) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
transforms.tracingChannelImport(state, node, null, []);
|
|
95
|
+
const index = node.body.findIndex(tracingChannelPredicate);
|
|
96
|
+
const code = `
|
|
97
|
+
const ${channelVariable} = tr_ch_apm_tracingChannel("orchestrion:${name}:${channelName}")
|
|
98
|
+
`;
|
|
99
|
+
node.body.splice(index + 1, 0, (0, import_meriyah.parse)(code).body[0]);
|
|
100
|
+
},
|
|
101
|
+
traceCallback: traceAny,
|
|
102
|
+
tracePromise: traceAny,
|
|
103
|
+
traceSync: traceAny
|
|
104
|
+
};
|
|
105
|
+
function traceAny(state, node, _parent, ancestry) {
|
|
106
|
+
const program = ancestry[ancestry.length - 1];
|
|
107
|
+
if (node.type === "ClassDeclaration" || node.type === "ClassExpression") {
|
|
108
|
+
traceInstanceMethod(state, node, program);
|
|
109
|
+
} else {
|
|
110
|
+
traceFunction(state, node, program);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function traceFunction(state, node, program) {
|
|
114
|
+
transforms.tracingChannelDeclaration(state, program, null, []);
|
|
115
|
+
const { functionQuery } = state;
|
|
116
|
+
const methodName = "methodName" in functionQuery ? functionQuery.methodName : void 0;
|
|
117
|
+
const privateMethodName = "privateMethodName" in functionQuery ? functionQuery.privateMethodName : void 0;
|
|
118
|
+
const functionName = "functionName" in functionQuery ? functionQuery.functionName : void 0;
|
|
119
|
+
const isConstructor = methodName === "constructor" || !methodName && !privateMethodName && !functionName;
|
|
120
|
+
const type = isConstructor ? "ArrowFunctionExpression" : "FunctionExpression";
|
|
121
|
+
node.body = wrap(
|
|
122
|
+
state,
|
|
123
|
+
{
|
|
124
|
+
type,
|
|
125
|
+
params: node.params,
|
|
126
|
+
body: node.body,
|
|
127
|
+
async: node.async,
|
|
128
|
+
expression: false,
|
|
129
|
+
generator: node.generator
|
|
130
|
+
},
|
|
131
|
+
program
|
|
132
|
+
);
|
|
133
|
+
node.generator = false;
|
|
134
|
+
node.async = false;
|
|
135
|
+
wrapSuper(node);
|
|
136
|
+
}
|
|
137
|
+
function traceInstanceMethod(state, node, program) {
|
|
138
|
+
const { functionQuery, operator } = state;
|
|
139
|
+
const { methodName } = functionQuery;
|
|
140
|
+
if (!methodName) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const classBody = node.body;
|
|
144
|
+
if (classBody.body.some(({ key }) => key.name === methodName)) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
let ctor = classBody.body.find(({ kind }) => kind === "constructor");
|
|
148
|
+
transforms.tracingChannelDeclaration(state, program, null, []);
|
|
149
|
+
if (!ctor) {
|
|
150
|
+
ctor = (0, import_meriyah.parse)(
|
|
151
|
+
node.superClass ? "class A extends Object { constructor (...args) { super(...args) } }" : "class A { constructor () {} }"
|
|
152
|
+
).body[0].body.body[0];
|
|
153
|
+
classBody.body.unshift(ctor);
|
|
154
|
+
}
|
|
155
|
+
const ctorBody = (0, import_meriyah.parse)(`
|
|
156
|
+
const __apm$${methodName} = this["${methodName}"]
|
|
157
|
+
this["${methodName}"] = function () {}
|
|
158
|
+
`).body;
|
|
159
|
+
const fn = ctorBody[1].expression.right;
|
|
160
|
+
fn.async = operator === "tracePromise";
|
|
161
|
+
fn.body = wrap(
|
|
162
|
+
state,
|
|
163
|
+
{ type: "Identifier", name: `__apm$${methodName}` },
|
|
164
|
+
program
|
|
165
|
+
);
|
|
166
|
+
wrapSuper(fn);
|
|
167
|
+
ctor.value.body.body.push(...ctorBody);
|
|
168
|
+
}
|
|
169
|
+
function wrap(state, node, program) {
|
|
170
|
+
const { operator, moduleVersion } = state;
|
|
171
|
+
const wrapper = operator === "traceCallback" ? wrapCallback(state) : operator === "tracePromise" ? wrapPromise(state) : wrapSync(state);
|
|
172
|
+
const block = wrapper.body[0].body;
|
|
173
|
+
const common = (0, import_meriyah.parse)(
|
|
174
|
+
node.type === "ArrowFunctionExpression" ? `
|
|
175
|
+
const __apm$ctx = {
|
|
176
|
+
arguments,
|
|
177
|
+
moduleVersion: ${JSON.stringify(moduleVersion)}
|
|
178
|
+
};
|
|
179
|
+
const __apm$traced = () => {
|
|
180
|
+
const __apm$wrapped = () => {};
|
|
181
|
+
return __apm$wrapped(...arguments);
|
|
182
|
+
};
|
|
183
|
+
` : `
|
|
184
|
+
const __apm$ctx = {
|
|
185
|
+
arguments,
|
|
186
|
+
self: this,
|
|
187
|
+
moduleVersion: ${JSON.stringify(moduleVersion)}
|
|
188
|
+
};
|
|
189
|
+
const __apm$traced = () => {
|
|
190
|
+
const __apm$wrapped = () => {};
|
|
191
|
+
return __apm$wrapped.apply(this, arguments);
|
|
192
|
+
};
|
|
193
|
+
`
|
|
194
|
+
).body;
|
|
195
|
+
block.body.unshift(...common);
|
|
196
|
+
import_esquery.default.query(block, "[id.name=__apm$wrapped]")[0].init = node;
|
|
197
|
+
return block;
|
|
198
|
+
}
|
|
199
|
+
function wrapSuper(node) {
|
|
200
|
+
const members = /* @__PURE__ */ new Set();
|
|
201
|
+
import_esquery.default.traverse(
|
|
202
|
+
node.body,
|
|
203
|
+
import_esquery.default.parse("[object.type=Super]"),
|
|
204
|
+
(node2, parent) => {
|
|
205
|
+
const { name } = node2.property;
|
|
206
|
+
let child;
|
|
207
|
+
if (parent.callee) {
|
|
208
|
+
const { expression } = (0, import_meriyah.parse)(`__apm$super['${name}'].call(this)`).body[0];
|
|
209
|
+
parent.callee = child = expression.callee;
|
|
210
|
+
parent.arguments.unshift(...expression.arguments);
|
|
211
|
+
} else {
|
|
212
|
+
parent.expression = child = (0, import_meriyah.parse)(`__apm$super['${name}']`).body[0];
|
|
213
|
+
}
|
|
214
|
+
child.computed = parent.callee.computed;
|
|
215
|
+
child.optional = parent.callee.optional;
|
|
216
|
+
members.add(name);
|
|
217
|
+
}
|
|
218
|
+
);
|
|
219
|
+
for (const name of members) {
|
|
220
|
+
const member = (0, import_meriyah.parse)(`
|
|
221
|
+
class Wrapper {
|
|
222
|
+
wrapper () {
|
|
223
|
+
__apm$super['${name}'] = super['${name}']
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
`).body[0].body.body[0].value.body.body[0];
|
|
227
|
+
node.body.body.unshift(member);
|
|
228
|
+
}
|
|
229
|
+
if (members.size > 0) {
|
|
230
|
+
node.body.body.unshift((0, import_meriyah.parse)("const __apm$super = {}").body[0]);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
function wrapCallback(state) {
|
|
234
|
+
const {
|
|
235
|
+
channelName,
|
|
236
|
+
functionQuery: { callbackIndex = -1 }
|
|
237
|
+
} = state;
|
|
238
|
+
const channelVariable = formatChannelVariable(channelName);
|
|
239
|
+
return (0, import_meriyah.parse)(`
|
|
240
|
+
function wrapper () {
|
|
241
|
+
const __apm$cb = Array.prototype.at.call(arguments, ${callbackIndex});
|
|
242
|
+
|
|
243
|
+
if (!${channelVariable}.start.hasSubscribers) return __apm$traced();
|
|
244
|
+
|
|
245
|
+
function __apm$wrappedCb(err, res) {
|
|
246
|
+
if (err) {
|
|
247
|
+
__apm$ctx.error = err;
|
|
248
|
+
${channelVariable}.error.publish(__apm$ctx);
|
|
249
|
+
} else {
|
|
250
|
+
__apm$ctx.result = res;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
${channelVariable}.asyncStart.runStores(__apm$ctx, () => {
|
|
254
|
+
try {
|
|
255
|
+
if (__apm$cb) {
|
|
256
|
+
return __apm$cb.apply(this, arguments);
|
|
257
|
+
}
|
|
258
|
+
} finally {
|
|
259
|
+
${channelVariable}.asyncEnd.publish(__apm$ctx);
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (typeof __apm$cb !== 'function') {
|
|
265
|
+
return __apm$traced();
|
|
266
|
+
}
|
|
267
|
+
Array.prototype.splice.call(arguments, ${callbackIndex}, 1, __apm$wrappedCb);
|
|
268
|
+
|
|
269
|
+
return ${channelVariable}.start.runStores(__apm$ctx, () => {
|
|
270
|
+
try {
|
|
271
|
+
return __apm$traced();
|
|
272
|
+
} catch (err) {
|
|
273
|
+
__apm$ctx.error = err;
|
|
274
|
+
${channelVariable}.error.publish(__apm$ctx);
|
|
275
|
+
throw err;
|
|
276
|
+
} finally {
|
|
277
|
+
__apm$ctx.self ??= this;
|
|
278
|
+
${channelVariable}.end.publish(__apm$ctx);
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
`);
|
|
283
|
+
}
|
|
284
|
+
function wrapPromise(state) {
|
|
285
|
+
const { channelName } = state;
|
|
286
|
+
const channelVariable = formatChannelVariable(channelName);
|
|
287
|
+
return (0, import_meriyah.parse)(`
|
|
288
|
+
function wrapper () {
|
|
289
|
+
if (!tr_ch_apm_hasSubscribers(${channelVariable})) return __apm$traced();
|
|
290
|
+
|
|
291
|
+
return ${channelVariable}.start.runStores(__apm$ctx, () => {
|
|
292
|
+
try {
|
|
293
|
+
let promise = __apm$traced();
|
|
294
|
+
if (typeof promise?.then !== 'function') {
|
|
295
|
+
__apm$ctx.result = promise;
|
|
296
|
+
return promise;
|
|
297
|
+
}
|
|
298
|
+
// Mirror Node.js core diagnostics_channel behaviour: for native Promise
|
|
299
|
+
// instances, chain normally (safe since there is no subclass API to
|
|
300
|
+
// preserve). For Promise subclasses and other thenables, side-chain the
|
|
301
|
+
// callbacks for event publishing and return the original so that any
|
|
302
|
+
// subclass-specific methods (e.g. APIPromise.withResponse()) remain
|
|
303
|
+
// accessible to the caller.
|
|
304
|
+
if (promise instanceof Promise && promise.constructor === Promise) {
|
|
305
|
+
return promise.then(
|
|
306
|
+
result => {
|
|
307
|
+
__apm$ctx.result = result;
|
|
308
|
+
${channelVariable}.asyncStart.publish(__apm$ctx);
|
|
309
|
+
${channelVariable}.asyncEnd.publish(__apm$ctx);
|
|
310
|
+
return result;
|
|
311
|
+
},
|
|
312
|
+
err => {
|
|
313
|
+
__apm$ctx.error = err;
|
|
314
|
+
${channelVariable}.error.publish(__apm$ctx);
|
|
315
|
+
${channelVariable}.asyncStart.publish(__apm$ctx);
|
|
316
|
+
${channelVariable}.asyncEnd.publish(__apm$ctx);
|
|
317
|
+
throw err;
|
|
318
|
+
}
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
promise.then(
|
|
322
|
+
result => {
|
|
323
|
+
__apm$ctx.result = result;
|
|
324
|
+
${channelVariable}.asyncStart.publish(__apm$ctx);
|
|
325
|
+
${channelVariable}.asyncEnd.publish(__apm$ctx);
|
|
326
|
+
},
|
|
327
|
+
err => {
|
|
328
|
+
__apm$ctx.error = err;
|
|
329
|
+
${channelVariable}.error.publish(__apm$ctx);
|
|
330
|
+
${channelVariable}.asyncStart.publish(__apm$ctx);
|
|
331
|
+
${channelVariable}.asyncEnd.publish(__apm$ctx);
|
|
332
|
+
}
|
|
333
|
+
);
|
|
334
|
+
return promise;
|
|
335
|
+
} catch (err) {
|
|
336
|
+
__apm$ctx.error = err;
|
|
337
|
+
${channelVariable}.error.publish(__apm$ctx);
|
|
338
|
+
throw err;
|
|
339
|
+
} finally {
|
|
340
|
+
__apm$ctx.self ??= this;
|
|
341
|
+
${channelVariable}.end.publish(__apm$ctx);
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
`);
|
|
346
|
+
}
|
|
347
|
+
function wrapSync(state) {
|
|
348
|
+
const { channelName } = state;
|
|
349
|
+
const channelVariable = formatChannelVariable(channelName);
|
|
350
|
+
return (0, import_meriyah.parse)(`
|
|
351
|
+
function wrapper () {
|
|
352
|
+
if (!tr_ch_apm_hasSubscribers(${channelVariable})) return __apm$traced();
|
|
353
|
+
|
|
354
|
+
return ${channelVariable}.start.runStores(__apm$ctx, () => {
|
|
355
|
+
try {
|
|
356
|
+
const result = __apm$traced();
|
|
357
|
+
__apm$ctx.result = result;
|
|
358
|
+
return result;
|
|
359
|
+
} catch (err) {
|
|
360
|
+
__apm$ctx.error = err;
|
|
361
|
+
${channelVariable}.error.publish(__apm$ctx);
|
|
362
|
+
throw err;
|
|
363
|
+
} finally {
|
|
364
|
+
__apm$ctx.self ??= this;
|
|
365
|
+
${channelVariable}.end.publish(__apm$ctx);
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
`);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// src/auto-instrumentations/orchestrion-js/transformer.ts
|
|
373
|
+
var Transformer = class {
|
|
374
|
+
moduleName;
|
|
375
|
+
version;
|
|
376
|
+
filePath;
|
|
377
|
+
configs = [];
|
|
378
|
+
dcModule;
|
|
379
|
+
constructor(moduleName, version, filePath, configs, dcModule) {
|
|
380
|
+
this.moduleName = moduleName;
|
|
381
|
+
this.version = version;
|
|
382
|
+
this.filePath = filePath;
|
|
383
|
+
this.configs = configs;
|
|
384
|
+
this.dcModule = dcModule;
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Instruments `code` by injecting diagnostics_channel tracing around the
|
|
388
|
+
* target functions defined by this transformer's configs.
|
|
389
|
+
*/
|
|
390
|
+
transform(code, moduleType) {
|
|
391
|
+
if (Buffer.isBuffer(code)) {
|
|
392
|
+
code = code.toString();
|
|
393
|
+
}
|
|
394
|
+
if (!code) {
|
|
395
|
+
return { code };
|
|
396
|
+
}
|
|
397
|
+
let ast;
|
|
398
|
+
let aliases = {};
|
|
399
|
+
let injectionCount = 0;
|
|
400
|
+
for (const config of this.configs) {
|
|
401
|
+
const { astQuery, functionQuery } = config;
|
|
402
|
+
if (!ast) {
|
|
403
|
+
const options = {
|
|
404
|
+
loc: true,
|
|
405
|
+
ranges: true,
|
|
406
|
+
raw: true,
|
|
407
|
+
module: moduleType === "esm"
|
|
408
|
+
};
|
|
409
|
+
try {
|
|
410
|
+
ast = (0, import_meriyah2.parse)(code, options);
|
|
411
|
+
} catch {
|
|
412
|
+
ast = (0, import_meriyah2.parse)(code, { ...options, module: !options.module });
|
|
413
|
+
}
|
|
414
|
+
if (moduleType === "esm") {
|
|
415
|
+
aliases = this.collectExportAliases(ast);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
const resolvedFunctionQuery = this.resolveExportAlias(
|
|
419
|
+
functionQuery,
|
|
420
|
+
aliases
|
|
421
|
+
);
|
|
422
|
+
const query = astQuery || this.fromFunctionQuery(resolvedFunctionQuery);
|
|
423
|
+
const state = {
|
|
424
|
+
...config,
|
|
425
|
+
dcModule: this.dcModule,
|
|
426
|
+
moduleType,
|
|
427
|
+
moduleVersion: this.version,
|
|
428
|
+
functionQuery: resolvedFunctionQuery,
|
|
429
|
+
operator: this.getOperator(resolvedFunctionQuery.kind)
|
|
430
|
+
};
|
|
431
|
+
import_esquery2.default.traverse(ast, import_esquery2.default.parse(query), (...args) => {
|
|
432
|
+
injectionCount++;
|
|
433
|
+
this.visit(state, ...args);
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
if (injectionCount === 0 && this.configs.length > 0) {
|
|
437
|
+
const names = this.configs.map(({ astQuery, functionQuery }) => {
|
|
438
|
+
const resolvedQuery = this.resolveExportAlias(functionQuery, aliases);
|
|
439
|
+
const queryName = (q) => q.methodName || q.privateMethodName || q.functionName || q.propertyName || astQuery || "unknown";
|
|
440
|
+
const originalName = queryName(functionQuery);
|
|
441
|
+
const originalAlias = functionQuery.className || functionQuery.functionName;
|
|
442
|
+
const resolvedAlias = resolvedQuery.className || resolvedQuery.functionName;
|
|
443
|
+
if (originalAlias && originalAlias !== resolvedAlias) {
|
|
444
|
+
return `${originalAlias} (local name: ${resolvedAlias})`;
|
|
445
|
+
}
|
|
446
|
+
return originalName;
|
|
447
|
+
});
|
|
448
|
+
throw new Error(
|
|
449
|
+
`Failed to find injection points for: ${JSON.stringify(names)}`
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
if (ast) {
|
|
453
|
+
const file = `${this.moduleName}/${this.filePath}`;
|
|
454
|
+
const sourceMap = new import_source_map.SourceMapGenerator({ file });
|
|
455
|
+
const transformedCode = (0, import_astring.generate)(ast, { sourceMap });
|
|
456
|
+
const map = sourceMap.toString();
|
|
457
|
+
return { code: transformedCode, map };
|
|
458
|
+
}
|
|
459
|
+
return { code };
|
|
460
|
+
}
|
|
461
|
+
free() {
|
|
462
|
+
}
|
|
463
|
+
visit(state, ...args) {
|
|
464
|
+
const transform = transforms[state.operator];
|
|
465
|
+
const { index = 0 } = state.functionQuery;
|
|
466
|
+
const [node] = args;
|
|
467
|
+
const type = node.init?.type || node.type;
|
|
468
|
+
if (type !== "ClassDeclaration" && type !== "ClassExpression") {
|
|
469
|
+
if (node.type === "VariableDeclarator") {
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
state.functionIndex = state.functionIndex === void 0 ? 0 : state.functionIndex + 1;
|
|
473
|
+
if (index !== null && index !== state.functionIndex) {
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
transform(state, ...args);
|
|
478
|
+
}
|
|
479
|
+
getOperator(kind) {
|
|
480
|
+
switch (kind) {
|
|
481
|
+
case "Async":
|
|
482
|
+
return "tracePromise";
|
|
483
|
+
case "Callback":
|
|
484
|
+
return "traceCallback";
|
|
485
|
+
case "Sync":
|
|
486
|
+
return "traceSync";
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
collectExportAliases(ast) {
|
|
490
|
+
const aliases = {};
|
|
491
|
+
for (const node of ast.body) {
|
|
492
|
+
if (node.type === "ExportNamedDeclaration" && !node.source) {
|
|
493
|
+
for (const spec of node.specifiers) {
|
|
494
|
+
if (spec.exported && spec.local) {
|
|
495
|
+
const exportedName = spec.exported.name ?? spec.exported.value;
|
|
496
|
+
const localName = spec.local.name ?? spec.local.value;
|
|
497
|
+
if (exportedName && localName) {
|
|
498
|
+
aliases[exportedName] = localName;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
return aliases;
|
|
505
|
+
}
|
|
506
|
+
resolveExportAlias(functionQuery, aliases) {
|
|
507
|
+
if (!("isExportAlias" in functionQuery) || !functionQuery.isExportAlias) {
|
|
508
|
+
return functionQuery;
|
|
509
|
+
}
|
|
510
|
+
if ("className" in functionQuery && aliases[functionQuery.className]) {
|
|
511
|
+
return {
|
|
512
|
+
...functionQuery,
|
|
513
|
+
className: aliases[functionQuery.className]
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
if ("functionName" in functionQuery && aliases[functionQuery.functionName]) {
|
|
517
|
+
return {
|
|
518
|
+
...functionQuery,
|
|
519
|
+
functionName: aliases[functionQuery.functionName]
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
return functionQuery;
|
|
523
|
+
}
|
|
524
|
+
functionQueryLabel(functionQuery) {
|
|
525
|
+
if ("methodName" in functionQuery) {
|
|
526
|
+
return functionQuery.methodName;
|
|
527
|
+
}
|
|
528
|
+
if ("privateMethodName" in functionQuery) {
|
|
529
|
+
return functionQuery.privateMethodName;
|
|
530
|
+
}
|
|
531
|
+
if ("functionName" in functionQuery) {
|
|
532
|
+
return functionQuery.functionName;
|
|
533
|
+
}
|
|
534
|
+
if ("propertyName" in functionQuery) {
|
|
535
|
+
return functionQuery.propertyName;
|
|
536
|
+
}
|
|
537
|
+
return "unknown";
|
|
538
|
+
}
|
|
539
|
+
fromFunctionQuery(functionQuery) {
|
|
540
|
+
const queries = [];
|
|
541
|
+
if ("className" in functionQuery) {
|
|
542
|
+
const { className } = functionQuery;
|
|
543
|
+
const methodName = this.functionQueryLabel(functionQuery);
|
|
544
|
+
const keyType = "privateMethodName" in functionQuery ? "PrivateIdentifier" : "Identifier";
|
|
545
|
+
queries.push(
|
|
546
|
+
`[id.name="${className}"]`,
|
|
547
|
+
`[id.name="${className}"] > ClassExpression`,
|
|
548
|
+
`[id.name="${className}"] > ClassBody > [key.name="${methodName}"][key.type=${keyType}] > [async]`,
|
|
549
|
+
`[id.name="${className}"] > ClassExpression > ClassBody > [key.name="${methodName}"][key.type=${keyType}] > [async]`
|
|
550
|
+
);
|
|
551
|
+
} else if ("methodName" in functionQuery) {
|
|
552
|
+
const { methodName } = functionQuery;
|
|
553
|
+
queries.push(
|
|
554
|
+
`ClassBody > [key.name="${methodName}"][key.type=Identifier] > [async]`,
|
|
555
|
+
`Property[key.name="${methodName}"][key.type=Identifier] > [async]`
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
if ("functionName" in functionQuery) {
|
|
559
|
+
const { functionName } = functionQuery;
|
|
560
|
+
queries.push(`FunctionDeclaration[id.name="${functionName}"][async]`);
|
|
561
|
+
}
|
|
562
|
+
if ("objectName" in functionQuery) {
|
|
563
|
+
const { objectName, propertyName } = functionQuery;
|
|
564
|
+
const objectSelector = objectName === "this" ? "left.object.type=ThisExpression" : `left.object.name="${objectName}"`;
|
|
565
|
+
queries.push(
|
|
566
|
+
`AssignmentExpression[${objectSelector}][left.property.name="${propertyName}"] > [async]`
|
|
567
|
+
);
|
|
568
|
+
}
|
|
569
|
+
return queries.join(", ");
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
|
|
573
|
+
// src/auto-instrumentations/orchestrion-js/matcher.ts
|
|
574
|
+
var InstrumentationMatcher = class {
|
|
575
|
+
configs = [];
|
|
576
|
+
dcModule;
|
|
577
|
+
transformers = {};
|
|
578
|
+
constructor(configs, dcModule) {
|
|
579
|
+
this.configs = configs;
|
|
580
|
+
this.dcModule = dcModule || "diagnostics_channel";
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Returns a Transformer for the given module/file/version, or undefined if no
|
|
584
|
+
* registered config matches.
|
|
585
|
+
*/
|
|
586
|
+
getTransformer(moduleName, version, filePath) {
|
|
587
|
+
filePath = filePath.replace(/\\/g, "/");
|
|
588
|
+
const id = `${moduleName}/${filePath}@${version}`;
|
|
589
|
+
if (this.transformers[id]) {
|
|
590
|
+
return this.transformers[id];
|
|
591
|
+
}
|
|
592
|
+
const configs = this.configs.filter(
|
|
593
|
+
({ module: mod }) => mod.name === moduleName && mod.filePath === filePath && (0, import_semifies.default)(version, mod.versionRange)
|
|
594
|
+
);
|
|
595
|
+
if (configs.length === 0) {
|
|
596
|
+
return void 0;
|
|
597
|
+
}
|
|
598
|
+
this.transformers[id] = new Transformer(
|
|
599
|
+
moduleName,
|
|
600
|
+
version,
|
|
601
|
+
filePath,
|
|
602
|
+
configs,
|
|
603
|
+
this.dcModule
|
|
604
|
+
);
|
|
605
|
+
return this.transformers[id];
|
|
606
|
+
}
|
|
607
|
+
free() {
|
|
608
|
+
this.transformers = {};
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
|
|
612
|
+
// src/auto-instrumentations/orchestrion-js/index.ts
|
|
613
|
+
function create(configs, dcModule) {
|
|
614
|
+
return new InstrumentationMatcher(configs, dcModule);
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
// src/auto-instrumentations/bundler/plugin.ts
|
|
42
618
|
var import_path = require("path");
|
|
43
619
|
var import_fs = require("fs");
|
|
44
620
|
var import_url = require("url");
|
|
@@ -328,6 +904,10 @@ var aiSDKChannels = defineChannels("ai", {
|
|
|
328
904
|
channelName: "ToolLoopAgent.stream",
|
|
329
905
|
kind: "async"
|
|
330
906
|
}),
|
|
907
|
+
workflowAgentStream: channel({
|
|
908
|
+
channelName: "WorkflowAgent.stream",
|
|
909
|
+
kind: "async"
|
|
910
|
+
}),
|
|
331
911
|
v7CreateTelemetryDispatcher: channel({
|
|
332
912
|
channelName: "createTelemetryDispatcher",
|
|
333
913
|
kind: "sync-stream"
|
|
@@ -526,6 +1106,18 @@ var aiSDKConfigs = [
|
|
|
526
1106
|
kind: "Sync"
|
|
527
1107
|
}
|
|
528
1108
|
},
|
|
1109
|
+
{
|
|
1110
|
+
channelName: aiSDKChannels.v7CreateTelemetryDispatcher.channelName,
|
|
1111
|
+
module: {
|
|
1112
|
+
name: "ai",
|
|
1113
|
+
versionRange: ">=7.0.0-0 <8.0.0",
|
|
1114
|
+
filePath: "dist/internal/index.js"
|
|
1115
|
+
},
|
|
1116
|
+
functionQuery: {
|
|
1117
|
+
functionName: "createTelemetryDispatcher",
|
|
1118
|
+
kind: "Sync"
|
|
1119
|
+
}
|
|
1120
|
+
},
|
|
529
1121
|
// streamObject - async function (v3 only, before the sync refactor in v4)
|
|
530
1122
|
{
|
|
531
1123
|
channelName: aiSDKChannels.streamObject.channelName,
|
|
@@ -3486,7 +4078,7 @@ var unplugin = (0, import_unplugin.createUnplugin)(
|
|
|
3486
4078
|
additionalInstrumentations: options.instrumentations
|
|
3487
4079
|
});
|
|
3488
4080
|
const dcModule = options.browser === false ? void 0 : "dc-browser";
|
|
3489
|
-
const instrumentationMatcher =
|
|
4081
|
+
const instrumentationMatcher = create(allInstrumentations, dcModule);
|
|
3490
4082
|
return {
|
|
3491
4083
|
name: "code-transformer",
|
|
3492
4084
|
enforce: "pre",
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
webpackPlugin
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-T6J4C7LX.mjs";
|
|
4
|
+
import "../chunk-TKRPRPGD.mjs";
|
|
5
|
+
import "../chunk-BRQX23KL.mjs";
|
|
6
|
+
import "../chunk-M6DLIJ2Z.mjs";
|
|
7
7
|
|
|
8
8
|
// src/auto-instrumentations/bundler/next.ts
|
|
9
9
|
import { createRequire } from "module";
|