braintrust 3.25.0 → 3.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +6 -0
- package/dev/dist/index.d.mts +130 -2
- package/dev/dist/index.d.ts +130 -2
- package/dev/dist/index.js +2455 -1116
- package/dev/dist/index.mjs +1599 -260
- package/dist/apply-auto-instrumentation.js +439 -398
- package/dist/apply-auto-instrumentation.mjs +242 -201
- package/dist/auto-instrumentations/bundler/esbuild.cjs +853 -337
- package/dist/auto-instrumentations/bundler/esbuild.d.mts +4 -4
- package/dist/auto-instrumentations/bundler/esbuild.d.ts +4 -4
- package/dist/auto-instrumentations/bundler/esbuild.mjs +5 -8
- package/dist/auto-instrumentations/bundler/next.cjs +852 -356
- package/dist/auto-instrumentations/bundler/next.mjs +6 -29
- package/dist/auto-instrumentations/bundler/rollup.cjs +853 -337
- package/dist/auto-instrumentations/bundler/rollup.d.mts +4 -4
- package/dist/auto-instrumentations/bundler/rollup.d.ts +4 -4
- package/dist/auto-instrumentations/bundler/rollup.mjs +5 -8
- package/dist/auto-instrumentations/bundler/vite.cjs +853 -337
- package/dist/auto-instrumentations/bundler/vite.d.mts +4 -4
- package/dist/auto-instrumentations/bundler/vite.d.ts +4 -4
- package/dist/auto-instrumentations/bundler/vite.mjs +5 -8
- package/dist/auto-instrumentations/bundler/webpack-loader.cjs +1006 -266
- package/dist/auto-instrumentations/bundler/webpack-loader.d.ts +20 -12
- package/dist/auto-instrumentations/bundler/webpack.cjs +853 -337
- package/dist/auto-instrumentations/bundler/webpack.d.mts +4 -4
- package/dist/auto-instrumentations/bundler/webpack.d.ts +4 -4
- package/dist/auto-instrumentations/bundler/webpack.mjs +5 -4
- package/dist/auto-instrumentations/{chunk-JPVCUKTY.mjs → chunk-6E22MYSW.mjs} +165 -73
- package/dist/auto-instrumentations/{chunk-VT6DDNKM.mjs → chunk-AKKPLXTP.mjs} +631 -194
- package/dist/auto-instrumentations/chunk-NRE4QUQR.mjs +509 -0
- package/dist/auto-instrumentations/{chunk-7P6563SW.mjs → chunk-V5LEODRX.mjs} +2 -6
- package/dist/auto-instrumentations/{chunk-M6DLIJ2Z.mjs → chunk-XYN63IG5.mjs} +124 -194
- package/dist/auto-instrumentations/{chunk-CZ24KNHT.mjs → chunk-XZHHE4Y3.mjs} +77 -68
- package/dist/auto-instrumentations/hook.mjs +247 -182
- package/dist/auto-instrumentations/index.cjs +557 -48
- package/dist/auto-instrumentations/index.d.mts +6 -2
- package/dist/auto-instrumentations/index.d.ts +6 -2
- package/dist/auto-instrumentations/index.mjs +6 -1
- package/dist/auto-instrumentations/loader/cjs-patch.cjs +492 -195
- package/dist/auto-instrumentations/loader/cjs-patch.d.mts +2 -2
- package/dist/auto-instrumentations/loader/cjs-patch.d.ts +2 -2
- package/dist/auto-instrumentations/loader/cjs-patch.mjs +3 -2
- package/dist/auto-instrumentations/loader/esm-hook.mjs +1 -1
- package/dist/auto-instrumentations/plugin-B-aZh7EP.d.ts +30 -0
- package/dist/auto-instrumentations/plugin-Bnj4E_6B.d.mts +30 -0
- package/dist/auto-instrumentations/{types-RNPaKi9o.d.mts → types-C1fVeiCp.d.mts} +1 -1
- package/dist/auto-instrumentations/{types-RNPaKi9o.d.ts → types-C1fVeiCp.d.ts} +1 -1
- package/dist/browser.d.mts +817 -197
- package/dist/browser.d.ts +817 -197
- package/dist/browser.js +1883 -265
- package/dist/browser.mjs +1883 -265
- package/dist/{chunk-ABR2QWDP.mjs → chunk-PN7EWK66.mjs} +581 -133
- package/dist/{chunk-GSIDVFE6.js → chunk-VRZZQPAA.js} +1670 -736
- package/dist/{chunk-P25IOOU4.js → chunk-VYNNEKSA.js} +586 -138
- package/dist/{chunk-2SANLSWX.mjs → chunk-XIZOM2HO.mjs} +1052 -118
- package/dist/cli.js +1601 -263
- package/dist/edge-light.d.mts +1 -1
- package/dist/edge-light.d.ts +1 -1
- package/dist/edge-light.js +1883 -268
- package/dist/edge-light.mjs +1883 -268
- package/dist/index.d.mts +817 -197
- package/dist/index.d.ts +817 -197
- package/dist/index.js +695 -435
- package/dist/index.mjs +264 -4
- package/dist/instrumentation/index.d.mts +130 -6
- package/dist/instrumentation/index.d.ts +130 -6
- package/dist/instrumentation/index.js +1510 -80
- package/dist/instrumentation/index.mjs +1510 -80
- package/dist/vitest-evals-reporter.js +16 -16
- package/dist/vitest-evals-reporter.mjs +2 -2
- package/dist/workerd.d.mts +1 -1
- package/dist/workerd.d.ts +1 -1
- package/dist/workerd.js +1883 -268
- package/dist/workerd.mjs +1883 -268
- package/licenses/node-diagnostics-channel/LICENSE +19 -0
- package/package.json +34 -35
- package/dist/auto-instrumentations/plugin-D0KHwSJv.d.mts +0 -44
- package/dist/auto-instrumentations/plugin-G6fgxk1b.d.ts +0 -44
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
+
GLOBAL_INSTRUMENTATION_HOOKS_KEY,
|
|
3
|
+
GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION,
|
|
4
|
+
GLOBAL_INSTRUMENTATION_HOOKS_REGISTRY_BRAND,
|
|
5
|
+
GLOBAL_INSTRUMENTATION_HOOK_BRAND,
|
|
2
6
|
aiSDKChannels,
|
|
3
7
|
anthropicChannels,
|
|
4
8
|
classifyMastraTarget,
|
|
5
9
|
claudeAgentSDKChannels,
|
|
10
|
+
cloudflareAIChatChannels,
|
|
11
|
+
cloudflareAgentsChannels,
|
|
6
12
|
cohereChannels,
|
|
7
13
|
cursorSDKChannels,
|
|
8
14
|
flueChannels,
|
|
@@ -14,6 +20,7 @@ import {
|
|
|
14
20
|
groqChannels,
|
|
15
21
|
harnessAgentChannels,
|
|
16
22
|
huggingFaceChannels,
|
|
23
|
+
huggingFaceTransformersChannels,
|
|
17
24
|
isInstrumentationIntegrationDisabled,
|
|
18
25
|
langChainChannels,
|
|
19
26
|
langSmithChannels,
|
|
@@ -24,16 +31,14 @@ import {
|
|
|
24
31
|
openRouterAgentChannels,
|
|
25
32
|
openRouterChannels,
|
|
26
33
|
patchMastraSource,
|
|
27
|
-
patchTracingChannel,
|
|
28
34
|
piCodingAgentChannels,
|
|
29
35
|
readDisabledInstrumentationEnvConfig,
|
|
30
36
|
smithyClientChannels,
|
|
31
37
|
smithyCoreChannels,
|
|
32
38
|
strandsAgentSDKChannels
|
|
33
|
-
} from "./chunk-
|
|
39
|
+
} from "./chunk-PN7EWK66.mjs";
|
|
34
40
|
|
|
35
41
|
// src/node/apply-auto-instrumentation-entry.ts
|
|
36
|
-
import * as diagnostics_channel from "node:diagnostics_channel";
|
|
37
42
|
import { register } from "node:module";
|
|
38
43
|
import { pathToFileURL } from "node:url";
|
|
39
44
|
|
|
@@ -634,6 +639,46 @@ var claudeAgentSDKConfigs = [
|
|
|
634
639
|
}
|
|
635
640
|
];
|
|
636
641
|
|
|
642
|
+
// src/auto-instrumentations/configs/cloudflare-ai-chat.ts
|
|
643
|
+
var cloudflareAIChatVersionRange = ">=0.9.0 <0.10.0";
|
|
644
|
+
var cloudflareAIChatConfigs = [
|
|
645
|
+
{
|
|
646
|
+
// AIChatAgent subclasses replace onChatMessage, so there is no stable
|
|
647
|
+
// public implementation for the transformer to target. This runner is
|
|
648
|
+
// the narrowest shared boundary around every chat turn; keep the version
|
|
649
|
+
// range tight because it is an internal method.
|
|
650
|
+
channelName: cloudflareAIChatChannels.runExclusiveChatTurn.channelName,
|
|
651
|
+
module: {
|
|
652
|
+
name: "@cloudflare/ai-chat",
|
|
653
|
+
versionRange: cloudflareAIChatVersionRange,
|
|
654
|
+
filePath: "dist/index.js"
|
|
655
|
+
},
|
|
656
|
+
functionQuery: {
|
|
657
|
+
className: "AIChatAgent",
|
|
658
|
+
methodName: "_runExclusiveChatTurn",
|
|
659
|
+
kind: "Async"
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
];
|
|
663
|
+
|
|
664
|
+
// src/auto-instrumentations/configs/cloudflare-agents.ts
|
|
665
|
+
var cloudflareAgentsVersionRange = ">=0.17.0 <0.18.0";
|
|
666
|
+
var cloudflareAgentsConfigs = [
|
|
667
|
+
{
|
|
668
|
+
channelName: cloudflareAgentsChannels.runAgentTool.channelName,
|
|
669
|
+
module: {
|
|
670
|
+
name: "agents",
|
|
671
|
+
versionRange: cloudflareAgentsVersionRange,
|
|
672
|
+
filePath: "dist/index.js"
|
|
673
|
+
},
|
|
674
|
+
functionQuery: {
|
|
675
|
+
className: "Agent",
|
|
676
|
+
methodName: "runAgentTool",
|
|
677
|
+
kind: "Async"
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
];
|
|
681
|
+
|
|
637
682
|
// src/auto-instrumentations/configs/cohere.ts
|
|
638
683
|
var cohereConfigs = [
|
|
639
684
|
{
|
|
@@ -1786,6 +1831,67 @@ var huggingFaceConfigs = [
|
|
|
1786
1831
|
}
|
|
1787
1832
|
];
|
|
1788
1833
|
|
|
1834
|
+
// src/auto-instrumentations/configs/huggingface-transformers.ts
|
|
1835
|
+
var moduleFiles = [
|
|
1836
|
+
{
|
|
1837
|
+
filePath: "dist/transformers.mjs",
|
|
1838
|
+
versionRange: ">=3.0.0 <3.4.0"
|
|
1839
|
+
},
|
|
1840
|
+
{
|
|
1841
|
+
filePath: "dist/transformers.cjs",
|
|
1842
|
+
versionRange: ">=3.0.0 <3.4.0"
|
|
1843
|
+
},
|
|
1844
|
+
{
|
|
1845
|
+
filePath: "dist/transformers.js",
|
|
1846
|
+
versionRange: ">=3.0.0 <3.4.0"
|
|
1847
|
+
},
|
|
1848
|
+
{
|
|
1849
|
+
filePath: "dist/transformers.node.mjs",
|
|
1850
|
+
versionRange: ">=3.4.0 <5.0.0"
|
|
1851
|
+
},
|
|
1852
|
+
{
|
|
1853
|
+
filePath: "dist/transformers.node.cjs",
|
|
1854
|
+
versionRange: ">=3.4.0 <5.0.0"
|
|
1855
|
+
},
|
|
1856
|
+
{
|
|
1857
|
+
filePath: "dist/transformers.web.js",
|
|
1858
|
+
versionRange: ">=3.4.0 <5.0.0"
|
|
1859
|
+
}
|
|
1860
|
+
];
|
|
1861
|
+
var pipelineClasses = [
|
|
1862
|
+
"TextGenerationPipeline",
|
|
1863
|
+
"Text2TextGenerationPipeline",
|
|
1864
|
+
"FeatureExtractionPipeline",
|
|
1865
|
+
"QuestionAnsweringPipeline"
|
|
1866
|
+
];
|
|
1867
|
+
var huggingFaceTransformersConfigs = moduleFiles.flatMap(({ filePath, versionRange: versionRange2 }) => [
|
|
1868
|
+
{
|
|
1869
|
+
channelName: huggingFaceTransformersChannels.pipeline.channelName,
|
|
1870
|
+
module: {
|
|
1871
|
+
name: "@huggingface/transformers",
|
|
1872
|
+
versionRange: versionRange2,
|
|
1873
|
+
filePath
|
|
1874
|
+
},
|
|
1875
|
+
functionQuery: {
|
|
1876
|
+
functionName: "pipeline",
|
|
1877
|
+
kind: "Async"
|
|
1878
|
+
}
|
|
1879
|
+
},
|
|
1880
|
+
...pipelineClasses.map((className) => ({
|
|
1881
|
+
channelName: huggingFaceTransformersChannels.pipelineCall.channelName,
|
|
1882
|
+
module: {
|
|
1883
|
+
name: "@huggingface/transformers",
|
|
1884
|
+
versionRange: versionRange2,
|
|
1885
|
+
filePath
|
|
1886
|
+
},
|
|
1887
|
+
functionQuery: {
|
|
1888
|
+
className,
|
|
1889
|
+
methodName: "_call",
|
|
1890
|
+
kind: "Async"
|
|
1891
|
+
}
|
|
1892
|
+
}))
|
|
1893
|
+
]);
|
|
1894
|
+
|
|
1789
1895
|
// src/auto-instrumentations/configs/langchain.ts
|
|
1790
1896
|
var langChainCoreVersionRange = ">=0.3.42";
|
|
1791
1897
|
var langChainCallbackManagerFilePath = "dist/callbacks/manager.js";
|
|
@@ -2544,6 +2650,14 @@ var defaultInstrumentationConfigGroups = [
|
|
|
2544
2650
|
integrations: ["claudeAgentSDK"],
|
|
2545
2651
|
configs: claudeAgentSDKConfigs
|
|
2546
2652
|
},
|
|
2653
|
+
{
|
|
2654
|
+
integrations: ["cloudflareAIChat"],
|
|
2655
|
+
configs: cloudflareAIChatConfigs
|
|
2656
|
+
},
|
|
2657
|
+
{
|
|
2658
|
+
integrations: ["cloudflareAgents"],
|
|
2659
|
+
configs: cloudflareAgentsConfigs
|
|
2660
|
+
},
|
|
2547
2661
|
{ integrations: ["cursor", "cursorSDK"], configs: cursorSDKConfigs },
|
|
2548
2662
|
{
|
|
2549
2663
|
integrations: ["openAIAgents"],
|
|
@@ -2553,7 +2667,10 @@ var defaultInstrumentationConfigGroups = [
|
|
|
2553
2667
|
integrations: ["google", "googleGenAI"],
|
|
2554
2668
|
configs: googleGenAIConfigs
|
|
2555
2669
|
},
|
|
2556
|
-
{
|
|
2670
|
+
{
|
|
2671
|
+
integrations: ["huggingface"],
|
|
2672
|
+
configs: [...huggingFaceConfigs, ...huggingFaceTransformersConfigs]
|
|
2673
|
+
},
|
|
2557
2674
|
{
|
|
2558
2675
|
integrations: ["langchain", "langgraph"],
|
|
2559
2676
|
configs: langchainConfigs
|
|
@@ -2631,52 +2748,79 @@ import { SourceMapGenerator } from "source-map";
|
|
|
2631
2748
|
// src/auto-instrumentations/orchestrion-js/transforms.ts
|
|
2632
2749
|
import esquery from "esquery";
|
|
2633
2750
|
import { parse } from "meriyah";
|
|
2634
|
-
var tracingChannelPredicate = (node) => node.declarations?.[0]?.id?.properties?.[0]?.value?.name === "tr_ch_apm_tracingChannel";
|
|
2635
2751
|
var CHANNEL_REGEX = /[^\w]/g;
|
|
2752
|
+
var SHARED_HOOK_LOOKUP = "tr_ch_bt$get_hook";
|
|
2636
2753
|
function formatChannelVariable(channelName) {
|
|
2637
|
-
return `
|
|
2754
|
+
return `tr_ch_bt$${channelName.replace(CHANNEL_REGEX, "_")}`;
|
|
2755
|
+
}
|
|
2756
|
+
function formatChannelGetter(channelName) {
|
|
2757
|
+
return `tr_ch_bt$get_${channelName.replace(CHANNEL_REGEX, "_")}`;
|
|
2638
2758
|
}
|
|
2639
2759
|
var transforms = {
|
|
2640
|
-
|
|
2641
|
-
if (node.body.some(tracingChannelPredicate)) {
|
|
2642
|
-
return;
|
|
2643
|
-
}
|
|
2644
|
-
const options = { module: moduleType === "esm" };
|
|
2645
|
-
const index = node.body.findIndex(
|
|
2646
|
-
(child) => child.directive === "use strict"
|
|
2647
|
-
);
|
|
2648
|
-
const dc = moduleType === "esm" ? `import tr_ch_apm_dc from "${dcModule}"` : `const tr_ch_apm_dc = ${"require"}("${dcModule}")`;
|
|
2649
|
-
const tracingChannel2 = "const { tracingChannel: tr_ch_apm_tracingChannel } = tr_ch_apm_dc";
|
|
2650
|
-
const hasSubscribers = `const tr_ch_apm_hasSubscribers = ch => ch.start.hasSubscribers
|
|
2651
|
-
|| ch.end.hasSubscribers
|
|
2652
|
-
|| ch.asyncStart.hasSubscribers
|
|
2653
|
-
|| ch.asyncEnd.hasSubscribers
|
|
2654
|
-
|| ch.error.hasSubscribers`;
|
|
2655
|
-
node.body.splice(
|
|
2656
|
-
index + 1,
|
|
2657
|
-
0,
|
|
2658
|
-
parse(dc, options).body[0],
|
|
2659
|
-
parse(tracingChannel2, options).body[0],
|
|
2660
|
-
parse(hasSubscribers, options).body[0]
|
|
2661
|
-
);
|
|
2662
|
-
},
|
|
2663
|
-
tracingChannelDeclaration(state2, node) {
|
|
2760
|
+
tracingHookDeclaration(state2, node) {
|
|
2664
2761
|
const {
|
|
2665
2762
|
channelName,
|
|
2666
|
-
module: { name }
|
|
2763
|
+
module: { name },
|
|
2764
|
+
operator
|
|
2667
2765
|
} = state2;
|
|
2668
2766
|
const channelVariable = formatChannelVariable(channelName);
|
|
2767
|
+
const channelGetter = formatChannelGetter(channelName);
|
|
2768
|
+
const hasSharedHookLookup = node.body.some(
|
|
2769
|
+
(child) => child.declarations?.[0]?.id?.name === SHARED_HOOK_LOOKUP
|
|
2770
|
+
);
|
|
2669
2771
|
if (node.body.some(
|
|
2670
|
-
(child) => child.declarations?.[0]?.id?.name ===
|
|
2772
|
+
(child) => child.declarations?.[0]?.id?.name === channelGetter
|
|
2671
2773
|
)) {
|
|
2672
2774
|
return;
|
|
2673
2775
|
}
|
|
2674
|
-
|
|
2675
|
-
|
|
2776
|
+
const sharedHookLookup = hasSharedHookLookup ? "" : `
|
|
2777
|
+
const ${SHARED_HOOK_LOOKUP} = (__bt$hookName, __bt$operator) => {
|
|
2778
|
+
try {
|
|
2779
|
+
const __bt$hooks = globalThis[${JSON.stringify(
|
|
2780
|
+
GLOBAL_INSTRUMENTATION_HOOKS_KEY
|
|
2781
|
+
)}];
|
|
2782
|
+
if (
|
|
2783
|
+
!(__bt$hooks instanceof Map) ||
|
|
2784
|
+
__bt$hooks[Symbol.for(${JSON.stringify(
|
|
2785
|
+
GLOBAL_INSTRUMENTATION_HOOKS_REGISTRY_BRAND
|
|
2786
|
+
)})] !== ${GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION}
|
|
2787
|
+
) return undefined;
|
|
2788
|
+
const __bt$hook = Map.prototype.get.call(
|
|
2789
|
+
__bt$hooks,
|
|
2790
|
+
__bt$hookName
|
|
2791
|
+
);
|
|
2792
|
+
if (
|
|
2793
|
+
(__bt$hook === null ||
|
|
2794
|
+
(typeof __bt$hook !== "object" &&
|
|
2795
|
+
typeof __bt$hook !== "function")) ||
|
|
2796
|
+
__bt$hook[Symbol.for(${JSON.stringify(
|
|
2797
|
+
GLOBAL_INSTRUMENTATION_HOOK_BRAND
|
|
2798
|
+
)})] !== ${GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION} ||
|
|
2799
|
+
typeof __bt$hook.hasSubscribers !== "boolean" ||
|
|
2800
|
+
typeof __bt$hook[__bt$operator] !== "function"
|
|
2801
|
+
) return undefined;
|
|
2802
|
+
return __bt$hook;
|
|
2803
|
+
} catch {
|
|
2804
|
+
return undefined;
|
|
2805
|
+
}
|
|
2806
|
+
};
|
|
2807
|
+
`;
|
|
2676
2808
|
const code = `
|
|
2677
|
-
|
|
2809
|
+
${sharedHookLookup}
|
|
2810
|
+
let ${channelVariable};
|
|
2811
|
+
const ${channelGetter} = () =>
|
|
2812
|
+
${channelVariable} ??= ${SHARED_HOOK_LOOKUP}(
|
|
2813
|
+
${JSON.stringify(`orchestrion:${name}:${channelName}`)},
|
|
2814
|
+
${JSON.stringify(operator)}
|
|
2815
|
+
);
|
|
2678
2816
|
`;
|
|
2679
|
-
node.body.
|
|
2817
|
+
const sharedHookLookupIndex = node.body.findIndex(
|
|
2818
|
+
(child) => child.declarations?.[0]?.id?.name === SHARED_HOOK_LOOKUP
|
|
2819
|
+
);
|
|
2820
|
+
const index = sharedHookLookupIndex === -1 ? node.body.findIndex(
|
|
2821
|
+
(child) => child.directive === "use strict"
|
|
2822
|
+
) : sharedHookLookupIndex;
|
|
2823
|
+
node.body.splice(index + 1, 0, ...parse(code).body);
|
|
2680
2824
|
},
|
|
2681
2825
|
traceCallback: traceAny,
|
|
2682
2826
|
tracePromise: traceAny,
|
|
@@ -2691,25 +2835,21 @@ function traceAny(state2, node, _parent, ancestry) {
|
|
|
2691
2835
|
}
|
|
2692
2836
|
}
|
|
2693
2837
|
function traceFunction(state2, node, program) {
|
|
2694
|
-
transforms.
|
|
2838
|
+
transforms.tracingHookDeclaration(state2, program, null, []);
|
|
2695
2839
|
const { functionQuery } = state2;
|
|
2696
2840
|
const methodName = "methodName" in functionQuery ? functionQuery.methodName : void 0;
|
|
2697
2841
|
const privateMethodName = "privateMethodName" in functionQuery ? functionQuery.privateMethodName : void 0;
|
|
2698
2842
|
const functionName = "functionName" in functionQuery ? functionQuery.functionName : void 0;
|
|
2699
2843
|
const isConstructor = methodName === "constructor" || !methodName && !privateMethodName && !functionName;
|
|
2700
2844
|
const type = isConstructor ? "ArrowFunctionExpression" : "FunctionExpression";
|
|
2701
|
-
node.body = wrap(
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
generator: node.generator
|
|
2710
|
-
},
|
|
2711
|
-
program
|
|
2712
|
-
);
|
|
2845
|
+
node.body = wrap(state2, {
|
|
2846
|
+
type,
|
|
2847
|
+
params: node.params,
|
|
2848
|
+
body: node.body,
|
|
2849
|
+
async: node.async,
|
|
2850
|
+
expression: false,
|
|
2851
|
+
generator: node.generator
|
|
2852
|
+
});
|
|
2713
2853
|
node.generator = false;
|
|
2714
2854
|
node.async = false;
|
|
2715
2855
|
wrapSuper(node);
|
|
@@ -2721,11 +2861,11 @@ function traceInstanceMethod(state2, node, program) {
|
|
|
2721
2861
|
return;
|
|
2722
2862
|
}
|
|
2723
2863
|
const classBody = node.body;
|
|
2724
|
-
if (classBody.body.some(({ key }) => key
|
|
2864
|
+
if (classBody.body.some(({ key }) => key?.name === methodName)) {
|
|
2725
2865
|
return;
|
|
2726
2866
|
}
|
|
2727
2867
|
let ctor = classBody.body.find(({ kind }) => kind === "constructor");
|
|
2728
|
-
transforms.
|
|
2868
|
+
transforms.tracingHookDeclaration(state2, program, null, []);
|
|
2729
2869
|
if (!ctor) {
|
|
2730
2870
|
ctor = parse(
|
|
2731
2871
|
node.superClass ? "class A extends Object { constructor (...args) { super(...args) } }" : "class A { constructor () {} }"
|
|
@@ -2733,47 +2873,46 @@ function traceInstanceMethod(state2, node, program) {
|
|
|
2733
2873
|
classBody.body.unshift(ctor);
|
|
2734
2874
|
}
|
|
2735
2875
|
const ctorBody = parse(`
|
|
2736
|
-
const
|
|
2876
|
+
const __bt$${methodName} = this["${methodName}"]
|
|
2737
2877
|
this["${methodName}"] = function () {}
|
|
2738
2878
|
`).body;
|
|
2739
2879
|
const fn = ctorBody[1].expression.right;
|
|
2740
2880
|
fn.async = operator === "tracePromise";
|
|
2741
|
-
fn.body = wrap(
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
);
|
|
2881
|
+
fn.body = wrap(state2, {
|
|
2882
|
+
type: "Identifier",
|
|
2883
|
+
name: `__bt$${methodName}`
|
|
2884
|
+
});
|
|
2746
2885
|
wrapSuper(fn);
|
|
2747
2886
|
ctor.value.body.body.push(...ctorBody);
|
|
2748
2887
|
}
|
|
2749
|
-
function wrap(state2, node
|
|
2888
|
+
function wrap(state2, node) {
|
|
2750
2889
|
const { operator, moduleVersion } = state2;
|
|
2751
2890
|
const wrapper = operator === "traceCallback" ? wrapCallback(state2) : operator === "tracePromise" ? wrapPromise(state2) : wrapSync(state2);
|
|
2752
2891
|
const block = wrapper.body[0].body;
|
|
2753
2892
|
const common = parse(
|
|
2754
2893
|
node.type === "ArrowFunctionExpression" ? `
|
|
2755
|
-
const
|
|
2894
|
+
const __bt$ctx = {
|
|
2756
2895
|
arguments,
|
|
2757
2896
|
moduleVersion: ${JSON.stringify(moduleVersion)}
|
|
2758
2897
|
};
|
|
2759
|
-
const
|
|
2760
|
-
const
|
|
2761
|
-
return
|
|
2898
|
+
const __bt$traced = () => {
|
|
2899
|
+
const __bt$wrapped = () => {};
|
|
2900
|
+
return __bt$wrapped(...arguments);
|
|
2762
2901
|
};
|
|
2763
2902
|
` : `
|
|
2764
|
-
const
|
|
2903
|
+
const __bt$ctx = {
|
|
2765
2904
|
arguments,
|
|
2766
2905
|
self: this,
|
|
2767
2906
|
moduleVersion: ${JSON.stringify(moduleVersion)}
|
|
2768
2907
|
};
|
|
2769
|
-
const
|
|
2770
|
-
const
|
|
2771
|
-
return
|
|
2908
|
+
const __bt$traced = () => {
|
|
2909
|
+
const __bt$wrapped = () => {};
|
|
2910
|
+
return __bt$wrapped.apply(this, arguments);
|
|
2772
2911
|
};
|
|
2773
2912
|
`
|
|
2774
2913
|
).body;
|
|
2775
2914
|
block.body.unshift(...common);
|
|
2776
|
-
esquery.query(block, "[id.name=
|
|
2915
|
+
esquery.query(block, "[id.name=__bt$wrapped]")[0].init = node;
|
|
2777
2916
|
return block;
|
|
2778
2917
|
}
|
|
2779
2918
|
function wrapSuper(node) {
|
|
@@ -2785,11 +2924,11 @@ function wrapSuper(node) {
|
|
|
2785
2924
|
const { name } = node2.property;
|
|
2786
2925
|
let child;
|
|
2787
2926
|
if (parent.callee) {
|
|
2788
|
-
const { expression } = parse(`
|
|
2927
|
+
const { expression } = parse(`__bt$super['${name}'].call(this)`).body[0];
|
|
2789
2928
|
parent.callee = child = expression.callee;
|
|
2790
2929
|
parent.arguments.unshift(...expression.arguments);
|
|
2791
2930
|
} else {
|
|
2792
|
-
parent.expression = child = parse(`
|
|
2931
|
+
parent.expression = child = parse(`__bt$super['${name}']`).body[0];
|
|
2793
2932
|
}
|
|
2794
2933
|
child.computed = parent.callee.computed;
|
|
2795
2934
|
child.optional = parent.callee.optional;
|
|
@@ -2800,14 +2939,14 @@ function wrapSuper(node) {
|
|
|
2800
2939
|
const member = parse(`
|
|
2801
2940
|
class Wrapper {
|
|
2802
2941
|
wrapper () {
|
|
2803
|
-
|
|
2942
|
+
__bt$super['${name}'] = super['${name}']
|
|
2804
2943
|
}
|
|
2805
2944
|
}
|
|
2806
2945
|
`).body[0].body.body[0].value.body.body[0];
|
|
2807
2946
|
node.body.body.unshift(member);
|
|
2808
2947
|
}
|
|
2809
2948
|
if (members.size > 0) {
|
|
2810
|
-
node.body.body.unshift(parse("const
|
|
2949
|
+
node.body.body.unshift(parse("const __bt$super = {}").body[0]);
|
|
2811
2950
|
}
|
|
2812
2951
|
}
|
|
2813
2952
|
function wrapCallback(state2) {
|
|
@@ -2815,136 +2954,41 @@ function wrapCallback(state2) {
|
|
|
2815
2954
|
channelName,
|
|
2816
2955
|
functionQuery: { callbackIndex = -1 }
|
|
2817
2956
|
} = state2;
|
|
2818
|
-
const
|
|
2957
|
+
const channelGetter = formatChannelGetter(channelName);
|
|
2819
2958
|
return parse(`
|
|
2820
2959
|
function wrapper () {
|
|
2821
|
-
const
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
} else {
|
|
2830
|
-
__apm$ctx.result = res;
|
|
2831
|
-
}
|
|
2832
|
-
|
|
2833
|
-
${channelVariable}.asyncStart.runStores(__apm$ctx, () => {
|
|
2834
|
-
try {
|
|
2835
|
-
if (__apm$cb) {
|
|
2836
|
-
return __apm$cb.apply(this, arguments);
|
|
2837
|
-
}
|
|
2838
|
-
} finally {
|
|
2839
|
-
${channelVariable}.asyncEnd.publish(__apm$ctx);
|
|
2840
|
-
}
|
|
2841
|
-
});
|
|
2842
|
-
}
|
|
2843
|
-
|
|
2844
|
-
if (typeof __apm$cb !== 'function') {
|
|
2845
|
-
return __apm$traced();
|
|
2846
|
-
}
|
|
2847
|
-
Array.prototype.splice.call(arguments, ${callbackIndex}, 1, __apm$wrappedCb);
|
|
2848
|
-
|
|
2849
|
-
return ${channelVariable}.start.runStores(__apm$ctx, () => {
|
|
2850
|
-
try {
|
|
2851
|
-
return __apm$traced();
|
|
2852
|
-
} catch (err) {
|
|
2853
|
-
__apm$ctx.error = err;
|
|
2854
|
-
${channelVariable}.error.publish(__apm$ctx);
|
|
2855
|
-
throw err;
|
|
2856
|
-
} finally {
|
|
2857
|
-
__apm$ctx.self ??= this;
|
|
2858
|
-
${channelVariable}.end.publish(__apm$ctx);
|
|
2859
|
-
}
|
|
2860
|
-
});
|
|
2960
|
+
const __bt$hook = ${channelGetter}();
|
|
2961
|
+
if (!__bt$hook?.hasSubscribers) return __bt$traced();
|
|
2962
|
+
__bt$ctx.self ??= this;
|
|
2963
|
+
return __bt$hook.traceCallback(
|
|
2964
|
+
__bt$traced,
|
|
2965
|
+
${callbackIndex},
|
|
2966
|
+
__bt$ctx
|
|
2967
|
+
);
|
|
2861
2968
|
}
|
|
2862
2969
|
`);
|
|
2863
2970
|
}
|
|
2864
2971
|
function wrapPromise(state2) {
|
|
2865
2972
|
const { channelName } = state2;
|
|
2866
|
-
const
|
|
2973
|
+
const channelGetter = formatChannelGetter(channelName);
|
|
2867
2974
|
return parse(`
|
|
2868
2975
|
function wrapper () {
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
let promise = __apm$traced();
|
|
2874
|
-
if (typeof promise?.then !== 'function') {
|
|
2875
|
-
__apm$ctx.result = promise;
|
|
2876
|
-
return promise;
|
|
2877
|
-
}
|
|
2878
|
-
// Mirror Node.js core diagnostics_channel behaviour: for native Promise
|
|
2879
|
-
// instances, chain normally (safe since there is no subclass API to
|
|
2880
|
-
// preserve). For Promise subclasses and other thenables, side-chain the
|
|
2881
|
-
// callbacks for event publishing and return the original so that any
|
|
2882
|
-
// subclass-specific methods (e.g. APIPromise.withResponse()) remain
|
|
2883
|
-
// accessible to the caller.
|
|
2884
|
-
if (promise instanceof Promise && promise.constructor === Promise) {
|
|
2885
|
-
return promise.then(
|
|
2886
|
-
result => {
|
|
2887
|
-
__apm$ctx.result = result;
|
|
2888
|
-
${channelVariable}.asyncStart.publish(__apm$ctx);
|
|
2889
|
-
${channelVariable}.asyncEnd.publish(__apm$ctx);
|
|
2890
|
-
return result;
|
|
2891
|
-
},
|
|
2892
|
-
err => {
|
|
2893
|
-
__apm$ctx.error = err;
|
|
2894
|
-
${channelVariable}.error.publish(__apm$ctx);
|
|
2895
|
-
${channelVariable}.asyncStart.publish(__apm$ctx);
|
|
2896
|
-
${channelVariable}.asyncEnd.publish(__apm$ctx);
|
|
2897
|
-
throw err;
|
|
2898
|
-
}
|
|
2899
|
-
);
|
|
2900
|
-
}
|
|
2901
|
-
promise.then(
|
|
2902
|
-
result => {
|
|
2903
|
-
__apm$ctx.result = result;
|
|
2904
|
-
${channelVariable}.asyncStart.publish(__apm$ctx);
|
|
2905
|
-
${channelVariable}.asyncEnd.publish(__apm$ctx);
|
|
2906
|
-
},
|
|
2907
|
-
err => {
|
|
2908
|
-
__apm$ctx.error = err;
|
|
2909
|
-
${channelVariable}.error.publish(__apm$ctx);
|
|
2910
|
-
${channelVariable}.asyncStart.publish(__apm$ctx);
|
|
2911
|
-
${channelVariable}.asyncEnd.publish(__apm$ctx);
|
|
2912
|
-
}
|
|
2913
|
-
);
|
|
2914
|
-
return promise;
|
|
2915
|
-
} catch (err) {
|
|
2916
|
-
__apm$ctx.error = err;
|
|
2917
|
-
${channelVariable}.error.publish(__apm$ctx);
|
|
2918
|
-
throw err;
|
|
2919
|
-
} finally {
|
|
2920
|
-
__apm$ctx.self ??= this;
|
|
2921
|
-
${channelVariable}.end.publish(__apm$ctx);
|
|
2922
|
-
}
|
|
2923
|
-
});
|
|
2976
|
+
const __bt$hook = ${channelGetter}();
|
|
2977
|
+
if (!__bt$hook?.hasSubscribers) return __bt$traced();
|
|
2978
|
+
__bt$ctx.self ??= this;
|
|
2979
|
+
return __bt$hook.tracePromise(__bt$traced, __bt$ctx);
|
|
2924
2980
|
}
|
|
2925
2981
|
`);
|
|
2926
2982
|
}
|
|
2927
2983
|
function wrapSync(state2) {
|
|
2928
2984
|
const { channelName } = state2;
|
|
2929
|
-
const
|
|
2985
|
+
const channelGetter = formatChannelGetter(channelName);
|
|
2930
2986
|
return parse(`
|
|
2931
2987
|
function wrapper () {
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
const result = __apm$traced();
|
|
2937
|
-
__apm$ctx.result = result;
|
|
2938
|
-
return result;
|
|
2939
|
-
} catch (err) {
|
|
2940
|
-
__apm$ctx.error = err;
|
|
2941
|
-
${channelVariable}.error.publish(__apm$ctx);
|
|
2942
|
-
throw err;
|
|
2943
|
-
} finally {
|
|
2944
|
-
__apm$ctx.self ??= this;
|
|
2945
|
-
${channelVariable}.end.publish(__apm$ctx);
|
|
2946
|
-
}
|
|
2947
|
-
});
|
|
2988
|
+
const __bt$hook = ${channelGetter}();
|
|
2989
|
+
if (!__bt$hook?.hasSubscribers) return __bt$traced();
|
|
2990
|
+
__bt$ctx.self ??= this;
|
|
2991
|
+
return __bt$hook.traceSync(__bt$traced, __bt$ctx);
|
|
2948
2992
|
}
|
|
2949
2993
|
`);
|
|
2950
2994
|
}
|
|
@@ -2955,16 +2999,14 @@ var Transformer = class {
|
|
|
2955
2999
|
version;
|
|
2956
3000
|
filePath;
|
|
2957
3001
|
configs = [];
|
|
2958
|
-
|
|
2959
|
-
constructor(moduleName, version, filePath, configs, dcModule) {
|
|
3002
|
+
constructor(moduleName, version, filePath, configs) {
|
|
2960
3003
|
this.moduleName = moduleName;
|
|
2961
3004
|
this.version = version;
|
|
2962
3005
|
this.filePath = filePath;
|
|
2963
3006
|
this.configs = configs;
|
|
2964
|
-
this.dcModule = dcModule;
|
|
2965
3007
|
}
|
|
2966
3008
|
/**
|
|
2967
|
-
* Instruments `code` by injecting
|
|
3009
|
+
* Instruments `code` by injecting global tracing hooks around the
|
|
2968
3010
|
* target functions defined by this transformer's configs.
|
|
2969
3011
|
*/
|
|
2970
3012
|
transform(code, moduleType) {
|
|
@@ -3002,8 +3044,6 @@ var Transformer = class {
|
|
|
3002
3044
|
const query = astQuery || this.fromFunctionQuery(resolvedFunctionQuery);
|
|
3003
3045
|
const state2 = {
|
|
3004
3046
|
...config,
|
|
3005
|
-
dcModule: this.dcModule,
|
|
3006
|
-
moduleType,
|
|
3007
3047
|
moduleVersion: this.version,
|
|
3008
3048
|
functionQuery: resolvedFunctionQuery,
|
|
3009
3049
|
operator: this.getOperator(resolvedFunctionQuery.kind)
|
|
@@ -3153,11 +3193,9 @@ var Transformer = class {
|
|
|
3153
3193
|
// src/auto-instrumentations/orchestrion-js/matcher.ts
|
|
3154
3194
|
var InstrumentationMatcher = class {
|
|
3155
3195
|
configs = [];
|
|
3156
|
-
dcModule;
|
|
3157
3196
|
transformers = {};
|
|
3158
|
-
constructor(configs
|
|
3197
|
+
constructor(configs) {
|
|
3159
3198
|
this.configs = configs;
|
|
3160
|
-
this.dcModule = dcModule || "diagnostics_channel";
|
|
3161
3199
|
}
|
|
3162
3200
|
/**
|
|
3163
3201
|
* Returns a Transformer for the given module/file/version, or undefined if no
|
|
@@ -3179,8 +3217,7 @@ var InstrumentationMatcher = class {
|
|
|
3179
3217
|
moduleName,
|
|
3180
3218
|
version,
|
|
3181
3219
|
filePath,
|
|
3182
|
-
configs
|
|
3183
|
-
this.dcModule
|
|
3220
|
+
configs
|
|
3184
3221
|
);
|
|
3185
3222
|
return this.transformers[id];
|
|
3186
3223
|
}
|
|
@@ -3190,8 +3227,8 @@ var InstrumentationMatcher = class {
|
|
|
3190
3227
|
};
|
|
3191
3228
|
|
|
3192
3229
|
// src/auto-instrumentations/orchestrion-js/index.ts
|
|
3193
|
-
function create(configs
|
|
3194
|
-
return new InstrumentationMatcher(configs
|
|
3230
|
+
function create(configs) {
|
|
3231
|
+
return new InstrumentationMatcher(configs);
|
|
3195
3232
|
}
|
|
3196
3233
|
|
|
3197
3234
|
// src/auto-instrumentations/loader/cjs-patch.ts
|
|
@@ -3280,6 +3317,9 @@ function applySpecialCasePatch(input) {
|
|
|
3280
3317
|
if (input.packageName === "openai" && input.modulePath.includes("api-promise")) {
|
|
3281
3318
|
return input.source + OPENAI_API_PROMISE_PATCH;
|
|
3282
3319
|
}
|
|
3320
|
+
if (input.browser) {
|
|
3321
|
+
return null;
|
|
3322
|
+
}
|
|
3283
3323
|
const mastraTarget = classifyMastraTarget(
|
|
3284
3324
|
input.packageName,
|
|
3285
3325
|
input.modulePath
|
|
@@ -3308,7 +3348,7 @@ var ModulePatch = class {
|
|
|
3308
3348
|
/**
|
|
3309
3349
|
* Patches the Node.js module class method that is responsible for compiling code.
|
|
3310
3350
|
* If a module is found that has an instrumentator, it will transform the code before compiling it
|
|
3311
|
-
* with
|
|
3351
|
+
* with global hook calls.
|
|
3312
3352
|
*/
|
|
3313
3353
|
patch() {
|
|
3314
3354
|
const self = this;
|
|
@@ -3367,7 +3407,9 @@ function resolveModulePrototype() {
|
|
|
3367
3407
|
}
|
|
3368
3408
|
|
|
3369
3409
|
// src/node/apply-auto-instrumentation-entry.ts
|
|
3370
|
-
var stateKey = /* @__PURE__ */ Symbol.for(
|
|
3410
|
+
var stateKey = /* @__PURE__ */ Symbol.for(
|
|
3411
|
+
`braintrust.applyAutoInstrumentation.global-hooks.v${GLOBAL_INSTRUMENTATION_HOOKS_PROTOCOL_VERSION}`
|
|
3412
|
+
);
|
|
3371
3413
|
var existingState = Object.getOwnPropertyDescriptor(
|
|
3372
3414
|
globalThis,
|
|
3373
3415
|
stateKey
|
|
@@ -3384,7 +3426,6 @@ if (state !== existingState) {
|
|
|
3384
3426
|
});
|
|
3385
3427
|
}
|
|
3386
3428
|
if (!state.applied) {
|
|
3387
|
-
patchTracingChannel(diagnostics_channel.tracingChannel);
|
|
3388
3429
|
const allConfigs = getDefaultAutoInstrumentationConfigs();
|
|
3389
3430
|
const currentModuleUrl = getCurrentModuleUrl();
|
|
3390
3431
|
register("./auto-instrumentations/loader/esm-hook.mjs", {
|