braintrust 3.7.1 → 3.9.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 +228 -5
- package/dev/dist/index.d.ts +228 -5
- package/dev/dist/index.js +6259 -1261
- package/dev/dist/index.mjs +6161 -1163
- package/dist/auto-instrumentations/bundler/esbuild.cjs +995 -55
- package/dist/auto-instrumentations/bundler/esbuild.mjs +2 -2
- package/dist/auto-instrumentations/bundler/rollup.cjs +995 -55
- package/dist/auto-instrumentations/bundler/rollup.mjs +2 -2
- package/dist/auto-instrumentations/bundler/vite.cjs +995 -55
- package/dist/auto-instrumentations/bundler/vite.mjs +2 -2
- package/dist/auto-instrumentations/bundler/webpack-loader.cjs +995 -55
- package/dist/auto-instrumentations/bundler/webpack-loader.d.ts +11 -9
- package/dist/auto-instrumentations/bundler/webpack.cjs +995 -55
- package/dist/auto-instrumentations/bundler/webpack.mjs +2 -2
- package/dist/auto-instrumentations/{chunk-NY4CGTN6.mjs → chunk-G7F6HZGE.mjs} +9 -1
- package/dist/auto-instrumentations/{chunk-EVUKFMHG.mjs → chunk-ITP7RAUY.mjs} +21 -3
- package/dist/auto-instrumentations/chunk-KIMMUFAK.mjs +1781 -0
- package/dist/auto-instrumentations/{chunk-VLEJ5AEK.mjs → chunk-P5YLNB2A.mjs} +21 -3
- package/dist/auto-instrumentations/hook.mjs +1206 -82
- package/dist/auto-instrumentations/index.cjs +1161 -55
- package/dist/auto-instrumentations/index.d.mts +22 -1
- package/dist/auto-instrumentations/index.d.ts +22 -1
- package/dist/auto-instrumentations/index.mjs +172 -1
- package/dist/auto-instrumentations/loader/cjs-patch.cjs +34 -6
- package/dist/auto-instrumentations/loader/cjs-patch.d.mts +1 -0
- package/dist/auto-instrumentations/loader/cjs-patch.d.ts +1 -0
- package/dist/auto-instrumentations/loader/cjs-patch.mjs +15 -5
- package/dist/auto-instrumentations/loader/esm-hook.mjs +10 -4
- package/dist/auto-instrumentations/loader/get-package-version.cjs +20 -2
- package/dist/auto-instrumentations/loader/get-package-version.mjs +1 -1
- package/dist/browser.d.mts +501 -18
- package/dist/browser.d.ts +501 -18
- package/dist/browser.js +6985 -1211
- package/dist/browser.mjs +6985 -1211
- package/dist/cli.js +6160 -1133
- package/dist/edge-light.d.mts +1 -1
- package/dist/edge-light.d.ts +1 -1
- package/dist/edge-light.js +16054 -10191
- package/dist/edge-light.mjs +16054 -10191
- package/dist/index.d.mts +501 -18
- package/dist/index.d.ts +501 -18
- package/dist/index.js +7144 -1370
- package/dist/index.mjs +6985 -1211
- package/dist/instrumentation/index.d.mts +17 -0
- package/dist/instrumentation/index.d.ts +17 -0
- package/dist/instrumentation/index.js +5929 -1053
- package/dist/instrumentation/index.mjs +5929 -1053
- package/dist/workerd.d.mts +1 -1
- package/dist/workerd.d.ts +1 -1
- package/dist/workerd.js +16054 -10191
- package/dist/workerd.mjs +16054 -10191
- package/package.json +13 -8
- package/util/dist/index.d.mts +42 -1
- package/util/dist/index.d.ts +42 -1
- package/util/dist/index.js +5 -1
- package/util/dist/index.mjs +4 -0
- package/dist/auto-instrumentations/chunk-YCKND42U.mjs +0 -839
|
@@ -66,6 +66,27 @@ declare const claudeAgentSDKConfigs: InstrumentationConfig[];
|
|
|
66
66
|
*/
|
|
67
67
|
declare const googleGenAIConfigs: InstrumentationConfig[];
|
|
68
68
|
|
|
69
|
+
declare const huggingFaceConfigs: InstrumentationConfig[];
|
|
70
|
+
|
|
71
|
+
declare const openRouterAgentConfigs: InstrumentationConfig[];
|
|
72
|
+
|
|
69
73
|
declare const openRouterConfigs: InstrumentationConfig[];
|
|
70
74
|
|
|
71
|
-
|
|
75
|
+
declare const mistralConfigs: InstrumentationConfig[];
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Instrumentation configurations for the Google ADK (@google/adk).
|
|
79
|
+
*
|
|
80
|
+
* Runner.runAsync and BaseAgent.runAsync are async generators (`async *`).
|
|
81
|
+
* They synchronously return an AsyncGenerator object, so we use kind "Sync"
|
|
82
|
+
* paired with "sync-stream" channels — the same pattern used by the
|
|
83
|
+
* Claude Agent SDK's `query` function.
|
|
84
|
+
*
|
|
85
|
+
* FunctionTool.runAsync is a regular async method (returns Promise<unknown>)
|
|
86
|
+
* and uses kind "Async".
|
|
87
|
+
*/
|
|
88
|
+
declare const googleADKConfigs: InstrumentationConfig[];
|
|
89
|
+
|
|
90
|
+
declare const cohereConfigs: InstrumentationConfig[];
|
|
91
|
+
|
|
92
|
+
export { aiSDKConfigs, anthropicConfigs, claudeAgentSDKConfigs, cohereConfigs, googleADKConfigs, googleGenAIConfigs, huggingFaceConfigs, mistralConfigs, openRouterAgentConfigs, openRouterConfigs, openaiConfigs };
|
|
@@ -66,6 +66,27 @@ declare const claudeAgentSDKConfigs: InstrumentationConfig[];
|
|
|
66
66
|
*/
|
|
67
67
|
declare const googleGenAIConfigs: InstrumentationConfig[];
|
|
68
68
|
|
|
69
|
+
declare const huggingFaceConfigs: InstrumentationConfig[];
|
|
70
|
+
|
|
71
|
+
declare const openRouterAgentConfigs: InstrumentationConfig[];
|
|
72
|
+
|
|
69
73
|
declare const openRouterConfigs: InstrumentationConfig[];
|
|
70
74
|
|
|
71
|
-
|
|
75
|
+
declare const mistralConfigs: InstrumentationConfig[];
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Instrumentation configurations for the Google ADK (@google/adk).
|
|
79
|
+
*
|
|
80
|
+
* Runner.runAsync and BaseAgent.runAsync are async generators (`async *`).
|
|
81
|
+
* They synchronously return an AsyncGenerator object, so we use kind "Sync"
|
|
82
|
+
* paired with "sync-stream" channels — the same pattern used by the
|
|
83
|
+
* Claude Agent SDK's `query` function.
|
|
84
|
+
*
|
|
85
|
+
* FunctionTool.runAsync is a regular async method (returns Promise<unknown>)
|
|
86
|
+
* and uses kind "Async".
|
|
87
|
+
*/
|
|
88
|
+
declare const googleADKConfigs: InstrumentationConfig[];
|
|
89
|
+
|
|
90
|
+
declare const cohereConfigs: InstrumentationConfig[];
|
|
91
|
+
|
|
92
|
+
export { aiSDKConfigs, anthropicConfigs, claudeAgentSDKConfigs, cohereConfigs, googleADKConfigs, googleGenAIConfigs, huggingFaceConfigs, mistralConfigs, openRouterAgentConfigs, openRouterConfigs, openaiConfigs };
|
|
@@ -1,16 +1,187 @@
|
|
|
1
1
|
import {
|
|
2
2
|
aiSDKConfigs,
|
|
3
3
|
anthropicConfigs,
|
|
4
|
+
channel,
|
|
4
5
|
claudeAgentSDKConfigs,
|
|
6
|
+
cohereConfigs,
|
|
7
|
+
defineChannels,
|
|
5
8
|
googleGenAIConfigs,
|
|
9
|
+
huggingFaceConfigs,
|
|
10
|
+
mistralConfigs,
|
|
11
|
+
openRouterAgentConfigs,
|
|
6
12
|
openRouterConfigs,
|
|
7
13
|
openaiConfigs
|
|
8
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-KIMMUFAK.mjs";
|
|
15
|
+
|
|
16
|
+
// src/instrumentation/plugins/google-adk-channels.ts
|
|
17
|
+
var googleADKChannels = defineChannels("@google/adk", {
|
|
18
|
+
runnerRunAsync: channel({
|
|
19
|
+
channelName: "runner.runAsync",
|
|
20
|
+
kind: "sync-stream"
|
|
21
|
+
}),
|
|
22
|
+
agentRunAsync: channel({
|
|
23
|
+
channelName: "agent.runAsync",
|
|
24
|
+
kind: "sync-stream"
|
|
25
|
+
}),
|
|
26
|
+
toolRunAsync: channel({
|
|
27
|
+
channelName: "tool.runAsync",
|
|
28
|
+
kind: "async"
|
|
29
|
+
})
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// src/auto-instrumentations/configs/google-adk.ts
|
|
33
|
+
var googleADKVersionRange = ">=0.1.0";
|
|
34
|
+
var googleADKBundledIndexVersionRange = ">=0.6.1 <0.7.0";
|
|
35
|
+
var googleADKConfigs = [
|
|
36
|
+
// --- Runner.runAsync --- async generator, kind "Sync" + sync-stream channel
|
|
37
|
+
// Runner.runAsync — ESM individual module file
|
|
38
|
+
{
|
|
39
|
+
channelName: googleADKChannels.runnerRunAsync.channelName,
|
|
40
|
+
module: {
|
|
41
|
+
name: "@google/adk",
|
|
42
|
+
versionRange: googleADKVersionRange,
|
|
43
|
+
filePath: "dist/esm/runner/runner.js"
|
|
44
|
+
},
|
|
45
|
+
functionQuery: {
|
|
46
|
+
className: "Runner",
|
|
47
|
+
methodName: "runAsync",
|
|
48
|
+
kind: "Sync"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
// Runner.runAsync — bundled CJS/ESM indexes
|
|
52
|
+
// The bundled entrypoints minify class names, so target the 12th sync
|
|
53
|
+
// `runAsync` method in file order rather than a class name. This mapping is
|
|
54
|
+
// only validated against the current 0.6.x bundle layout, so keep the range
|
|
55
|
+
// tight until we verify newer bundled outputs.
|
|
56
|
+
{
|
|
57
|
+
channelName: googleADKChannels.runnerRunAsync.channelName,
|
|
58
|
+
module: {
|
|
59
|
+
name: "@google/adk",
|
|
60
|
+
versionRange: googleADKBundledIndexVersionRange,
|
|
61
|
+
filePath: "dist/cjs/index.js"
|
|
62
|
+
},
|
|
63
|
+
functionQuery: {
|
|
64
|
+
methodName: "runAsync",
|
|
65
|
+
kind: "Sync",
|
|
66
|
+
index: 11
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
channelName: googleADKChannels.runnerRunAsync.channelName,
|
|
71
|
+
module: {
|
|
72
|
+
name: "@google/adk",
|
|
73
|
+
versionRange: googleADKBundledIndexVersionRange,
|
|
74
|
+
filePath: "dist/esm/index.js"
|
|
75
|
+
},
|
|
76
|
+
functionQuery: {
|
|
77
|
+
methodName: "runAsync",
|
|
78
|
+
kind: "Sync",
|
|
79
|
+
index: 11
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
// --- BaseAgent.runAsync --- async generator, kind "Sync" + sync-stream channel
|
|
83
|
+
// BaseAgent.runAsync — ESM individual module file
|
|
84
|
+
{
|
|
85
|
+
channelName: googleADKChannels.agentRunAsync.channelName,
|
|
86
|
+
module: {
|
|
87
|
+
name: "@google/adk",
|
|
88
|
+
versionRange: googleADKVersionRange,
|
|
89
|
+
filePath: "dist/esm/agents/base_agent.js"
|
|
90
|
+
},
|
|
91
|
+
functionQuery: {
|
|
92
|
+
className: "BaseAgent",
|
|
93
|
+
methodName: "runAsync",
|
|
94
|
+
kind: "Sync"
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
// BaseAgent.runAsync — bundled CJS/ESM indexes
|
|
98
|
+
// The bundled entrypoints minify class names, so target the first sync
|
|
99
|
+
// `runAsync` method in file order rather than a class name. This mapping is
|
|
100
|
+
// only validated against the current 0.6.x bundle layout, so keep the range
|
|
101
|
+
// tight until we verify newer bundled outputs.
|
|
102
|
+
{
|
|
103
|
+
channelName: googleADKChannels.agentRunAsync.channelName,
|
|
104
|
+
module: {
|
|
105
|
+
name: "@google/adk",
|
|
106
|
+
versionRange: googleADKBundledIndexVersionRange,
|
|
107
|
+
filePath: "dist/cjs/index.js"
|
|
108
|
+
},
|
|
109
|
+
functionQuery: {
|
|
110
|
+
methodName: "runAsync",
|
|
111
|
+
kind: "Sync",
|
|
112
|
+
index: 0
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
channelName: googleADKChannels.agentRunAsync.channelName,
|
|
117
|
+
module: {
|
|
118
|
+
name: "@google/adk",
|
|
119
|
+
versionRange: googleADKBundledIndexVersionRange,
|
|
120
|
+
filePath: "dist/esm/index.js"
|
|
121
|
+
},
|
|
122
|
+
functionQuery: {
|
|
123
|
+
methodName: "runAsync",
|
|
124
|
+
kind: "Sync",
|
|
125
|
+
index: 0
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
// --- FunctionTool.runAsync --- regular async, kind "Async"
|
|
129
|
+
// FunctionTool.runAsync — ESM individual module file
|
|
130
|
+
{
|
|
131
|
+
channelName: googleADKChannels.toolRunAsync.channelName,
|
|
132
|
+
module: {
|
|
133
|
+
name: "@google/adk",
|
|
134
|
+
versionRange: googleADKVersionRange,
|
|
135
|
+
filePath: "dist/esm/tools/function_tool.js"
|
|
136
|
+
},
|
|
137
|
+
functionQuery: {
|
|
138
|
+
className: "FunctionTool",
|
|
139
|
+
methodName: "runAsync",
|
|
140
|
+
kind: "Async"
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
// FunctionTool.runAsync — bundled CJS/ESM indexes
|
|
144
|
+
// The bundled entrypoints minify class names, so target the first async
|
|
145
|
+
// `runAsync` method in file order rather than a class name. This mapping is
|
|
146
|
+
// only validated against the current 0.6.x bundle layout, so keep the range
|
|
147
|
+
// tight until we verify newer bundled outputs.
|
|
148
|
+
{
|
|
149
|
+
channelName: googleADKChannels.toolRunAsync.channelName,
|
|
150
|
+
module: {
|
|
151
|
+
name: "@google/adk",
|
|
152
|
+
versionRange: googleADKBundledIndexVersionRange,
|
|
153
|
+
filePath: "dist/cjs/index.js"
|
|
154
|
+
},
|
|
155
|
+
functionQuery: {
|
|
156
|
+
methodName: "runAsync",
|
|
157
|
+
kind: "Async",
|
|
158
|
+
index: 1
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
channelName: googleADKChannels.toolRunAsync.channelName,
|
|
163
|
+
module: {
|
|
164
|
+
name: "@google/adk",
|
|
165
|
+
versionRange: googleADKBundledIndexVersionRange,
|
|
166
|
+
filePath: "dist/esm/index.js"
|
|
167
|
+
},
|
|
168
|
+
functionQuery: {
|
|
169
|
+
methodName: "runAsync",
|
|
170
|
+
kind: "Async",
|
|
171
|
+
index: 1
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
];
|
|
9
175
|
export {
|
|
10
176
|
aiSDKConfigs,
|
|
11
177
|
anthropicConfigs,
|
|
12
178
|
claudeAgentSDKConfigs,
|
|
179
|
+
cohereConfigs,
|
|
180
|
+
googleADKConfigs,
|
|
13
181
|
googleGenAIConfigs,
|
|
182
|
+
huggingFaceConfigs,
|
|
183
|
+
mistralConfigs,
|
|
184
|
+
openRouterAgentConfigs,
|
|
14
185
|
openRouterConfigs,
|
|
15
186
|
openaiConfigs
|
|
16
187
|
};
|
|
@@ -34,7 +34,7 @@ __export(cjs_patch_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(cjs_patch_exports);
|
|
36
36
|
var import_code_transformer = require("@apm-js-collab/code-transformer");
|
|
37
|
-
var
|
|
37
|
+
var NodeModule = __toESM(require("module"));
|
|
38
38
|
var import_node_path2 = require("path");
|
|
39
39
|
var import_module_details_from_path = __toESM(require("module-details-from-path"));
|
|
40
40
|
|
|
@@ -52,11 +52,29 @@ function readPackageJson(baseDir) {
|
|
|
52
52
|
return void 0;
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
+
function resolvePackageBaseDir(baseDir) {
|
|
56
|
+
try {
|
|
57
|
+
return (0, import_node_fs.realpathSync)(baseDir);
|
|
58
|
+
} catch {
|
|
59
|
+
return baseDir;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function readPackageJsonWithFallback(baseDir) {
|
|
63
|
+
const packageJson = readPackageJson(baseDir);
|
|
64
|
+
if (packageJson) {
|
|
65
|
+
return packageJson;
|
|
66
|
+
}
|
|
67
|
+
const resolvedBaseDir = resolvePackageBaseDir(baseDir);
|
|
68
|
+
if (resolvedBaseDir === baseDir) {
|
|
69
|
+
return void 0;
|
|
70
|
+
}
|
|
71
|
+
return readPackageJson(resolvedBaseDir);
|
|
72
|
+
}
|
|
55
73
|
function getPackageVersion(baseDir) {
|
|
56
74
|
if (packageVersions.has(baseDir)) {
|
|
57
75
|
return packageVersions.get(baseDir);
|
|
58
76
|
}
|
|
59
|
-
const packageJson =
|
|
77
|
+
const packageJson = readPackageJsonWithFallback(baseDir);
|
|
60
78
|
if (typeof packageJson?.version === "string") {
|
|
61
79
|
packageVersions.set(baseDir, packageJson.version);
|
|
62
80
|
return packageJson.version;
|
|
@@ -67,7 +85,7 @@ function getPackageName(baseDir) {
|
|
|
67
85
|
if (packageNames.has(baseDir)) {
|
|
68
86
|
return packageNames.get(baseDir);
|
|
69
87
|
}
|
|
70
|
-
const packageJson =
|
|
88
|
+
const packageJson = readPackageJsonWithFallback(baseDir);
|
|
71
89
|
if (typeof packageJson?.name === "string") {
|
|
72
90
|
packageNames.set(baseDir, packageJson.name);
|
|
73
91
|
return packageJson.name;
|
|
@@ -79,13 +97,16 @@ function getPackageName(baseDir) {
|
|
|
79
97
|
var ModulePatch = class {
|
|
80
98
|
packages;
|
|
81
99
|
instrumentator;
|
|
100
|
+
modulePrototype;
|
|
82
101
|
originalCompile;
|
|
83
102
|
constructor({
|
|
84
103
|
instrumentations = []
|
|
85
104
|
} = {}) {
|
|
105
|
+
const modulePrototype = resolveModulePrototype();
|
|
86
106
|
this.packages = new Set(instrumentations.map((i) => i.module.name));
|
|
87
107
|
this.instrumentator = (0, import_code_transformer.create)(instrumentations);
|
|
88
|
-
this.
|
|
108
|
+
this.modulePrototype = modulePrototype;
|
|
109
|
+
this.originalCompile = modulePrototype._compile;
|
|
89
110
|
}
|
|
90
111
|
/**
|
|
91
112
|
* Patches the Node.js module class method that is responsible for compiling code.
|
|
@@ -94,7 +115,7 @@ var ModulePatch = class {
|
|
|
94
115
|
*/
|
|
95
116
|
patch() {
|
|
96
117
|
const self = this;
|
|
97
|
-
|
|
118
|
+
this.modulePrototype._compile = function wrappedCompile(...args) {
|
|
98
119
|
const [content, filename] = args;
|
|
99
120
|
const normalizedForPlatform = filename.split("/").join(import_node_path2.sep);
|
|
100
121
|
const resolvedModule = (0, import_module_details_from_path.default)(normalizedForPlatform);
|
|
@@ -129,9 +150,16 @@ var ModulePatch = class {
|
|
|
129
150
|
* **Note**: This is intended to be used in testing only.
|
|
130
151
|
*/
|
|
131
152
|
unpatch() {
|
|
132
|
-
|
|
153
|
+
this.modulePrototype._compile = this.originalCompile;
|
|
133
154
|
}
|
|
134
155
|
};
|
|
156
|
+
function resolveModulePrototype() {
|
|
157
|
+
const moduleCtor = NodeModule.Module;
|
|
158
|
+
if (moduleCtor && typeof moduleCtor === "function") {
|
|
159
|
+
return moduleCtor.prototype;
|
|
160
|
+
}
|
|
161
|
+
return NodeModule.prototype;
|
|
162
|
+
}
|
|
135
163
|
// Annotate the CommonJS export names for ESM import in node:
|
|
136
164
|
0 && (module.exports = {
|
|
137
165
|
ModulePatch
|
|
@@ -8,6 +8,7 @@ import { InstrumentationConfig } from '@apm-js-collab/code-transformer';
|
|
|
8
8
|
declare class ModulePatch {
|
|
9
9
|
private packages;
|
|
10
10
|
private instrumentator;
|
|
11
|
+
private modulePrototype;
|
|
11
12
|
private originalCompile;
|
|
12
13
|
constructor({ instrumentations, }?: {
|
|
13
14
|
instrumentations?: InstrumentationConfig[];
|
|
@@ -8,6 +8,7 @@ import { InstrumentationConfig } from '@apm-js-collab/code-transformer';
|
|
|
8
8
|
declare class ModulePatch {
|
|
9
9
|
private packages;
|
|
10
10
|
private instrumentator;
|
|
11
|
+
private modulePrototype;
|
|
11
12
|
private originalCompile;
|
|
12
13
|
constructor({ instrumentations, }?: {
|
|
13
14
|
instrumentations?: InstrumentationConfig[];
|
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getPackageName,
|
|
3
3
|
getPackageVersion
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-P5YLNB2A.mjs";
|
|
5
5
|
|
|
6
6
|
// src/auto-instrumentations/loader/cjs-patch.ts
|
|
7
7
|
import {
|
|
8
8
|
create
|
|
9
9
|
} from "@apm-js-collab/code-transformer";
|
|
10
|
-
import * as
|
|
10
|
+
import * as NodeModule from "module";
|
|
11
11
|
import { sep } from "path";
|
|
12
12
|
import moduleDetailsFromPath from "module-details-from-path";
|
|
13
13
|
var ModulePatch = class {
|
|
14
14
|
packages;
|
|
15
15
|
instrumentator;
|
|
16
|
+
modulePrototype;
|
|
16
17
|
originalCompile;
|
|
17
18
|
constructor({
|
|
18
19
|
instrumentations = []
|
|
19
20
|
} = {}) {
|
|
21
|
+
const modulePrototype = resolveModulePrototype();
|
|
20
22
|
this.packages = new Set(instrumentations.map((i) => i.module.name));
|
|
21
23
|
this.instrumentator = create(instrumentations);
|
|
22
|
-
this.
|
|
24
|
+
this.modulePrototype = modulePrototype;
|
|
25
|
+
this.originalCompile = modulePrototype._compile;
|
|
23
26
|
}
|
|
24
27
|
/**
|
|
25
28
|
* Patches the Node.js module class method that is responsible for compiling code.
|
|
@@ -28,7 +31,7 @@ var ModulePatch = class {
|
|
|
28
31
|
*/
|
|
29
32
|
patch() {
|
|
30
33
|
const self = this;
|
|
31
|
-
|
|
34
|
+
this.modulePrototype._compile = function wrappedCompile(...args) {
|
|
32
35
|
const [content, filename] = args;
|
|
33
36
|
const normalizedForPlatform = filename.split("/").join(sep);
|
|
34
37
|
const resolvedModule = moduleDetailsFromPath(normalizedForPlatform);
|
|
@@ -63,9 +66,16 @@ var ModulePatch = class {
|
|
|
63
66
|
* **Note**: This is intended to be used in testing only.
|
|
64
67
|
*/
|
|
65
68
|
unpatch() {
|
|
66
|
-
|
|
69
|
+
this.modulePrototype._compile = this.originalCompile;
|
|
67
70
|
}
|
|
68
71
|
};
|
|
72
|
+
function resolveModulePrototype() {
|
|
73
|
+
const moduleCtor = NodeModule.Module;
|
|
74
|
+
if (moduleCtor && typeof moduleCtor === "function") {
|
|
75
|
+
return moduleCtor.prototype;
|
|
76
|
+
}
|
|
77
|
+
return NodeModule.prototype;
|
|
78
|
+
}
|
|
69
79
|
export {
|
|
70
80
|
ModulePatch
|
|
71
81
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
+
getPackageName,
|
|
2
3
|
getPackageVersion
|
|
3
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-ITP7RAUY.mjs";
|
|
4
5
|
|
|
5
6
|
// src/auto-instrumentations/loader/esm-hook.mts
|
|
6
7
|
import { readFile } from "fs/promises";
|
|
@@ -23,11 +24,15 @@ async function resolve(specifier, context, nextResolve) {
|
|
|
23
24
|
const filePath = url.url.startsWith("file:") ? fileURLToPath(url.url) : url.url;
|
|
24
25
|
const normalizedForPlatform = filePath.split("/").join(sep);
|
|
25
26
|
const resolvedModule = moduleDetailsFromPath(normalizedForPlatform);
|
|
26
|
-
if (resolvedModule
|
|
27
|
+
if (resolvedModule) {
|
|
28
|
+
const packageName = getPackageName(resolvedModule.basedir) ?? resolvedModule.name;
|
|
29
|
+
if (!packages?.has(packageName)) {
|
|
30
|
+
return url;
|
|
31
|
+
}
|
|
27
32
|
const version = getPackageVersion(resolvedModule.basedir);
|
|
28
33
|
const normalizedModulePath = resolvedModule.path.replace(/\\/g, "/");
|
|
29
34
|
const transformer = instrumentator.getTransformer(
|
|
30
|
-
|
|
35
|
+
packageName,
|
|
31
36
|
version,
|
|
32
37
|
normalizedModulePath
|
|
33
38
|
);
|
|
@@ -50,9 +55,10 @@ async function load(url, context, nextLoad) {
|
|
|
50
55
|
if (code) {
|
|
51
56
|
const transformer = transformers.get(url);
|
|
52
57
|
try {
|
|
58
|
+
const moduleType = result.format === "module" ? "esm" : result.format === "commonjs" ? "cjs" : "unknown";
|
|
53
59
|
const transformedCode = transformer.transform(
|
|
54
60
|
code.toString("utf8"),
|
|
55
|
-
|
|
61
|
+
moduleType
|
|
56
62
|
);
|
|
57
63
|
result.source = transformedCode?.code;
|
|
58
64
|
result.shortCircuit = true;
|
|
@@ -37,11 +37,29 @@ function readPackageJson(baseDir) {
|
|
|
37
37
|
return void 0;
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
+
function resolvePackageBaseDir(baseDir) {
|
|
41
|
+
try {
|
|
42
|
+
return (0, import_node_fs.realpathSync)(baseDir);
|
|
43
|
+
} catch {
|
|
44
|
+
return baseDir;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function readPackageJsonWithFallback(baseDir) {
|
|
48
|
+
const packageJson = readPackageJson(baseDir);
|
|
49
|
+
if (packageJson) {
|
|
50
|
+
return packageJson;
|
|
51
|
+
}
|
|
52
|
+
const resolvedBaseDir = resolvePackageBaseDir(baseDir);
|
|
53
|
+
if (resolvedBaseDir === baseDir) {
|
|
54
|
+
return void 0;
|
|
55
|
+
}
|
|
56
|
+
return readPackageJson(resolvedBaseDir);
|
|
57
|
+
}
|
|
40
58
|
function getPackageVersion(baseDir) {
|
|
41
59
|
if (packageVersions.has(baseDir)) {
|
|
42
60
|
return packageVersions.get(baseDir);
|
|
43
61
|
}
|
|
44
|
-
const packageJson =
|
|
62
|
+
const packageJson = readPackageJsonWithFallback(baseDir);
|
|
45
63
|
if (typeof packageJson?.version === "string") {
|
|
46
64
|
packageVersions.set(baseDir, packageJson.version);
|
|
47
65
|
return packageJson.version;
|
|
@@ -52,7 +70,7 @@ function getPackageName(baseDir) {
|
|
|
52
70
|
if (packageNames.has(baseDir)) {
|
|
53
71
|
return packageNames.get(baseDir);
|
|
54
72
|
}
|
|
55
|
-
const packageJson =
|
|
73
|
+
const packageJson = readPackageJsonWithFallback(baseDir);
|
|
56
74
|
if (typeof packageJson?.name === "string") {
|
|
57
75
|
packageNames.set(baseDir, packageJson.name);
|
|
58
76
|
return packageJson.name;
|