braintrust 3.11.0 → 3.12.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.
Files changed (75) hide show
  1. package/README.md +8 -8
  2. package/dev/dist/index.d.mts +1 -1
  3. package/dev/dist/index.d.ts +1 -1
  4. package/dev/dist/index.js +2607 -316
  5. package/dev/dist/index.mjs +2388 -97
  6. package/dist/apply-auto-instrumentation.browser.d.mts +2 -0
  7. package/dist/apply-auto-instrumentation.browser.d.ts +2 -0
  8. package/dist/apply-auto-instrumentation.browser.js +18 -0
  9. package/dist/apply-auto-instrumentation.browser.mjs +0 -0
  10. package/dist/apply-auto-instrumentation.d.mts +2 -0
  11. package/dist/apply-auto-instrumentation.d.ts +2 -0
  12. package/dist/apply-auto-instrumentation.js +2534 -0
  13. package/dist/apply-auto-instrumentation.mjs +2534 -0
  14. package/dist/auto-instrumentations/bundler/esbuild.cjs +1802 -1283
  15. package/dist/auto-instrumentations/bundler/esbuild.d.mts +9 -5
  16. package/dist/auto-instrumentations/bundler/esbuild.d.ts +9 -5
  17. package/dist/auto-instrumentations/bundler/esbuild.mjs +10 -2
  18. package/dist/auto-instrumentations/bundler/next.cjs +3268 -0
  19. package/dist/auto-instrumentations/bundler/next.d.mts +3 -0
  20. package/dist/auto-instrumentations/bundler/next.d.ts +3 -0
  21. package/dist/auto-instrumentations/bundler/next.mjs +189 -0
  22. package/dist/auto-instrumentations/bundler/rollup.cjs +1802 -1283
  23. package/dist/auto-instrumentations/bundler/rollup.d.mts +9 -5
  24. package/dist/auto-instrumentations/bundler/rollup.d.ts +9 -5
  25. package/dist/auto-instrumentations/bundler/rollup.mjs +10 -2
  26. package/dist/auto-instrumentations/bundler/vite.cjs +1802 -1283
  27. package/dist/auto-instrumentations/bundler/vite.d.mts +9 -5
  28. package/dist/auto-instrumentations/bundler/vite.d.ts +9 -5
  29. package/dist/auto-instrumentations/bundler/vite.mjs +10 -2
  30. package/dist/auto-instrumentations/bundler/webpack-loader.cjs +1860 -1308
  31. package/dist/auto-instrumentations/bundler/webpack-loader.d.ts +3 -3
  32. package/dist/auto-instrumentations/bundler/webpack.cjs +1802 -1283
  33. package/dist/auto-instrumentations/bundler/webpack.d.mts +9 -5
  34. package/dist/auto-instrumentations/bundler/webpack.d.ts +9 -5
  35. package/dist/auto-instrumentations/bundler/webpack.mjs +6 -6
  36. package/dist/auto-instrumentations/{chunk-DIV5TO4S.mjs → chunk-2DPA74KK.mjs} +337 -1
  37. package/dist/auto-instrumentations/chunk-73BZUKVI.mjs +300 -0
  38. package/dist/auto-instrumentations/chunk-AFXRW7I7.mjs +18 -0
  39. package/dist/auto-instrumentations/hook.mjs +1712 -1460
  40. package/dist/auto-instrumentations/index.cjs +93 -0
  41. package/dist/auto-instrumentations/index.d.mts +5 -1
  42. package/dist/auto-instrumentations/index.d.ts +5 -1
  43. package/dist/auto-instrumentations/index.mjs +6 -247
  44. package/dist/auto-instrumentations/loader/esm-hook.mjs +19 -2
  45. package/dist/auto-instrumentations/plugin-D7nDswtC.d.mts +44 -0
  46. package/dist/auto-instrumentations/plugin-D7nDswtC.d.ts +44 -0
  47. package/dist/browser.d.mts +120 -31
  48. package/dist/browser.d.ts +120 -31
  49. package/dist/browser.js +2395 -123
  50. package/dist/browser.mjs +2395 -123
  51. package/dist/chunk-BW4DF4CY.js +816 -0
  52. package/dist/chunk-MSLBGITU.mjs +816 -0
  53. package/dist/cli.js +2407 -96
  54. package/dist/edge-light.d.mts +1 -1
  55. package/dist/edge-light.d.ts +1 -1
  56. package/dist/edge-light.js +2395 -123
  57. package/dist/edge-light.mjs +2395 -123
  58. package/dist/index.d.mts +120 -31
  59. package/dist/index.d.ts +120 -31
  60. package/dist/index.js +3362 -1849
  61. package/dist/index.mjs +2505 -992
  62. package/dist/instrumentation/index.d.mts +7860 -48
  63. package/dist/instrumentation/index.d.ts +7860 -48
  64. package/dist/instrumentation/index.js +2395 -95
  65. package/dist/instrumentation/index.mjs +2394 -95
  66. package/dist/workerd.d.mts +1 -1
  67. package/dist/workerd.d.ts +1 -1
  68. package/dist/workerd.js +2395 -123
  69. package/dist/workerd.mjs +2395 -123
  70. package/package.json +23 -3
  71. package/util/dist/index.js +6 -0
  72. package/util/dist/index.mjs +6 -0
  73. package/dist/auto-instrumentations/chunk-G6ZWXGZB.mjs +0 -116
  74. package/dist/auto-instrumentations/plugin-Df3qKIl2.d.mts +0 -22
  75. package/dist/auto-instrumentations/plugin-Df3qKIl2.d.ts +0 -22
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braintrust",
3
- "version": "3.11.0",
3
+ "version": "3.12.0",
4
4
  "description": "SDK for integrating Braintrust",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,6 +11,7 @@
