braintrust 3.12.0 → 3.14.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 (55) hide show
  1. package/dev/dist/index.d.mts +31 -14
  2. package/dev/dist/index.d.ts +31 -14
  3. package/dev/dist/index.js +919 -485
  4. package/dev/dist/index.mjs +480 -46
  5. package/dist/apply-auto-instrumentation.js +204 -174
  6. package/dist/apply-auto-instrumentation.mjs +35 -5
  7. package/dist/auto-instrumentations/bundler/esbuild.cjs +226 -1
  8. package/dist/auto-instrumentations/bundler/esbuild.mjs +3 -2
  9. package/dist/auto-instrumentations/bundler/next.cjs +226 -1
  10. package/dist/auto-instrumentations/bundler/next.mjs +4 -3
  11. package/dist/auto-instrumentations/bundler/rollup.cjs +226 -1
  12. package/dist/auto-instrumentations/bundler/rollup.mjs +3 -2
  13. package/dist/auto-instrumentations/bundler/vite.cjs +226 -1
  14. package/dist/auto-instrumentations/bundler/vite.mjs +3 -2
  15. package/dist/auto-instrumentations/bundler/webpack-loader.cjs +9 -0
  16. package/dist/auto-instrumentations/bundler/webpack.cjs +226 -1
  17. package/dist/auto-instrumentations/bundler/webpack.mjs +4 -3
  18. package/dist/auto-instrumentations/{chunk-2DPA74KK.mjs → chunk-E5DUYJWK.mjs} +1 -0
  19. package/dist/auto-instrumentations/chunk-J57YF7WS.mjs +208 -0
  20. package/dist/auto-instrumentations/{chunk-AFXRW7I7.mjs → chunk-OTUQ7KH5.mjs} +1 -1
  21. package/dist/auto-instrumentations/chunk-QFMACSOL.mjs +280 -0
  22. package/dist/auto-instrumentations/{chunk-73BZUKVI.mjs → chunk-XKAAVWT6.mjs} +24 -2
  23. package/dist/auto-instrumentations/hook.mjs +7981 -7
  24. package/dist/auto-instrumentations/index.cjs +1 -0
  25. package/dist/auto-instrumentations/index.mjs +1 -1
  26. package/dist/auto-instrumentations/loader/cjs-patch.cjs +194 -4
  27. package/dist/auto-instrumentations/loader/cjs-patch.mjs +13 -27
  28. package/dist/auto-instrumentations/loader/esm-hook.mjs +24 -10
  29. package/dist/browser.d.mts +274 -30
  30. package/dist/browser.d.ts +274 -30
  31. package/dist/browser.js +407 -48
  32. package/dist/browser.mjs +407 -48
  33. package/dist/{chunk-BW4DF4CY.js → chunk-NKD77KGB.js} +180 -1
  34. package/dist/{chunk-MSLBGITU.mjs → chunk-NU2GSPHX.mjs} +180 -1
  35. package/dist/cli.js +494 -94
  36. package/dist/edge-light.d.mts +1 -1
  37. package/dist/edge-light.d.ts +1 -1
  38. package/dist/edge-light.js +407 -48
  39. package/dist/edge-light.mjs +407 -48
  40. package/dist/index.d.mts +274 -30
  41. package/dist/index.d.ts +274 -30
  42. package/dist/index.js +1267 -857
  43. package/dist/index.mjs +465 -55
  44. package/dist/instrumentation/index.d.mts +47 -11
  45. package/dist/instrumentation/index.d.ts +47 -11
  46. package/dist/instrumentation/index.js +116 -26
  47. package/dist/instrumentation/index.mjs +116 -26
  48. package/dist/workerd.d.mts +1 -1
  49. package/dist/workerd.d.ts +1 -1
  50. package/dist/workerd.js +407 -48
  51. package/dist/workerd.mjs +407 -48
  52. package/package.json +3 -23
  53. package/util/dist/index.d.mts +3 -1
  54. package/util/dist/index.d.ts +3 -1
  55. package/dist/auto-instrumentations/chunk-MWZXZQUO.mjs +0 -81
