braintrust 3.11.0 → 3.13.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 (77) hide show
  1. package/README.md +8 -8
  2. package/dev/dist/index.d.mts +26 -7
  3. package/dev/dist/index.d.ts +26 -7
  4. package/dev/dist/index.js +2717 -335
  5. package/dev/dist/index.mjs +2499 -117
  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 +1803 -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 +3269 -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 +1803 -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 +1803 -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 +1861 -1308
  31. package/dist/auto-instrumentations/bundler/webpack-loader.d.ts +3 -3
  32. package/dist/auto-instrumentations/bundler/webpack.cjs +1803 -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-E5DUYJWK.mjs} +338 -1
  37. package/dist/auto-instrumentations/chunk-GJOO4ESL.mjs +300 -0
  38. package/dist/auto-instrumentations/chunk-WFEUJACP.mjs +18 -0
  39. package/dist/auto-instrumentations/hook.mjs +1713 -1460
  40. package/dist/auto-instrumentations/index.cjs +94 -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 +264 -47
  48. package/dist/browser.d.ts +264 -47
  49. package/dist/browser.js +2521 -159
  50. package/dist/browser.mjs +2521 -159
  51. package/dist/chunk-26JGOELH.js +817 -0
  52. package/dist/chunk-75IQCUB2.mjs +817 -0
  53. package/dist/cli.js +2510 -122
  54. package/dist/edge-light.d.mts +1 -1
  55. package/dist/edge-light.d.ts +1 -1
  56. package/dist/edge-light.js +2521 -159
  57. package/dist/edge-light.mjs +2521 -159
  58. package/dist/index.d.mts +264 -47
  59. package/dist/index.d.ts +264 -47
  60. package/dist/index.js +3498 -1850
  61. package/dist/index.mjs +2635 -987
  62. package/dist/instrumentation/index.d.mts +7897 -48
  63. package/dist/instrumentation/index.d.ts +7897 -48
  64. package/dist/instrumentation/index.js +2408 -95
  65. package/dist/instrumentation/index.mjs +2407 -95
  66. package/dist/workerd.d.mts +1 -1
  67. package/dist/workerd.d.ts +1 -1
  68. package/dist/workerd.js +2521 -159
  69. package/dist/workerd.mjs +2521 -159
  70. package/package.json +23 -17
  71. package/util/dist/index.d.mts +3 -1
  72. package/util/dist/index.d.ts +3 -1
  73. package/util/dist/index.js +6 -0
  74. package/util/dist/index.mjs +6 -0
  75. package/dist/auto-instrumentations/chunk-G6ZWXGZB.mjs +0 -116
  76. package/dist/auto-instrumentations/plugin-Df3qKIl2.d.mts +0 -22
  77. 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.13.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,28 +138,16 @@
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",
122
- "test:external:openai": "bash scripts/test-provider.sh test:openai openai",
123
- "test:external:anthropic": "bash scripts/test-provider.sh test:anthropic @anthropic-ai/sdk",
124
- "test:external:google-genai": "bash scripts/test-provider.sh test:google-genai @google/genai",
125
- "test:external:ai-sdk": "pnpm run test:external:ai-sdk-v5 && pnpm run test:external:ai-sdk-v6",
126
- "test:external:ai-sdk-v5": "cd src/wrappers/ai-sdk/tests/v5 && pnpm install --ignore-workspace && pnpm test",
127
- "test:external:ai-sdk-v6": "cd src/wrappers/ai-sdk/tests/v6 && pnpm install --ignore-workspace && pnpm test",
128
- "test:external:claude-agent-sdk": "cd src/wrappers/claude-agent-sdk && pnpm install && pnpm test",
129
- "test:all": "pnpm run test:checks && pnpm run test:external",
141
+ "test:all": "pnpm run test:checks",
130
142
  "test:api-compat": "vitest run tests/api-compatibility/api-compatibility.test.ts",
131
- "test:anthropic": "vitest run src/wrappers/anthropic.test.ts",
132
- "test:openai": "vitest run src/wrappers/oai.test.ts",
133
143
  "test:otel": "vitest run --dir src/otel",
134
144
  "test:otel-no-deps": "vitest run src/otel/otel-no-deps.test.ts --reporter=verbose",
135
- "test:google-genai": "vitest run src/wrappers/google-genai.test.ts",
136
145
  "test:ai-sdk-v1": "vitest run src/wrappers/ai-sdk-v1.test.ts",
137
146
  "test:ai-sdk-v2": "vitest run src/wrappers/ai-sdk-v2.test.ts src/wrappers/ai-sdk-v1.test.ts",
