braintrust 3.13.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 (50) hide show
  1. package/dev/dist/index.d.mts +6 -8
  2. package/dev/dist/index.d.ts +6 -8
  3. package/dev/dist/index.js +809 -466
  4. package/dev/dist/index.mjs +367 -24
  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 +225 -1
  8. package/dist/auto-instrumentations/bundler/esbuild.mjs +2 -1
  9. package/dist/auto-instrumentations/bundler/next.cjs +225 -1
  10. package/dist/auto-instrumentations/bundler/next.mjs +3 -2
  11. package/dist/auto-instrumentations/bundler/rollup.cjs +225 -1
  12. package/dist/auto-instrumentations/bundler/rollup.mjs +2 -1
  13. package/dist/auto-instrumentations/bundler/vite.cjs +225 -1
  14. package/dist/auto-instrumentations/bundler/vite.mjs +2 -1
  15. package/dist/auto-instrumentations/bundler/webpack-loader.cjs +8 -0
  16. package/dist/auto-instrumentations/bundler/webpack.cjs +225 -1
  17. package/dist/auto-instrumentations/bundler/webpack.mjs +3 -2
  18. package/dist/auto-instrumentations/chunk-J57YF7WS.mjs +208 -0
  19. package/dist/auto-instrumentations/{chunk-WFEUJACP.mjs → chunk-OTUQ7KH5.mjs} +1 -1
  20. package/dist/auto-instrumentations/chunk-QFMACSOL.mjs +280 -0
  21. package/dist/auto-instrumentations/{chunk-GJOO4ESL.mjs → chunk-XKAAVWT6.mjs} +23 -1
  22. package/dist/auto-instrumentations/hook.mjs +7980 -7
  23. package/dist/auto-instrumentations/loader/cjs-patch.cjs +194 -4
  24. package/dist/auto-instrumentations/loader/cjs-patch.mjs +13 -27
  25. package/dist/auto-instrumentations/loader/esm-hook.mjs +24 -10
  26. package/dist/browser.d.mts +127 -11
  27. package/dist/browser.d.ts +127 -11
  28. package/dist/browser.js +293 -24
  29. package/dist/browser.mjs +293 -24
  30. package/dist/{chunk-26JGOELH.js → chunk-NKD77KGB.js} +179 -1
  31. package/dist/{chunk-75IQCUB2.mjs → chunk-NU2GSPHX.mjs} +179 -1
  32. package/dist/cli.js +374 -51
  33. package/dist/edge-light.d.mts +1 -1
  34. package/dist/edge-light.d.ts +1 -1
  35. package/dist/edge-light.js +293 -24
  36. package/dist/edge-light.mjs +293 -24
  37. package/dist/index.d.mts +127 -11
  38. package/dist/index.d.ts +127 -11
  39. package/dist/index.js +1113 -838
  40. package/dist/index.mjs +305 -30
  41. package/dist/instrumentation/index.d.mts +7 -8
  42. package/dist/instrumentation/index.d.ts +7 -8
  43. package/dist/instrumentation/index.js +101 -24
  44. package/dist/instrumentation/index.mjs +101 -24
  45. package/dist/workerd.d.mts +1 -1
  46. package/dist/workerd.d.ts +1 -1
  47. package/dist/workerd.js +293 -24
  48. package/dist/workerd.mjs +293 -24
  49. package/package.json +1 -7
  50. package/dist/auto-instrumentations/chunk-MWZXZQUO.mjs +0 -81