package/dist/cli.js CHANGED
@@ -1232,7 +1232,7 @@ var require_package = __commonJS({
1232
1232
  "package.json"(exports2, module2) {
1233
1233
  module2.exports = {
1234
1234
  name: "braintrust",
1235
- version: "3.12.0",
1235
+ version: "3.14.0",
1236
1236
  description: "SDK for integrating Braintrust",
1237
1237
  repository: {
1238
1238
  type: "git",
@@ -1370,29 +1370,16 @@ var require_package = __commonJS({
1370
1370
  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/**"',
1371
1371
  "test:core": "pnpm prune && pnpm test",
1372
1372
  "test:checks": "pnpm run test:core && pnpm run test:vitest",
1373
- "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",
1374
- "test:external:sequential": "pnpm run test:external:openai && pnpm run test:external:anthropic && pnpm run test:external:google-genai",
1375
- "test:external:openai": "bash scripts/test-provider.sh test:openai openai",
1376
- "test:external:anthropic": "bash scripts/test-provider.sh test:anthropic @anthropic-ai/sdk",
1377
- "test:external:google-genai": "bash scripts/test-provider.sh test:google-genai @google/genai",
1378
- "test:external:ai-sdk": "pnpm run test:external:ai-sdk-v5 && pnpm run test:external:ai-sdk-v6",
1379
- "test:external:ai-sdk-v5": "cd src/wrappers/ai-sdk/tests/v5 && pnpm install --ignore-workspace && pnpm test",
1380
- "test:external:ai-sdk-v6": "cd src/wrappers/ai-sdk/tests/v6 && pnpm install --ignore-workspace && pnpm test",
1381
- "test:external:claude-agent-sdk": "cd src/wrappers/claude-agent-sdk && pnpm install && pnpm test",
1382
- "test:all": "pnpm run test:checks && pnpm run test:external",
1373
+ "test:all": "pnpm run test:checks",
1383
1374
  "test:api-compat": "vitest run tests/api-compatibility/api-compatibility.test.ts",
1384
- "test:anthropic": "vitest run src/wrappers/anthropic.test.ts",
1385
- "test:openai": "vitest run src/wrappers/oai.test.ts",
1386
1375
  "test:otel": "vitest run --dir src/otel",
1387
1376
  "test:otel-no-deps": "vitest run src/otel/otel-no-deps.test.ts --reporter=verbose",
1388
- "test:google-genai": "vitest run src/wrappers/google-genai.test.ts",
1389
1377
  "test:ai-sdk-v1": "vitest run src/wrappers/ai-sdk-v1.test.ts",
1390
1378
  "test:ai-sdk-v2": "vitest run src/wrappers/ai-sdk-v2.test.ts src/wrappers/ai-sdk-v1.test.ts",
1391
1379
  "test:ai-sdk-v3": "vitest run src/wrappers/ai-sdk-v3.test.ts",
1392
1380
  "test:zod-v3": "vitest run src/zod/zod-v3-serialization.test.ts",
1393
1381
  "test:zod-v4": "vitest run src/zod/zod-v4-serialization.test.ts",
1394
1382
  "test:mastra": "vitest run src/wrappers/mastra.test.ts",
1395
- "test:claude-agent-sdk": "pnpm --filter @braintrust/claude-agent-sdk-tests test",
1396
1383
  "test:vitest": "pnpm --filter @braintrust/vitest-wrapper-tests test",
1397
1384
  "test:output": "tsx scripts/test-output.ts --with-comparison --with-metrics --with-progress",
1398
1385
  bench: "tsx src/queue.bench.ts",
@@ -1407,28 +1394,22 @@ var require_package = __commonJS({
1407
1394
  author: "",
1408
1395
  license: "MIT",
1409
1396
  devDependencies: {
1410
- "@ai-sdk/anthropic": "2.0.37",
1411
1397
  "@anthropic-ai/sdk": "^0.60.0",
1412
- "@google/adk": "^0.6.1",
1413
- "@google/genai": "^1.25.0",
1414
1398
  "@nodelib/fs.walk": "^1.2.8",
1415
1399
  "@types/argparse": "^2.0.14",
1416
1400
  "@types/async": "^3.2.24",
1417
1401
  "@types/cli-progress": "^3.11.5",
1418
1402
  "@types/cors": "^2.8.17",
1419
1403
  "@types/express": "^5.0.0",
1420
- "@types/graceful-fs": "^4.1.9",
1421
1404
  "@types/http-errors": "^2.0.4",
1422
1405
  "@types/mustache": "^4.2.5",
1423
1406
  "@types/node": "^20.10.5",
1424
1407
  "@types/pluralize": "^0.0.30",
1425
1408
  "@types/tar": "^6.1.13",
1426
- "@types/uuid": "^9.0.7",
1427
1409
  "@typescript-eslint/eslint-plugin": "^8.49.0",
1428
1410
  "@typescript-eslint/parser": "^8.49.0",
1429
1411
  ai: "^6.0.0",
1430
1412
  async: "^3.2.5",
1431
- autoevals: "^0.0.131",
1432
1413
  "cross-env": "^7.0.3",
1433
1414
  "eslint-plugin-node-import": "^1.0.5",
1434
1415
  openai: "6.25.0",
@@ -1460,7 +1441,6 @@ var require_package = __commonJS({
1460
1441
  esbuild: "0.28.0",
1461
1442
  "eventsource-parser": "^1.1.2",
1462
1443
  express: "^5.2.1",
1463
- "graceful-fs": "^4.2.11",
1464
1444
  "http-errors": "^2.0.0",
1465
1445
  minimatch: "^10.2.5",
1466
1446
  "module-details-from-path": "^1.0.4",
@@ -1470,7 +1450,7 @@ var require_package = __commonJS({
1470
1450
  "source-map": "^0.7.4",
1471
1451
  "termi-link": "^1.0.1",
1472
1452
  unplugin: "^2.3.5",
1473
- uuid: "^9.0.1",
1453
+ uuid: "^11.1.1",
1474
1454
  "zod-to-json-schema": "^3.25.0"
1475
1455
  },
1476
1456
  peerDependencies: {
@@ -1494,8 +1474,8 @@ __export(cli_exports, {
1494
1474
  });
1495
1475
  module.exports = __toCommonJS(cli_exports);
1496
1476
  var esbuild = __toESM(require("esbuild"));
1497
- var dotenv2 = __toESM(require("dotenv"));
1498
- var import_node_fs2 = __toESM(require("node:fs"));
1477
+ var dotenv3 = __toESM(require("dotenv"));
1478
+ var import_node_fs3 = __toESM(require("node:fs"));
1499
1479
  var import_node_os = __toESM(require("node:os"));
1500
1480
  var import_node_path5 = __toESM(require("node:path"));
1501
1481
  var import_node_util5 = __toESM(require("node:util"));
@@ -1593,6 +1573,7 @@ var iso = {
1593
1573
  getRepoInfo: async (_settings) => void 0,
1594
1574
  getPastNAncestors: async () => [],
1595
1575
  getEnv: (_name) => void 0,
1576
+ getBraintrustApiKey: async () => void 0,
1596
1577
  getCallerLocation: () => void 0,
1597
1578
  newAsyncLocalStorage: () => new DefaultAsyncLocalStorage(),
1598
1579
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -5456,6 +5437,76 @@ var LRUCache = class {
5456
5437
  }
5457
5438
  };
5458
5439
 
5440
+ // src/prompt-cache/cache-config.ts
5441
+ var CACHE_LOCATION_ENV_VAR = "BRAINTRUST_CACHE_LOCATION";
5442
+ var DEFAULT_CACHE_MEMORY_MAX = 1 << 10;
5443
+ var DEFAULT_CACHE_DISK_MAX = 1 << 20;
5444
+ var warnedInvalidCacheModeEnvValue = false;
5445
+ var warnedUnavailableDiskCacheMode = false;
5446
+ function warnInvalidCacheMode(value) {
5447
+ if (warnedInvalidCacheModeEnvValue) {
5448
+ return;
5449
+ }
5450
+ warnedInvalidCacheModeEnvValue = true;
5451
+ debugLogger.warn(
5452
+ `Invalid ${CACHE_LOCATION_ENV_VAR} value "${value}". Expected "mixed", "memory", "disk", or "none". Falling back to "mixed".`
5453
+ );
5454
+ }
5455
+ function warnUnavailableDiskCache() {
5456
+ if (warnedUnavailableDiskCacheMode) {
5457
+ return;
5458
+ }
5459
+ warnedUnavailableDiskCacheMode = true;
5460
+ debugLogger.warn(
5461
+ `Disk cache is not supported on this platform, so ${CACHE_LOCATION_ENV_VAR}="disk" disables prompt and parameters caching.`
5462
+ );
5463
+ }
5464
+ function parseCacheMode() {
5465
+ const value = isomorph_default.getEnv(CACHE_LOCATION_ENV_VAR);
5466
+ const normalized = value?.trim().toLowerCase();
5467
+ if (!normalized) {
5468
+ return "mixed";
5469
+ }
5470
+ if (normalized === "mixed" || normalized === "memory" || normalized === "disk" || normalized === "none") {
5471
+ return normalized;
5472
+ }
5473
+ warnInvalidCacheMode(value ?? "");
5474
+ return "mixed";
5475
+ }
5476
+ function parsePositiveIntegerEnv(envVar, defaultValue) {
5477
+ const value = Number(isomorph_default.getEnv(envVar));
5478
+ return Number.isInteger(value) && value > 0 ? value : defaultValue;
5479
+ }
5480
+ function createCacheLayers({
5481
+ memoryMaxEnvVar,
5482
+ diskCacheDirEnvVar,
5483
+ diskMaxEnvVar,
5484
+ getDefaultDiskCacheDir
5485
+ }) {
5486
+ const mode = parseCacheMode();
5487
+ const memoryCache = mode === "mixed" || mode === "memory" ? new LRUCache({
5488
+ max: parsePositiveIntegerEnv(
5489
+ memoryMaxEnvVar,
5490
+ DEFAULT_CACHE_MEMORY_MAX
5491
+ )
5492
+ }) : void 0;
5493
+ let diskCache;
5494
+ if (mode === "mixed" || mode === "disk") {
5495
+ if (canUseDiskCache()) {
5496
+ diskCache = new DiskCache({
5497
+ cacheDir: isomorph_default.getEnv(diskCacheDirEnvVar) ?? getDefaultDiskCacheDir(),
5498
+ max: parsePositiveIntegerEnv(diskMaxEnvVar, DEFAULT_CACHE_DISK_MAX)
5499
+ });
5500
+ } else if (mode === "disk") {
5501
+ warnUnavailableDiskCache();
5502
+ }
5503
+ }
5504
+ if (diskCache) {
5505
+ return { memoryCache, diskCache };
5506
+ }
5507
+ return { memoryCache };
5508
+ }
5509
+
5459
5510
  // src/prompt-cache/prompt-cache.ts
5460
5511
  function createCacheKey(key) {
5461
5512
  if (key.id) {
@@ -5483,16 +5534,18 @@ var PromptCache = class {
5483
5534
  */
5484
5535
  async get(key) {
5485
5536
  const cacheKey = createCacheKey(key);
5486
- const memoryPrompt = this.memoryCache.get(cacheKey);
5487
- if (memoryPrompt !== void 0) {
5488
- return memoryPrompt;
5537
+ if (this.memoryCache) {
5538
+ const memoryPrompt = this.memoryCache.get(cacheKey);
5539
+ if (memoryPrompt !== void 0) {
5540
+ return memoryPrompt;
5541
+ }
5489
5542
  }
5490
5543
  if (this.diskCache) {
5491
5544
  const diskPrompt = await this.diskCache.get(cacheKey);
5492
5545
  if (!diskPrompt) {
5493
5546
  return void 0;
5494
5547
  }
5495
- this.memoryCache.set(cacheKey, diskPrompt);
5548
+ this.memoryCache?.set(cacheKey, diskPrompt);
5496
5549
  return diskPrompt;
5497
5550
  }
5498
5551
  return void 0;
@@ -5507,7 +5560,7 @@ var PromptCache = class {
5507
5560
  */
5508
5561
  async set(key, value) {
5509
5562
  const cacheKey = createCacheKey(key);
5510
- this.memoryCache.set(cacheKey, value);
5563
+ this.memoryCache?.set(cacheKey, value);
5511
5564
  if (this.diskCache) {
5512
5565
  await this.diskCache.set(cacheKey, value);
5513
5566
  }
@@ -5537,23 +5590,25 @@ var ParametersCache = class {
5537
5590
  }
5538
5591
  async get(key) {
5539
5592
  const cacheKey = createCacheKey2(key);
5540
- const memoryParams = this.memoryCache.get(cacheKey);
5541
- if (memoryParams !== void 0) {
5542
- return memoryParams;
5593
+ if (this.memoryCache) {
5594
+ const memoryParams = this.memoryCache.get(cacheKey);
5595
+ if (memoryParams !== void 0) {
5596
+ return memoryParams;
5597
+ }
5543
5598
  }
5544
5599
  if (this.diskCache) {
5545
5600
  const diskParams = await this.diskCache.get(cacheKey);
5546
5601
  if (!diskParams) {
5547
5602
  return void 0;
5548
5603
  }
5549
- this.memoryCache.set(cacheKey, diskParams);
5604
+ this.memoryCache?.set(cacheKey, diskParams);
5550
5605
  return diskParams;
5551
5606
  }
5552
5607
  return void 0;
5553
5608
  }
5554
5609
  async set(key, value) {
5555
5610
  const cacheKey = createCacheKey2(key);
5556
- this.memoryCache.set(cacheKey, value);
5611
+ this.memoryCache?.set(cacheKey, value);
5557
5612
  if (this.diskCache) {
5558
5613
  await this.diskCache.set(cacheKey, value);
5559
5614
  }
@@ -6085,21 +6140,22 @@ var BraintrustState = class _BraintrustState {
6085
6140
  setGlobalDebugLogLevel(void 0);
6086
6141
  }
6087
6142
  this.resetLoginInfo();
6088
- const memoryCache = new LRUCache({
6089
- max: Number(isomorph_default.getEnv("BRAINTRUST_PROMPT_CACHE_MEMORY_MAX")) ?? 1 << 10
6143
+ const { memoryCache, diskCache } = createCacheLayers({
6144
+ memoryMaxEnvVar: "BRAINTRUST_PROMPT_CACHE_MEMORY_MAX",
6145
+ diskCacheDirEnvVar: "BRAINTRUST_PROMPT_CACHE_DIR",
6146
+ diskMaxEnvVar: "BRAINTRUST_PROMPT_CACHE_DISK_MAX",
6147
+ getDefaultDiskCacheDir: () => `${isomorph_default.getEnv("HOME") ?? isomorph_default.homedir()}/.braintrust/prompt_cache`
6090
6148
  });
6091
- const diskCache = canUseDiskCache() ? new DiskCache({
6092
- cacheDir: isomorph_default.getEnv("BRAINTRUST_PROMPT_CACHE_DIR") ?? `${isomorph_default.getEnv("HOME") ?? isomorph_default.homedir()}/.braintrust/prompt_cache`,
6093
- max: Number(isomorph_default.getEnv("BRAINTRUST_PROMPT_CACHE_DISK_MAX")) ?? 1 << 20
6094
- }) : void 0;
6095
6149
  this.promptCache = new PromptCache({ memoryCache, diskCache });
6096
- const parametersMemoryCache = new LRUCache({
6097
- max: Number(isomorph_default.getEnv("BRAINTRUST_PARAMETERS_CACHE_MEMORY_MAX")) ?? 1 << 10
6150
+ const {
6151
+ memoryCache: parametersMemoryCache,
6152
+ diskCache: parametersDiskCache
6153
+ } = createCacheLayers({
6154
+ memoryMaxEnvVar: "BRAINTRUST_PARAMETERS_CACHE_MEMORY_MAX",
6155
+ diskCacheDirEnvVar: "BRAINTRUST_PARAMETERS_CACHE_DIR",
6156
+ diskMaxEnvVar: "BRAINTRUST_PARAMETERS_CACHE_DISK_MAX",
6157
+ getDefaultDiskCacheDir: () => `${isomorph_default.getEnv("HOME") ?? isomorph_default.homedir()}/.braintrust/parameters_cache`
6098
6158
  });
6099
- const parametersDiskCache = canUseDiskCache() ? new DiskCache({
6100
- cacheDir: isomorph_default.getEnv("BRAINTRUST_PARAMETERS_CACHE_DIR") ?? `${isomorph_default.getEnv("HOME") ?? isomorph_default.homedir()}/.braintrust/parameters_cache`,
6101
- max: Number(isomorph_default.getEnv("BRAINTRUST_PARAMETERS_CACHE_DISK_MAX")) ?? 1 << 20
6102
- }) : void 0;
6103
6159
  this.parametersCache = new ParametersCache({
6104
6160
  memoryCache: parametersMemoryCache,
6105
6161
  diskCache: parametersDiskCache
@@ -8470,10 +8526,11 @@ async function login(options = {}) {
8470
8526
  async function loginToState(options = {}) {
8471
8527
  const {
8472
8528
  appUrl = isomorph_default.getEnv("BRAINTRUST_APP_URL") || "https://www.braintrust.dev",
8473
- apiKey = isomorph_default.getEnv("BRAINTRUST_API_KEY"),
8529
+ apiKey: apiKeyArg,
8474
8530
  orgName = isomorph_default.getEnv("BRAINTRUST_ORG_NAME"),
8475
8531
  fetch: fetch2 = globalThis.fetch
8476
8532
  } = options || {};
8533
+ const apiKey = apiKeyArg !== void 0 ? apiKeyArg : await isomorph_default.getBraintrustApiKey();
8477
8534
  const appPublicUrl = isomorph_default.getEnv("BRAINTRUST_APP_PUBLIC_URL") || appUrl;
8478
8535
  const state = new BraintrustState(options);
8479
8536
  state.resetLoginInfo();
@@ -9492,9 +9549,15 @@ var SpanImpl = class _SpanImpl {
9492
9549
  const cachedSpan = {
9493
9550
  input: partialRecord.input,
9494
9551
  output: partialRecord.output,
9552
+ expected: partialRecord.expected,
9553
+ error: partialRecord.error,
9554
+ scores: partialRecord.scores,
9555
+ metrics: partialRecord.metrics,
9495
9556
  metadata: partialRecord.metadata,
9557
+ tags: partialRecord.tags,
9496
9558
  span_id: this._spanId,
9497
9559
  span_parents: this._spanParents,
9560
+ is_root: this._spanId === this._rootSpanId,
9498
9561
  span_attributes: partialRecord.span_attributes
9499
9562
  };
9500
9563
  this._state.spanCache.queueWrite(
@@ -9830,6 +9893,7 @@ var Dataset2 = class extends ObjectFetcher {
9830
9893
  metadata,
9831
9894
  tags,
9832
9895
  output,
9896
+ origin,
9833
9897
  isMerge
9834
9898
  }) {
9835
9899
  return new LazyValue(async () => {
@@ -9844,6 +9908,7 @@ var Dataset2 = class extends ObjectFetcher {
9844
9908
  created: !isMerge ? (/* @__PURE__ */ new Date()).toISOString() : void 0,
9845
9909
  //if we're merging/updating an event we will not add this ts
9846
9910
  metadata,
9911
+ origin,
9847
9912
  ...!!isMerge ? {
9848
9913
  [IS_MERGE_FIELD]: true
9849
9914
  } : {}
@@ -9863,6 +9928,7 @@ var Dataset2 = class extends ObjectFetcher {
9863
9928
  * about anything else that's relevant, that you can use to help find and analyze examples later. For example, you could log the
9864
9929
  * `prompt`, example's `id`, or anything else that would be useful to slice/dice later. The values in `metadata` can be any
9865
9930
  * JSON-serializable type, but its keys must be strings.
9931
+ * @param event.origin (Optional) a reference to the source object this dataset record was derived from.
9866
9932
  * @param event.id (Optional) a unique identifier for the event. If you don't provide one, Braintrust will generate one for you.
9867
9933
  * @param event.output: (Deprecated) The output of your application. Use `expected` instead.
9868
9934
  * @returns The `id` of the logged record.
@@ -9873,7 +9939,8 @@ var Dataset2 = class extends ObjectFetcher {
9873
9939
  metadata,
9874
9940
  tags,
9875
9941
  id,
9876
- output
9942
+ output,
9943
+ origin
9877
9944
  }) {
9878
9945
  this.validateEvent({ metadata, expected, output, tags });
9879
9946
  const rowId = id || (0, import_uuid2.v4)();
@@ -9885,6 +9952,7 @@ var Dataset2 = class extends ObjectFetcher {
9885
9952
  metadata,
9886
9953
  tags,
9887
9954
  output,
9955
+ origin,
9888
9956
  isMerge: false
9889
9957
  })
9890
9958
  );
@@ -11706,8 +11774,12 @@ async function invoke(args) {
11706
11774
 
11707
11775
  // src/trace.ts
11708
11776
  var SpanFetcher = class _SpanFetcher extends ObjectFetcher {
11709
- constructor(objectType, _objectId, rootSpanId, _state, spanTypeFilter) {
11710
- const filterExpr = _SpanFetcher.buildFilter(rootSpanId, spanTypeFilter);
11777
+ constructor(objectType, _objectId, rootSpanId, _state, spanTypeFilter, includeScorers = false) {
11778
+ const filterExpr = _SpanFetcher.buildFilter(
11779
+ rootSpanId,
11780
+ spanTypeFilter,
11781
+ includeScorers
11782
+ );
11711
11783
  super(objectType, void 0, void 0, {
11712
11784
  filter: filterExpr
11713
11785
  });
@@ -11716,16 +11788,17 @@ var SpanFetcher = class _SpanFetcher extends ObjectFetcher {
11716
11788
  this._state = _state;
11717
11789
  this.spanTypeFilter = spanTypeFilter;
11718
11790
  }
11719
- static buildFilter(rootSpanId, spanTypeFilter) {
11791
+ static buildFilter(rootSpanId, spanTypeFilter, includeScorers = false) {
11720
11792
  const children = [
11721
11793
  // Base filter: root_span_id = 'value'
11722
11794
  {
11723
11795
  op: "eq",
11724
11796
  left: { op: "ident", name: ["root_span_id"] },
11725
11797
  right: { op: "literal", value: rootSpanId }
11726
- },
11727
- // Exclude span_attributes.purpose = 'score'
11728
- {
11798
+ }
11799
+ ];
11800
+ if (!includeScorers) {
11801
+ children.push({
11729
11802
  op: "or",
11730
11803
  children: [
11731
11804
  {
@@ -11738,8 +11811,8 @@ var SpanFetcher = class _SpanFetcher extends ObjectFetcher {
11738
11811
  right: { op: "literal", value: "scorer" }
11739
11812
  }
11740
11813
  ]
11741
- }
11742
- ];
11814
+ });
11815
+ }
11743
11816
  if (spanTypeFilter && spanTypeFilter.length > 0) {
11744
11817
  children.push({
11745
11818
  op: "in",
@@ -11765,35 +11838,49 @@ var CachedSpanFetcher = class {
11765
11838
  fetchFn;
11766
11839
  constructor(objectTypeOrFetchFn, objectId, rootSpanId, getState) {
11767
11840
  if (typeof objectTypeOrFetchFn === "function") {
11768
- this.fetchFn = objectTypeOrFetchFn;
11841
+ this.fetchFn = (spanType) => objectTypeOrFetchFn(spanType);
11769
11842
  } else {
11770
11843
  const objectType = objectTypeOrFetchFn;
11771
- this.fetchFn = async (spanType) => {
11844
+ this.fetchFn = async (spanType, includeScorers) => {
11772
11845
  const state = await getState();
11773
11846
  const fetcher = new SpanFetcher(
11774
11847
  objectType,
11775
11848
  objectId,
11776
11849
  rootSpanId,
11777
11850
  state,
11778
- spanType
11851
+ spanType,
11852
+ includeScorers
11779
11853
  );
11780
11854
  const rows = await fetcher.fetchedData();
11781
- return rows.filter((row) => row.span_attributes?.purpose !== "scorer").map((row) => ({
11855
+ return rows.map((row) => ({
11782
11856
  input: row.input,
11783
11857
  output: row.output,
11858
+ expected: row.expected,
11859
+ error: row.error,
11860
+ scores: row.scores,
11861
+ metrics: row.metrics,
11784
11862
  metadata: row.metadata,
11785
11863
  span_id: row.span_id,
11786
11864
  span_parents: row.span_parents,
11865
+ is_root: row.is_root,
11787
11866
  span_attributes: row.span_attributes,
11788
11867
  id: row.id,
11789
11868
  _xact_id: row._xact_id,
11790
11869
  _pagination_key: row._pagination_key,
11791
- root_span_id: row.root_span_id
11870
+ root_span_id: row.root_span_id,
11871
+ created: row.created,
11872
+ tags: row.tags
11792
11873
  }));
11793
11874
  };
11794
11875
  }
11795
11876
  }
11796
- async getSpans({ spanType } = {}) {
11877
+ async getSpans({
11878
+ spanType,
11879
+ includeScorers = false
11880
+ } = {}) {
11881
+ if (includeScorers) {
11882
+ return this.fetchFn(spanType, true);
11883
+ }
11797
11884
  if (this.allFetched) {
11798
11885
  return this.getFromCache(spanType);
11799
11886
  }
@@ -11810,7 +11897,7 @@ var CachedSpanFetcher = class {
11810
11897
  return this.getFromCache(spanType);
11811
11898
  }
11812
11899
  async fetchSpans(spanType) {
11813
- const spans = await this.fetchFn(spanType);
11900
+ const spans = await this.fetchFn(spanType, false);
11814
11901
  for (const span of spans) {
11815
11902
  const type = span.span_attributes?.type ?? "";
11816
11903
  const existing = this.spanCache.get(type) ?? [];
@@ -11888,10 +11975,13 @@ var LocalTrace = class {
11888
11975
  * First checks the local span cache for recently logged spans, then falls
11889
11976
  * back to CachedSpanFetcher which handles BTQL fetching and caching.
11890
11977
  */
11891
- async getSpans({ spanType } = {}) {
11978
+ async getSpans({
11979
+ spanType,
11980
+ includeScorers = false
11981
+ } = {}) {
11892
11982
  const cachedSpans = this.state.spanCache.getByRootSpanId(this.rootSpanId);
11893
11983
  if (cachedSpans && cachedSpans.length > 0) {
11894
- let spans = cachedSpans.filter(
11984
+ let spans = includeScorers ? cachedSpans : cachedSpans.filter(
11895
11985
  (span) => span.span_attributes?.purpose !== "scorer"
11896
11986
  );
11897
11987
  if (spanType && spanType.length > 0) {
@@ -11902,13 +11992,19 @@ var LocalTrace = class {
11902
11992
  return spans.map((span) => ({
11903
11993
  input: span.input,
11904
11994
  output: span.output,
11995
+ expected: span.expected,
11996
+ error: span.error,
11997
+ scores: span.scores,
11998
+ metrics: span.metrics,
11905
11999
  metadata: span.metadata,
11906
12000
  span_id: span.span_id,
11907
12001
  span_parents: span.span_parents,
11908
- span_attributes: span.span_attributes
12002
+ is_root: span.is_root,
12003
+ span_attributes: span.span_attributes,
12004
+ tags: span.tags
11909
12005
  }));
11910
12006
  }
11911
- return this.cachedFetcher.getSpans({ spanType });
12007
+ return this.cachedFetcher.getSpans({ spanType, includeScorers });
11912
12008
  }
11913
12009
  /**
11914
12010
  * Get the thread (preprocessed messages) for this trace.
@@ -13353,6 +13449,7 @@ var fsSync = __toESM(require("node:fs"));
13353
13449
  var crypto = __toESM(require("node:crypto"));
13354
13450
  var import_node_util3 = require("node:util");
13355
13451
  var zlib = __toESM(require("node:zlib"));
13452
+ var dotenv = __toESM(require("dotenv"));
13356
13453
 
13357
13454
  // src/gitutil.ts
13358
13455
  var import_simple_git = require("simple-git");
@@ -29315,7 +29412,7 @@ var BraintrustPlugin = class extends BasePlugin {
29315
29412
  this.config = config3;
29316
29413
  }
29317
29414
  onEnable() {
29318
- const integrations = this.config.integrations || {};
29415
+ const integrations = this.config.integrations ?? {};
29319
29416
  if (integrations.openai !== false) {
29320
29417
  this.openaiPlugin = new OpenAIPlugin();
29321
29418
  this.openaiPlugin.enable();
@@ -29380,7 +29477,7 @@ var BraintrustPlugin = class extends BasePlugin {
29380
29477
  this.genkitPlugin = new GenkitPlugin();
29381
29478
  this.genkitPlugin.enable();
29382
29479
  }
29383
- if (getIntegrationConfig(integrations, "gitHubCopilot") !== false) {
29480
+ if (integrations.gitHubCopilot !== false) {
29384
29481
  this.gitHubCopilotPlugin = new GitHubCopilotPlugin();
29385
29482
  this.gitHubCopilotPlugin.enable();
29386
29483
  }
@@ -29493,6 +29590,7 @@ var envIntegrationAliases = {
29493
29590
  cursorsdk: "cursorSDK",
29494
29591
  flue: "flue",
29495
29592
  "flue-runtime": "flue",
29593
+ mastra: "mastra",
29496
29594
  "openai-agents": "openAIAgents",
29497
29595
  openaiagents: "openAIAgents",
29498
29596
  "openai-agents-core": "openAIAgents",
@@ -29535,6 +29633,7 @@ function getDefaultInstrumentationIntegrations() {
29535
29633
  cursor: true,
29536
29634
  cursorSDK: true,
29537
29635
  flue: true,
29636
+ mastra: true,
29538
29637
  openAIAgents: true,
29539
29638
  openrouter: true,
29540
29639
  openrouterAgent: true,
@@ -29559,6 +29658,9 @@ function readDisabledInstrumentationEnvConfig(disabledList) {
29559
29658
  }
29560
29659
  return { integrations };
29561
29660
  }
29661
+ function isInstrumentationIntegrationDisabled(integrations, ...names) {
29662
+ return names.some((name) => integrations?.[name] === false);
29663
+ }
29562
29664
 
29563
29665
  // src/instrumentation/registry.ts
29564
29666
  var REGISTRY_STATE_KEY = /* @__PURE__ */ Symbol.for("braintrust.registry");
@@ -29652,12 +29754,318 @@ var PluginRegistry = class {
29652
29754
  };
29653
29755
  var registry = new PluginRegistry();
29654
29756
 
29757
+ // src/auto-instrumentations/loader/mastra-observability-patch.ts
29758
+ var MASTRA_EXPORTER_FACTORY_GLOBAL = "__braintrustMastraExporterFactory";
29759
+ function installMastraExporterFactory(factory) {
29760
+ const globals = globalThis;
29761
+ globals[MASTRA_EXPORTER_FACTORY_GLOBAL] ??= factory;
29762
+ }
29763
+ var EXPORTER_FACTORY_KEY = JSON.stringify(MASTRA_EXPORTER_FACTORY_GLOBAL);
29764
+ var OBSERVABILITY_APPEND_BODY = `
29765
+ ;(function __braintrustWrapObservability() {
29766
+ // Top-level so we can both read and reassign the var binding the original
29767
+ // entry declared.
29768
+ if (typeof Observability === "undefined") return;
29769
+ if (Observability.__braintrustWrapped) return;
29770
+ function __braintrustEnsureExporter(rawConfig) {
29771
+ try {
29772
+ var factory = globalThis[${EXPORTER_FACTORY_KEY}];
29773
+ if (typeof factory !== "function") return rawConfig;
29774
+ var config = rawConfig && typeof rawConfig === "object" ? rawConfig : {};
29775
+ var configsIn = config.configs && typeof config.configs === "object" ? config.configs : null;
29776
+ var configsOut = {};
29777
+ var hadEntries = false;
29778
+ if (configsIn) {
29779
+ for (var name in configsIn) {
29780
+ if (!Object.prototype.hasOwnProperty.call(configsIn, name)) continue;
29781
+ hadEntries = true;
29782
+ var inst = configsIn[name] || {};
29783
+ var existing = Array.isArray(inst.exporters) ? inst.exporters : [];
29784
+ var hasOurs = existing.some(function (e) { return e && e.name === "braintrust"; });
29785
+ configsOut[name] = Object.assign({}, inst, {
29786
+ exporters: hasOurs ? existing : existing.concat([factory()]),
29787
+ });
29788
+ }
29789
+ }
29790
+ if (!hadEntries) {
29791
+ configsOut.default = {
29792
+ serviceName: "mastra",
29793
+ exporters: [factory()],
29794
+ };
29795
+ }
29796
+ return Object.assign({}, config, { configs: configsOut });
29797
+ } catch (e) {
29798
+ return rawConfig;
29799
+ }
29800
+ }
29801
+ var __OriginalObservability = Observability;
29802
+ Observability = new Proxy(__OriginalObservability, {
29803
+ construct: function (target, args, newTarget) {
29804
+ var nextArgs = args.slice();
29805
+ nextArgs[0] = __braintrustEnsureExporter(nextArgs[0]);
29806
+ return Reflect.construct(target, nextArgs, newTarget);
29807
+ },
29808
+ });
29809
+ Observability.__braintrustWrapped = true;
29810
+ if (typeof exports !== "undefined" && exports && typeof exports === "object") {
29811
+ try {
29812
+ Object.defineProperty(exports, "Observability", {
29813
+ enumerable: true,
29814
+ configurable: true,
29815
+ get: function () { return Observability; },
29816
+ });
29817
+ } catch (e) {}
29818
+ }
29819
+ })();
29820
+ `;
29821
+
29822
+ // src/wrappers/mastra.ts
29823
+ var MASTRA_BRAINTRUST_EXPORTER_NAME = "braintrust";
29824
+ var SPAN_TYPE_MAP = {
29825
+ agent_run: "task" /* TASK */,
29826
+ model_generation: "llm" /* LLM */,
29827
+ model_step: "llm" /* LLM */,
29828
+ model_chunk: "llm" /* LLM */,
29829
+ tool_call: "tool" /* TOOL */,
29830
+ mcp_tool_call: "tool" /* TOOL */,
29831
+ workflow_run: "task" /* TASK */,
29832
+ workflow_step: "function" /* FUNCTION */,
29833
+ workflow_conditional: "function" /* FUNCTION */,
29834
+ workflow_conditional_eval: "function" /* FUNCTION */,
29835
+ workflow_parallel: "function" /* FUNCTION */,
29836
+ workflow_loop: "function" /* FUNCTION */,
29837
+ workflow_sleep: "function" /* FUNCTION */,
29838
+ workflow_wait_event: "function" /* FUNCTION */,
29839
+ memory_operation: "function" /* FUNCTION */,
29840
+ workspace_action: "function" /* FUNCTION */,
29841
+ rag_ingestion: "task" /* TASK */,
29842
+ rag_embedding: "llm" /* LLM */,
29843
+ rag_vector_operation: "function" /* FUNCTION */,
29844
+ rag_action: "function" /* FUNCTION */,
29845
+ graph_action: "function" /* FUNCTION */,
29846
+ scorer_run: "score" /* SCORE */,
29847
+ scorer_step: "score" /* SCORE */,
29848
+ processor_run: "function" /* FUNCTION */,
29849
+ generic: "function" /* FUNCTION */
29850
+ };
29851
+ function spanTypeFor(mastraType) {
29852
+ return SPAN_TYPE_MAP[mastraType] ?? "function" /* FUNCTION */;
29853
+ }
29854
+ function epochSeconds(value) {
29855
+ if (value === void 0) return void 0;
29856
+ const ms = value instanceof Date ? value.getTime() : typeof value === "number" ? value : Date.parse(value);
29857
+ return Number.isFinite(ms) ? ms / 1e3 : void 0;
29858
+ }
29859
+ function modelMetrics(attributes) {
29860
+ if (!isObject(attributes)) return void 0;
29861
+ const usage = isObject(attributes.usage) ? attributes.usage : void 0;
29862
+ if (!usage) return void 0;
29863
+ const out = {};
29864
+ if (typeof usage.inputTokens === "number")
29865
+ out.prompt_tokens = usage.inputTokens;
29866
+ if (typeof usage.outputTokens === "number")
29867
+ out.completion_tokens = usage.outputTokens;
29868
+ if (typeof usage.inputTokens === "number" && typeof usage.outputTokens === "number") {
29869
+ out.tokens = usage.inputTokens + usage.outputTokens;
29870
+ }
29871
+ const inputDetails = isObject(usage.inputDetails) ? usage.inputDetails : void 0;
29872
+ const outputDetails = isObject(usage.outputDetails) ? usage.outputDetails : void 0;
29873
+ if (inputDetails && typeof inputDetails.cacheRead === "number") {
29874
+ out.prompt_cached_tokens = inputDetails.cacheRead;
29875
+ }
29876
+ if (inputDetails && typeof inputDetails.cacheWrite === "number") {
29877
+ out.prompt_cache_creation_tokens = inputDetails.cacheWrite;
29878
+ }
29879
+ if (outputDetails && typeof outputDetails.reasoning === "number") {
29880
+ out.completion_reasoning_tokens = outputDetails.reasoning;
29881
+ }
29882
+ return Object.keys(out).length > 0 ? out : void 0;
29883
+ }
29884
+ function buildMetadata(exported) {
29885
+ const out = {};
29886
+ if (exported.entityId !== void 0) out.entity_id = exported.entityId;
29887
+ if (exported.entityName !== void 0) out.entity_name = exported.entityName;
29888
+ if (exported.entityType !== void 0) out.entity_type = exported.entityType;
29889
+ if (exported.metadata && isObject(exported.metadata)) {
29890
+ Object.assign(out, exported.metadata);
29891
+ }
29892
+ if (exported.attributes && isObject(exported.attributes)) {
29893
+ for (const [key, value] of Object.entries(exported.attributes)) {
29894
+ if (key === "usage") continue;
29895
+ if (value !== void 0) out[key] = value;
29896
+ }
29897
+ }
29898
+ if (exported.tags && exported.tags.length > 0) {
29899
+ out.tags = exported.tags;
29900
+ }
29901
+ if (exported.requestContext && isObject(exported.requestContext)) {
29902
+ out.request_context = exported.requestContext;
29903
+ }
29904
+ return out;
29905
+ }
29906
+ var BraintrustObservabilityExporter = class {
29907
+ name = MASTRA_BRAINTRUST_EXPORTER_NAME;
29908
+ spans = /* @__PURE__ */ new Map();
29909
+ // Captured at the first SPAN_STARTED event. Mastra's observability bus may
29910
+ // dispatch later events outside the user's AsyncLocalStorage context, where
29911
+ // `currentSpan()` returns NOOP_SPAN — which would make our `startSpan()`
29912
+ // calls go to a no-op logger and silently drop. Anchoring on the parent
29913
+ // we observe while still in-context keeps the whole Mastra subtree under
29914
+ // the user's traced scenario.
29915
+ capturedParent;
29916
+ constructor() {
29917
+ _internalSetInitialState();
29918
+ }
29919
+ async exportTracingEvent(event) {
29920
+ const exported = event.exportedSpan;
29921
+ if (exported.isInternal === true) return;
29922
+ try {
29923
+ switch (event.type) {
29924
+ case "span_started":
29925
+ this.onStart(exported);
29926
+ break;
29927
+ case "span_updated":
29928
+ this.onUpdate(exported);
29929
+ break;
29930
+ case "span_ended":
29931
+ this.onEnd(exported);
29932
+ break;
29933
+ }
29934
+ } catch (err) {
29935
+ logExporterError(err);
29936
+ }
29937
+ }
29938
+ async flush() {
29939
+ const state = _internalGetGlobalState();
29940
+ if (state) {
29941
+ await state.bgLogger().flush();
29942
+ }
29943
+ }
29944
+ async shutdown() {
29945
+ await this.flush();
29946
+ this.spans.clear();
29947
+ }
29948
+ onStart(exported) {
29949
+ if (this.spans.has(exported.id)) return;
29950
+ const args = {
29951
+ name: exported.name,
29952
+ spanAttributes: { type: spanTypeFor(exported.type) },
29953
+ startTime: epochSeconds(exported.startTime)
29954
+ };
29955
+ const parentRecord = exported.parentSpanId ? this.spans.get(exported.parentSpanId) : void 0;
29956
+ if (!this.capturedParent) {
29957
+ const probe = currentSpan();
29958
+ if (probe && probe.spanId) {
29959
+ this.capturedParent = probe;
29960
+ }
29961
+ }
29962
+ const span = parentRecord ? parentRecord.span.startSpan(args) : this.capturedParent ? this.capturedParent.startSpan(args) : startSpan(args);
29963
+ const record = { span, hasLoggedInput: false };
29964
+ this.logPayload(record, exported);
29965
+ this.spans.set(exported.id, record);
29966
+ if (exported.isEvent === true) {
29967
+ span.end({ endTime: args.startTime });
29968
+ this.spans.delete(exported.id);
29969
+ }
29970
+ }
29971
+ onUpdate(exported) {
29972
+ const record = this.spans.get(exported.id);
29973
+ if (!record) return;
29974
+ this.logPayload(record, exported);
29975
+ }
29976
+ onEnd(exported) {
29977
+ const record = this.spans.get(exported.id);
29978
+ if (!record) return;
29979
+ this.logPayload(record, exported);
29980
+ if (exported.errorInfo) {
29981
+ record.span.log({
29982
+ error: exported.errorInfo.message || exported.errorInfo.name || "Unknown Mastra error"
29983
+ });
29984
+ }
29985
+ record.span.end({ endTime: epochSeconds(exported.endTime) });
29986
+ this.spans.delete(exported.id);
29987
+ }
29988
+ logPayload(record, exported) {
29989
+ const event = {};
29990
+ if (exported.input !== void 0) {
29991
+ event.input = exported.input;
29992
+ record.hasLoggedInput = true;
29993
+ }
29994
+ if (exported.output !== void 0) {
29995
+ event.output = exported.output;
29996
+ }
29997
+ const metadata = buildMetadata(exported);
29998
+ if (Object.keys(metadata).length > 0) {
29999
+ event.metadata = metadata;
30000
+ }
30001
+ const metrics = modelMetrics(exported.attributes);
30002
+ if (metrics) {
30003
+ event.metrics = metrics;
30004
+ }
30005
+ if (Object.keys(event).length > 0) {
30006
+ record.span.log(event);
30007
+ }
30008
+ }
30009
+ };
30010
+ function logExporterError(err) {
30011
+ debugLogger.warn("Mastra exporter failure:", err);
30012
+ }
30013
+
29655
30014
  // src/node/config.ts
30015
+ var BRAINTRUST_ENV_SEARCH_PARENT_LIMIT = 64;
29656
30016
  function configureNode() {
29657
30017
  isomorph_default.buildType = "node";
29658
30018
  isomorph_default.getRepoInfo = getRepoInfo;
29659
30019
  isomorph_default.getPastNAncestors = getPastNAncestors;
29660
- isomorph_default.getEnv = (name) => process.env[name];
30020
+ isomorph_default.getEnv = (name) => {
30021
+ const value = process.env[name];
30022
+ return name === "BRAINTRUST_API_KEY" && !value?.trim() ? void 0 : value;
30023
+ };
30024
+ isomorph_default.getBraintrustApiKey = async () => {
30025
+ const value = process.env.BRAINTRUST_API_KEY;
30026
+ if (value?.trim()) {
30027
+ return value;
30028
+ }
30029
+ const envPaths = [];
30030
+ for (let dir2 = process.cwd(), depth = 0; depth <= BRAINTRUST_ENV_SEARCH_PARENT_LIMIT; dir2 = path.dirname(dir2), depth++) {
30031
+ envPaths.push(path.join(dir2, ".env.braintrust"));
30032
+ if (path.dirname(dir2) === dir2) {
30033
+ break;
30034
+ }
30035
+ }
30036
+ const pending = /* @__PURE__ */ new Map();
30037
+ envPaths.forEach((envPath, index) => {
30038
+ pending.set(
30039
+ index,
30040
+ fs.readFile(envPath, "utf8").then(
30041
+ (contents) => ({ contents, envPath, index }),
30042
+ (error2) => ({ error: error2, envPath, index })
30043
+ )
30044
+ );
30045
+ });
30046
+ const results = [];
30047
+ let nearestUnresolvedIndex = 0;
30048
+ while (pending.size > 0) {
30049
+ const result = await Promise.race(pending.values());
30050
+ pending.delete(result.index);
30051
+ results[result.index] = result;
30052
+ while (results[nearestUnresolvedIndex]) {
30053
+ const nearestResult = results[nearestUnresolvedIndex];
30054
+ if ("contents" in nearestResult) {
30055
+ const parsed = dotenv.parse(nearestResult.contents);
30056
+ const apiKey = parsed.BRAINTRUST_API_KEY;
30057
+ return apiKey?.trim() ? apiKey : void 0;
30058
+ }
30059
+ const e = nearestResult.error;
30060
+ if (typeof e === "object" && e !== null && "code" in e && e.code === "ENOENT") {
30061
+ nearestUnresolvedIndex++;
30062
+ continue;
30063
+ }
30064
+ return void 0;
30065
+ }
30066
+ }
30067
+ return void 0;
30068
+ };
29661
30069
  isomorph_default.getCallerLocation = getCallerLocation;
29662
30070
  isomorph_default.newAsyncLocalStorage = () => new import_node_async_hooks.AsyncLocalStorage();
29663
30071
  isomorph_default.newTracingChannel = (nameOrChannels) => diagnostics_channel.tracingChannel(nameOrChannels);
@@ -29688,6 +30096,12 @@ function configureNode() {
29688
30096
  isomorph_default.gunzip = (0, import_node_util3.promisify)(zlib.gunzip);
29689
30097
  isomorph_default.hash = (data) => crypto.createHash("sha256").update(data).digest("hex");
29690
30098
  _internalSetInitialState();
30099
+ const disabled = readDisabledInstrumentationEnvConfig(
30100
+ isomorph_default.getEnv("BRAINTRUST_DISABLE_INSTRUMENTATION")
30101
+ ).integrations;
30102
+ if (!isInstrumentationIntegrationDisabled(disabled, "mastra")) {
30103
+ installMastraExporterFactory(() => new BraintrustObservabilityExporter());
30104
+ }
29691
30105
  registry.enable();
29692
30106
  }
29693
30107
 
@@ -29695,7 +30109,7 @@ function configureNode() {
29695
30109
  var import_env2 = require("@next/env");
29696
30110
 
29697
30111
  // src/cli/functions/upload.ts
29698
- var import_node_fs = __toESM(require("node:fs"));
30112
+ var import_node_fs2 = __toESM(require("node:fs"));
29699
30113
  var import_node_path3 = __toESM(require("node:path"));
29700
30114
  var import_node_zlib = require("node:zlib");
29701
30115
  var import_v312 = require("zod/v3");
@@ -29706,21 +30120,7 @@ var fs2 = __toESM(require("node:fs/promises"));
29706
30120
 
29707
30121
  // src/cli/jest/nodeModulesPaths.ts
29708
30122
  var path2 = __toESM(require("node:path"));
29709
-
29710
- // src/cli/jest/tryRealpath.ts
29711
- var import_graceful_fs = require("graceful-fs");
29712
- function tryRealpath(path8) {
29713
- try {
29714
- path8 = import_graceful_fs.realpathSync.native(path8);
29715
- } catch (error2) {
29716
- if (error2.code !== "ENOENT" && error2.code !== "EISDIR") {
29717
- throw error2;
29718
- }
29719
- }
29720
- return path8;
29721
- }
29722
-
29723
- // src/cli/jest/nodeModulesPaths.ts
30123
+ var import_node_fs = require("node:fs");
29724
30124
  function nodeModulesPaths(basedir, options) {
29725
30125
  const modules = options && options.moduleDirectory ? Array.from(options.moduleDirectory) : ["node_modules"];
29726
30126
  const basedirAbs = path2.resolve(basedir);
@@ -29732,7 +30132,7 @@ function nodeModulesPaths(basedir, options) {
29732
30132
  }
29733
30133
  let physicalBasedir;
29734
30134
  try {
29735
- physicalBasedir = tryRealpath(basedirAbs);
30135
+ physicalBasedir = import_node_fs.realpathSync.native(basedirAbs);
29736
30136
  } catch {
29737
30137
  physicalBasedir = basedirAbs;
29738
30138
  }
@@ -30709,7 +31109,7 @@ async function uploadBundles({
30709
31109
  if (!pathInfo) {
30710
31110
  return true;
30711
31111
  }
30712
- const bundleStream = import_node_fs.default.createReadStream(bundleFile).pipe((0, import_node_zlib.createGzip)());
31112
+ const bundleStream = import_node_fs2.default.createReadStream(bundleFile).pipe((0, import_node_zlib.createGzip)());
30713
31113
  const bundleData = await new Promise((resolve2, reject2) => {
30714
31114
  const chunks = [];
30715
31115
  bundleStream.on("data", (chunk) => {
@@ -30817,7 +31217,7 @@ async function buildBundledFunctionEntry({
30817
31217
 
30818
31218
  // src/cli/util/bundle.ts
30819
31219
  var import_env = require("@next/env");
30820
- var dotenv = __toESM(require("dotenv"));
31220
+ var dotenv2 = __toESM(require("dotenv"));
30821
31221
 
30822
31222
  // src/cli/util/debug-logging.ts
30823
31223
  var VERBOSE_DEPRECATION_MESSAGE = "--verbose is deprecated and will be removed in a future version of braintrust. Use --debug-logging debug to see full stack traces and troubleshooting details.";
@@ -30844,7 +31244,7 @@ async function loadCLIEnv(args) {
30844
31244
  normalizeDebugLoggingArgs(args);
30845
31245
  (0, import_env.loadEnvConfig)(process.cwd(), true);
30846
31246
  if (args.env_file) {
30847
- const loaded = dotenv.config({ path: args.env_file });
31247
+ const loaded = dotenv2.config({ path: args.env_file });
30848
31248
  if (loaded.error) {
30849
31249
  console.error(error(`Error loading ${args.env_file}: ${loaded.error}`));
30850
31250
  process.exit(1);
@@ -32222,7 +32622,7 @@ function checkMatch(pathInput, include_patterns, exclude_patterns) {
32222
32622
  async function collectFiles(inputPath, mode) {
32223
32623
  let pathStat = null;
32224
32624
  try {
32225
- pathStat = import_node_fs2.default.lstatSync(inputPath);
32625
+ pathStat = import_node_fs3.default.lstatSync(inputPath);
32226
32626
  } catch (e) {
32227
32627
  console.error(error(`Error reading ${inputPath}: ${e}`));
32228
32628
  process.exit(1);
@@ -32395,7 +32795,7 @@ async function run(args) {
32395
32795
  normalizeDebugLoggingArgs(args);
32396
32796
  (0, import_env2.loadEnvConfig)(process.cwd(), true);
32397
32797
  if (args.env_file) {
32398
- const loaded = dotenv2.config({ path: args.env_file });
32798
+ const loaded = dotenv3.config({ path: args.env_file });
32399
32799
  if (loaded.error) {
32400
32800
  console.error(error(`Error loading ${args.env_file}: ${loaded.error}`));
32401
32801
  process.exit(1);
@@ -32473,7 +32873,7 @@ async function run(args) {
32473
32873
  }
32474
32874
  function addAuthArgs(parser) {
32475
32875
  parser.add_argument("--api-key", {
32476
- help: "Specify a braintrust api key. If the parameter is not specified, the BRAINTRUST_API_KEY environment variable will be used."
32876
+ help: "Specify a braintrust api key. If the parameter is not specified, BRAINTRUST_API_KEY or the nearest .env.braintrust file will be used."
32477
32877
  });
32478
32878
  parser.add_argument("--org-name", {
32479
32879
  help: "The name of a specific organization to connect to. This is useful if you belong to multiple."