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.
- package/dev/dist/index.d.mts +31 -14
- package/dev/dist/index.d.ts +31 -14
- package/dev/dist/index.js +919 -485
- package/dev/dist/index.mjs +480 -46
- package/dist/apply-auto-instrumentation.js +204 -174
- package/dist/apply-auto-instrumentation.mjs +35 -5
- package/dist/auto-instrumentations/bundler/esbuild.cjs +226 -1
- package/dist/auto-instrumentations/bundler/esbuild.mjs +3 -2
- package/dist/auto-instrumentations/bundler/next.cjs +226 -1
- package/dist/auto-instrumentations/bundler/next.mjs +4 -3
- package/dist/auto-instrumentations/bundler/rollup.cjs +226 -1
- package/dist/auto-instrumentations/bundler/rollup.mjs +3 -2
- package/dist/auto-instrumentations/bundler/vite.cjs +226 -1
- package/dist/auto-instrumentations/bundler/vite.mjs +3 -2
- package/dist/auto-instrumentations/bundler/webpack-loader.cjs +9 -0
- package/dist/auto-instrumentations/bundler/webpack.cjs +226 -1
- package/dist/auto-instrumentations/bundler/webpack.mjs +4 -3
- package/dist/auto-instrumentations/{chunk-2DPA74KK.mjs → chunk-E5DUYJWK.mjs} +1 -0
- package/dist/auto-instrumentations/chunk-J57YF7WS.mjs +208 -0
- package/dist/auto-instrumentations/{chunk-AFXRW7I7.mjs → chunk-OTUQ7KH5.mjs} +1 -1
- package/dist/auto-instrumentations/chunk-QFMACSOL.mjs +280 -0
- package/dist/auto-instrumentations/{chunk-73BZUKVI.mjs → chunk-XKAAVWT6.mjs} +24 -2
- package/dist/auto-instrumentations/hook.mjs +7981 -7
- package/dist/auto-instrumentations/index.cjs +1 -0
- package/dist/auto-instrumentations/index.mjs +1 -1
- package/dist/auto-instrumentations/loader/cjs-patch.cjs +194 -4
- package/dist/auto-instrumentations/loader/cjs-patch.mjs +13 -27
- package/dist/auto-instrumentations/loader/esm-hook.mjs +24 -10
- package/dist/browser.d.mts +274 -30
- package/dist/browser.d.ts +274 -30
- package/dist/browser.js +407 -48
- package/dist/browser.mjs +407 -48
- package/dist/{chunk-BW4DF4CY.js → chunk-NKD77KGB.js} +180 -1
- package/dist/{chunk-MSLBGITU.mjs → chunk-NU2GSPHX.mjs} +180 -1
- package/dist/cli.js +494 -94
- package/dist/edge-light.d.mts +1 -1
- package/dist/edge-light.d.ts +1 -1
- package/dist/edge-light.js +407 -48
- package/dist/edge-light.mjs +407 -48
- package/dist/index.d.mts +274 -30
- package/dist/index.d.ts +274 -30
- package/dist/index.js +1267 -857
- package/dist/index.mjs +465 -55
- package/dist/instrumentation/index.d.mts +47 -11
- package/dist/instrumentation/index.d.ts +47 -11
- package/dist/instrumentation/index.js +116 -26
- package/dist/instrumentation/index.mjs +116 -26
- package/dist/workerd.d.mts +1 -1
- package/dist/workerd.d.ts +1 -1
- package/dist/workerd.js +407 -48
- package/dist/workerd.mjs +407 -48
- package/package.json +3 -23
- package/util/dist/index.d.mts +3 -1
- package/util/dist/index.d.ts +3 -1
- package/dist/auto-instrumentations/chunk-MWZXZQUO.mjs +0 -81
|
@@ -175,6 +175,7 @@ var iso = {
|
|
|
175
175
|
getRepoInfo: async (_settings) => void 0,
|
|
176
176
|
getPastNAncestors: async () => [],
|
|
177
177
|
getEnv: (_name) => void 0,
|
|
178
|
+
getBraintrustApiKey: async () => void 0,
|
|
178
179
|
getCallerLocation: () => void 0,
|
|
179
180
|
newAsyncLocalStorage: () => new DefaultAsyncLocalStorage(),
|
|
180
181
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -684,6 +685,7 @@ var envIntegrationAliases = {
|
|
|
684
685
|
cursorsdk: "cursorSDK",
|
|
685
686
|
flue: "flue",
|
|
686
687
|
"flue-runtime": "flue",
|
|
688
|
+
mastra: "mastra",
|
|
687
689
|
"openai-agents": "openAIAgents",
|
|
688
690
|
openaiagents: "openAIAgents",
|
|
689
691
|
"openai-agents-core": "openAIAgents",
|
|
@@ -726,6 +728,7 @@ function getDefaultInstrumentationIntegrations() {
|
|
|
726
728
|
cursor: true,
|
|
727
729
|
cursorSDK: true,
|
|
728
730
|
flue: true,
|
|
731
|
+
mastra: true,
|
|
729
732
|
openAIAgents: true,
|
|
730
733
|
openrouter: true,
|
|
731
734
|
openrouterAgent: true,
|
|
@@ -754,6 +757,179 @@ function isInstrumentationIntegrationDisabled(integrations, ...names) {
|
|
|
754
757
|
return names.some((name) => _optionalChain([integrations, 'optionalAccess', _34 => _34[name]]) === false);
|
|
755
758
|
}
|
|
756
759
|
|
|
760
|
+
// src/auto-instrumentations/loader/mastra-observability-patch.ts
|
|
761
|
+
var MASTRA_EXPORTER_FACTORY_GLOBAL = "__braintrustMastraExporterFactory";
|
|
762
|
+
function installMastraExporterFactory(factory) {
|
|
763
|
+
const globals = globalThis;
|
|
764
|
+
globals[MASTRA_EXPORTER_FACTORY_GLOBAL] ??= factory;
|
|
765
|
+
}
|
|
766
|
+
var MASTRA_CORE_PACKAGE = "@mastra/core";
|
|
767
|
+
var MASTRA_OBSERVABILITY_PACKAGE = "@mastra/observability";
|
|
768
|
+
var MASTRA_CORE_ENTRY_PATHS = /* @__PURE__ */ new Set([
|
|
769
|
+
"dist/index.js",
|
|
770
|
+
"dist/index.cjs",
|
|
771
|
+
"dist/mastra/index.js",
|
|
772
|
+
"dist/mastra/index.cjs"
|
|
773
|
+
]);
|
|
774
|
+
var MASTRA_OBSERVABILITY_ENTRY_PATHS = /* @__PURE__ */ new Set([
|
|
775
|
+
"dist/index.js",
|
|
776
|
+
"dist/index.cjs"
|
|
777
|
+
]);
|
|
778
|
+
function classifyMastraTarget(packageName, modulePath) {
|
|
779
|
+
if (packageName === MASTRA_CORE_PACKAGE && MASTRA_CORE_ENTRY_PATHS.has(modulePath)) {
|
|
780
|
+
return "core";
|
|
781
|
+
}
|
|
782
|
+
if (packageName === MASTRA_OBSERVABILITY_PACKAGE && MASTRA_OBSERVABILITY_ENTRY_PATHS.has(modulePath)) {
|
|
783
|
+
return "observability";
|
|
784
|
+
}
|
|
785
|
+
return null;
|
|
786
|
+
}
|
|
787
|
+
function extractChunkPath(source) {
|
|
788
|
+
const esmMatch = source.match(
|
|
789
|
+
/export\s*\{\s*Mastra(?:\s+as\s+\w+)?\s*\}\s*from\s*['"]([^'"]+)['"]/
|
|
790
|
+
);
|
|
791
|
+
if (esmMatch) return esmMatch[1];
|
|
792
|
+
const cjsMatch = source.match(
|
|
793
|
+
/require\s*\(\s*['"]([^'"]+chunk-[^'"]+)['"]\s*\)/
|
|
794
|
+
);
|
|
795
|
+
if (cjsMatch) return cjsMatch[1];
|
|
796
|
+
return null;
|
|
797
|
+
}
|
|
798
|
+
var EXPORTER_FACTORY_KEY = JSON.stringify(MASTRA_EXPORTER_FACTORY_GLOBAL);
|
|
799
|
+
var MASTRA_PROXY_HANDLER_BODY = `
|
|
800
|
+
{
|
|
801
|
+
construct(target, args, newTarget) {
|
|
802
|
+
var firstArg = args[0];
|
|
803
|
+
if (
|
|
804
|
+
(!firstArg || typeof firstArg !== "object" || !firstArg.observability) &&
|
|
805
|
+
__braintrustObservabilityClass
|
|
806
|
+
) {
|
|
807
|
+
try {
|
|
808
|
+
// serviceName is required by Mastra's Observability validator; pass
|
|
809
|
+
// something sensible by default. Users who want a different name
|
|
810
|
+
// should construct Observability themselves.
|
|
811
|
+
var observability = new __braintrustObservabilityClass({
|
|
812
|
+
configs: { default: { serviceName: "mastra" } },
|
|
813
|
+
});
|
|
814
|
+
args = args.slice();
|
|
815
|
+
args[0] = Object.assign({}, firstArg, { observability: observability });
|
|
816
|
+
} catch (e) {
|
|
817
|
+
// Fall through. Mastra will use its own NoOp; user code still works,
|
|
818
|
+
// just without auto-instrumentation.
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
return Reflect.construct(target, args, newTarget);
|
|
822
|
+
},
|
|
823
|
+
}`;
|
|
824
|
+
function buildMastraEsmWrapper(chunkPath) {
|
|
825
|
+
const chunk = JSON.stringify(chunkPath);
|
|
826
|
+
return `import { Mastra as __braintrustOrigMastra } from ${chunk};
|
|
827
|
+
import { createRequire as __braintrustCreateRequire } from "node:module";
|
|
828
|
+
|
|
829
|
+
let __braintrustObservabilityClass = null;
|
|
830
|
+
try {
|
|
831
|
+
// Resolve @mastra/observability relative to this module (the Mastra entry),
|
|
832
|
+
// so it's looked up from the user's node_modules tree.
|
|
833
|
+
const __braintrustRequire = __braintrustCreateRequire(import.meta.url);
|
|
834
|
+
__braintrustObservabilityClass =
|
|
835
|
+
__braintrustRequire("@mastra/observability").Observability;
|
|
836
|
+
} catch (e) {
|
|
837
|
+
// @mastra/observability isn't installed; the construct trap will skip the
|
|
838
|
+
// auto-construct branch and Mastra falls back to its own NoOp.
|
|
839
|
+
}
|
|
840
|
+
const Mastra = new Proxy(__braintrustOrigMastra, ${MASTRA_PROXY_HANDLER_BODY});
|
|
841
|
+
export { Mastra };
|
|
842
|
+
`;
|
|
843
|
+
}
|
|
844
|
+
function buildMastraCjsWrapper(chunkPath) {
|
|
845
|
+
const chunk = JSON.stringify(chunkPath);
|
|
846
|
+
return `'use strict';
|
|
847
|
+
const __braintrustChunk = require(${chunk});
|
|
848
|
+
|
|
849
|
+
let __braintrustObservabilityClass = null;
|
|
850
|
+
try {
|
|
851
|
+
__braintrustObservabilityClass = require("@mastra/observability").Observability;
|
|
852
|
+
} catch (e) {
|
|
853
|
+
// @mastra/observability isn't installed; same fallback as the ESM wrapper.
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
const __braintrustWrappedMastra = new Proxy(
|
|
857
|
+
__braintrustChunk.Mastra,
|
|
858
|
+
${MASTRA_PROXY_HANDLER_BODY},
|
|
859
|
+
);
|
|
860
|
+
Object.defineProperty(exports, "Mastra", {
|
|
861
|
+
enumerable: true,
|
|
862
|
+
configurable: true,
|
|
863
|
+
get: function () { return __braintrustWrappedMastra; }
|
|
864
|
+
});
|
|
865
|
+
`;
|
|
866
|
+
}
|
|
867
|
+
var OBSERVABILITY_APPEND_BODY = `
|
|
868
|
+
;(function __braintrustWrapObservability() {
|
|
869
|
+
// Top-level so we can both read and reassign the var binding the original
|
|
870
|
+
// entry declared.
|
|
871
|
+
if (typeof Observability === "undefined") return;
|
|
872
|
+
if (Observability.__braintrustWrapped) return;
|
|
873
|
+
function __braintrustEnsureExporter(rawConfig) {
|
|
874
|
+
try {
|
|
875
|
+
var factory = globalThis[${EXPORTER_FACTORY_KEY}];
|
|
876
|
+
if (typeof factory !== "function") return rawConfig;
|
|
877
|
+
var config = rawConfig && typeof rawConfig === "object" ? rawConfig : {};
|
|
878
|
+
var configsIn = config.configs && typeof config.configs === "object" ? config.configs : null;
|
|
879
|
+
var configsOut = {};
|
|
880
|
+
var hadEntries = false;
|
|
881
|
+
if (configsIn) {
|
|
882
|
+
for (var name in configsIn) {
|
|
883
|
+
if (!Object.prototype.hasOwnProperty.call(configsIn, name)) continue;
|
|
884
|
+
hadEntries = true;
|
|
885
|
+
var inst = configsIn[name] || {};
|
|
886
|
+
var existing = Array.isArray(inst.exporters) ? inst.exporters : [];
|
|
887
|
+
var hasOurs = existing.some(function (e) { return e && e.name === "braintrust"; });
|
|
888
|
+
configsOut[name] = Object.assign({}, inst, {
|
|
889
|
+
exporters: hasOurs ? existing : existing.concat([factory()]),
|
|
890
|
+
});
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
if (!hadEntries) {
|
|
894
|
+
configsOut.default = {
|
|
895
|
+
serviceName: "mastra",
|
|
896
|
+
exporters: [factory()],
|
|
897
|
+
};
|
|
898
|
+
}
|
|
899
|
+
return Object.assign({}, config, { configs: configsOut });
|
|
900
|
+
} catch (e) {
|
|
901
|
+
return rawConfig;
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
var __OriginalObservability = Observability;
|
|
905
|
+
Observability = new Proxy(__OriginalObservability, {
|
|
906
|
+
construct: function (target, args, newTarget) {
|
|
907
|
+
var nextArgs = args.slice();
|
|
908
|
+
nextArgs[0] = __braintrustEnsureExporter(nextArgs[0]);
|
|
909
|
+
return Reflect.construct(target, nextArgs, newTarget);
|
|
910
|
+
},
|
|
911
|
+
});
|
|
912
|
+
Observability.__braintrustWrapped = true;
|
|
913
|
+
if (typeof exports !== "undefined" && exports && typeof exports === "object") {
|
|
914
|
+
try {
|
|
915
|
+
Object.defineProperty(exports, "Observability", {
|
|
916
|
+
enumerable: true,
|
|
917
|
+
configurable: true,
|
|
918
|
+
get: function () { return Observability; },
|
|
919
|
+
});
|
|
920
|
+
} catch (e) {}
|
|
921
|
+
}
|
|
922
|
+
})();
|
|
923
|
+
`;
|
|
924
|
+
function patchMastraSource(source, target, format) {
|
|
925
|
+
if (target === "core") {
|
|
926
|
+
const chunkPath = extractChunkPath(source);
|
|
927
|
+
if (!chunkPath) return source;
|
|
928
|
+
return format === "esm" ? buildMastraEsmWrapper(chunkPath) : buildMastraCjsWrapper(chunkPath);
|
|
929
|
+
}
|
|
930
|
+
return source + OBSERVABILITY_APPEND_BODY;
|
|
931
|
+
}
|
|
932
|
+
|
|
757
933
|
// src/instrumentation/plugins/openai-agents-channels.ts
|
|
758
934
|
var openAIAgentsCoreChannels = defineChannels("@openai/agents-core", {
|
|
759
935
|
onTraceStart: channel({
|
|
@@ -813,4 +989,7 @@ var langChainChannels = defineChannels("@langchain/core", {
|
|
|
813
989
|
|
|
814
990
|
|
|
815
991
|
|
|
816
|
-
|
|
992
|
+
|
|
993
|
+
|
|
994
|
+
|
|
995
|
+
exports.__export = __export; exports.patchTracingChannel = patchTracingChannel; exports.isomorph_default = isomorph_default; exports.openAIChannels = openAIChannels; exports.openAICodexChannels = openAICodexChannels; exports.anthropicChannels = anthropicChannels; exports.aiSDKChannels = aiSDKChannels; exports.claudeAgentSDKChannels = claudeAgentSDKChannels; exports.cursorSDKChannels = cursorSDKChannels; exports.openAIAgentsCoreChannels = openAIAgentsCoreChannels; exports.googleGenAIChannels = googleGenAIChannels; exports.huggingFaceChannels = huggingFaceChannels; exports.openRouterAgentChannels = openRouterAgentChannels; exports.openRouterChannels = openRouterChannels; exports.mistralChannels = mistralChannels; exports.googleADKChannels = googleADKChannels; exports.cohereChannels = cohereChannels; exports.groqChannels = groqChannels; exports.genkitChannels = genkitChannels; exports.genkitCoreChannels = genkitCoreChannels; exports.gitHubCopilotChannels = gitHubCopilotChannels; exports.flueChannels = flueChannels; exports.langChainChannels = langChainChannels; exports.getDefaultInstrumentationIntegrations = getDefaultInstrumentationIntegrations; exports.readDisabledInstrumentationEnvConfig = readDisabledInstrumentationEnvConfig; exports.isInstrumentationIntegrationDisabled = isInstrumentationIntegrationDisabled; exports.installMastraExporterFactory = installMastraExporterFactory; exports.classifyMastraTarget = classifyMastraTarget; exports.patchMastraSource = patchMastraSource;
|
|
@@ -175,6 +175,7 @@ var iso = {
|
|
|
175
175
|
getRepoInfo: async (_settings) => void 0,
|
|
176
176
|
getPastNAncestors: async () => [],
|
|
177
177
|
getEnv: (_name) => void 0,
|
|
178
|
+
getBraintrustApiKey: async () => void 0,
|
|
178
179
|
getCallerLocation: () => void 0,
|
|
179
180
|
newAsyncLocalStorage: () => new DefaultAsyncLocalStorage(),
|
|
180
181
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -684,6 +685,7 @@ var envIntegrationAliases = {
|
|
|
684
685
|
cursorsdk: "cursorSDK",
|
|
685
686
|
flue: "flue",
|
|
686
687
|
"flue-runtime": "flue",
|
|
688
|
+
mastra: "mastra",
|
|
687
689
|
"openai-agents": "openAIAgents",
|
|
688
690
|
openaiagents: "openAIAgents",
|
|
689
691
|
"openai-agents-core": "openAIAgents",
|
|
@@ -726,6 +728,7 @@ function getDefaultInstrumentationIntegrations() {
|
|
|
726
728
|
cursor: true,
|
|
727
729
|
cursorSDK: true,
|
|
728
730
|
flue: true,
|
|
731
|
+
mastra: true,
|
|
729
732
|
openAIAgents: true,
|
|
730
733
|
openrouter: true,
|
|
731
734
|
openrouterAgent: true,
|
|
@@ -754,6 +757,179 @@ function isInstrumentationIntegrationDisabled(integrations, ...names) {
|
|
|
754
757
|
return names.some((name) => integrations?.[name] === false);
|
|
755
758
|
}
|
|
756
759
|
|
|
760
|
+
// src/auto-instrumentations/loader/mastra-observability-patch.ts
|
|
761
|
+
var MASTRA_EXPORTER_FACTORY_GLOBAL = "__braintrustMastraExporterFactory";
|
|
762
|
+
function installMastraExporterFactory(factory) {
|
|
763
|
+
const globals = globalThis;
|
|
764
|
+
globals[MASTRA_EXPORTER_FACTORY_GLOBAL] ??= factory;
|
|
765
|
+
}
|
|
766
|
+
var MASTRA_CORE_PACKAGE = "@mastra/core";
|
|
767
|
+
var MASTRA_OBSERVABILITY_PACKAGE = "@mastra/observability";
|
|
768
|
+
var MASTRA_CORE_ENTRY_PATHS = /* @__PURE__ */ new Set([
|
|
769
|
+
"dist/index.js",
|
|
770
|
+
"dist/index.cjs",
|
|
771
|
+
"dist/mastra/index.js",
|
|
772
|
+
"dist/mastra/index.cjs"
|
|
773
|
+
]);
|
|
774
|
+
var MASTRA_OBSERVABILITY_ENTRY_PATHS = /* @__PURE__ */ new Set([
|
|
775
|
+
"dist/index.js",
|
|
776
|
+
"dist/index.cjs"
|
|
777
|
+
]);
|
|
778
|
+
function classifyMastraTarget(packageName, modulePath) {
|
|
779
|
+
if (packageName === MASTRA_CORE_PACKAGE && MASTRA_CORE_ENTRY_PATHS.has(modulePath)) {
|
|
780
|
+
return "core";
|
|
781
|
+
}
|
|
782
|
+
if (packageName === MASTRA_OBSERVABILITY_PACKAGE && MASTRA_OBSERVABILITY_ENTRY_PATHS.has(modulePath)) {
|
|
783
|
+
return "observability";
|
|
784
|
+
}
|
|
785
|
+
return null;
|
|
786
|
+
}
|
|
787
|
+
function extractChunkPath(source) {
|
|
788
|
+
const esmMatch = source.match(
|
|
789
|
+
/export\s*\{\s*Mastra(?:\s+as\s+\w+)?\s*\}\s*from\s*['"]([^'"]+)['"]/
|
|
790
|
+
);
|
|
791
|
+
if (esmMatch) return esmMatch[1];
|
|
792
|
+
const cjsMatch = source.match(
|
|
793
|
+
/require\s*\(\s*['"]([^'"]+chunk-[^'"]+)['"]\s*\)/
|
|
794
|
+
);
|
|
795
|
+
if (cjsMatch) return cjsMatch[1];
|
|
796
|
+
return null;
|
|
797
|
+
}
|
|
798
|
+
var EXPORTER_FACTORY_KEY = JSON.stringify(MASTRA_EXPORTER_FACTORY_GLOBAL);
|
|
799
|
+
var MASTRA_PROXY_HANDLER_BODY = `
|
|
800
|
+
{
|
|
801
|
+
construct(target, args, newTarget) {
|
|
802
|
+
var firstArg = args[0];
|
|
803
|
+
if (
|
|
804
|
+
(!firstArg || typeof firstArg !== "object" || !firstArg.observability) &&
|
|
805
|
+
__braintrustObservabilityClass
|
|
806
|
+
) {
|
|
807
|
+
try {
|
|
808
|
+
// serviceName is required by Mastra's Observability validator; pass
|
|
809
|
+
// something sensible by default. Users who want a different name
|
|
810
|
+
// should construct Observability themselves.
|
|
811
|
+
var observability = new __braintrustObservabilityClass({
|
|
812
|
+
configs: { default: { serviceName: "mastra" } },
|
|
813
|
+
});
|
|
814
|
+
args = args.slice();
|
|
815
|
+
args[0] = Object.assign({}, firstArg, { observability: observability });
|
|
816
|
+
} catch (e) {
|
|
817
|
+
// Fall through. Mastra will use its own NoOp; user code still works,
|
|
818
|
+
// just without auto-instrumentation.
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
return Reflect.construct(target, args, newTarget);
|
|
822
|
+
},
|
|
823
|
+
}`;
|
|
824
|
+
function buildMastraEsmWrapper(chunkPath) {
|
|
825
|
+
const chunk = JSON.stringify(chunkPath);
|
|
826
|
+
return `import { Mastra as __braintrustOrigMastra } from ${chunk};
|
|
827
|
+
import { createRequire as __braintrustCreateRequire } from "node:module";
|
|
828
|
+
|
|
829
|
+
let __braintrustObservabilityClass = null;
|
|
830
|
+
try {
|
|
831
|
+
// Resolve @mastra/observability relative to this module (the Mastra entry),
|
|
832
|
+
// so it's looked up from the user's node_modules tree.
|
|
833
|
+
const __braintrustRequire = __braintrustCreateRequire(import.meta.url);
|
|
834
|
+
__braintrustObservabilityClass =
|
|
835
|
+
__braintrustRequire("@mastra/observability").Observability;
|
|
836
|
+
} catch (e) {
|
|
837
|
+
// @mastra/observability isn't installed; the construct trap will skip the
|
|
838
|
+
// auto-construct branch and Mastra falls back to its own NoOp.
|
|
839
|
+
}
|
|
840
|
+
const Mastra = new Proxy(__braintrustOrigMastra, ${MASTRA_PROXY_HANDLER_BODY});
|
|
841
|
+
export { Mastra };
|
|
842
|
+
`;
|
|
843
|
+
}
|
|
844
|
+
function buildMastraCjsWrapper(chunkPath) {
|
|
845
|
+
const chunk = JSON.stringify(chunkPath);
|
|
846
|
+
return `'use strict';
|
|
847
|
+
const __braintrustChunk = require(${chunk});
|
|
848
|
+
|
|
849
|
+
let __braintrustObservabilityClass = null;
|
|
850
|
+
try {
|
|
851
|
+
__braintrustObservabilityClass = require("@mastra/observability").Observability;
|
|
852
|
+
} catch (e) {
|
|
853
|
+
// @mastra/observability isn't installed; same fallback as the ESM wrapper.
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
const __braintrustWrappedMastra = new Proxy(
|
|
857
|
+
__braintrustChunk.Mastra,
|
|
858
|
+
${MASTRA_PROXY_HANDLER_BODY},
|
|
859
|
+
);
|
|
860
|
+
Object.defineProperty(exports, "Mastra", {
|
|
861
|
+
enumerable: true,
|
|
862
|
+
configurable: true,
|
|
863
|
+
get: function () { return __braintrustWrappedMastra; }
|
|
864
|
+
});
|
|
865
|
+
`;
|
|
866
|
+
}
|
|
867
|
+
var OBSERVABILITY_APPEND_BODY = `
|
|
868
|
+
;(function __braintrustWrapObservability() {
|
|
869
|
+
// Top-level so we can both read and reassign the var binding the original
|
|
870
|
+
// entry declared.
|
|
871
|
+
if (typeof Observability === "undefined") return;
|
|
872
|
+
if (Observability.__braintrustWrapped) return;
|
|
873
|
+
function __braintrustEnsureExporter(rawConfig) {
|
|
874
|
+
try {
|
|
875
|
+
var factory = globalThis[${EXPORTER_FACTORY_KEY}];
|
|
876
|
+
if (typeof factory !== "function") return rawConfig;
|
|
877
|
+
var config = rawConfig && typeof rawConfig === "object" ? rawConfig : {};
|
|
878
|
+
var configsIn = config.configs && typeof config.configs === "object" ? config.configs : null;
|
|
879
|
+
var configsOut = {};
|
|
880
|
+
var hadEntries = false;
|
|
881
|
+
if (configsIn) {
|
|
882
|
+
for (var name in configsIn) {
|
|
883
|
+
if (!Object.prototype.hasOwnProperty.call(configsIn, name)) continue;
|
|
884
|
+
hadEntries = true;
|
|
885
|
+
var inst = configsIn[name] || {};
|
|
886
|
+
var existing = Array.isArray(inst.exporters) ? inst.exporters : [];
|
|
887
|
+
var hasOurs = existing.some(function (e) { return e && e.name === "braintrust"; });
|
|
888
|
+
configsOut[name] = Object.assign({}, inst, {
|
|
889
|
+
exporters: hasOurs ? existing : existing.concat([factory()]),
|
|
890
|
+
});
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
if (!hadEntries) {
|
|
894
|
+
configsOut.default = {
|
|
895
|
+
serviceName: "mastra",
|
|
896
|
+
exporters: [factory()],
|
|
897
|
+
};
|
|
898
|
+
}
|
|
899
|
+
return Object.assign({}, config, { configs: configsOut });
|
|
900
|
+
} catch (e) {
|
|
901
|
+
return rawConfig;
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
var __OriginalObservability = Observability;
|
|
905
|
+
Observability = new Proxy(__OriginalObservability, {
|
|
906
|
+
construct: function (target, args, newTarget) {
|
|
907
|
+
var nextArgs = args.slice();
|
|
908
|
+
nextArgs[0] = __braintrustEnsureExporter(nextArgs[0]);
|
|
909
|
+
return Reflect.construct(target, nextArgs, newTarget);
|
|
910
|
+
},
|
|
911
|
+
});
|
|
912
|
+
Observability.__braintrustWrapped = true;
|
|
913
|
+
if (typeof exports !== "undefined" && exports && typeof exports === "object") {
|
|
914
|
+
try {
|
|
915
|
+
Object.defineProperty(exports, "Observability", {
|
|
916
|
+
enumerable: true,
|
|
917
|
+
configurable: true,
|
|
918
|
+
get: function () { return Observability; },
|
|
919
|
+
});
|
|
920
|
+
} catch (e) {}
|
|
921
|
+
}
|
|
922
|
+
})();
|
|
923
|
+
`;
|
|
924
|
+
function patchMastraSource(source, target, format) {
|
|
925
|
+
if (target === "core") {
|
|
926
|
+
const chunkPath = extractChunkPath(source);
|
|
927
|
+
if (!chunkPath) return source;
|
|
928
|
+
return format === "esm" ? buildMastraEsmWrapper(chunkPath) : buildMastraCjsWrapper(chunkPath);
|
|
929
|
+
}
|
|
930
|
+
return source + OBSERVABILITY_APPEND_BODY;
|
|
931
|
+
}
|
|
932
|
+
|
|
757
933
|
// src/instrumentation/plugins/openai-agents-channels.ts
|
|
758
934
|
var openAIAgentsCoreChannels = defineChannels("@openai/agents-core", {
|
|
759
935
|
onTraceStart: channel({
|
|
@@ -812,5 +988,8 @@ export {
|
|
|
812
988
|
langChainChannels,
|
|
813
989
|
getDefaultInstrumentationIntegrations,
|
|
814
990
|
readDisabledInstrumentationEnvConfig,
|
|
815
|
-
isInstrumentationIntegrationDisabled
|
|
991
|
+
isInstrumentationIntegrationDisabled,
|
|
992
|
+
installMastraExporterFactory,
|
|
993
|
+
classifyMastraTarget,
|
|
994
|
+
patchMastraSource
|
|
816
995
|
};
|