@@ -63,6 +63,7 @@ var envIntegrationAliases = {
63
63
  cursorsdk: "cursorSDK",
64
64
  flue: "flue",
65
65
  "flue-runtime": "flue",
66
+ mastra: "mastra",
66
67
  "openai-agents": "openAIAgents",
67
68
  openaiagents: "openAIAgents",
68
69
  "openai-agents-core": "openAIAgents",
@@ -2990,6 +2991,13 @@ var defaultInstrumentationConfigGroups = [
2990
2991
  integrations: ["gitHubCopilot"],
2991
2992
  configs: gitHubCopilotConfigs
2992
2993
  }
2994
+ // Note: `@mastra/core` is not listed here because its instrumentation
2995
+ // doesn't go through the AST `code-transformer` matcher — Mastra's
2996
+ // content-hashed chunks make `filePath`-based matching too brittle.
2997
+ // Instead it's handled by the source-replacement entry in
2998
+ // `loader/special-case-patches.ts`, which both the runtime loader
2999
+ // (`hook.mjs` → `cjs-patch.ts`/`esm-hook.mts`) and the bundler plugin
3000
+ // (`bundler/plugin.ts`) call. The `mastra` env-var disable still works.
2993
3001
  ];
2994
3002
  function getDefaultInstrumentationConfigs({
2995
3003
  additionalInstrumentations,
@@ -3007,6 +3015,211 @@ function getDefaultInstrumentationConfigs({
3007
3015
  ];
3008
3016
  }
3009
3017
 
3018
+ // src/auto-instrumentations/loader/mastra-observability-patch.ts
3019
+ var MASTRA_EXPORTER_FACTORY_GLOBAL = "__braintrustMastraExporterFactory";
3020
+ var MASTRA_CORE_PACKAGE = "@mastra/core";
3021
+ var MASTRA_OBSERVABILITY_PACKAGE = "@mastra/observability";
3022
+ var MASTRA_CORE_ENTRY_PATHS = /* @__PURE__ */ new Set([
3023
+ "dist/index.js",
3024
+ "dist/index.cjs",
3025
+ "dist/mastra/index.js",
3026
+ "dist/mastra/index.cjs"
3027
+ ]);
3028
+ var MASTRA_OBSERVABILITY_ENTRY_PATHS = /* @__PURE__ */ new Set([
3029
+ "dist/index.js",
3030
+ "dist/index.cjs"
3031
+ ]);
3032
+ function classifyMastraTarget(packageName, modulePath) {
3033
+ if (packageName === MASTRA_CORE_PACKAGE && MASTRA_CORE_ENTRY_PATHS.has(modulePath)) {
3034
+ return "core";
3035
+ }
3036
+ if (packageName === MASTRA_OBSERVABILITY_PACKAGE && MASTRA_OBSERVABILITY_ENTRY_PATHS.has(modulePath)) {
3037
+ return "observability";
3038
+ }
3039
+ return null;
3040
+ }
3041
+ function extractChunkPath(source) {
3042
+ const esmMatch = source.match(
3043
+ /export\s*\{\s*Mastra(?:\s+as\s+\w+)?\s*\}\s*from\s*['"]([^'"]+)['"]/
3044
+ );
3045
+ if (esmMatch) return esmMatch[1];
3046
+ const cjsMatch = source.match(
3047
+ /require\s*\(\s*['"]([^'"]+chunk-[^'"]+)['"]\s*\)/
3048
+ );
3049
+ if (cjsMatch) return cjsMatch[1];
3050
+ return null;
3051
+ }
3052
+ var EXPORTER_FACTORY_KEY = JSON.stringify(MASTRA_EXPORTER_FACTORY_GLOBAL);
3053
+ var MASTRA_PROXY_HANDLER_BODY = `
3054
+ {
3055
+ construct(target, args, newTarget) {
3056
+ var firstArg = args[0];
3057
+ if (
3058
+ (!firstArg || typeof firstArg !== "object" || !firstArg.observability) &&
3059
+ __braintrustObservabilityClass
3060
+ ) {
3061
+ try {
3062
+ // serviceName is required by Mastra's Observability validator; pass
3063
+ // something sensible by default. Users who want a different name
3064
+ // should construct Observability themselves.
3065
+ var observability = new __braintrustObservabilityClass({
3066
+ configs: { default: { serviceName: "mastra" } },
3067
+ });
3068
+ args = args.slice();
3069
+ args[0] = Object.assign({}, firstArg, { observability: observability });
3070
+ } catch (e) {
3071
+ // Fall through. Mastra will use its own NoOp; user code still works,
3072
+ // just without auto-instrumentation.
3073
+ }
3074
+ }
3075
+ return Reflect.construct(target, args, newTarget);
3076
+ },
3077
+ }`;
3078
+ function buildMastraEsmWrapper(chunkPath) {
3079
+ const chunk = JSON.stringify(chunkPath);
3080
+ return `import { Mastra as __braintrustOrigMastra } from ${chunk};
3081
+ import { createRequire as __braintrustCreateRequire } from "node:module";
3082
+
3083
+ let __braintrustObservabilityClass = null;
3084
+ try {
3085
+ // Resolve @mastra/observability relative to this module (the Mastra entry),
3086
+ // so it's looked up from the user's node_modules tree.
3087
+ const __braintrustRequire = __braintrustCreateRequire(import.meta.url);
3088
+ __braintrustObservabilityClass =
3089
+ __braintrustRequire("@mastra/observability").Observability;
3090
+ } catch (e) {
3091
+ // @mastra/observability isn't installed; the construct trap will skip the
3092
+ // auto-construct branch and Mastra falls back to its own NoOp.
3093
+ }
3094
+ const Mastra = new Proxy(__braintrustOrigMastra, ${MASTRA_PROXY_HANDLER_BODY});
3095
+ export { Mastra };
3096
+ `;
3097
+ }
3098
+ function buildMastraCjsWrapper(chunkPath) {
3099
+ const chunk = JSON.stringify(chunkPath);
3100
+ return `'use strict';
3101
+ const __braintrustChunk = require(${chunk});
3102
+
3103
+ let __braintrustObservabilityClass = null;
3104
+ try {
3105
+ __braintrustObservabilityClass = require("@mastra/observability").Observability;
3106
+ } catch (e) {
3107
+ // @mastra/observability isn't installed; same fallback as the ESM wrapper.
3108
+ }
3109
+
3110
+ const __braintrustWrappedMastra = new Proxy(
3111
+ __braintrustChunk.Mastra,
3112
+ ${MASTRA_PROXY_HANDLER_BODY},
3113
+ );
3114
+ Object.defineProperty(exports, "Mastra", {
3115
+ enumerable: true,
3116
+ configurable: true,
3117
+ get: function () { return __braintrustWrappedMastra; }
3118
+ });
3119
+ `;
3120
+ }
3121
+ var OBSERVABILITY_APPEND_BODY = `
3122
+ ;(function __braintrustWrapObservability() {
3123
+ // Top-level so we can both read and reassign the var binding the original
3124
+ // entry declared.
3125
+ if (typeof Observability === "undefined") return;
3126
+ if (Observability.__braintrustWrapped) return;
3127
+ function __braintrustEnsureExporter(rawConfig) {
3128
+ try {
3129
+ var factory = globalThis[${EXPORTER_FACTORY_KEY}];
3130
+ if (typeof factory !== "function") return rawConfig;
3131
+ var config = rawConfig && typeof rawConfig === "object" ? rawConfig : {};
3132
+ var configsIn = config.configs && typeof config.configs === "object" ? config.configs : null;
3133
+ var configsOut = {};
3134
+ var hadEntries = false;
3135
+ if (configsIn) {
3136
+ for (var name in configsIn) {
3137
+ if (!Object.prototype.hasOwnProperty.call(configsIn, name)) continue;
3138
+ hadEntries = true;
3139
+ var inst = configsIn[name] || {};
3140
+ var existing = Array.isArray(inst.exporters) ? inst.exporters : [];
3141
+ var hasOurs = existing.some(function (e) { return e && e.name === "braintrust"; });
3142
+ configsOut[name] = Object.assign({}, inst, {
3143
+ exporters: hasOurs ? existing : existing.concat([factory()]),
3144
+ });
3145
+ }
3146
+ }
3147
+ if (!hadEntries) {
3148
+ configsOut.default = {
3149
+ serviceName: "mastra",
3150
+ exporters: [factory()],
3151
+ };
3152
+ }
3153
+ return Object.assign({}, config, { configs: configsOut });
3154
+ } catch (e) {
3155
+ return rawConfig;
3156
+ }
3157
+ }
3158
+ var __OriginalObservability = Observability;
3159
+ Observability = new Proxy(__OriginalObservability, {
3160
+ construct: function (target, args, newTarget) {
3161
+ var nextArgs = args.slice();
3162
+ nextArgs[0] = __braintrustEnsureExporter(nextArgs[0]);
3163
+ return Reflect.construct(target, nextArgs, newTarget);
3164
+ },
3165
+ });
3166
+ Observability.__braintrustWrapped = true;
3167
+ if (typeof exports !== "undefined" && exports && typeof exports === "object") {
3168
+ try {
3169
+ Object.defineProperty(exports, "Observability", {
3170
+ enumerable: true,
3171
+ configurable: true,
3172
+ get: function () { return Observability; },
3173
+ });
3174
+ } catch (e) {}
3175
+ }
3176
+ })();
3177
+ `;
3178
+ function patchMastraSource(source, target, format) {
3179
+ if (target === "core") {
3180
+ const chunkPath = extractChunkPath(source);
3181
+ if (!chunkPath) return source;
3182
+ return format === "esm" ? buildMastraEsmWrapper(chunkPath) : buildMastraCjsWrapper(chunkPath);
3183
+ }
3184
+ return source + OBSERVABILITY_APPEND_BODY;
3185
+ }
3186
+
3187
+ // src/auto-instrumentations/loader/openai-api-promise-patch.ts
3188
+ var OPENAI_API_PROMISE_PATCH = `
3189
+ ;(function __btPatchAPIPromise() {
3190
+ if (typeof APIPromise === "undefined" || APIPromise.prototype.__btParsePatched) return;
3191
+ APIPromise.prototype.__btParsePatched = true;
3192
+ var _origThen = APIPromise.prototype.then;
3193
+ APIPromise.prototype.then = function __btThen(onfulfilled, onrejected) {
3194
+ if (!this.__btParseWrapped && Object.prototype.hasOwnProperty.call(this, "parseResponse")) {
3195
+ this.__btParseWrapped = true;
3196
+ var _origParse = this.parseResponse;
3197
+ var _cached;
3198
+ this.parseResponse = function() {
3199
+ if (!_cached) _cached = _origParse.apply(this, arguments);
3200
+ return _cached;
3201
+ };
3202
+ }
3203
+ return _origThen.call(this, onfulfilled, onrejected);
3204
+ };
3205
+ })();
3206
+ `;
3207
+
3208
+ // src/auto-instrumentations/loader/special-case-patches.ts
3209
+ function applySpecialCasePatch(input) {
3210
+ if (input.packageName === "openai" && input.modulePath.includes("api-promise")) {
3211
+ return input.source + OPENAI_API_PROMISE_PATCH;
3212
+ }
3213
+ const mastraTarget = classifyMastraTarget(
3214
+ input.packageName,
3215
+ input.modulePath
3216
+ );
3217
+ if (mastraTarget) {
3218
+ return patchMastraSource(input.source, mastraTarget, input.format);
3219
+ }
3220
+ return null;
3221
+ }
3222
+
3010
3223
  // src/auto-instrumentations/bundler/plugin.ts
3011
3224
  function getModuleVersion(basedir) {
3012
3225
  try {
@@ -3045,6 +3258,18 @@ var unplugin = (0, import_unplugin.createUnplugin)(
3045
3258
  return null;
3046
3259
  }
3047
3260
  const moduleName = moduleDetails.name;
3261
+ const normalizedModulePath = moduleDetails.path.replace(/\\/g, "/");
3262
+ if (options.browser !== true) {
3263
+ const patched = applySpecialCasePatch({
3264
+ packageName: moduleName,
3265
+ modulePath: normalizedModulePath,
3266
+ source: code,
3267
+ format: isModule ? "esm" : "cjs"
3268
+ });
3269
+ if (patched !== null) {
3270
+ return { code: patched, map: null };
3271
+ }
3272
+ }
3048
3273
  const moduleVersion = getModuleVersion(moduleDetails.basedir);
3049
3274
  if (!moduleVersion) {
3050
3275
  console.warn(
@@ -3052,7 +3277,6 @@ var unplugin = (0, import_unplugin.createUnplugin)(
3052
3277
  );
3053
3278
  return null;
3054
3279
  }
3055
- const normalizedModulePath = moduleDetails.path.replace(/\\/g, "/");
3056
3280
  const transformer = instrumentationMatcher.getTransformer(
3057
3281
  moduleName,
3058
3282
  moduleVersion,
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  unplugin
3
- } from "../chunk-GJOO4ESL.mjs";
3
+ } from "../chunk-XKAAVWT6.mjs";
4
4
  import "../chunk-E5DUYJWK.mjs";
5
+ import "../chunk-J57YF7WS.mjs";
5
6
 
6
7
  // src/auto-instrumentations/bundler/rollup.ts
7
8
  function braintrustRollupPlugin(options = {}) {
@@ -63,6 +63,7 @@ var envIntegrationAliases = {
63
63
  cursorsdk: "cursorSDK",
64
64
  flue: "flue",
65
65
  "flue-runtime": "flue",
66
+ mastra: "mastra",
66
67
  "openai-agents": "openAIAgents",
67
68
  openaiagents: "openAIAgents",
68
69
  "openai-agents-core": "openAIAgents",
@@ -2990,6 +2991,13 @@ var defaultInstrumentationConfigGroups = [
2990
2991
  integrations: ["gitHubCopilot"],
2991
2992
  configs: gitHubCopilotConfigs
2992
2993
  }
2994
+ // Note: `@mastra/core` is not listed here because its instrumentation
2995
+ // doesn't go through the AST `code-transformer` matcher — Mastra's
2996
+ // content-hashed chunks make `filePath`-based matching too brittle.
2997
+ // Instead it's handled by the source-replacement entry in
2998
+ // `loader/special-case-patches.ts`, which both the runtime loader
2999
+ // (`hook.mjs` → `cjs-patch.ts`/`esm-hook.mts`) and the bundler plugin
3000
+ // (`bundler/plugin.ts`) call. The `mastra` env-var disable still works.
2993
3001
  ];
2994
3002
  function getDefaultInstrumentationConfigs({
2995
3003
  additionalInstrumentations,
@@ -3007,6 +3015,211 @@ function getDefaultInstrumentationConfigs({
3007
3015
  ];
3008
3016
  }
3009
3017
 
3018
+ // src/auto-instrumentations/loader/mastra-observability-patch.ts
3019
+ var MASTRA_EXPORTER_FACTORY_GLOBAL = "__braintrustMastraExporterFactory";
3020
+ var MASTRA_CORE_PACKAGE = "@mastra/core";
3021
+ var MASTRA_OBSERVABILITY_PACKAGE = "@mastra/observability";
3022
+ var MASTRA_CORE_ENTRY_PATHS = /* @__PURE__ */ new Set([
3023
+ "dist/index.js",
3024
+ "dist/index.cjs",
3025
+ "dist/mastra/index.js",
3026
+ "dist/mastra/index.cjs"
3027
+ ]);
3028
+ var MASTRA_OBSERVABILITY_ENTRY_PATHS = /* @__PURE__ */ new Set([
3029
+ "dist/index.js",
3030
+ "dist/index.cjs"
3031
+ ]);
3032
+ function classifyMastraTarget(packageName, modulePath) {
3033
+ if (packageName === MASTRA_CORE_PACKAGE && MASTRA_CORE_ENTRY_PATHS.has(modulePath)) {
3034
+ return "core";
3035
+ }
3036
+ if (packageName === MASTRA_OBSERVABILITY_PACKAGE && MASTRA_OBSERVABILITY_ENTRY_PATHS.has(modulePath)) {
3037
+ return "observability";
3038
+ }
3039
+ return null;
3040
+ }
3041
+ function extractChunkPath(source) {
3042
+ const esmMatch = source.match(
3043
+ /export\s*\{\s*Mastra(?:\s+as\s+\w+)?\s*\}\s*from\s*['"]([^'"]+)['"]/
3044
+ );
3045
+ if (esmMatch) return esmMatch[1];
3046
+ const cjsMatch = source.match(
3047
+ /require\s*\(\s*['"]([^'"]+chunk-[^'"]+)['"]\s*\)/
3048
+ );
3049
+ if (cjsMatch) return cjsMatch[1];
3050
+ return null;
3051
+ }
3052
+ var EXPORTER_FACTORY_KEY = JSON.stringify(MASTRA_EXPORTER_FACTORY_GLOBAL);
3053
+ var MASTRA_PROXY_HANDLER_BODY = `
3054
+ {
3055
+ construct(target, args, newTarget) {
3056
+ var firstArg = args[0];
3057
+ if (
3058
+ (!firstArg || typeof firstArg !== "object" || !firstArg.observability) &&
3059
+ __braintrustObservabilityClass
3060
+ ) {
3061
+ try {
3062
+ // serviceName is required by Mastra's Observability validator; pass
3063
+ // something sensible by default. Users who want a different name
3064
+ // should construct Observability themselves.
3065
+ var observability = new __braintrustObservabilityClass({
3066
+ configs: { default: { serviceName: "mastra" } },
3067
+ });
3068
+ args = args.slice();
3069
+ args[0] = Object.assign({}, firstArg, { observability: observability });
3070
+ } catch (e) {
3071
+ // Fall through. Mastra will use its own NoOp; user code still works,
3072
+ // just without auto-instrumentation.
3073
+ }
3074
+ }
3075
+ return Reflect.construct(target, args, newTarget);
3076
+ },
3077
+ }`;
3078
+ function buildMastraEsmWrapper(chunkPath) {
3079
+ const chunk = JSON.stringify(chunkPath);
3080
+ return `import { Mastra as __braintrustOrigMastra } from ${chunk};
3081
+ import { createRequire as __braintrustCreateRequire } from "node:module";
3082
+
3083
+ let __braintrustObservabilityClass = null;
3084
+ try {
3085
+ // Resolve @mastra/observability relative to this module (the Mastra entry),
3086
+ // so it's looked up from the user's node_modules tree.
3087
+ const __braintrustRequire = __braintrustCreateRequire(import.meta.url);
3088
+ __braintrustObservabilityClass =
3089
+ __braintrustRequire("@mastra/observability").Observability;
3090
+ } catch (e) {
3091
+ // @mastra/observability isn't installed; the construct trap will skip the
3092
+ // auto-construct branch and Mastra falls back to its own NoOp.
3093
+ }
3094
+ const Mastra = new Proxy(__braintrustOrigMastra, ${MASTRA_PROXY_HANDLER_BODY});
3095
+ export { Mastra };
3096
+ `;
3097
+ }
3098
+ function buildMastraCjsWrapper(chunkPath) {
3099
+ const chunk = JSON.stringify(chunkPath);
3100
+ return `'use strict';
3101
+ const __braintrustChunk = require(${chunk});
3102
+
3103
+ let __braintrustObservabilityClass = null;
3104
+ try {
3105
+ __braintrustObservabilityClass = require("@mastra/observability").Observability;
3106
+ } catch (e) {
3107
+ // @mastra/observability isn't installed; same fallback as the ESM wrapper.
3108
+ }
3109
+
3110
+ const __braintrustWrappedMastra = new Proxy(
3111
+ __braintrustChunk.Mastra,
3112
+ ${MASTRA_PROXY_HANDLER_BODY},
3113
+ );
3114
+ Object.defineProperty(exports, "Mastra", {
3115
+ enumerable: true,
3116
+ configurable: true,
3117
+ get: function () { return __braintrustWrappedMastra; }
3118
+ });
3119
+ `;
3120
+ }
3121
+ var OBSERVABILITY_APPEND_BODY = `
3122
+ ;(function __braintrustWrapObservability() {
3123
+ // Top-level so we can both read and reassign the var binding the original
3124
+ // entry declared.
3125
+ if (typeof Observability === "undefined") return;
3126
+ if (Observability.__braintrustWrapped) return;
3127
+ function __braintrustEnsureExporter(rawConfig) {
3128
+ try {
3129
+ var factory = globalThis[${EXPORTER_FACTORY_KEY}];
3130
+ if (typeof factory !== "function") return rawConfig;
3131
+ var config = rawConfig && typeof rawConfig === "object" ? rawConfig : {};
3132
+ var configsIn = config.configs && typeof config.configs === "object" ? config.configs : null;
3133
+ var configsOut = {};
3134
+ var hadEntries = false;
3135
+ if (configsIn) {
3136
+ for (var name in configsIn) {
3137
+ if (!Object.prototype.hasOwnProperty.call(configsIn, name)) continue;
3138
+ hadEntries = true;
3139
+ var inst = configsIn[name] || {};
3140
+ var existing = Array.isArray(inst.exporters) ? inst.exporters : [];
3141
+ var hasOurs = existing.some(function (e) { return e && e.name === "braintrust"; });
3142
+ configsOut[name] = Object.assign({}, inst, {
3143
+ exporters: hasOurs ? existing : existing.concat([factory()]),
3144
+ });
3145
+ }
3146
+ }
3147
+ if (!hadEntries) {
3148
+ configsOut.default = {
3149
+ serviceName: "mastra",
3150
+ exporters: [factory()],
3151
+ };
3152
+ }
3153
+ return Object.assign({}, config, { configs: configsOut });
3154
+ } catch (e) {
3155
+ return rawConfig;
3156
+ }
3157
+ }
3158
+ var __OriginalObservability = Observability;
3159
+ Observability = new Proxy(__OriginalObservability, {
3160
+ construct: function (target, args, newTarget) {
3161
+ var nextArgs = args.slice();
3162
+ nextArgs[0] = __braintrustEnsureExporter(nextArgs[0]);
3163
+ return Reflect.construct(target, nextArgs, newTarget);
3164
+ },
3165
+ });
3166
+ Observability.__braintrustWrapped = true;
3167
+ if (typeof exports !== "undefined" && exports && typeof exports === "object") {
3168
+ try {
3169
+ Object.defineProperty(exports, "Observability", {
3170
+ enumerable: true,
3171
+ configurable: true,
3172
+ get: function () { return Observability; },
3173
+ });
3174
+ } catch (e) {}
3175
+ }
3176
+ })();
3177
+ `;
3178
+ function patchMastraSource(source, target, format) {
3179
+ if (target === "core") {
3180
+ const chunkPath = extractChunkPath(source);
3181
+ if (!chunkPath) return source;
3182
+ return format === "esm" ? buildMastraEsmWrapper(chunkPath) : buildMastraCjsWrapper(chunkPath);
3183
+ }
3184
+ return source + OBSERVABILITY_APPEND_BODY;
3185
+ }
3186
+
3187
+ // src/auto-instrumentations/loader/openai-api-promise-patch.ts
3188
+ var OPENAI_API_PROMISE_PATCH = `
3189
+ ;(function __btPatchAPIPromise() {
3190
+ if (typeof APIPromise === "undefined" || APIPromise.prototype.__btParsePatched) return;
3191
+ APIPromise.prototype.__btParsePatched = true;
3192
+ var _origThen = APIPromise.prototype.then;
3193
+ APIPromise.prototype.then = function __btThen(onfulfilled, onrejected) {
3194
+ if (!this.__btParseWrapped && Object.prototype.hasOwnProperty.call(this, "parseResponse")) {
3195
+ this.__btParseWrapped = true;
3196
+ var _origParse = this.parseResponse;
3197
+ var _cached;
3198
+ this.parseResponse = function() {
3199
+ if (!_cached) _cached = _origParse.apply(this, arguments);
3200
+ return _cached;
3201
+ };
3202
+ }
3203
+ return _origThen.call(this, onfulfilled, onrejected);
3204
+ };
3205
+ })();
3206
+ `;
3207
+
3208
+ // src/auto-instrumentations/loader/special-case-patches.ts
3209
+ function applySpecialCasePatch(input) {
3210
+ if (input.packageName === "openai" && input.modulePath.includes("api-promise")) {
3211
+ return input.source + OPENAI_API_PROMISE_PATCH;
3212
+ }
3213
+ const mastraTarget = classifyMastraTarget(
3214
+ input.packageName,
3215
+ input.modulePath
3216
+ );
3217
+ if (mastraTarget) {
3218
+ return patchMastraSource(input.source, mastraTarget, input.format);
3219
+ }
3220
+ return null;
3221
+ }
3222
+
3010
3223
  // src/auto-instrumentations/bundler/plugin.ts
3011
3224
  function getModuleVersion(basedir) {
3012
3225
  try {
@@ -3045,6 +3258,18 @@ var unplugin = (0, import_unplugin.createUnplugin)(
3045
3258
  return null;
3046
3259
  }
3047
3260
  const moduleName = moduleDetails.name;
3261
+ const normalizedModulePath = moduleDetails.path.replace(/\\/g, "/");
3262
+ if (options.browser !== true) {
3263
+ const patched = applySpecialCasePatch({
3264
+ packageName: moduleName,
3265
+ modulePath: normalizedModulePath,
3266
+ source: code,
3267
+ format: isModule ? "esm" : "cjs"
3268
+ });
3269
+ if (patched !== null) {
3270
+ return { code: patched, map: null };
3271
+ }
3272
+ }
3048
3273
  const moduleVersion = getModuleVersion(moduleDetails.basedir);
3049
3274
  if (!moduleVersion) {
3050
3275
  console.warn(
@@ -3052,7 +3277,6 @@ var unplugin = (0, import_unplugin.createUnplugin)(
3052
3277
  );
3053
3278
  return null;
3054
3279
  }
3055
- const normalizedModulePath = moduleDetails.path.replace(/\\/g, "/");
3056
3280
  const transformer = instrumentationMatcher.getTransformer(
3057
3281
  moduleName,
3058
3282
  moduleVersion,
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  unplugin
3
- } from "../chunk-GJOO4ESL.mjs";
3
+ } from "../chunk-XKAAVWT6.mjs";
4
4
  import "../chunk-E5DUYJWK.mjs";
5
+ import "../chunk-J57YF7WS.mjs";
5
6
 
6
7
  // src/auto-instrumentations/bundler/vite.ts
7
8
  function braintrustVitePlugin(options = {}) {
@@ -48,6 +48,7 @@ var envIntegrationAliases = {
48
48
  cursorsdk: "cursorSDK",
49
49
  flue: "flue",
50
50
  "flue-runtime": "flue",
51
+ mastra: "mastra",
51
52
  "openai-agents": "openAIAgents",
52
53
  openaiagents: "openAIAgents",
53
54
  "openai-agents-core": "openAIAgents",
@@ -2975,6 +2976,13 @@ var defaultInstrumentationConfigGroups = [
2975
2976
  integrations: ["gitHubCopilot"],
2976
2977
  configs: gitHubCopilotConfigs
2977
2978
  }
2979
+ // Note: `@mastra/core` is not listed here because its instrumentation
2980
+ // doesn't go through the AST `code-transformer` matcher — Mastra's
2981
+ // content-hashed chunks make `filePath`-based matching too brittle.
2982
+ // Instead it's handled by the source-replacement entry in
2983
+ // `loader/special-case-patches.ts`, which both the runtime loader
2984
+ // (`hook.mjs` → `cjs-patch.ts`/`esm-hook.mts`) and the bundler plugin
2985
+ // (`bundler/plugin.ts`) call. The `mastra` env-var disable still works.
2978
2986
  ];
2979
2987
  function getDefaultInstrumentationConfigs({
2980
2988
  additionalInstrumentations,