braintrust 3.26.0 → 3.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dev/dist/index.d.mts +519 -186
- package/dev/dist/index.d.ts +519 -186
- package/dev/dist/index.js +3727 -1526
- package/dev/dist/index.mjs +2815 -614
- package/dist/apply-auto-instrumentation.js +372 -261
- package/dist/apply-auto-instrumentation.mjs +171 -60
- package/dist/auto-instrumentations/bundler/esbuild.cjs +458 -61
- package/dist/auto-instrumentations/bundler/esbuild.mjs +5 -4
- package/dist/auto-instrumentations/bundler/next.cjs +460 -63
- package/dist/auto-instrumentations/bundler/next.mjs +6 -5
- package/dist/auto-instrumentations/bundler/rollup.cjs +458 -61
- package/dist/auto-instrumentations/bundler/rollup.mjs +5 -4
- package/dist/auto-instrumentations/bundler/vite.cjs +487 -62
- package/dist/auto-instrumentations/bundler/vite.mjs +34 -5
- package/dist/auto-instrumentations/bundler/webpack-loader.cjs +444 -61
- package/dist/auto-instrumentations/bundler/webpack.cjs +458 -61
- package/dist/auto-instrumentations/bundler/webpack.mjs +6 -5
- package/dist/auto-instrumentations/{chunk-6E22MYSW.mjs → chunk-26PKVUKB.mjs} +109 -5
- package/dist/auto-instrumentations/{chunk-AKKPLXTP.mjs → chunk-2AMDGD65.mjs} +160 -57
- package/dist/auto-instrumentations/{chunk-V5LEODRX.mjs → chunk-HD35AM3M.mjs} +1 -1
- package/dist/auto-instrumentations/{chunk-XYN63IG5.mjs → chunk-I55G56ZL.mjs} +21 -58
- package/dist/auto-instrumentations/{chunk-NRE4QUQR.mjs → chunk-JPUFNW7X.mjs} +140 -0
- package/dist/auto-instrumentations/{chunk-XZHHE4Y3.mjs → chunk-NP7V4XB2.mjs} +157 -3
- package/dist/auto-instrumentations/hook.mjs +396 -32
- package/dist/auto-instrumentations/index.cjs +298 -2
- package/dist/auto-instrumentations/index.d.mts +5 -1
- package/dist/auto-instrumentations/index.d.ts +5 -1
- package/dist/auto-instrumentations/index.mjs +6 -2
- package/dist/auto-instrumentations/loader/cjs-patch.cjs +105 -57
- package/dist/auto-instrumentations/loader/cjs-patch.mjs +2 -2
- package/dist/auto-instrumentations/loader/esm-hook.mjs +1 -1
- package/dist/browser.d.mts +683 -56
- package/dist/browser.d.ts +683 -56
- package/dist/browser.js +4242 -655
- package/dist/browser.mjs +4242 -655
- package/dist/{chunk-VYNNEKSA.js → chunk-BBE7SNRV.js} +248 -10
- package/dist/{chunk-VRZZQPAA.js → chunk-OBBWQW6K.js} +3351 -1392
- package/dist/{chunk-XIZOM2HO.mjs → chunk-UPFNQCGB.mjs} +2419 -460
- package/dist/{chunk-PN7EWK66.mjs → chunk-ZHUHZWFY.mjs} +241 -3
- package/dist/cli.js +2867 -668
- package/dist/edge-light.d.mts +1 -1
- package/dist/edge-light.d.ts +1 -1
- package/dist/edge-light.js +4242 -655
- package/dist/edge-light.mjs +4242 -655
- package/dist/index.d.mts +1267 -640
- package/dist/index.d.ts +1267 -640
- package/dist/index.js +2107 -630
- package/dist/index.mjs +1649 -172
- package/dist/instrumentation/index.d.mts +198 -6
- package/dist/instrumentation/index.d.ts +198 -6
- package/dist/instrumentation/index.js +2661 -581
- package/dist/instrumentation/index.mjs +2661 -581
- package/dist/vitest-evals-reporter.js +45 -43
- package/dist/vitest-evals-reporter.mjs +5 -3
- package/dist/workerd.d.mts +1 -1
- package/dist/workerd.d.ts +1 -1
- package/dist/workerd.js +4242 -655
- package/dist/workerd.mjs +4242 -655
- package/package.json +2 -3
- package/util/dist/index.d.mts +1545 -100
- package/util/dist/index.d.ts +1545 -100
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
braintrustWebpackPlugin,
|
|
3
3
|
webpackPlugin
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
4
|
+
} from "../chunk-HD35AM3M.mjs";
|
|
5
|
+
import "../chunk-26PKVUKB.mjs";
|
|
6
|
+
import "../chunk-NP7V4XB2.mjs";
|
|
7
|
+
import "../chunk-I55G56ZL.mjs";
|
|
8
|
+
import "../chunk-JPUFNW7X.mjs";
|
|
9
|
+
import "../chunk-P5YLNB2A.mjs";
|
|
9
10
|
export {
|
|
10
11
|
braintrustWebpackPlugin,
|
|
11
12
|
webpackPlugin
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
claudeAgentSDKConfigs,
|
|
8
8
|
cloudflareAIChatConfigs,
|
|
9
9
|
cloudflareAgentsConfigs,
|
|
10
|
+
cloudflareThinkConfigs,
|
|
10
11
|
cohereConfigs,
|
|
11
12
|
cursorSDKConfigs,
|
|
12
13
|
defineChannels,
|
|
@@ -19,21 +20,25 @@ import {
|
|
|
19
20
|
langSmithConfigs,
|
|
20
21
|
langchainConfigs,
|
|
21
22
|
mistralConfigs,
|
|
23
|
+
ollamaConfigs,
|
|
22
24
|
openAIAgentsCoreConfigs,
|
|
23
25
|
openAICodexConfigs,
|
|
24
26
|
openRouterAgentConfigs,
|
|
25
27
|
openRouterConfigs,
|
|
26
28
|
openaiConfigs,
|
|
27
29
|
piCodingAgentConfigs
|
|
28
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-NP7V4XB2.mjs";
|
|
29
31
|
import {
|
|
30
32
|
applySpecialCasePatch,
|
|
31
33
|
create
|
|
32
|
-
} from "./chunk-
|
|
34
|
+
} from "./chunk-I55G56ZL.mjs";
|
|
35
|
+
import {
|
|
36
|
+
getPackageName
|
|
37
|
+
} from "./chunk-P5YLNB2A.mjs";
|
|
33
38
|
|
|
34
39
|
// src/auto-instrumentations/bundler/plugin.ts
|
|
35
40
|
import { createUnplugin } from "unplugin";
|
|
36
|
-
import { extname, join, sep } from "path";
|
|
41
|
+
import { extname, isAbsolute, join, sep } from "path";
|
|
37
42
|
import { readFileSync } from "fs";
|
|
38
43
|
import { fileURLToPath } from "url";
|
|
39
44
|
import moduleDetailsFromPath from "module-details-from-path";
|
|
@@ -68,6 +73,7 @@ var envIntegrationAliases = {
|
|
|
68
73
|
cloudflareaichat: "cloudflareAIChat",
|
|
69
74
|
"cloudflare-ai-chat": "cloudflareAIChat",
|
|
70
75
|
"@cloudflare/ai-chat": "cloudflareAIChat",
|
|
76
|
+
cloudflarethink: "cloudflareThink",
|
|
71
77
|
cursor: "cursor",
|
|
72
78
|
"cursor-sdk": "cursorSDK",
|
|
73
79
|
cursorsdk: "cursorSDK",
|
|
@@ -88,6 +94,7 @@ var envIntegrationAliases = {
|
|
|
88
94
|
openrouteragent: "openrouterAgent",
|
|
89
95
|
"openrouter-agent": "openrouterAgent",
|
|
90
96
|
mistral: "mistral",
|
|
97
|
+
ollama: "ollama",
|
|
91
98
|
googleadk: "googleADK",
|
|
92
99
|
"google-adk": "googleADK",
|
|
93
100
|
cohere: "cohere",
|
|
@@ -108,7 +115,10 @@ var envIntegrationAliases = {
|
|
|
108
115
|
"langchain-js": "langchain",
|
|
109
116
|
"@langchain": "langchain",
|
|
110
117
|
langgraph: "langgraph",
|
|
111
|
-
langsmith: "langsmith"
|
|
118
|
+
langsmith: "langsmith",
|
|
119
|
+
voyage: "voyageai",
|
|
120
|
+
"voyage-ai": "voyageai",
|
|
121
|
+
voyageai: "voyageai"
|
|
112
122
|
};
|
|
113
123
|
function readDisabledInstrumentationEnvConfig(disabledList) {
|
|
114
124
|
const integrations = {};
|
|
@@ -297,6 +307,77 @@ var strandsAgentSDKConfigs = [
|
|
|
297
307
|
}
|
|
298
308
|
];
|
|
299
309
|
|
|
310
|
+
// src/instrumentation/plugins/voyageai-channels.ts
|
|
311
|
+
var voyageAIChannels = defineChannels(
|
|
312
|
+
"voyageai",
|
|
313
|
+
{
|
|
314
|
+
embed: channel({
|
|
315
|
+
channelName: "embed",
|
|
316
|
+
kind: "async"
|
|
317
|
+
}),
|
|
318
|
+
multimodalEmbed: channel({
|
|
319
|
+
channelName: "multimodalEmbed",
|
|
320
|
+
kind: "async"
|
|
321
|
+
}),
|
|
322
|
+
rerank: channel({
|
|
323
|
+
channelName: "rerank",
|
|
324
|
+
kind: "async"
|
|
325
|
+
}),
|
|
326
|
+
contextualizedEmbed: channel({
|
|
327
|
+
channelName: "contextualizedEmbed",
|
|
328
|
+
kind: "async"
|
|
329
|
+
})
|
|
330
|
+
},
|
|
331
|
+
{ instrumentationName: INSTRUMENTATION_NAMES.VOYAGEAI }
|
|
332
|
+
);
|
|
333
|
+
|
|
334
|
+
// src/auto-instrumentations/configs/voyageai.ts
|
|
335
|
+
var GENERATED_CLIENT_MODULES = [
|
|
336
|
+
"dist/cjs/Client.js",
|
|
337
|
+
"dist/esm/Client.mjs"
|
|
338
|
+
];
|
|
339
|
+
var generatedClientOperations = [
|
|
340
|
+
{
|
|
341
|
+
channelName: voyageAIChannels.embed.channelName,
|
|
342
|
+
methodName: "embed",
|
|
343
|
+
versionRange: ">=0.2.0 <1.0.0"
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
channelName: voyageAIChannels.multimodalEmbed.channelName,
|
|
347
|
+
methodName: "multimodalEmbed",
|
|
348
|
+
versionRange: ">=0.2.0 <1.0.0"
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
channelName: voyageAIChannels.rerank.channelName,
|
|
352
|
+
methodName: "rerank",
|
|
353
|
+
versionRange: ">=0.2.0 <1.0.0"
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
channelName: voyageAIChannels.contextualizedEmbed.channelName,
|
|
357
|
+
methodName: "contextualizedEmbed",
|
|
358
|
+
versionRange: ">=0.2.0 <1.0.0"
|
|
359
|
+
}
|
|
360
|
+
];
|
|
361
|
+
var voyageAIConfigs = [
|
|
362
|
+
...GENERATED_CLIENT_MODULES.flatMap(
|
|
363
|
+
(filePath) => generatedClientOperations.map(
|
|
364
|
+
({ channelName, methodName, versionRange }) => ({
|
|
365
|
+
channelName,
|
|
366
|
+
module: {
|
|
367
|
+
name: "voyageai",
|
|
368
|
+
versionRange,
|
|
369
|
+
filePath
|
|
370
|
+
},
|
|
371
|
+
functionQuery: {
|
|
372
|
+
className: "VoyageAIClient",
|
|
373
|
+
methodName,
|
|
374
|
+
kind: "Async"
|
|
375
|
+
}
|
|
376
|
+
})
|
|
377
|
+
)
|
|
378
|
+
)
|
|
379
|
+
];
|
|
380
|
+
|
|
300
381
|
// src/auto-instrumentations/configs/all.ts
|
|
301
382
|
var defaultInstrumentationConfigGroups = [
|
|
302
383
|
{ integrations: ["openai"], configs: openaiConfigs },
|
|
@@ -325,6 +406,10 @@ var defaultInstrumentationConfigGroups = [
|
|
|
325
406
|
integrations: ["cloudflareAgents"],
|
|
326
407
|
configs: cloudflareAgentsConfigs
|
|
327
408
|
},
|
|
409
|
+
{
|
|
410
|
+
integrations: ["cloudflareThink"],
|
|
411
|
+
configs: cloudflareThinkConfigs
|
|
412
|
+
},
|
|
328
413
|
{ integrations: ["cursor", "cursorSDK"], configs: cursorSDKConfigs },
|
|
329
414
|
{
|
|
330
415
|
integrations: ["openAIAgents"],
|
|
@@ -349,6 +434,7 @@ var defaultInstrumentationConfigGroups = [
|
|
|
349
434
|
configs: openRouterAgentConfigs
|
|
350
435
|
},
|
|
351
436
|
{ integrations: ["mistral"], configs: mistralConfigs },
|
|
437
|
+
{ integrations: ["ollama"], configs: ollamaConfigs },
|
|
352
438
|
{ integrations: ["googleADK"], configs: googleADKConfigs },
|
|
353
439
|
{ integrations: ["cohere"], configs: cohereConfigs },
|
|
354
440
|
{ integrations: ["groq"], configs: groqConfigs },
|
|
@@ -371,6 +457,10 @@ var defaultInstrumentationConfigGroups = [
|
|
|
371
457
|
{
|
|
372
458
|
integrations: ["flue"],
|
|
373
459
|
configs: flueConfigs
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
integrations: ["voyageai"],
|
|
463
|
+
configs: voyageAIConfigs
|
|
374
464
|
}
|
|
375
465
|
// Note: `@mastra/core` is not listed here because its instrumentation
|
|
376
466
|
// doesn't go through the AST `code-transformer` matcher — Mastra's
|
|
@@ -417,6 +507,20 @@ var unplugin = createUnplugin((options = {}) => {
|
|
|
417
507
|
return {
|
|
418
508
|
name: "code-transformer",
|
|
419
509
|
enforce: "pre",
|
|
510
|
+
transformInclude(id) {
|
|
511
|
+
const pathWithoutQuery = id.split("?", 1)[0];
|
|
512
|
+
if (!pathWithoutQuery) {
|
|
513
|
+
return false;
|
|
514
|
+
}
|
|
515
|
+
if (pathWithoutQuery.startsWith("file:")) {
|
|
516
|
+
try {
|
|
517
|
+
return isAbsolute(fileURLToPath(pathWithoutQuery));
|
|
518
|
+
} catch {
|
|
519
|
+
return false;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
return isAbsolute(pathWithoutQuery);
|
|
523
|
+
},
|
|
420
524
|
transform(code, id) {
|
|
421
525
|
if (!id) {
|
|
422
526
|
return null;
|
|
@@ -433,7 +537,7 @@ var unplugin = createUnplugin((options = {}) => {
|
|
|
433
537
|
if (!moduleDetails) {
|
|
434
538
|
return null;
|
|
435
539
|
}
|
|
436
|
-
const moduleName = moduleDetails.name;
|
|
540
|
+
const moduleName = getPackageName(moduleDetails.basedir) ?? moduleDetails.name;
|
|
437
541
|
const normalizedModulePath = moduleDetails.path.replace(/\\/g, "/");
|
|
438
542
|
const moduleVersion = getModuleVersion(moduleDetails.basedir);
|
|
439
543
|
const patched = applySpecialCasePatch({
|
|
@@ -3,8 +3,10 @@ var GLOBAL_INSTRUMENTATION_HOOKS_KEY = "__braintrust_instrumentation_hooks";
|
|
|
3
3
|
var GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION = 1;
|
|
4
4
|
var GLOBAL_INSTRUMENTATION_HOOKS_REGISTRY_BRAND = "braintrust.global-instrumentation-hooks.registry";
|
|
5
5
|
var GLOBAL_INSTRUMENTATION_HOOK_BRAND = "braintrust.global-instrumentation-hooks.hook";
|
|
6
|
+
var GLOBAL_INVOCATION_HOOK_BRAND = "braintrust.global-instrumentation-hooks.invocation-hook";
|
|
6
7
|
var registryBrand = Symbol.for(GLOBAL_INSTRUMENTATION_HOOKS_REGISTRY_BRAND);
|
|
7
8
|
var hookBrand = Symbol.for(GLOBAL_INSTRUMENTATION_HOOK_BRAND);
|
|
9
|
+
var invocationHookBrand = Symbol.for(GLOBAL_INVOCATION_HOOK_BRAND);
|
|
8
10
|
var errorReporter;
|
|
9
11
|
function setGlobalHookErrorReporter(reporter) {
|
|
10
12
|
const previousReporter = errorReporter;
|
|
@@ -149,12 +151,69 @@ var traceEvents = [
|
|
|
149
151
|
"asyncEnd",
|
|
150
152
|
"error"
|
|
151
153
|
];
|
|
154
|
+
function traceInvocation(hook, operator, target, thisArg, args, additional, callbackIndex = -1) {
|
|
155
|
+
const context = {
|
|
156
|
+
...additional,
|
|
157
|
+
arguments: args,
|
|
158
|
+
self: thisArg
|
|
159
|
+
};
|
|
160
|
+
const invoke = () => hook.invoke(target, thisArg, args, additional);
|
|
161
|
+
if (operator === "traceCallback") {
|
|
162
|
+
return hook.traceCallback(invoke, callbackIndex, context);
|
|
163
|
+
}
|
|
164
|
+
if (operator === "tracePromise") {
|
|
165
|
+
return hook.tracePromise(invoke, context);
|
|
166
|
+
}
|
|
167
|
+
return hook.traceSync(invoke, context);
|
|
168
|
+
}
|
|
169
|
+
var InvocationHook = class {
|
|
170
|
+
interceptors = [];
|
|
171
|
+
get hasInterceptors() {
|
|
172
|
+
return this.interceptors.length > 0;
|
|
173
|
+
}
|
|
174
|
+
intercept(interceptor) {
|
|
175
|
+
if (typeof interceptor !== "function") {
|
|
176
|
+
throw new TypeError("interceptor must be a function");
|
|
177
|
+
}
|
|
178
|
+
this.interceptors = [...this.interceptors, interceptor];
|
|
179
|
+
let active = true;
|
|
180
|
+
return () => {
|
|
181
|
+
if (!active) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
active = false;
|
|
185
|
+
const index = this.interceptors.indexOf(interceptor);
|
|
186
|
+
if (index !== -1) {
|
|
187
|
+
this.interceptors = [
|
|
188
|
+
...this.interceptors.slice(0, index),
|
|
189
|
+
...this.interceptors.slice(index + 1)
|
|
190
|
+
];
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
invoke(target, thisArg, args, additional) {
|
|
195
|
+
const interceptors = this.interceptors;
|
|
196
|
+
if (interceptors.length === 0) {
|
|
197
|
+
return Reflect.apply(target, thisArg, args);
|
|
198
|
+
}
|
|
199
|
+
let next = target;
|
|
200
|
+
for (let index = interceptors.length - 1; index >= 0; index -= 1) {
|
|
201
|
+
const interceptor = interceptors[index];
|
|
202
|
+
const downstream = next;
|
|
203
|
+
next = function(...nextArgs) {
|
|
204
|
+
return interceptor(downstream, this, nextArgs, additional);
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
return Reflect.apply(next, thisArg, args);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
152
210
|
var TracingHook = class {
|
|
153
211
|
start;
|
|
154
212
|
end;
|
|
155
213
|
asyncStart;
|
|
156
214
|
asyncEnd;
|
|
157
215
|
error;
|
|
216
|
+
invocationHook = new InvocationHook();
|
|
158
217
|
constructor(nameOrChannels) {
|
|
159
218
|
Object.defineProperty(this, hookBrand, {
|
|
160
219
|
configurable: false,
|
|
@@ -162,6 +221,12 @@ var TracingHook = class {
|
|
|
162
221
|
value: GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
|
|
163
222
|
writable: false
|
|
164
223
|
});
|
|
224
|
+
Object.defineProperty(this, invocationHookBrand, {
|
|
225
|
+
configurable: false,
|
|
226
|
+
enumerable: false,
|
|
227
|
+
value: GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
|
|
228
|
+
writable: false
|
|
229
|
+
});
|
|
165
230
|
if (typeof nameOrChannels === "string") {
|
|
166
231
|
this.start = new HookChannel(`tracing:${nameOrChannels}:start`);
|
|
167
232
|
this.end = new HookChannel(`tracing:${nameOrChannels}:end`);
|
|
@@ -179,6 +244,26 @@ var TracingHook = class {
|
|
|
179
244
|
get hasSubscribers() {
|
|
180
245
|
return this.start.hasSubscribers || this.end.hasSubscribers || this.asyncStart.hasSubscribers || this.asyncEnd.hasSubscribers || this.error.hasSubscribers;
|
|
181
246
|
}
|
|
247
|
+
get hasInterceptors() {
|
|
248
|
+
return this.invocationHook.hasInterceptors;
|
|
249
|
+
}
|
|
250
|
+
intercept(interceptor) {
|
|
251
|
+
return this.invocationHook.intercept(interceptor);
|
|
252
|
+
}
|
|
253
|
+
invoke(target, thisArg, args, additional) {
|
|
254
|
+
return this.invocationHook.invoke(target, thisArg, args, additional);
|
|
255
|
+
}
|
|
256
|
+
traceInvocation(operator, target, thisArg, args, additional, callbackIndex = -1) {
|
|
257
|
+
return traceInvocation(
|
|
258
|
+
this,
|
|
259
|
+
operator,
|
|
260
|
+
target,
|
|
261
|
+
thisArg,
|
|
262
|
+
args,
|
|
263
|
+
additional,
|
|
264
|
+
callbackIndex
|
|
265
|
+
);
|
|
266
|
+
}
|
|
182
267
|
subscribe(handlers) {
|
|
183
268
|
for (const eventName of traceEvents) {
|
|
184
269
|
const handler = handlers[eventName];
|
|
@@ -400,6 +485,60 @@ function hasTracingHookShape(value) {
|
|
|
400
485
|
return false;
|
|
401
486
|
}
|
|
402
487
|
}
|
|
488
|
+
function hasInvocationHookShape(value) {
|
|
489
|
+
if (typeof value !== "object" && typeof value !== "function" || value === null) {
|
|
490
|
+
return false;
|
|
491
|
+
}
|
|
492
|
+
try {
|
|
493
|
+
const hook = value;
|
|
494
|
+
return value[invocationHookBrand] === GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION && typeof hook.hasInterceptors === "boolean" && typeof hook.intercept === "function" && typeof hook.invoke === "function";
|
|
495
|
+
} catch {
|
|
496
|
+
return false;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
function installInvocationHook(value) {
|
|
500
|
+
const hasInvocationHook = hasInvocationHookShape(value);
|
|
501
|
+
const invocationHook = new InvocationHook();
|
|
502
|
+
try {
|
|
503
|
+
if (!hasInvocationHook) {
|
|
504
|
+
Object.defineProperties(value, {
|
|
505
|
+
[invocationHookBrand]: {
|
|
506
|
+
configurable: false,
|
|
507
|
+
enumerable: false,
|
|
508
|
+
value: GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
|
|
509
|
+
writable: false
|
|
510
|
+
},
|
|
511
|
+
hasInterceptors: {
|
|
512
|
+
configurable: false,
|
|
513
|
+
enumerable: false,
|
|
514
|
+
get: () => invocationHook.hasInterceptors
|
|
515
|
+
},
|
|
516
|
+
intercept: {
|
|
517
|
+
configurable: false,
|
|
518
|
+
enumerable: false,
|
|
519
|
+
value: invocationHook.intercept.bind(invocationHook),
|
|
520
|
+
writable: false
|
|
521
|
+
},
|
|
522
|
+
invoke: {
|
|
523
|
+
configurable: false,
|
|
524
|
+
enumerable: false,
|
|
525
|
+
value: invocationHook.invoke.bind(invocationHook),
|
|
526
|
+
writable: false
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
if (typeof value.traceInvocation !== "function") {
|
|
531
|
+
Object.defineProperty(value, "traceInvocation", {
|
|
532
|
+
configurable: false,
|
|
533
|
+
enumerable: false,
|
|
534
|
+
value: traceInvocation.bind(void 0, value),
|
|
535
|
+
writable: false
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
} catch (error) {
|
|
539
|
+
reportError(error);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
403
542
|
function isCompatibleTracingHook(value) {
|
|
404
543
|
try {
|
|
405
544
|
return value[hookBrand] === GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION && hasTracingHookShape(value);
|
|
@@ -486,6 +625,7 @@ function newGlobalTracingChannel(nameOrChannels) {
|
|
|
486
625
|
return inertTracingHook;
|
|
487
626
|
}
|
|
488
627
|
if (isCompatibleTracingHook(existing)) {
|
|
628
|
+
installInvocationHook(existing);
|
|
489
629
|
return existing;
|
|
490
630
|
}
|
|
491
631
|
if (existing !== void 0) {
|
|
@@ -706,8 +846,7 @@ var transforms = {
|
|
|
706
846
|
tracingHookDeclaration(state, node) {
|
|
707
847
|
const {
|
|
708
848
|
channelName,
|
|
709
|
-
module: { name }
|
|
710
|
-
operator
|
|
849
|
+
module: { name }
|
|
711
850
|
} = state;
|
|
712
851
|
const channelVariable = formatChannelVariable(channelName);
|
|
713
852
|
const channelGetter = formatChannelGetter(channelName);
|
|
@@ -720,7 +859,7 @@ var transforms = {
|
|
|
720
859
|
return;
|
|
721
860
|
}
|
|
722
861
|
const sharedHookLookup = hasSharedHookLookup ? "" : `
|
|
723
|
-
const ${SHARED_HOOK_LOOKUP} = (__bt$hookName
|
|
862
|
+
const ${SHARED_HOOK_LOOKUP} = (__bt$hookName) => {
|
|
724
863
|
try {
|
|
725
864
|
const __bt$hooks = globalThis[${JSON.stringify(
|
|
726
865
|
GLOBAL_INSTRUMENTATION_HOOKS_KEY
|
|
@@ -742,8 +881,7 @@ var transforms = {
|
|
|
742
881
|
__bt$hook[Symbol.for(${JSON.stringify(
|
|
743
882
|
GLOBAL_INSTRUMENTATION_HOOK_BRAND
|
|
744
883
|
)})] !== ${GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION} ||
|
|
745
|
-
typeof __bt$hook.
|
|
746
|
-
typeof __bt$hook[__bt$operator] !== "function"
|
|
884
|
+
typeof __bt$hook.traceInvocation !== "function"
|
|
747
885
|
) return undefined;
|
|
748
886
|
return __bt$hook;
|
|
749
887
|
} catch {
|
|
@@ -756,8 +894,7 @@ var transforms = {
|
|
|
756
894
|
let ${channelVariable};
|
|
757
895
|
const ${channelGetter} = () =>
|
|
758
896
|
${channelVariable} ??= ${SHARED_HOOK_LOOKUP}(
|
|
759
|
-
${JSON.stringify(`orchestrion:${name}:${channelName}`)}
|
|
760
|
-
${JSON.stringify(operator)}
|
|
897
|
+
${JSON.stringify(`orchestrion:${name}:${channelName}`)}
|
|
761
898
|
);
|
|
762
899
|
`;
|
|
763
900
|
const sharedHookLookupIndex = node.body.findIndex(
|
|
@@ -832,28 +969,18 @@ function traceInstanceMethod(state, node, program) {
|
|
|
832
969
|
ctor.value.body.body.push(...ctorBody);
|
|
833
970
|
}
|
|
834
971
|
function wrap(state, node) {
|
|
835
|
-
const
|
|
836
|
-
const wrapper = operator === "traceCallback" ? wrapCallback(state) : operator === "tracePromise" ? wrapPromise(state) : wrapSync(state);
|
|
972
|
+
const wrapper = wrapInvocation(state);
|
|
837
973
|
const block = wrapper.body[0].body;
|
|
838
974
|
const common = parse(
|
|
839
975
|
node.type === "ArrowFunctionExpression" ? `
|
|
840
|
-
const __bt$
|
|
841
|
-
arguments,
|
|
842
|
-
moduleVersion: ${JSON.stringify(moduleVersion)}
|
|
843
|
-
};
|
|
844
|
-
const __bt$traced = () => {
|
|
976
|
+
const __bt$target = (...__bt$args) => {
|
|
845
977
|
const __bt$wrapped = () => {};
|
|
846
|
-
return __bt$wrapped(...
|
|
978
|
+
return __bt$wrapped(...__bt$args);
|
|
847
979
|
};
|
|
848
980
|
` : `
|
|
849
|
-
const __bt$
|
|
850
|
-
arguments,
|
|
851
|
-
self: this,
|
|
852
|
-
moduleVersion: ${JSON.stringify(moduleVersion)}
|
|
853
|
-
};
|
|
854
|
-
const __bt$traced = () => {
|
|
981
|
+
const __bt$target = function (...__bt$args) {
|
|
855
982
|
const __bt$wrapped = () => {};
|
|
856
|
-
return __bt$wrapped.apply(this,
|
|
983
|
+
return __bt$wrapped.apply(this, __bt$args);
|
|
857
984
|
};
|
|
858
985
|
`
|
|
859
986
|
).body;
|
|
@@ -895,49 +1022,25 @@ function wrapSuper(node) {
|
|
|
895
1022
|
node.body.body.unshift(parse("const __bt$super = {}").body[0]);
|
|
896
1023
|
}
|
|
897
1024
|
}
|
|
898
|
-
function
|
|
899
|
-
const {
|
|
900
|
-
channelName,
|
|
901
|
-
functionQuery: { callbackIndex = -1 }
|
|
902
|
-
} = state;
|
|
1025
|
+
function wrapInvocation(state) {
|
|
1026
|
+
const { channelName, moduleVersion, operator, functionQuery } = state;
|
|
903
1027
|
const channelGetter = formatChannelGetter(channelName);
|
|
1028
|
+
const callbackIndex = functionQuery.callbackIndex ?? -1;
|
|
904
1029
|
return parse(`
|
|
905
1030
|
function wrapper () {
|
|
906
1031
|
const __bt$hook = ${channelGetter}();
|
|
907
|
-
if (!__bt$hook
|
|
908
|
-
__bt$
|
|
909
|
-
|
|
910
|
-
__bt$
|
|
911
|
-
|
|
912
|
-
|
|
1032
|
+
if (!__bt$hook) return __bt$target.apply(this, arguments);
|
|
1033
|
+
return __bt$hook.traceInvocation(
|
|
1034
|
+
${JSON.stringify(operator)},
|
|
1035
|
+
__bt$target,
|
|
1036
|
+
this,
|
|
1037
|
+
arguments,
|
|
1038
|
+
{ moduleVersion: ${JSON.stringify(moduleVersion)} },
|
|
1039
|
+
${callbackIndex}
|
|
913
1040
|
);
|
|
914
1041
|
}
|
|
915
1042
|
`);
|
|
916
1043
|
}
|
|
917
|
-
function wrapPromise(state) {
|
|
918
|
-
const { channelName } = state;
|
|
919
|
-
const channelGetter = formatChannelGetter(channelName);
|
|
920
|
-
return parse(`
|
|
921
|
-
function wrapper () {
|
|
922
|
-
const __bt$hook = ${channelGetter}();
|
|
923
|
-
if (!__bt$hook?.hasSubscribers) return __bt$traced();
|
|
924
|
-
__bt$ctx.self ??= this;
|
|
925
|
-
return __bt$hook.tracePromise(__bt$traced, __bt$ctx);
|
|
926
|
-
}
|
|
927
|
-
`);
|
|
928
|
-
}
|
|
929
|
-
function wrapSync(state) {
|
|
930
|
-
const { channelName } = state;
|
|
931
|
-
const channelGetter = formatChannelGetter(channelName);
|
|
932
|
-
return parse(`
|
|
933
|
-
function wrapper () {
|
|
934
|
-
const __bt$hook = ${channelGetter}();
|
|
935
|
-
if (!__bt$hook?.hasSubscribers) return __bt$traced();
|
|
936
|
-
__bt$ctx.self ??= this;
|
|
937
|
-
return __bt$hook.traceSync(__bt$traced, __bt$ctx);
|
|
938
|
-
}
|
|
939
|
-
`);
|
|
940
|
-
}
|
|
941
1044
|
|
|
942
1045
|
// src/auto-instrumentations/orchestrion-js/transformer.ts
|
|
943
1046
|
var Transformer = class {
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
|
|
4
4
|
GLOBAL_INSTRUMENTATION_HOOKS_REGISTRY_BRAND,
|
|
5
5
|
GLOBAL_INSTRUMENTATION_HOOK_BRAND
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-JPUFNW7X.mjs";
|
|
7
7
|
|
|
8
8
|
// src/auto-instrumentations/orchestrion-js/matcher.ts
|
|
9
9
|
import semifies from "semifies";
|
|
@@ -29,8 +29,7 @@ var transforms = {
|
|
|
29
29
|
tracingHookDeclaration(state, node) {
|
|
30
30
|
const {
|
|
31
31
|
channelName,
|
|
32
|
-
module: { name }
|
|
33
|
-
operator
|
|
32
|
+
module: { name }
|
|
34
33
|
} = state;
|
|
35
34
|
const channelVariable = formatChannelVariable(channelName);
|
|
36
35
|
const channelGetter = formatChannelGetter(channelName);
|
|
@@ -43,7 +42,7 @@ var transforms = {
|
|
|
43
42
|
return;
|
|
44
43
|
}
|
|
45
44
|
const sharedHookLookup = hasSharedHookLookup ? "" : `
|
|
46
|
-
const ${SHARED_HOOK_LOOKUP} = (__bt$hookName
|
|
45
|
+
const ${SHARED_HOOK_LOOKUP} = (__bt$hookName) => {
|
|
47
46
|
try {
|
|
48
47
|
const __bt$hooks = globalThis[${JSON.stringify(
|
|
49
48
|
GLOBAL_INSTRUMENTATION_HOOKS_KEY
|
|
@@ -65,8 +64,7 @@ var transforms = {
|
|
|
65
64
|
__bt$hook[Symbol.for(${JSON.stringify(
|
|
66
65
|
GLOBAL_INSTRUMENTATION_HOOK_BRAND
|
|
67
66
|
)})] !== ${GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION} ||
|
|
68
|
-
typeof __bt$hook.
|
|
69
|
-
typeof __bt$hook[__bt$operator] !== "function"
|
|
67
|
+
typeof __bt$hook.traceInvocation !== "function"
|
|
70
68
|
) return undefined;
|
|
71
69
|
return __bt$hook;
|
|
72
70
|
} catch {
|
|
@@ -79,8 +77,7 @@ var transforms = {
|
|
|
79
77
|
let ${channelVariable};
|
|
80
78
|
const ${channelGetter} = () =>
|
|
81
79
|
${channelVariable} ??= ${SHARED_HOOK_LOOKUP}(
|
|
82
|
-
${JSON.stringify(`orchestrion:${name}:${channelName}`)}
|
|
83
|
-
${JSON.stringify(operator)}
|
|
80
|
+
${JSON.stringify(`orchestrion:${name}:${channelName}`)}
|
|
84
81
|
);
|
|
85
82
|
`;
|
|
86
83
|
const sharedHookLookupIndex = node.body.findIndex(
|
|
@@ -155,28 +152,18 @@ function traceInstanceMethod(state, node, program) {
|
|
|
155
152
|
ctor.value.body.body.push(...ctorBody);
|
|
156
153
|
}
|
|
157
154
|
function wrap(state, node) {
|
|
158
|
-
const
|
|
159
|
-
const wrapper = operator === "traceCallback" ? wrapCallback(state) : operator === "tracePromise" ? wrapPromise(state) : wrapSync(state);
|
|
155
|
+
const wrapper = wrapInvocation(state);
|
|
160
156
|
const block = wrapper.body[0].body;
|
|
161
157
|
const common = parse(
|
|
162
158
|
node.type === "ArrowFunctionExpression" ? `
|
|
163
|
-
const __bt$
|
|
164
|
-
arguments,
|
|
165
|
-
moduleVersion: ${JSON.stringify(moduleVersion)}
|
|
166
|
-
};
|
|
167
|
-
const __bt$traced = () => {
|
|
159
|
+
const __bt$target = (...__bt$args) => {
|
|
168
160
|
const __bt$wrapped = () => {};
|
|
169
|
-
return __bt$wrapped(...
|
|
161
|
+
return __bt$wrapped(...__bt$args);
|
|
170
162
|
};
|
|
171
163
|
` : `
|
|
172
|
-
const __bt$
|
|
173
|
-
arguments,
|
|
174
|
-
self: this,
|
|
175
|
-
moduleVersion: ${JSON.stringify(moduleVersion)}
|
|
176
|
-
};
|
|
177
|
-
const __bt$traced = () => {
|
|
164
|
+
const __bt$target = function (...__bt$args) {
|
|
178
165
|
const __bt$wrapped = () => {};
|
|
179
|
-
return __bt$wrapped.apply(this,
|
|
166
|
+
return __bt$wrapped.apply(this, __bt$args);
|
|
180
167
|
};
|
|
181
168
|
`
|
|
182
169
|
).body;
|
|
@@ -218,49 +205,25 @@ function wrapSuper(node) {
|
|
|
218
205
|
node.body.body.unshift(parse("const __bt$super = {}").body[0]);
|
|
219
206
|
}
|
|
220
207
|
}
|
|
221
|
-
function
|
|
222
|
-
const {
|
|
223
|
-
channelName,
|
|
224
|
-
functionQuery: { callbackIndex = -1 }
|
|
225
|
-
} = state;
|
|
208
|
+
function wrapInvocation(state) {
|
|
209
|
+
const { channelName, moduleVersion, operator, functionQuery } = state;
|
|
226
210
|
const channelGetter = formatChannelGetter(channelName);
|
|
211
|
+
const callbackIndex = functionQuery.callbackIndex ?? -1;
|
|
227
212
|
return parse(`
|
|
228
213
|
function wrapper () {
|
|
229
214
|
const __bt$hook = ${channelGetter}();
|
|
230
|
-
if (!__bt$hook
|
|
231
|
-
__bt$
|
|
232
|
-
|
|
233
|
-
__bt$
|
|
234
|
-
|
|
235
|
-
|
|
215
|
+
if (!__bt$hook) return __bt$target.apply(this, arguments);
|
|
216
|
+
return __bt$hook.traceInvocation(
|
|
217
|
+
${JSON.stringify(operator)},
|
|
218
|
+
__bt$target,
|
|
219
|
+
this,
|
|
220
|
+
arguments,
|
|
221
|
+
{ moduleVersion: ${JSON.stringify(moduleVersion)} },
|
|
222
|
+
${callbackIndex}
|
|
236
223
|
);
|
|
237
224
|
}
|
|
238
225
|
`);
|
|
239
226
|
}
|
|
240
|
-
function wrapPromise(state) {
|
|
241
|
-
const { channelName } = state;
|
|
242
|
-
const channelGetter = formatChannelGetter(channelName);
|
|
243
|
-
return parse(`
|
|
244
|
-
function wrapper () {
|
|
245
|
-
const __bt$hook = ${channelGetter}();
|
|
246
|
-
if (!__bt$hook?.hasSubscribers) return __bt$traced();
|
|
247
|
-
__bt$ctx.self ??= this;
|
|
248
|
-
return __bt$hook.tracePromise(__bt$traced, __bt$ctx);
|
|
249
|
-
}
|
|
250
|
-
`);
|
|
251
|
-
}
|
|
252
|
-
function wrapSync(state) {
|
|
253
|
-
const { channelName } = state;
|
|
254
|
-
const channelGetter = formatChannelGetter(channelName);
|
|
255
|
-
return parse(`
|
|
256
|
-
function wrapper () {
|
|
257
|
-
const __bt$hook = ${channelGetter}();
|
|
258
|
-
if (!__bt$hook?.hasSubscribers) return __bt$traced();
|
|
259
|
-
__bt$ctx.self ??= this;
|
|
260
|
-
return __bt$hook.traceSync(__bt$traced, __bt$ctx);
|
|
261
|
-
}
|
|
262
|
-
`);
|
|
263
|
-
}
|
|
264
227
|
|
|
265
228
|
// src/auto-instrumentations/orchestrion-js/transformer.ts
|
|
266
229
|
var Transformer = class {
|