138
147
  "test:ai-sdk-v3": "vitest run src/wrappers/ai-sdk-v3.test.ts",
139
148
  "test:zod-v3": "vitest run src/zod/zod-v3-serialization.test.ts",
140
149
  "test:zod-v4": "vitest run src/zod/zod-v4-serialization.test.ts",
141
150
  "test:mastra": "vitest run src/wrappers/mastra.test.ts",
142
- "test:claude-agent-sdk": "pnpm --filter @braintrust/claude-agent-sdk-tests test",
143
151
  "test:vitest": "pnpm --filter @braintrust/vitest-wrapper-tests test",
144
152
  "test:output": "tsx scripts/test-output.ts --with-comparison --with-metrics --with-progress",
145
153
  "bench": "tsx src/queue.bench.ts",
@@ -170,7 +178,6 @@
170
178
  "@types/node": "^20.10.5",
171
179
  "@types/pluralize": "^0.0.30",
172
180
  "@types/tar": "^6.1.13",
173
- "@types/uuid": "^9.0.7",
174
181
  "@typescript-eslint/eslint-plugin": "^8.49.0",
175
182
  "@typescript-eslint/parser": "^8.49.0",
176
183
  "ai": "^6.0.0",
@@ -179,7 +186,6 @@
179
186
  "cross-env": "^7.0.3",
180
187
  "eslint-plugin-node-import": "^1.0.5",
181
188
  "openai": "6.25.0",
182
- "openapi-zod-client": "^1.18.3",
183
189
  "rollup": "^4.60.3",
184
190
  "tar": "^7.5.2",
185
191
  "tinybench": "^4.0.1",
@@ -218,7 +224,7 @@
218
224
  "source-map": "^0.7.4",
219
225
  "termi-link": "^1.0.1",
220
226
  "unplugin": "^2.3.5",
221
- "uuid": "^9.0.1",
227
+ "uuid": "^11.1.1",
222
228
  "zod-to-json-schema": "^3.25.0"
223
229
  },
224
230
  "peerDependencies": {
@@ -4842,6 +4842,7 @@ declare const ObjectReference: z.ZodObject<{
4842
4842
  _xact_id?: string | null | undefined;
4843
4843
  created?: string | null | undefined;
4844
4844
  }>;
4845
+ type ObjectReferenceType = z.infer<typeof ObjectReference>;
4845
4846
 
4846
4847
  type IdField = {
4847
4848
  id: string;
@@ -4862,7 +4863,7 @@ type OtherExperimentLogFields = {
4862
4863
  metadata: Record<string, unknown>;
4863
4864
  metrics: Record<string, unknown>;
4864
4865
  datasetRecordId: string;
4865
- origin: z.infer<typeof ObjectReference>;
4866
+ origin: ObjectReferenceType;
4866
4867
  span_attributes: Record<string, unknown>;
4867
4868
  [ASYNC_SCORING_CONTROL_FIELD]: AsyncScoringControlType;
4868
4869
  [MERGE_PATHS_FIELD]: string[][];
@@ -4916,6 +4917,7 @@ type DatasetEvent = {
4916
4917
  tags?: string[];
4917
4918
  metadata?: unknown;
4918
4919
  created?: string;
4920
+ origin?: ObjectReferenceType;
4919
4921
  id: string;
4920
4922
  dataset_id: string;
4921
4923
  } & ({
@@ -4842,6 +4842,7 @@ declare const ObjectReference: z.ZodObject<{
4842
4842
  _xact_id?: string | null | undefined;
4843
4843
  created?: string | null | undefined;
4844
4844
  }>;
4845
+ type ObjectReferenceType = z.infer<typeof ObjectReference>;
4845
4846
 
4846
4847
  type IdField = {
4847
4848
  id: string;
@@ -4862,7 +4863,7 @@ type OtherExperimentLogFields = {
4862
4863
  metadata: Record<string, unknown>;
4863
4864
  metrics: Record<string, unknown>;
4864
4865
  datasetRecordId: string;
4865
- origin: z.infer<typeof ObjectReference>;
4866
+ origin: ObjectReferenceType;
4866
4867
  span_attributes: Record<string, unknown>;
4867
4868
  [ASYNC_SCORING_CONTROL_FIELD]: AsyncScoringControlType;
4868
4869
  [MERGE_PATHS_FIELD]: string[][];
@@ -4916,6 +4917,7 @@ type DatasetEvent = {
4916
4917
  tags?: string[];
4917
4918
  metadata?: unknown;
4918
4919
  created?: string;
4920
+ origin?: ObjectReferenceType;
4919
4921
  id: string;
4920
4922
  dataset_id: string;
4921
4923
  } & ({
@@ -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 };