11
11
  "main": "./dist/index.js",
12
12
  "module": "./dist/index.mjs",
13
13
  "types": "./dist/index.d.ts",
14
+ "sideEffects": true,
14
15
  "browser": {
15
16
  "./dist/index.js": "./dist/browser.js",
16
17
  "./dist/index.d.ts": "./dist/browser.d.ts",
@@ -50,6 +51,19 @@
50
51
  "require": "./dist/browser.js",
51
52
  "default": "./dist/browser.mjs"
52
53
  },
54
+ "./apply-auto-instrumentation": {
55
+ "types": "./dist/apply-auto-instrumentation.d.ts",
56
+ "edge-light": "./dist/apply-auto-instrumentation.browser.mjs",
57
+ "workerd": "./dist/apply-auto-instrumentation.browser.mjs",
58
+ "node": {
59
+ "import": "./dist/apply-auto-instrumentation.mjs",
60
+ "require": "./dist/apply-auto-instrumentation.js"
61
+ },
62
+ "browser": "./dist/apply-auto-instrumentation.browser.mjs",
63
+ "import": "./dist/apply-auto-instrumentation.mjs",
64
+ "require": "./dist/apply-auto-instrumentation.js",
65
+ "default": "./dist/apply-auto-instrumentation.mjs"
66
+ },
53
67
  "./node": {
54
68
  "types": "./dist/index.d.ts",
55
69
  "import": "./dist/index.mjs",
@@ -87,6 +101,12 @@
87
101
  "module": "./dist/auto-instrumentations/bundler/webpack.mjs",
88
102
  "require": "./dist/auto-instrumentations/bundler/webpack.cjs"
89
103
  },
104
+ "./next": {
105
+ "types": "./dist/auto-instrumentations/bundler/next.d.ts",
106
+ "import": "./dist/auto-instrumentations/bundler/next.mjs",
107
+ "module": "./dist/auto-instrumentations/bundler/next.mjs",
108
+ "require": "./dist/auto-instrumentations/bundler/next.cjs"
109
+ },
90
110
  "./webpack-loader": {
91
111
  "types": "./dist/auto-instrumentations/bundler/webpack-loader.d.ts",
92
112
  "require": "./dist/auto-instrumentations/bundler/webpack-loader.cjs"
@@ -118,7 +138,8 @@
118
138
  "test": "vitest run --exclude \"src/wrappers/**/*.test.ts\" --exclude \"src/otel/**/*.test.ts\" --exclude \"smoke/**/*.test.ts\" --exclude \"src/zod/**/*.test.ts\" --exclude \"tests/api-compatibility/**\"",
119
139
  "test:core": "pnpm prune && pnpm test",
120
140
  "test:checks": "pnpm run test:core && pnpm run test:vitest",
121
- "test:external": "pnpm run test:external:openai && pnpm run test:external:anthropic && pnpm run test:external:google-genai && pnpm run test:external:ai-sdk && pnpm run test:external:claude-agent-sdk",
141
+ "test:external": "pnpm run test:external:sequential && node scripts/run-parallel.mjs test:external:ai-sdk-v5 test:external:ai-sdk-v6 test:external:claude-agent-sdk",
142
+ "test:external:sequential": "pnpm run test:external:openai && pnpm run test:external:anthropic && pnpm run test:external:google-genai",
122
143
  "test:external:openai": "bash scripts/test-provider.sh test:openai openai",
123
144
  "test:external:anthropic": "bash scripts/test-provider.sh test:anthropic @anthropic-ai/sdk",
124
145
  "test:external:google-genai": "bash scripts/test-provider.sh test:google-genai @google/genai",
@@ -179,7 +200,6 @@
179
200
  "cross-env": "^7.0.3",
180
201
  "eslint-plugin-node-import": "^1.0.5",
181
202
  "openai": "6.25.0",
182
- "openapi-zod-client": "^1.18.3",
183
203
  "rollup": "^4.60.3",
184
204
  "tar": "^7.5.2",
185
205
  "tinybench": "^4.0.1",
@@ -688,6 +688,11 @@ function isPromiseLike(value) {
688
688
 
689
689
  // util/object_util.ts
690
690
  var SET_UNION_FIELDS = /* @__PURE__ */ new Set(["tags"]);
691
+ var FORBIDDEN_MERGE_KEYS = /* @__PURE__ */ new Set([
692
+ "__proto__",
693
+ "constructor",
694
+ "prototype"
695
+ ]);
691
696
  function mergeDictsWithPaths({
692
697
  mergeInto,
693
698
  mergeFrom,
@@ -710,6 +715,7 @@ function mergeDictsWithPathsHelper({
710
715
  mergePaths
711
716
  }) {
712
717
  Object.entries(mergeFrom).forEach(([k, mergeFromV]) => {
718
+ if (FORBIDDEN_MERGE_KEYS.has(k)) return;
713
719
  const fullPath = path.concat([k]);
714
720
  const fullPathSerialized = JSON.stringify(fullPath);
715
721
  const mergeIntoV = recordFind(mergeInto, k);
@@ -688,6 +688,11 @@ function isPromiseLike(value) {
688
688
 
689
689
  // util/object_util.ts
690
690
  var SET_UNION_FIELDS = /* @__PURE__ */ new Set(["tags"]);
691
+ var FORBIDDEN_MERGE_KEYS = /* @__PURE__ */ new Set([
692
+ "__proto__",
693
+ "constructor",
694
+ "prototype"
695
+ ]);
691
696
  function mergeDictsWithPaths({
692
697
  mergeInto,
693
698
  mergeFrom,
@@ -710,6 +715,7 @@ function mergeDictsWithPathsHelper({
710
715
  mergePaths
711
716
  }) {
712
717
  Object.entries(mergeFrom).forEach(([k, mergeFromV]) => {
718
+ if (FORBIDDEN_MERGE_KEYS.has(k)) return;
713
719
  const fullPath = path.concat([k]);
714
720
  const fullPathSerialized = JSON.stringify(fullPath);
715
721
  const mergeIntoV = recordFind(mergeInto, k);
@@ -1,116 +0,0 @@
1
- import {
2
- aiSDKConfigs,
3
- anthropicConfigs,
4
- claudeAgentSDKConfigs,
5
- cohereConfigs,
6
- cursorSDKConfigs,
7
- genkitConfigs,
8
- gitHubCopilotConfigs,
9
- googleGenAIConfigs,
10
- groqConfigs,
11
- huggingFaceConfigs,
12
- mistralConfigs,
13
- openAICodexConfigs,
14
- openRouterAgentConfigs,
15
- openRouterConfigs,
16
- openaiConfigs
17
- } from "./chunk-DIV5TO4S.mjs";
18
-
19
- // src/auto-instrumentations/bundler/plugin.ts
20
- import { createUnplugin } from "unplugin";
21
- import {
22
- create
23
- } from "@apm-js-collab/code-transformer";
24
- import { extname, join, sep } from "path";
25
- import { readFileSync } from "fs";
26
- import { fileURLToPath } from "url";
27
- import moduleDetailsFromPath from "module-details-from-path";
28
- function getModuleVersion(basedir) {
29
- try {
30
- const packageJsonPath = join(basedir, "package.json");
31
- const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
32
- if (packageJson.version) {
33
- return packageJson.version;
34
- }
35
- } catch (error) {
36
- }
37
- return void 0;
38
- }
39
- var unplugin = createUnplugin((options = {}) => {
40
- const allInstrumentations = [
41
- ...openaiConfigs,
42
- ...openAICodexConfigs,
43
- ...anthropicConfigs,
44
- ...aiSDKConfigs,
45
- ...claudeAgentSDKConfigs,
46
- ...cursorSDKConfigs,
47
- ...googleGenAIConfigs,
48
- ...huggingFaceConfigs,
49
- ...openRouterConfigs,
50
- ...openRouterAgentConfigs,
51
- ...mistralConfigs,
52
- ...cohereConfigs,
53
- ...groqConfigs,
54
- ...genkitConfigs,
55
- ...gitHubCopilotConfigs,
56
- ...options.instrumentations || []
57
- ];
58
- const dcModule = options.browser === false ? void 0 : "dc-browser";
59
- const instrumentationMatcher = create(allInstrumentations, dcModule);
60
- return {
61
- name: "code-transformer",
62
- enforce: "pre",
63
- transform(code, id) {
64
- if (!id) {
65
- return null;
66
- }
67
- const filePath = id.startsWith("file:") ? fileURLToPath(id) : id;
68
- const ext = extname(filePath);
69
- let isModule = ext === ".mjs" || ext === ".ts" || ext === ".tsx";
70
- if (ext === ".js") {
71
- isModule = code.includes("export ") || code.includes("import ");
72
- }
73
- const normalizedForPlatform = filePath.split("/").join(sep);
74
- const moduleDetails = moduleDetailsFromPath(normalizedForPlatform);
75
- if (!moduleDetails) {
76
- return null;
77
- }
78
- const moduleName = moduleDetails.name;
79
- const moduleVersion = getModuleVersion(moduleDetails.basedir);
80
- if (!moduleVersion) {
81
- console.warn(
82
- `No 'package.json' version found for module ${moduleName} at ${moduleDetails.basedir}. Skipping transformation.`
83
- );
84
- return null;
85
- }
86
- const normalizedModulePath = moduleDetails.path.replace(/\\/g, "/");
87
- const transformer = instrumentationMatcher.getTransformer(
88
- moduleName,
89
- moduleVersion,
90
- normalizedModulePath
91
- );
92
- if (!transformer) {
93
- return null;
94
- }
95
- try {
96
- const moduleType = isModule ? "esm" : "cjs";
97
- const result = transformer.transform(code, moduleType);
98
- const transformedCode = result.code.replace(
99
- /const \{tracingChannel: ([A-Za-z_$][\w$]*)\} = ([A-Za-z_$][\w$]*);/g,
100
- "const $1 = $2.tracingChannel;"
101
- );
102
- return {
103
- code: transformedCode,
104
- map: result.map
105
- };
106
- } catch (error) {
107
- console.warn(`Code transformation failed for ${id}: ${error}`);
108
- return null;
109
- }
110
- }
111
- };
112
- });
113
-
114
- export {
115
- unplugin
116
- };
@@ -1,22 +0,0 @@
1
- import { InstrumentationConfig } from '@apm-js-collab/code-transformer';
2
-
3
- interface BundlerPluginOptions {
4
- /**
5
- * Enable debug logging
6
- */
7
- debug?: boolean;
8
- /**
9
- * Additional instrumentation configs to apply
10
- */
11
- instrumentations?: InstrumentationConfig[];
12
- /**
13
- * Whether to bundle for browser environments.
14
- *
15
- * When true, uses 'dc-browser' for browser-compatible diagnostics_channel polyfill.
16
- * When false, uses Node.js built-in 'diagnostics_channel' and 'async_hooks'.
17
- * Defaults to true (assumes browser build).
18
- */
19
- browser?: boolean;
20
- }
21
-
22
- export type { BundlerPluginOptions as B };
@@ -1,22 +0,0 @@
1
- import { InstrumentationConfig } from '@apm-js-collab/code-transformer';
2
-
3
- interface BundlerPluginOptions {
4
- /**
5
- * Enable debug logging
6
- */
7
- debug?: boolean;
8
- /**
9
- * Additional instrumentation configs to apply
10
- */
11
- instrumentations?: InstrumentationConfig[];
12
- /**
13
- * Whether to bundle for browser environments.
14
- *
15
- * When true, uses 'dc-browser' for browser-compatible diagnostics_channel polyfill.
16
- * When false, uses Node.js built-in 'diagnostics_channel' and 'async_hooks'.
17
- * Defaults to true (assumes browser build).
18
- */
19
- browser?: boolean;
20
- }
21
-
22
- export type { BundlerPluginOptions as B };