@mastra/braintrust 0.0.0-1.x-tester-20251106055847

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/CHANGELOG.md ADDED
@@ -0,0 +1,347 @@
1
+ # @mastra/braintrust
2
+
3
+ ## 0.0.0-1.x-tester-20251106055847
4
+
5
+ ### Major Changes
6
+
7
+ - Bump minimum required Node.js version to 22.13.0 ([#9706](https://github.com/mastra-ai/mastra/pull/9706))
8
+
9
+ - Renamed a bunch of observability/tracing-related things to drop the AI prefix. ([#9744](https://github.com/mastra-ai/mastra/pull/9744))
10
+
11
+ - ```([#9709](https://github.com/mastra-ai/mastra/pull/9709))
12
+ import { Mastra } from '@mastra/core';
13
+ import { Observability } from '@mastra/observability'; // Explicit import
14
+
15
+ const mastra = new Mastra({
16
+ ...other_config,
17
+ observability: new Observability({
18
+ default: { enabled: true }
19
+ }) // Instance
20
+ });
21
+ ```
22
+
23
+ Instead of:
24
+
25
+ ```
26
+ import { Mastra } from '@mastra/core';
27
+ import '@mastra/observability/init'; // Explicit import
28
+
29
+ const mastra = new Mastra({
30
+ ...other_config,
31
+ observability: {
32
+ default: { enabled: true }
33
+ }
34
+ });
35
+ ```
36
+
37
+ Also renamed a bunch of:
38
+ - `Tracing` things to `Observability` things.
39
+ - `AI-` things to just things.
40
+
41
+ - Mark as stable ([`83d5942`](https://github.com/mastra-ai/mastra/commit/83d5942669ce7bba4a6ca4fd4da697a10eb5ebdc))
42
+
43
+ - moved ai-tracing code into @mastra/observability ([#9661](https://github.com/mastra-ai/mastra/pull/9661))
44
+
45
+ ### Minor Changes
46
+
47
+ - Rename LLM span types and attributes to use Model prefix ([#9105](https://github.com/mastra-ai/mastra/pull/9105))
48
+
49
+ BREAKING CHANGE: This release renames tracing span types and attribute interfaces to use the "Model" prefix instead of "LLM":
50
+ - `AISpanType.LLM_GENERATION` → `AISpanType.MODEL_GENERATION`
51
+ - `AISpanType.LLM_STEP` → `AISpanType.MODEL_STEP`
52
+ - `AISpanType.LLM_CHUNK` → `AISpanType.MODEL_CHUNK`
53
+ - `LLMGenerationAttributes` → `ModelGenerationAttributes`
54
+ - `LLMStepAttributes` → `ModelStepAttributes`
55
+ - `LLMChunkAttributes` → `ModelChunkAttributes`
56
+ - `InternalSpans.LLM` → `InternalSpans.MODEL`
57
+
58
+ This change better reflects that these span types apply to all AI models, not just Large Language Models.
59
+
60
+ Migration guide:
61
+ - Update all imports: `import { ModelGenerationAttributes } from '@mastra/core/ai-tracing'`
62
+ - Update span type references: `AISpanType.MODEL_GENERATION`
63
+ - Update InternalSpans usage: `InternalSpans.MODEL`
64
+
65
+ ### Patch Changes
66
+
67
+ - Fixed import isssues in exporters. ([#9316](https://github.com/mastra-ai/mastra/pull/9316))
68
+
69
+ - Update peer dependencies to match core package version bump (1.0.0) ([#9237](https://github.com/mastra-ai/mastra/pull/9237))
70
+
71
+ - Updated dependencies [[`f743dbb`](https://github.com/mastra-ai/mastra/commit/f743dbb8b40d1627b5c10c0e6fc154f4ebb6e394), [`fec5129`](https://github.com/mastra-ai/mastra/commit/fec5129de7fc64423ea03661a56cef31dc747a0d), [`0491e7c`](https://github.com/mastra-ai/mastra/commit/0491e7c9b714cb0ba22187ee062147ec2dd7c712), [`f6f4903`](https://github.com/mastra-ai/mastra/commit/f6f4903397314f73362061dc5a3e8e7c61ea34aa), [`0e8ed46`](https://github.com/mastra-ai/mastra/commit/0e8ed467c54d6901a6a365f270ec15d6faadb36c), [`6c049d9`](https://github.com/mastra-ai/mastra/commit/6c049d94063fdcbd5b81c4912a2bf82a92c9cc0b), [`2f897df`](https://github.com/mastra-ai/mastra/commit/2f897df208508f46f51b7625e5dd20c37f93e0e3), [`3443770`](https://github.com/mastra-ai/mastra/commit/3443770662df8eb24c9df3589b2792d78cfcb811), [`f0a07e0`](https://github.com/mastra-ai/mastra/commit/f0a07e0111b3307c5fabfa4094c5c2cfb734fbe6), [`aaa40e7`](https://github.com/mastra-ai/mastra/commit/aaa40e788628b319baa8e889407d11ad626547fa), [`1521d71`](https://github.com/mastra-ai/mastra/commit/1521d716e5daedc74690c983fbd961123c56756b), [`9e1911d`](https://github.com/mastra-ai/mastra/commit/9e1911db2b4db85e0e768c3f15e0d61e319869f6), [`ebac155`](https://github.com/mastra-ai/mastra/commit/ebac15564a590117db7078233f927a7e28a85106), [`dd1c38d`](https://github.com/mastra-ai/mastra/commit/dd1c38d1b75f1b695c27b40d8d9d6ed00d5e0f6f), [`5948e6a`](https://github.com/mastra-ai/mastra/commit/5948e6a5146c83666ba3f294b2be576c82a513fb), [`83b08dc`](https://github.com/mastra-ai/mastra/commit/83b08dcf1bfcc915efab23c09207df90fa247908), [`8940859`](https://github.com/mastra-ai/mastra/commit/89408593658199b4ad67f7b65e888f344e64a442), [`f0f8f12`](https://github.com/mastra-ai/mastra/commit/f0f8f125c308f2d0fd36942ef652fd852df7522f), [`e629310`](https://github.com/mastra-ai/mastra/commit/e629310f1a73fa236d49ec7a1d1cceb6229dc7cc), [`4c6b492`](https://github.com/mastra-ai/mastra/commit/4c6b492c4dd591c6a592520c1f6855d6e936d71f), [`dff01d8`](https://github.com/mastra-ai/mastra/commit/dff01d81ce1f4e4087cfac20fa868e6db138dd14), [`9d819d5`](https://github.com/mastra-ai/mastra/commit/9d819d54b61481639f4008e4694791bddf187edd), [`71c8d6c`](https://github.com/mastra-ai/mastra/commit/71c8d6c161253207b2b9588bdadb7eed604f7253), [`6179a9b`](https://github.com/mastra-ai/mastra/commit/6179a9ba36ffac326de3cc3c43cdc8028d37c251), [`00f4921`](https://github.com/mastra-ai/mastra/commit/00f4921dd2c91a1e5446799599ef7116a8214a1a), [`ca8041c`](https://github.com/mastra-ai/mastra/commit/ca8041cce0379fda22ed293a565bcb5b6ddca68a), [`7051bf3`](https://github.com/mastra-ai/mastra/commit/7051bf38b3b122a069008f861f7bfc004a6d9f6e), [`a8f1494`](https://github.com/mastra-ai/mastra/commit/a8f1494f4bbdc2770bcf327d4c7d869e332183f1), [`0793497`](https://github.com/mastra-ai/mastra/commit/079349753620c40246ffd673e3f9d7d9820beff3), [`5df9cce`](https://github.com/mastra-ai/mastra/commit/5df9cce1a753438413f64c11eeef8f845745c2a8), [`a854ede`](https://github.com/mastra-ai/mastra/commit/a854ede62bf5ac0945a624ac48913dd69c73aabf), [`c576fc0`](https://github.com/mastra-ai/mastra/commit/c576fc0b100b2085afded91a37c97a0ea0ec09c7), [`3defc80`](https://github.com/mastra-ai/mastra/commit/3defc80cf2b88a1b7fc1cc4ddcb91e982a614609), [`f111eac`](https://github.com/mastra-ai/mastra/commit/f111eac5de509b2e5fccfc1882e7f74cda264c74), [`16153fe`](https://github.com/mastra-ai/mastra/commit/16153fe7eb13c99401f48e6ca32707c965ee28b9), [`9f4a683`](https://github.com/mastra-ai/mastra/commit/9f4a6833e88b52574665c028fd5508ad5c2f6004), [`bc94344`](https://github.com/mastra-ai/mastra/commit/bc943444a1342d8a662151b7bce1df7dae32f59c), [`57d157f`](https://github.com/mastra-ai/mastra/commit/57d157f0b163a95c3e6c9eae31bdb11d1bfc64f9), [`2a90c55`](https://github.com/mastra-ai/mastra/commit/2a90c55a86a9210697d5adaab5ee94584b079adc), [`eb09742`](https://github.com/mastra-ai/mastra/commit/eb09742197f66c4c38154c3beec78313e69760b2), [`96d35f6`](https://github.com/mastra-ai/mastra/commit/96d35f61376bc2b1bf148648a2c1985bd51bef55), [`5cbe88a`](https://github.com/mastra-ai/mastra/commit/5cbe88aefbd9f933bca669fd371ea36bf939ac6d), [`a1bd7b8`](https://github.com/mastra-ai/mastra/commit/a1bd7b8571db16b94eb01588f451a74758c96d65), [`d78b38d`](https://github.com/mastra-ai/mastra/commit/d78b38d898fce285260d3bbb4befade54331617f), [`0633100`](https://github.com/mastra-ai/mastra/commit/0633100a911ad22f5256471bdf753da21c104742), [`c710c16`](https://github.com/mastra-ai/mastra/commit/c710c1652dccfdc4111c8412bca7a6bb1d48b441), [`354ad0b`](https://github.com/mastra-ai/mastra/commit/354ad0b7b1b8183ac567f236a884fc7ede6d7138), [`cfae733`](https://github.com/mastra-ai/mastra/commit/cfae73394f4920635e6c919c8e95ff9a0788e2e5), [`e3dfda7`](https://github.com/mastra-ai/mastra/commit/e3dfda7b11bf3b8c4bb55637028befb5f387fc74), [`844ea5d`](https://github.com/mastra-ai/mastra/commit/844ea5dc0c248961e7bf73629ae7dcff503e853c), [`f0f8f12`](https://github.com/mastra-ai/mastra/commit/f0f8f125c308f2d0fd36942ef652fd852df7522f), [`0d7618b`](https://github.com/mastra-ai/mastra/commit/0d7618bc650bf2800934b243eca5648f4aeed9c2), [`7b763e5`](https://github.com/mastra-ai/mastra/commit/7b763e52fc3eaf699c2a99f2adf418dd46e4e9a5), [`d36cfbb`](https://github.com/mastra-ai/mastra/commit/d36cfbbb6565ba5f827883cc9bb648eb14befdc1), [`3697853`](https://github.com/mastra-ai/mastra/commit/3697853deeb72017d90e0f38a93c1e29221aeca0), [`b2e45ec`](https://github.com/mastra-ai/mastra/commit/b2e45eca727a8db01a81ba93f1a5219c7183c839), [`a534e95`](https://github.com/mastra-ai/mastra/commit/a534e9591f83b3cc1ebff99c67edf4cda7bf81d3), [`9d0e7fe`](https://github.com/mastra-ai/mastra/commit/9d0e7feca8ed98de959f53476ee1456073673348), [`53d927c`](https://github.com/mastra-ai/mastra/commit/53d927cc6f03bff33655b7e2b788da445a08731d), [`22f64bc`](https://github.com/mastra-ai/mastra/commit/22f64bc1d37149480b58bf2fefe35b79a1e3e7d5), [`83d5942`](https://github.com/mastra-ai/mastra/commit/83d5942669ce7bba4a6ca4fd4da697a10eb5ebdc), [`b7959e6`](https://github.com/mastra-ai/mastra/commit/b7959e6e25a46b480f9ea2217c4c6c588c423791), [`bda6370`](https://github.com/mastra-ai/mastra/commit/bda637009360649aaf579919e7873e33553c273e), [`d7acd8e`](https://github.com/mastra-ai/mastra/commit/d7acd8e987b5d7eff4fd98b0906c17c06a2e83d5), [`c7f1f7d`](https://github.com/mastra-ai/mastra/commit/c7f1f7d24f61f247f018cc2d1f33bf63212959a7), [`0bddc6d`](https://github.com/mastra-ai/mastra/commit/0bddc6d8dbd6f6008c0cba2e4960a2da75a55af1), [`735d8c1`](https://github.com/mastra-ai/mastra/commit/735d8c1c0d19fbc09e6f8b66cf41bc7655993838), [`acf322e`](https://github.com/mastra-ai/mastra/commit/acf322e0f1fd0189684cf529d91c694bea918a45), [`c942802`](https://github.com/mastra-ai/mastra/commit/c942802a477a925b01859a7b8688d4355715caaa), [`a0c8c1b`](https://github.com/mastra-ai/mastra/commit/a0c8c1b87d4fee252aebda73e8637fbe01d761c9), [`cc34739`](https://github.com/mastra-ai/mastra/commit/cc34739c34b6266a91bea561119240a7acf47887), [`c218bd3`](https://github.com/mastra-ai/mastra/commit/c218bd3759e32423735b04843a09404572631014), [`2c4438b`](https://github.com/mastra-ai/mastra/commit/2c4438b87817ab7eed818c7990fef010475af1a3), [`2b8893c`](https://github.com/mastra-ai/mastra/commit/2b8893cb108ef9acb72ee7835cd625610d2c1a4a), [`8e5c75b`](https://github.com/mastra-ai/mastra/commit/8e5c75bdb1d08a42d45309a4c72def4b6890230f), [`e59e0d3`](https://github.com/mastra-ai/mastra/commit/e59e0d32afb5fcf2c9f3c00c8f81f6c21d3a63fa), [`fa8409b`](https://github.com/mastra-ai/mastra/commit/fa8409bc39cfd8ba6643b9db5269b90b22e2a2f7), [`173c535`](https://github.com/mastra-ai/mastra/commit/173c535c0645b0da404fe09f003778f0b0d4e019)]:
72
+ - @mastra/core@0.0.0-1.x-tester-20251106055847
73
+ - @mastra/observability@0.0.0-1.x-tester-20251106055847
74
+
75
+ ## 0.1.9
76
+
77
+ ### Patch Changes
78
+
79
+ - Fix a `ERR_MODULE_NOT_FOUND` error that was caused by a bad import to `@mastra/core/dist/ai-tracing/exporters/index.js` ([#9129](https://github.com/mastra-ai/mastra/pull/9129))
80
+
81
+ - Updated dependencies []:
82
+ - @mastra/core@0.22.1
83
+
84
+ ## 0.1.9-alpha.0
85
+
86
+ ### Patch Changes
87
+
88
+ - Fix a `ERR_MODULE_NOT_FOUND` error that was caused by a bad import to `@mastra/core/dist/ai-tracing/exporters/index.js` ([#9129](https://github.com/mastra-ai/mastra/pull/9129))
89
+
90
+ - Updated dependencies []:
91
+ - @mastra/core@0.22.1-alpha.0
92
+
93
+ ## 0.1.8
94
+
95
+ ### Patch Changes
96
+
97
+ - Update peerdeps to 0.23.0-0 ([#9043](https://github.com/mastra-ai/mastra/pull/9043))
98
+
99
+ - Updated dependencies [[`c67ca32`](https://github.com/mastra-ai/mastra/commit/c67ca32e3c2cf69bfc146580770c720220ca44ac), [`efb5ed9`](https://github.com/mastra-ai/mastra/commit/efb5ed946ae7f410bc68c9430beb4b010afd25ec), [`dbc9e12`](https://github.com/mastra-ai/mastra/commit/dbc9e1216ba575ba59ead4afb727a01215f7de4f), [`99e41b9`](https://github.com/mastra-ai/mastra/commit/99e41b94957cdd25137d3ac12e94e8b21aa01b68), [`c28833c`](https://github.com/mastra-ai/mastra/commit/c28833c5b6d8e10eeffd7f7d39129d53b8bca240), [`8ea07b4`](https://github.com/mastra-ai/mastra/commit/8ea07b4bdc73e4218437dbb6dcb0f4b23e745a44), [`ba201b8`](https://github.com/mastra-ai/mastra/commit/ba201b8f8feac4c72350f2dbd52c13c7297ba7b0), [`f053e89`](https://github.com/mastra-ai/mastra/commit/f053e89160dbd0bd3333fc3492f68231b5c7c349), [`4fc4136`](https://github.com/mastra-ai/mastra/commit/4fc413652866a8d2240694fddb2562e9edbb70df), [`b78e04d`](https://github.com/mastra-ai/mastra/commit/b78e04d935a16ecb1e59c5c96e564903527edddd), [`d10baf5`](https://github.com/mastra-ai/mastra/commit/d10baf5a3c924f2a6654e23a3e318ed03f189b76), [`038c55a`](https://github.com/mastra-ai/mastra/commit/038c55a7090fc1b1513a966386d3072617f836ac), [`182f045`](https://github.com/mastra-ai/mastra/commit/182f0458f25bd70aa774e64fd923c8a483eddbf1), [`9a1a485`](https://github.com/mastra-ai/mastra/commit/9a1a4859b855e37239f652bf14b1ecd1029b8c4e), [`9257233`](https://github.com/mastra-ai/mastra/commit/9257233c4ffce09b2bedc2a9adbd70d7a83fa8e2), [`7620d2b`](https://github.com/mastra-ai/mastra/commit/7620d2bddeb4fae4c3c0a0b4e672969795fca11a), [`b2365f0`](https://github.com/mastra-ai/mastra/commit/b2365f038dd4c5f06400428b224af963f399ad50), [`0f1a4c9`](https://github.com/mastra-ai/mastra/commit/0f1a4c984fb4b104b2f0b63ba18c9fa77f567700), [`9029ba3`](https://github.com/mastra-ai/mastra/commit/9029ba34459c8859fed4c6b73efd8e2d0021e7ba), [`426cc56`](https://github.com/mastra-ai/mastra/commit/426cc561c85ae76a112ded2385532a91f9f9f074), [`00931fb`](https://github.com/mastra-ai/mastra/commit/00931fb1a21aa42c4fbc20c2c40dd62466b8fc8f), [`e473bfe`](https://github.com/mastra-ai/mastra/commit/e473bfe416c0b8e876973c2b6a6f13c394b7a93f), [`b78e04d`](https://github.com/mastra-ai/mastra/commit/b78e04d935a16ecb1e59c5c96e564903527edddd), [`2db6160`](https://github.com/mastra-ai/mastra/commit/2db6160e2022ff8827c15d30157e684683b934b5), [`8aeea37`](https://github.com/mastra-ai/mastra/commit/8aeea37efdde347c635a67fed56794943b7f74ec), [`02fe153`](https://github.com/mastra-ai/mastra/commit/02fe15351d6021d214da48ec982a0e9e4150bcee), [`648e2ca`](https://github.com/mastra-ai/mastra/commit/648e2ca42da54838c6ccbdaadc6fadd808fa6b86), [`74567b3`](https://github.com/mastra-ai/mastra/commit/74567b3d237ae3915cd0bca3cf55fa0a64e4e4a4), [`b65c5e0`](https://github.com/mastra-ai/mastra/commit/b65c5e0fe6f3c390a9a8bbcf69304d972c3a4afb), [`15a1733`](https://github.com/mastra-ai/mastra/commit/15a1733074cee8bd37370e1af34cd818e89fa7ac), [`fc2a774`](https://github.com/mastra-ai/mastra/commit/fc2a77468981aaddc3e77f83f0c4ad4a4af140da), [`4e08933`](https://github.com/mastra-ai/mastra/commit/4e08933625464dfde178347af5b6278fcf34188e)]:
100
+ - @mastra/core@0.22.0
101
+
102
+ ## 0.1.8-alpha.0
103
+
104
+ ### Patch Changes
105
+
106
+ - Update peerdeps to 0.23.0-0 ([#9043](https://github.com/mastra-ai/mastra/pull/9043))
107
+
108
+ - Updated dependencies [[`efb5ed9`](https://github.com/mastra-ai/mastra/commit/efb5ed946ae7f410bc68c9430beb4b010afd25ec), [`8ea07b4`](https://github.com/mastra-ai/mastra/commit/8ea07b4bdc73e4218437dbb6dcb0f4b23e745a44), [`ba201b8`](https://github.com/mastra-ai/mastra/commit/ba201b8f8feac4c72350f2dbd52c13c7297ba7b0), [`4fc4136`](https://github.com/mastra-ai/mastra/commit/4fc413652866a8d2240694fddb2562e9edbb70df), [`b78e04d`](https://github.com/mastra-ai/mastra/commit/b78e04d935a16ecb1e59c5c96e564903527edddd), [`d10baf5`](https://github.com/mastra-ai/mastra/commit/d10baf5a3c924f2a6654e23a3e318ed03f189b76), [`038c55a`](https://github.com/mastra-ai/mastra/commit/038c55a7090fc1b1513a966386d3072617f836ac), [`182f045`](https://github.com/mastra-ai/mastra/commit/182f0458f25bd70aa774e64fd923c8a483eddbf1), [`7620d2b`](https://github.com/mastra-ai/mastra/commit/7620d2bddeb4fae4c3c0a0b4e672969795fca11a), [`b2365f0`](https://github.com/mastra-ai/mastra/commit/b2365f038dd4c5f06400428b224af963f399ad50), [`9029ba3`](https://github.com/mastra-ai/mastra/commit/9029ba34459c8859fed4c6b73efd8e2d0021e7ba), [`426cc56`](https://github.com/mastra-ai/mastra/commit/426cc561c85ae76a112ded2385532a91f9f9f074), [`00931fb`](https://github.com/mastra-ai/mastra/commit/00931fb1a21aa42c4fbc20c2c40dd62466b8fc8f), [`e473bfe`](https://github.com/mastra-ai/mastra/commit/e473bfe416c0b8e876973c2b6a6f13c394b7a93f), [`b78e04d`](https://github.com/mastra-ai/mastra/commit/b78e04d935a16ecb1e59c5c96e564903527edddd), [`648e2ca`](https://github.com/mastra-ai/mastra/commit/648e2ca42da54838c6ccbdaadc6fadd808fa6b86), [`b65c5e0`](https://github.com/mastra-ai/mastra/commit/b65c5e0fe6f3c390a9a8bbcf69304d972c3a4afb)]:
109
+ - @mastra/core@0.22.0-alpha.1
110
+
111
+ ## 0.1.7
112
+
113
+ ### Patch Changes
114
+
115
+ - add traceId as root_span_id for braintrust traces ([#8821](https://github.com/mastra-ai/mastra/pull/8821))
116
+
117
+ - preserve Mastra span id when exported to Braintrust ([#8714](https://github.com/mastra-ai/mastra/pull/8714))
118
+
119
+ - Update peer dependencies to match core package version bump (0.21.0) ([#8619](https://github.com/mastra-ai/mastra/pull/8619))
120
+
121
+ - Update peer dependencies to match core package version bump (0.21.0) ([#8557](https://github.com/mastra-ai/mastra/pull/8557))
122
+
123
+ - Update peer dependencies to match core package version bump (0.21.0) ([#8626](https://github.com/mastra-ai/mastra/pull/8626))
124
+
125
+ - Update peer dependencies to match core package version bump (0.21.0) ([#8686](https://github.com/mastra-ai/mastra/pull/8686))
126
+
127
+ - Updated dependencies [[`1ed9670`](https://github.com/mastra-ai/mastra/commit/1ed9670d3ca50cb60dc2e517738c5eef3968ed27), [`b5a66b7`](https://github.com/mastra-ai/mastra/commit/b5a66b748a14fc8b3f63b04642ddb9621fbcc9e0), [`f59fc1e`](https://github.com/mastra-ai/mastra/commit/f59fc1e406b8912e692f6bff6cfd4754cc8d165c), [`158381d`](https://github.com/mastra-ai/mastra/commit/158381d39335be934b81ef8a1947bccace492c25), [`a1799bc`](https://github.com/mastra-ai/mastra/commit/a1799bcc1b5a1cdc188f2ac0165f17a1c4ac6f7b), [`6ff6094`](https://github.com/mastra-ai/mastra/commit/6ff60946f4ecfebdeef6e21d2b230c2204f2c9b8), [`fb703b9`](https://github.com/mastra-ai/mastra/commit/fb703b9634eeaff1a6eb2b5531ce0f9e8fb04727), [`37a2314`](https://github.com/mastra-ai/mastra/commit/37a23148e0e5a3b40d4f9f098b194671a8a49faf), [`7b1ef57`](https://github.com/mastra-ai/mastra/commit/7b1ef57fc071c2aa2a2e32905b18cd88719c5a39), [`05a9dee`](https://github.com/mastra-ai/mastra/commit/05a9dee3d355694d28847bfffb6289657fcf7dfa), [`e3c1077`](https://github.com/mastra-ai/mastra/commit/e3c107763aedd1643d3def5df450c235da9ff76c), [`1908ca0`](https://github.com/mastra-ai/mastra/commit/1908ca0521f90e43779cc29ab590173ca560443c), [`1bccdb3`](https://github.com/mastra-ai/mastra/commit/1bccdb33eb90cbeba2dc5ece1c2561fb774b26b6), [`5ef944a`](https://github.com/mastra-ai/mastra/commit/5ef944a3721d93105675cac2b2311432ff8cc393), [`d6b186f`](https://github.com/mastra-ai/mastra/commit/d6b186fb08f1caf1b86f73d3a5ee88fb999ca3be), [`ee68e82`](https://github.com/mastra-ai/mastra/commit/ee68e8289ea4408d29849e899bc6e78b3bd4e843), [`228228b`](https://github.com/mastra-ai/mastra/commit/228228b0b1de9291cb8887587f5cea1a8757ebad), [`ea33930`](https://github.com/mastra-ai/mastra/commit/ea339301e82d6318257720d811b043014ee44064), [`65493b3`](https://github.com/mastra-ai/mastra/commit/65493b31c36f6fdb78f9679f7e1ecf0c250aa5ee), [`a998b8f`](https://github.com/mastra-ai/mastra/commit/a998b8f858091c2ec47683e60766cf12d03001e4), [`b5a66b7`](https://github.com/mastra-ai/mastra/commit/b5a66b748a14fc8b3f63b04642ddb9621fbcc9e0), [`8a37bdd`](https://github.com/mastra-ai/mastra/commit/8a37bddb6d8614a32c5b70303d583d80c620ea61), [`135d6f2`](https://github.com/mastra-ai/mastra/commit/135d6f22a326ed1dffff858700669dff09d2c9eb)]:
128
+ - @mastra/core@0.21.0
129
+
130
+ ## 0.1.7-alpha.1
131
+
132
+ ### Patch Changes
133
+
134
+ - add traceId as root_span_id for braintrust traces ([#8821](https://github.com/mastra-ai/mastra/pull/8821))
135
+
136
+ - preserve Mastra span id when exported to Braintrust ([#8714](https://github.com/mastra-ai/mastra/pull/8714))
137
+
138
+ - Updated dependencies [[`1ed9670`](https://github.com/mastra-ai/mastra/commit/1ed9670d3ca50cb60dc2e517738c5eef3968ed27), [`158381d`](https://github.com/mastra-ai/mastra/commit/158381d39335be934b81ef8a1947bccace492c25), [`fb703b9`](https://github.com/mastra-ai/mastra/commit/fb703b9634eeaff1a6eb2b5531ce0f9e8fb04727), [`37a2314`](https://github.com/mastra-ai/mastra/commit/37a23148e0e5a3b40d4f9f098b194671a8a49faf), [`05a9dee`](https://github.com/mastra-ai/mastra/commit/05a9dee3d355694d28847bfffb6289657fcf7dfa), [`e3c1077`](https://github.com/mastra-ai/mastra/commit/e3c107763aedd1643d3def5df450c235da9ff76c), [`1bccdb3`](https://github.com/mastra-ai/mastra/commit/1bccdb33eb90cbeba2dc5ece1c2561fb774b26b6), [`5ef944a`](https://github.com/mastra-ai/mastra/commit/5ef944a3721d93105675cac2b2311432ff8cc393), [`d6b186f`](https://github.com/mastra-ai/mastra/commit/d6b186fb08f1caf1b86f73d3a5ee88fb999ca3be), [`65493b3`](https://github.com/mastra-ai/mastra/commit/65493b31c36f6fdb78f9679f7e1ecf0c250aa5ee), [`a998b8f`](https://github.com/mastra-ai/mastra/commit/a998b8f858091c2ec47683e60766cf12d03001e4), [`8a37bdd`](https://github.com/mastra-ai/mastra/commit/8a37bddb6d8614a32c5b70303d583d80c620ea61)]:
139
+ - @mastra/core@0.21.0-alpha.1
140
+
141
+ ## 0.1.7-alpha.0
142
+
143
+ ### Patch Changes
144
+
145
+ - Update peer dependencies to match core package version bump (0.21.0) ([#8619](https://github.com/mastra-ai/mastra/pull/8619))
146
+
147
+ - Update peer dependencies to match core package version bump (0.21.0) ([#8557](https://github.com/mastra-ai/mastra/pull/8557))
148
+
149
+ - Update peer dependencies to match core package version bump (0.21.0) ([#8626](https://github.com/mastra-ai/mastra/pull/8626))
150
+
151
+ - Update peer dependencies to match core package version bump (0.21.0) ([#8686](https://github.com/mastra-ai/mastra/pull/8686))
152
+
153
+ - Updated dependencies [[`b5a66b7`](https://github.com/mastra-ai/mastra/commit/b5a66b748a14fc8b3f63b04642ddb9621fbcc9e0), [`7b1ef57`](https://github.com/mastra-ai/mastra/commit/7b1ef57fc071c2aa2a2e32905b18cd88719c5a39), [`ee68e82`](https://github.com/mastra-ai/mastra/commit/ee68e8289ea4408d29849e899bc6e78b3bd4e843), [`228228b`](https://github.com/mastra-ai/mastra/commit/228228b0b1de9291cb8887587f5cea1a8757ebad), [`ea33930`](https://github.com/mastra-ai/mastra/commit/ea339301e82d6318257720d811b043014ee44064), [`b5a66b7`](https://github.com/mastra-ai/mastra/commit/b5a66b748a14fc8b3f63b04642ddb9621fbcc9e0), [`135d6f2`](https://github.com/mastra-ai/mastra/commit/135d6f22a326ed1dffff858700669dff09d2c9eb), [`59d036d`](https://github.com/mastra-ai/mastra/commit/59d036d4c2706b430b0e3f1f1e0ee853ce16ca04)]:
154
+ - @mastra/core@0.21.0-alpha.0
155
+
156
+ ## 0.1.6
157
+
158
+ ### Patch Changes
159
+
160
+ - Breaking change to move the agent.streamVNext/generateVNext implementation to the default stream/generate. The old stream/generate have now been moved to streamLegacy and generateLegacy ([#8097](https://github.com/mastra-ai/mastra/pull/8097))
161
+
162
+ - Updated dependencies [[`00cb6bd`](https://github.com/mastra-ai/mastra/commit/00cb6bdf78737c0fac14a5a0c7b532a11e38558a), [`869ba22`](https://github.com/mastra-ai/mastra/commit/869ba222e1d6b58fc1b65e7c9fd55ca4e01b8c2f), [`1b73665`](https://github.com/mastra-ai/mastra/commit/1b73665e8e23f5c09d49fcf3e7d709c75259259e), [`f7d7475`](https://github.com/mastra-ai/mastra/commit/f7d747507341aef60ed39e4b49318db1f86034a6), [`084b77b`](https://github.com/mastra-ai/mastra/commit/084b77b2955960e0190af8db3f77138aa83ed65c), [`a93ff84`](https://github.com/mastra-ai/mastra/commit/a93ff84b5e1af07ee236ac8873dac9b49aa5d501), [`bc5aacb`](https://github.com/mastra-ai/mastra/commit/bc5aacb646d468d325327e36117129f28cd13bf6), [`6b5af12`](https://github.com/mastra-ai/mastra/commit/6b5af12ce9e09066e0c32e821c203a6954498bea), [`bf60e4a`](https://github.com/mastra-ai/mastra/commit/bf60e4a89c515afd9570b7b79f33b95e7d07c397), [`d41aee5`](https://github.com/mastra-ai/mastra/commit/d41aee526d124e35f42720a08e64043229193679), [`e8fe13c`](https://github.com/mastra-ai/mastra/commit/e8fe13c4b4c255a42520127797ec394310f7c919), [`3ca833d`](https://github.com/mastra-ai/mastra/commit/3ca833dc994c38e3c9b4f9b4478a61cd8e07b32a), [`1edb8d1`](https://github.com/mastra-ai/mastra/commit/1edb8d1cfb963e72a12412990fb9170936c9904c), [`fbf6e32`](https://github.com/mastra-ai/mastra/commit/fbf6e324946332d0f5ed8930bf9d4d4479cefd7a), [`4753027`](https://github.com/mastra-ai/mastra/commit/4753027ee889288775c6958bdfeda03ff909af67)]:
163
+ - @mastra/core@0.20.0
164
+
165
+ ## 0.1.6-alpha.0
166
+
167
+ ### Patch Changes
168
+
169
+ - Breaking change to move the agent.streamVNext/generateVNext implementation to the default stream/generate. The old stream/generate have now been moved to streamLegacy and generateLegacy ([#8097](https://github.com/mastra-ai/mastra/pull/8097))
170
+
171
+ - Updated dependencies [[`00cb6bd`](https://github.com/mastra-ai/mastra/commit/00cb6bdf78737c0fac14a5a0c7b532a11e38558a), [`869ba22`](https://github.com/mastra-ai/mastra/commit/869ba222e1d6b58fc1b65e7c9fd55ca4e01b8c2f), [`1b73665`](https://github.com/mastra-ai/mastra/commit/1b73665e8e23f5c09d49fcf3e7d709c75259259e), [`f7d7475`](https://github.com/mastra-ai/mastra/commit/f7d747507341aef60ed39e4b49318db1f86034a6), [`084b77b`](https://github.com/mastra-ai/mastra/commit/084b77b2955960e0190af8db3f77138aa83ed65c), [`a93ff84`](https://github.com/mastra-ai/mastra/commit/a93ff84b5e1af07ee236ac8873dac9b49aa5d501), [`bc5aacb`](https://github.com/mastra-ai/mastra/commit/bc5aacb646d468d325327e36117129f28cd13bf6), [`6b5af12`](https://github.com/mastra-ai/mastra/commit/6b5af12ce9e09066e0c32e821c203a6954498bea), [`bf60e4a`](https://github.com/mastra-ai/mastra/commit/bf60e4a89c515afd9570b7b79f33b95e7d07c397), [`d41aee5`](https://github.com/mastra-ai/mastra/commit/d41aee526d124e35f42720a08e64043229193679), [`e8fe13c`](https://github.com/mastra-ai/mastra/commit/e8fe13c4b4c255a42520127797ec394310f7c919), [`3ca833d`](https://github.com/mastra-ai/mastra/commit/3ca833dc994c38e3c9b4f9b4478a61cd8e07b32a), [`1edb8d1`](https://github.com/mastra-ai/mastra/commit/1edb8d1cfb963e72a12412990fb9170936c9904c), [`fbf6e32`](https://github.com/mastra-ai/mastra/commit/fbf6e324946332d0f5ed8930bf9d4d4479cefd7a), [`4753027`](https://github.com/mastra-ai/mastra/commit/4753027ee889288775c6958bdfeda03ff909af67)]:
172
+ - @mastra/core@0.20.0-alpha.0
173
+
174
+ ## 0.1.5
175
+
176
+ ### Patch Changes
177
+
178
+ - Update peer deps ([#8154](https://github.com/mastra-ai/mastra/pull/8154))
179
+
180
+ - Updated dependencies [[`dc099b4`](https://github.com/mastra-ai/mastra/commit/dc099b40fb31147ba3f362f98d991892033c4c67), [`504438b`](https://github.com/mastra-ai/mastra/commit/504438b961bde211071186bba63a842c4e3db879), [`b342a68`](https://github.com/mastra-ai/mastra/commit/b342a68e1399cf1ece9ba11bda112db89d21118c), [`a7243e2`](https://github.com/mastra-ai/mastra/commit/a7243e2e58762667a6e3921e755e89d6bb0a3282), [`7fceb0a`](https://github.com/mastra-ai/mastra/commit/7fceb0a327d678e812f90f5387c5bc4f38bd039e), [`303a9c0`](https://github.com/mastra-ai/mastra/commit/303a9c0d7dd58795915979f06a0512359e4532fb), [`df64f9e`](https://github.com/mastra-ai/mastra/commit/df64f9ef814916fff9baedd861c988084e7c41de), [`370f8a6`](https://github.com/mastra-ai/mastra/commit/370f8a6480faec70fef18d72e5f7538f27004301), [`809eea0`](https://github.com/mastra-ai/mastra/commit/809eea092fa80c3f69b9eaf078d843b57fd2a88e), [`683e5a1`](https://github.com/mastra-ai/mastra/commit/683e5a1466e48b686825b2c11f84680f296138e4), [`3679378`](https://github.com/mastra-ai/mastra/commit/3679378673350aa314741dc826f837b1984149bc), [`7775bc2`](https://github.com/mastra-ai/mastra/commit/7775bc20bb1ad1ab24797fb420e4f96c65b0d8ec), [`623ffaf`](https://github.com/mastra-ai/mastra/commit/623ffaf2d969e11e99a0224633cf7b5a0815c857), [`9fc1613`](https://github.com/mastra-ai/mastra/commit/9fc16136400186648880fd990119ac15f7c02ee4), [`61f62aa`](https://github.com/mastra-ai/mastra/commit/61f62aa31bc88fe4ddf8da6240dbcfbeb07358bd), [`db1891a`](https://github.com/mastra-ai/mastra/commit/db1891a4707443720b7cd8a260dc7e1d49b3609c), [`e8f379d`](https://github.com/mastra-ai/mastra/commit/e8f379d390efa264c4e0874f9ac0cf8839b07777), [`652066b`](https://github.com/mastra-ai/mastra/commit/652066bd1efc6bb6813ba950ed1d7573e8b7d9d4), [`3e292ba`](https://github.com/mastra-ai/mastra/commit/3e292ba00837886d5d68a34cbc0d9b703c991883), [`418c136`](https://github.com/mastra-ai/mastra/commit/418c1366843d88e491bca3f87763899ce855ca29), [`ea8d386`](https://github.com/mastra-ai/mastra/commit/ea8d386cd8c5593664515fd5770c06bf2aa980ef), [`67b0f00`](https://github.com/mastra-ai/mastra/commit/67b0f005b520335c71fb85cbaa25df4ce8484a81), [`c2a4919`](https://github.com/mastra-ai/mastra/commit/c2a4919ba6797d8bdb1509e02287496eef69303e), [`c84b7d0`](https://github.com/mastra-ai/mastra/commit/c84b7d093c4657772140cbfd2b15ef72f3315ed5), [`0130986`](https://github.com/mastra-ai/mastra/commit/0130986fc62d0edcc626dd593282661dbb9af141)]:
181
+ - @mastra/core@0.19.0
182
+
183
+ ## 0.1.5-alpha.0
184
+
185
+ ### Patch Changes
186
+
187
+ - Update peer deps ([#8154](https://github.com/mastra-ai/mastra/pull/8154))
188
+
189
+ - Updated dependencies [[`504438b`](https://github.com/mastra-ai/mastra/commit/504438b961bde211071186bba63a842c4e3db879), [`a7243e2`](https://github.com/mastra-ai/mastra/commit/a7243e2e58762667a6e3921e755e89d6bb0a3282), [`7fceb0a`](https://github.com/mastra-ai/mastra/commit/7fceb0a327d678e812f90f5387c5bc4f38bd039e), [`df64f9e`](https://github.com/mastra-ai/mastra/commit/df64f9ef814916fff9baedd861c988084e7c41de), [`809eea0`](https://github.com/mastra-ai/mastra/commit/809eea092fa80c3f69b9eaf078d843b57fd2a88e), [`683e5a1`](https://github.com/mastra-ai/mastra/commit/683e5a1466e48b686825b2c11f84680f296138e4), [`3679378`](https://github.com/mastra-ai/mastra/commit/3679378673350aa314741dc826f837b1984149bc), [`7775bc2`](https://github.com/mastra-ai/mastra/commit/7775bc20bb1ad1ab24797fb420e4f96c65b0d8ec), [`db1891a`](https://github.com/mastra-ai/mastra/commit/db1891a4707443720b7cd8a260dc7e1d49b3609c), [`e8f379d`](https://github.com/mastra-ai/mastra/commit/e8f379d390efa264c4e0874f9ac0cf8839b07777), [`652066b`](https://github.com/mastra-ai/mastra/commit/652066bd1efc6bb6813ba950ed1d7573e8b7d9d4), [`ea8d386`](https://github.com/mastra-ai/mastra/commit/ea8d386cd8c5593664515fd5770c06bf2aa980ef), [`c2a4919`](https://github.com/mastra-ai/mastra/commit/c2a4919ba6797d8bdb1509e02287496eef69303e), [`0130986`](https://github.com/mastra-ai/mastra/commit/0130986fc62d0edcc626dd593282661dbb9af141)]:
190
+ - @mastra/core@0.19.0-alpha.1
191
+
192
+ ## 0.1.4
193
+
194
+ ### Patch Changes
195
+
196
+ - dependencies updates: ([#8098](https://github.com/mastra-ai/mastra/pull/8098))
197
+ - Updated dependency [`braintrust@^0.3.8` ↗︎](https://www.npmjs.com/package/braintrust/v/0.3.8) (from `^0.3.6`, in `dependencies`)
198
+
199
+ - Fix out of order spans for braintrust exporter ([#7660](https://github.com/mastra-ai/mastra/pull/7660))
200
+
201
+ - Update Peerdeps for packages based on core minor bump ([#8025](https://github.com/mastra-ai/mastra/pull/8025))
202
+
203
+ - Updated dependencies [[`cf34503`](https://github.com/mastra-ai/mastra/commit/cf345031de4e157f29087946449e60b965e9c8a9), [`6b4b1e4`](https://github.com/mastra-ai/mastra/commit/6b4b1e4235428d39e51cbda9832704c0ba70ab32), [`3469fca`](https://github.com/mastra-ai/mastra/commit/3469fca7bb7e5e19369ff9f7044716a5e4b02585), [`a61f23f`](https://github.com/mastra-ai/mastra/commit/a61f23fbbca4b88b763d94f1d784c47895ed72d7), [`4b339b8`](https://github.com/mastra-ai/mastra/commit/4b339b8141c20d6a6d80583c7e8c5c05d8c19492), [`d1dc606`](https://github.com/mastra-ai/mastra/commit/d1dc6067b0557a71190b68d56ee15b48c26d2411), [`c45298a`](https://github.com/mastra-ai/mastra/commit/c45298a0a0791db35cf79f1199d77004da0704cb), [`c4a8204`](https://github.com/mastra-ai/mastra/commit/c4a82046bfd241d6044e234bc5917d5a01fe6b55), [`d3bd4d4`](https://github.com/mastra-ai/mastra/commit/d3bd4d482a685bbb67bfa89be91c90dca3fa71ad), [`c591dfc`](https://github.com/mastra-ai/mastra/commit/c591dfc1e600fae1dedffe239357d250e146378f), [`1920c5c`](https://github.com/mastra-ai/mastra/commit/1920c5c6d666f687785c73021196aa551e579e0d), [`b6a3b65`](https://github.com/mastra-ai/mastra/commit/b6a3b65d830fa0ca7754ad6481661d1f2c878f21), [`af3abb6`](https://github.com/mastra-ai/mastra/commit/af3abb6f7c7585d856e22d27f4e7d2ece2186b9a)]:
204
+ - @mastra/core@0.18.0
205
+
206
+ ## 0.1.4-alpha.1
207
+
208
+ ### Patch Changes
209
+
210
+ - dependencies updates: ([#8098](https://github.com/mastra-ai/mastra/pull/8098))
211
+ - Updated dependency [`braintrust@^0.3.8` ↗︎](https://www.npmjs.com/package/braintrust/v/0.3.8) (from `^0.3.6`, in `dependencies`)
212
+
213
+ - Fix out of order spans for braintrust exporter ([#7660](https://github.com/mastra-ai/mastra/pull/7660))
214
+
215
+ - Updated dependencies [[`4b339b8`](https://github.com/mastra-ai/mastra/commit/4b339b8141c20d6a6d80583c7e8c5c05d8c19492), [`c591dfc`](https://github.com/mastra-ai/mastra/commit/c591dfc1e600fae1dedffe239357d250e146378f), [`1920c5c`](https://github.com/mastra-ai/mastra/commit/1920c5c6d666f687785c73021196aa551e579e0d), [`b6a3b65`](https://github.com/mastra-ai/mastra/commit/b6a3b65d830fa0ca7754ad6481661d1f2c878f21), [`af3abb6`](https://github.com/mastra-ai/mastra/commit/af3abb6f7c7585d856e22d27f4e7d2ece2186b9a)]:
216
+ - @mastra/core@0.18.0-alpha.3
217
+
218
+ ## 0.1.4-alpha.0
219
+
220
+ ### Patch Changes
221
+
222
+ - Update Peerdeps for packages based on core minor bump ([#8025](https://github.com/mastra-ai/mastra/pull/8025))
223
+
224
+ - Updated dependencies [[`cf34503`](https://github.com/mastra-ai/mastra/commit/cf345031de4e157f29087946449e60b965e9c8a9), [`6b4b1e4`](https://github.com/mastra-ai/mastra/commit/6b4b1e4235428d39e51cbda9832704c0ba70ab32), [`3469fca`](https://github.com/mastra-ai/mastra/commit/3469fca7bb7e5e19369ff9f7044716a5e4b02585), [`c4a8204`](https://github.com/mastra-ai/mastra/commit/c4a82046bfd241d6044e234bc5917d5a01fe6b55)]:
225
+ - @mastra/core@0.18.0-alpha.2
226
+
227
+ ## 0.1.3
228
+
229
+ ### Patch Changes
230
+
231
+ - Update peerdep of @mastra/core ([#7619](https://github.com/mastra-ai/mastra/pull/7619))
232
+
233
+ - updated exporter to use a lightweight span for exporting ([#7764](https://github.com/mastra-ai/mastra/pull/7764))
234
+
235
+ - Update package.json and README ([#7886](https://github.com/mastra-ai/mastra/pull/7886))
236
+
237
+ - Updated dependencies [[`197cbb2`](https://github.com/mastra-ai/mastra/commit/197cbb248fc8cb4bbf61bf70b770f1388b445df2), [`a1bb887`](https://github.com/mastra-ai/mastra/commit/a1bb887e8bfae44230f487648da72e96ef824561), [`6590763`](https://github.com/mastra-ai/mastra/commit/65907630ef4bf4127067cecd1cb21b56f55d5f1b), [`fb84c21`](https://github.com/mastra-ai/mastra/commit/fb84c21859d09bdc8f158bd5412bdc4b5835a61c), [`5802bf5`](https://github.com/mastra-ai/mastra/commit/5802bf57f6182e4b67c28d7d91abed349a8d14f3), [`5bda53a`](https://github.com/mastra-ai/mastra/commit/5bda53a9747bfa7d876d754fc92c83a06e503f62), [`c2eade3`](https://github.com/mastra-ai/mastra/commit/c2eade3508ef309662f065e5f340d7840295dd53), [`f26a8fd`](https://github.com/mastra-ai/mastra/commit/f26a8fd99fcb0497a5d86c28324430d7f6a5fb83), [`222965a`](https://github.com/mastra-ai/mastra/commit/222965a98ce8197b86673ec594244650b5960257), [`6047778`](https://github.com/mastra-ai/mastra/commit/6047778e501df460648f31decddf8e443f36e373), [`a0f5f1c`](https://github.com/mastra-ai/mastra/commit/a0f5f1ca39c3c5c6d26202e9fcab986b4fe14568), [`9d4fc09`](https://github.com/mastra-ai/mastra/commit/9d4fc09b2ad55caa7738c7ceb3a905e454f74cdd), [`05c7abf`](https://github.com/mastra-ai/mastra/commit/05c7abfe105a015b7760c9bf33ff4419727502a0), [`0324ceb`](https://github.com/mastra-ai/mastra/commit/0324ceb8af9d16c12a531f90e575f6aab797ac81), [`d75ccf0`](https://github.com/mastra-ai/mastra/commit/d75ccf06dfd2582b916aa12624e3cd61b279edf1), [`0f9d227`](https://github.com/mastra-ai/mastra/commit/0f9d227890a98db33865abbea39daf407cd55ef7), [`b356f5f`](https://github.com/mastra-ai/mastra/commit/b356f5f7566cb3edb755d91f00b72fc1420b2a37), [`de056a0`](https://github.com/mastra-ai/mastra/commit/de056a02cbb43f6aa0380ab2150ea404af9ec0dd), [`f5ce05f`](https://github.com/mastra-ai/mastra/commit/f5ce05f831d42c69559bf4c0fdb46ccb920fc3a3), [`60c9cec`](https://github.com/mastra-ai/mastra/commit/60c9cec7048a79a87440f7840c383875bd710d93), [`c93532a`](https://github.com/mastra-ai/mastra/commit/c93532a340b80e4dd946d4c138d9381de5f70399), [`6cb1fcb`](https://github.com/mastra-ai/mastra/commit/6cb1fcbc8d0378ffed0d17784c96e68f30cb0272), [`aee4f00`](https://github.com/mastra-ai/mastra/commit/aee4f00e61e1a42e81a6d74ff149dbe69e32695a), [`9f6f30f`](https://github.com/mastra-ai/mastra/commit/9f6f30f04ec6648bbca798ea8aad59317c40d8db), [`547c621`](https://github.com/mastra-ai/mastra/commit/547c62104af3f7a551b3754e9cbdf0a3fbba15e4), [`897995e`](https://github.com/mastra-ai/mastra/commit/897995e630d572fe2891e7ede817938cabb43251), [`0fed8f2`](https://github.com/mastra-ai/mastra/commit/0fed8f2aa84b167b3415ea6f8f70755775132c8d), [`4f9ea8c`](https://github.com/mastra-ai/mastra/commit/4f9ea8c95ea74ba9abbf3b2ab6106c7d7bc45689), [`1a1fbe6`](https://github.com/mastra-ai/mastra/commit/1a1fbe66efb7d94abc373ed0dd9676adb8122454), [`d706fad`](https://github.com/mastra-ai/mastra/commit/d706fad6e6e4b72357b18d229ba38e6c913c0e70), [`87fd07f`](https://github.com/mastra-ai/mastra/commit/87fd07ff35387a38728967163460231b5d33ae3b), [`5c3768f`](https://github.com/mastra-ai/mastra/commit/5c3768fa959454232ad76715c381f4aac00c6881), [`2685a78`](https://github.com/mastra-ai/mastra/commit/2685a78f224b8b04e20d4fab5ac1adb638190071), [`36f39c0`](https://github.com/mastra-ai/mastra/commit/36f39c00dc794952dc3c11aab91c2fa8bca74b11), [`239b5a4`](https://github.com/mastra-ai/mastra/commit/239b5a497aeae2e8b4d764f46217cfff2284788e), [`8a3f5e4`](https://github.com/mastra-ai/mastra/commit/8a3f5e4212ec36b302957deb4bd47005ab598382)]:
238
+ - @mastra/core@0.17.0
239
+
240
+ ## 0.1.3-alpha.2
241
+
242
+ ### Patch Changes
243
+
244
+ - Update package.json and README ([#7886](https://github.com/mastra-ai/mastra/pull/7886))
245
+
246
+ - Updated dependencies [[`fb84c21`](https://github.com/mastra-ai/mastra/commit/fb84c21859d09bdc8f158bd5412bdc4b5835a61c), [`9d4fc09`](https://github.com/mastra-ai/mastra/commit/9d4fc09b2ad55caa7738c7ceb3a905e454f74cdd), [`d75ccf0`](https://github.com/mastra-ai/mastra/commit/d75ccf06dfd2582b916aa12624e3cd61b279edf1), [`0fed8f2`](https://github.com/mastra-ai/mastra/commit/0fed8f2aa84b167b3415ea6f8f70755775132c8d), [`87fd07f`](https://github.com/mastra-ai/mastra/commit/87fd07ff35387a38728967163460231b5d33ae3b)]:
247
+ - @mastra/core@0.17.0-alpha.4
248
+
249
+ ## 0.1.3-alpha.1
250
+
251
+ ### Patch Changes
252
+
253
+ - Update peerdep of @mastra/core ([#7619](https://github.com/mastra-ai/mastra/pull/7619))
254
+
255
+ - Updated dependencies [[`a1bb887`](https://github.com/mastra-ai/mastra/commit/a1bb887e8bfae44230f487648da72e96ef824561), [`a0f5f1c`](https://github.com/mastra-ai/mastra/commit/a0f5f1ca39c3c5c6d26202e9fcab986b4fe14568), [`b356f5f`](https://github.com/mastra-ai/mastra/commit/b356f5f7566cb3edb755d91f00b72fc1420b2a37), [`f5ce05f`](https://github.com/mastra-ai/mastra/commit/f5ce05f831d42c69559bf4c0fdb46ccb920fc3a3), [`9f6f30f`](https://github.com/mastra-ai/mastra/commit/9f6f30f04ec6648bbca798ea8aad59317c40d8db), [`d706fad`](https://github.com/mastra-ai/mastra/commit/d706fad6e6e4b72357b18d229ba38e6c913c0e70), [`5c3768f`](https://github.com/mastra-ai/mastra/commit/5c3768fa959454232ad76715c381f4aac00c6881), [`8a3f5e4`](https://github.com/mastra-ai/mastra/commit/8a3f5e4212ec36b302957deb4bd47005ab598382)]:
256
+ - @mastra/core@0.17.0-alpha.3
257
+
258
+ ## 0.1.3-alpha.0
259
+
260
+ ### Patch Changes
261
+
262
+ - updated exporter to use a lightweight span for exporting ([#7764](https://github.com/mastra-ai/mastra/pull/7764))
263
+
264
+ - Updated dependencies [[`5802bf5`](https://github.com/mastra-ai/mastra/commit/5802bf57f6182e4b67c28d7d91abed349a8d14f3), [`5bda53a`](https://github.com/mastra-ai/mastra/commit/5bda53a9747bfa7d876d754fc92c83a06e503f62), [`f26a8fd`](https://github.com/mastra-ai/mastra/commit/f26a8fd99fcb0497a5d86c28324430d7f6a5fb83), [`1a1fbe6`](https://github.com/mastra-ai/mastra/commit/1a1fbe66efb7d94abc373ed0dd9676adb8122454), [`36f39c0`](https://github.com/mastra-ai/mastra/commit/36f39c00dc794952dc3c11aab91c2fa8bca74b11)]:
265
+ - @mastra/core@0.16.4-alpha.0
266
+
267
+ ## 0.1.2
268
+
269
+ ### Patch Changes
270
+
271
+ - "updated observability config" ([#7641](https://github.com/mastra-ai/mastra/pull/7641))
272
+
273
+ - Updated dependencies [[`b4379f7`](https://github.com/mastra-ai/mastra/commit/b4379f703fd74474f253420e8c3a684f2c4b2f8e), [`2a6585f`](https://github.com/mastra-ai/mastra/commit/2a6585f7cb71f023f805d521d1c3c95fb9a3aa59), [`3d26e83`](https://github.com/mastra-ai/mastra/commit/3d26e8353a945719028f087cc6ac4b06f0ce27d2), [`dd9119b`](https://github.com/mastra-ai/mastra/commit/dd9119b175a8f389082f75c12750e51f96d65dca), [`d34aaa1`](https://github.com/mastra-ai/mastra/commit/d34aaa1da5d3c5f991740f59e2fe6d28d3e2dd91), [`56e55d1`](https://github.com/mastra-ai/mastra/commit/56e55d1e9eb63e7d9e41aa46e012aae471256812), [`ce1e580`](https://github.com/mastra-ai/mastra/commit/ce1e580f6391e94a0c6816a9c5db0a21566a262f), [`b2babfa`](https://github.com/mastra-ai/mastra/commit/b2babfa9e75b22f2759179e71d8473f6dc5421ed), [`d8c3ba5`](https://github.com/mastra-ai/mastra/commit/d8c3ba516f4173282d293f7e64769cfc8738d360), [`a566c4e`](https://github.com/mastra-ai/mastra/commit/a566c4e92d86c1671707c54359b1d33934f7cc13), [`af333aa`](https://github.com/mastra-ai/mastra/commit/af333aa30fe6d1b127024b03a64736c46eddeca2), [`3863c52`](https://github.com/mastra-ai/mastra/commit/3863c52d44b4e5779968b802d977e87adf939d8e), [`6424c7e`](https://github.com/mastra-ai/mastra/commit/6424c7ec38b6921d66212431db1e0958f441b2a7), [`db94750`](https://github.com/mastra-ai/mastra/commit/db94750a41fd29b43eb1f7ce8e97ba8b9978c91b), [`a66a371`](https://github.com/mastra-ai/mastra/commit/a66a3716b00553d7f01842be9deb34f720b10fab), [`69fc3cd`](https://github.com/mastra-ai/mastra/commit/69fc3cd0fd814901785bdcf49bf536ab1e7fd975)]:
274
+ - @mastra/core@0.16.3
275
+
276
+ ## 0.1.2-alpha.0
277
+
278
+ ### Patch Changes
279
+
280
+ - "updated observability config" ([#7641](https://github.com/mastra-ai/mastra/pull/7641))
281
+
282
+ - Updated dependencies [[`b4379f7`](https://github.com/mastra-ai/mastra/commit/b4379f703fd74474f253420e8c3a684f2c4b2f8e), [`dd9119b`](https://github.com/mastra-ai/mastra/commit/dd9119b175a8f389082f75c12750e51f96d65dca), [`d34aaa1`](https://github.com/mastra-ai/mastra/commit/d34aaa1da5d3c5f991740f59e2fe6d28d3e2dd91), [`ce1e580`](https://github.com/mastra-ai/mastra/commit/ce1e580f6391e94a0c6816a9c5db0a21566a262f), [`b2babfa`](https://github.com/mastra-ai/mastra/commit/b2babfa9e75b22f2759179e71d8473f6dc5421ed), [`d8c3ba5`](https://github.com/mastra-ai/mastra/commit/d8c3ba516f4173282d293f7e64769cfc8738d360), [`a566c4e`](https://github.com/mastra-ai/mastra/commit/a566c4e92d86c1671707c54359b1d33934f7cc13), [`af333aa`](https://github.com/mastra-ai/mastra/commit/af333aa30fe6d1b127024b03a64736c46eddeca2), [`3863c52`](https://github.com/mastra-ai/mastra/commit/3863c52d44b4e5779968b802d977e87adf939d8e), [`6424c7e`](https://github.com/mastra-ai/mastra/commit/6424c7ec38b6921d66212431db1e0958f441b2a7), [`db94750`](https://github.com/mastra-ai/mastra/commit/db94750a41fd29b43eb1f7ce8e97ba8b9978c91b), [`a66a371`](https://github.com/mastra-ai/mastra/commit/a66a3716b00553d7f01842be9deb34f720b10fab), [`69fc3cd`](https://github.com/mastra-ai/mastra/commit/69fc3cd0fd814901785bdcf49bf536ab1e7fd975)]:
283
+ - @mastra/core@0.16.3-alpha.0
284
+
285
+ ## 0.1.1
286
+
287
+ ### Patch Changes
288
+
289
+ - add projectName as a top-level field and transform usage metrics for Braintrust ([#7596](https://github.com/mastra-ai/mastra/pull/7596))
290
+
291
+ - Updated dependencies [[`47b6dc9`](https://github.com/mastra-ai/mastra/commit/47b6dc94f4976d4f3d3882e8f19eb365bbc5976c), [`827d876`](https://github.com/mastra-ai/mastra/commit/827d8766f36a900afcaf64a040f7ba76249009b3), [`0662d02`](https://github.com/mastra-ai/mastra/commit/0662d02ef16916e67531890639fcd72c69cfb6e2), [`565d65f`](https://github.com/mastra-ai/mastra/commit/565d65fc16314a99f081975ec92f2636dff0c86d), [`6189844`](https://github.com/mastra-ai/mastra/commit/61898448e65bda02bb814fb15801a89dc6476938), [`4da3d68`](https://github.com/mastra-ai/mastra/commit/4da3d68a778e5c4d5a17351ef223289fe2f45a45), [`fd9bbfe`](https://github.com/mastra-ai/mastra/commit/fd9bbfee22484f8493582325f53e8171bf8e682b), [`7eaf1d1`](https://github.com/mastra-ai/mastra/commit/7eaf1d1cec7e828d7a98efc2a748ac395bbdba3b), [`6f046b5`](https://github.com/mastra-ai/mastra/commit/6f046b5ccc5c8721302a9a61d5d16c12374cc8d7), [`d7a8f59`](https://github.com/mastra-ai/mastra/commit/d7a8f59154b0621aec4f41a6b2ea2b3882f03cb7), [`0b0bbb2`](https://github.com/mastra-ai/mastra/commit/0b0bbb24f4198ead69792e92b68a350f52b45cf3), [`d951f41`](https://github.com/mastra-ai/mastra/commit/d951f41771e4e5da8da4b9f870949f9509e38756), [`4dda259`](https://github.com/mastra-ai/mastra/commit/4dda2593b6343f9258671de5fb237aeba3ef6bb7), [`8049e2e`](https://github.com/mastra-ai/mastra/commit/8049e2e8cce80a00353c64894c62b695ac34e35e), [`f3427cd`](https://github.com/mastra-ai/mastra/commit/f3427cdaf9eecd63360dfc897a4acbf5f4143a4e), [`defed1c`](https://github.com/mastra-ai/mastra/commit/defed1ca8040cc8d42e645c5a50a1bc52a4918d7), [`6991ced`](https://github.com/mastra-ai/mastra/commit/6991cedcb5a44a49d9fe58ef67926e1f96ba55b1), [`9cb9c42`](https://github.com/mastra-ai/mastra/commit/9cb9c422854ee81074989dd2d8dccc0500ba8d3e), [`8334859`](https://github.com/mastra-ai/mastra/commit/83348594d4f37b311ba4a94d679c5f8721d796d4), [`05f13b8`](https://github.com/mastra-ai/mastra/commit/05f13b8fb269ccfc4de98e9db58dbe16eae55a5e)]:
292
+ - @mastra/core@0.16.1
293
+
294
+ ## 0.1.1-alpha.0
295
+
296
+ ### Patch Changes
297
+
298
+ - add projectName as a top-level field and transform usage metrics for Braintrust ([#7596](https://github.com/mastra-ai/mastra/pull/7596))
299
+
300
+ - Updated dependencies [[`47b6dc9`](https://github.com/mastra-ai/mastra/commit/47b6dc94f4976d4f3d3882e8f19eb365bbc5976c), [`565d65f`](https://github.com/mastra-ai/mastra/commit/565d65fc16314a99f081975ec92f2636dff0c86d), [`4da3d68`](https://github.com/mastra-ai/mastra/commit/4da3d68a778e5c4d5a17351ef223289fe2f45a45), [`0b0bbb2`](https://github.com/mastra-ai/mastra/commit/0b0bbb24f4198ead69792e92b68a350f52b45cf3), [`d951f41`](https://github.com/mastra-ai/mastra/commit/d951f41771e4e5da8da4b9f870949f9509e38756), [`8049e2e`](https://github.com/mastra-ai/mastra/commit/8049e2e8cce80a00353c64894c62b695ac34e35e)]:
301
+ - @mastra/core@0.16.1-alpha.1
302
+
303
+ ## 0.1.0
304
+
305
+ ### Minor Changes
306
+
307
+ - 3fc9261: "Initial release of BraintrustExporter for ai-observability"
308
+
309
+ ### Patch Changes
310
+
311
+ - 376913a: Update peerdeps
312
+ - Updated dependencies [8fbf79e]
313
+ - Updated dependencies [fd83526]
314
+ - Updated dependencies [d0b90ab]
315
+ - Updated dependencies [6f5eb7a]
316
+ - Updated dependencies [a01cf14]
317
+ - Updated dependencies [a9e50ee]
318
+ - Updated dependencies [5397eb4]
319
+ - Updated dependencies [c9f4e4a]
320
+ - Updated dependencies [0acbc80]
321
+ - @mastra/core@0.16.0
322
+
323
+ ## 0.1.0-alpha.1
324
+
325
+ ### Patch Changes
326
+
327
+ - 376913a: Update peerdeps
328
+ - Updated dependencies [8fbf79e]
329
+ - @mastra/core@0.16.0-alpha.1
330
+
331
+ ## 0.1.0-alpha.0
332
+
333
+ ### Minor Changes
334
+
335
+ - 3fc9261: "Initial release of BraintrustExporter for ai-observability"
336
+
337
+ ### Patch Changes
338
+
339
+ - Updated dependencies [fd83526]
340
+ - Updated dependencies [d0b90ab]
341
+ - Updated dependencies [6f5eb7a]
342
+ - Updated dependencies [a01cf14]
343
+ - Updated dependencies [a9e50ee]
344
+ - Updated dependencies [5397eb4]
345
+ - Updated dependencies [c9f4e4a]
346
+ - Updated dependencies [0acbc80]
347
+ - @mastra/core@0.16.0-alpha.0
package/LICENSE.md ADDED
@@ -0,0 +1,15 @@
1
+ # Apache License 2.0
2
+
3
+ Copyright (c) 2025 Kepler Software, Inc.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # @mastra/braintrust
2
+
3
+ Braintrust AI Observability exporter for Mastra applications.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @mastra/braintrust
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { BraintrustExporter } from '@mastra/braintrust';
15
+
16
+ // Use with Mastra
17
+ const mastra = new Mastra({
18
+ ...,
19
+ observability: {
20
+ configs: {
21
+ braintrust: {
22
+ serviceName: 'service',
23
+ exporters: [
24
+ new BraintrustExporter({
25
+ apiKey: process.env.BRAINTRUST_API_KEY,
26
+ projectName: "mastra-tracing", // optional
27
+ endpoint: process.env.BRAINTRUST_ENDPOINT, // optional
28
+ }),
29
+ ],
30
+ },
31
+ },
32
+ },
33
+ });
34
+ ```
35
+
36
+ ## Features
37
+
38
+ ### Tracing
39
+
40
+ - **Automatic span mapping**: Root spans become Braintrust traces
41
+ - **Type-specific metadata**: Extracts relevant metadata for each span type (agents, tools, workflows)
42
+ - **Error tracking**: Automatic error status and message tracking
43
+ - **Hierarchical traces**: Maintains parent-child relationships
44
+ - **Event span support**: Zero-duration spans for event-type traces
package/dist/index.cjs ADDED
@@ -0,0 +1,279 @@
1
+ 'use strict';
2
+
3
+ var observability$1 = require('@mastra/core/observability');
4
+ var utils = require('@mastra/core/utils');
5
+ var observability = require('@mastra/observability');
6
+ var braintrust = require('braintrust');
7
+
8
+ // src/tracing.ts
9
+
10
+ // src/metrics.ts
11
+ function normalizeUsageMetrics(modelAttr) {
12
+ const metrics = {};
13
+ if (modelAttr.usage?.inputTokens !== void 0) {
14
+ metrics.prompt_tokens = modelAttr.usage?.inputTokens;
15
+ } else if (modelAttr.usage?.promptTokens !== void 0) {
16
+ metrics.prompt_tokens = modelAttr.usage?.promptTokens;
17
+ }
18
+ if (modelAttr.usage?.outputTokens !== void 0) {
19
+ metrics.completion_tokens = modelAttr.usage?.outputTokens;
20
+ } else if (modelAttr.usage?.completionTokens !== void 0) {
21
+ metrics.completion_tokens = modelAttr.usage?.completionTokens;
22
+ }
23
+ if (modelAttr.usage?.totalTokens !== void 0) {
24
+ metrics.tokens = modelAttr.usage?.totalTokens;
25
+ }
26
+ if (modelAttr.usage?.reasoningTokens !== void 0) {
27
+ metrics.completion_reasoning_tokens = modelAttr.usage?.reasoningTokens;
28
+ }
29
+ if (modelAttr.usage?.promptCacheHitTokens !== void 0) {
30
+ metrics.prompt_cached_tokens = modelAttr.usage?.promptCacheHitTokens;
31
+ }
32
+ if (modelAttr.usage?.promptCacheMissTokens !== void 0) {
33
+ metrics.prompt_cache_creation_tokens = modelAttr.usage?.promptCacheMissTokens;
34
+ }
35
+ return metrics;
36
+ }
37
+
38
+ // src/tracing.ts
39
+ var DEFAULT_SPAN_TYPE = "task";
40
+ var SPAN_TYPE_EXCEPTIONS = {
41
+ [observability$1.SpanType.MODEL_GENERATION]: "llm",
42
+ [observability$1.SpanType.MODEL_CHUNK]: "llm",
43
+ [observability$1.SpanType.TOOL_CALL]: "tool",
44
+ [observability$1.SpanType.MCP_TOOL_CALL]: "tool",
45
+ [observability$1.SpanType.WORKFLOW_CONDITIONAL_EVAL]: "function",
46
+ [observability$1.SpanType.WORKFLOW_WAIT_EVENT]: "function"
47
+ };
48
+ function mapSpanType(spanType) {
49
+ return SPAN_TYPE_EXCEPTIONS[spanType] ?? DEFAULT_SPAN_TYPE;
50
+ }
51
+ var BraintrustExporter = class extends observability.BaseExporter {
52
+ name = "braintrust";
53
+ traceMap = /* @__PURE__ */ new Map();
54
+ config;
55
+ constructor(config) {
56
+ super(config);
57
+ if (!config.apiKey) {
58
+ this.setDisabled(`Missing required credentials (apiKey: ${!!config.apiKey})`);
59
+ this.config = null;
60
+ return;
61
+ }
62
+ this.config = config;
63
+ }
64
+ async _exportTracingEvent(event) {
65
+ if (event.exportedSpan.isEvent) {
66
+ await this.handleEventSpan(event.exportedSpan);
67
+ return;
68
+ }
69
+ switch (event.type) {
70
+ case "span_started":
71
+ await this.handleSpanStarted(event.exportedSpan);
72
+ break;
73
+ case "span_updated":
74
+ await this.handleSpanUpdateOrEnd(event.exportedSpan, false);
75
+ break;
76
+ case "span_ended":
77
+ await this.handleSpanUpdateOrEnd(event.exportedSpan, true);
78
+ break;
79
+ }
80
+ }
81
+ async handleSpanStarted(span) {
82
+ if (span.isRootSpan) {
83
+ await this.initLogger(span);
84
+ }
85
+ const method = "handleSpanStarted";
86
+ const spanData = this.getSpanData({ span, method });
87
+ if (!spanData) {
88
+ return;
89
+ }
90
+ if (!span.isEvent) {
91
+ spanData.activeIds.add(span.id);
92
+ }
93
+ const braintrustParent = this.getBraintrustParent({ spanData, span, method });
94
+ if (!braintrustParent) {
95
+ return;
96
+ }
97
+ const payload = this.buildSpanPayload(span);
98
+ const braintrustSpan = braintrustParent.startSpan({
99
+ spanId: span.id,
100
+ name: span.name,
101
+ type: mapSpanType(span.type),
102
+ parentSpanIds: span.parentSpanId ? { spanId: span.parentSpanId, rootSpanId: span.traceId } : { spanId: span.traceId, rootSpanId: span.traceId },
103
+ ...payload
104
+ });
105
+ spanData.spans.set(span.id, braintrustSpan);
106
+ }
107
+ async handleSpanUpdateOrEnd(span, isEnd) {
108
+ const method = isEnd ? "handleSpanEnd" : "handleSpanUpdate";
109
+ const spanData = this.getSpanData({ span, method });
110
+ if (!spanData) {
111
+ return;
112
+ }
113
+ const braintrustSpan = spanData.spans.get(span.id);
114
+ if (!braintrustSpan) {
115
+ this.logger.warn("Braintrust exporter: No Braintrust span found for span update/end", {
116
+ traceId: span.traceId,
117
+ spanId: span.id,
118
+ spanName: span.name,
119
+ spanType: span.type,
120
+ isRootSpan: span.isRootSpan,
121
+ parentSpanId: span.parentSpanId,
122
+ method
123
+ });
124
+ return;
125
+ }
126
+ braintrustSpan.log(this.buildSpanPayload(span));
127
+ if (isEnd) {
128
+ if (span.endTime) {
129
+ braintrustSpan.end({ endTime: span.endTime.getTime() / 1e3 });
130
+ } else {
131
+ braintrustSpan.end();
132
+ }
133
+ if (!span.isEvent) {
134
+ spanData.activeIds.delete(span.id);
135
+ }
136
+ if (spanData.activeIds.size === 0) {
137
+ this.traceMap.delete(span.traceId);
138
+ }
139
+ }
140
+ }
141
+ async handleEventSpan(span) {
142
+ if (span.isRootSpan) {
143
+ this.logger.debug("Braintrust exporter: Creating logger for event", {
144
+ traceId: span.traceId,
145
+ spanId: span.id,
146
+ spanName: span.name,
147
+ method: "handleEventSpan"
148
+ });
149
+ await this.initLogger(span);
150
+ }
151
+ const method = "handleEventSpan";
152
+ const spanData = this.getSpanData({ span, method });
153
+ if (!spanData) {
154
+ return;
155
+ }
156
+ const braintrustParent = this.getBraintrustParent({ spanData, span, method });
157
+ if (!braintrustParent) {
158
+ return;
159
+ }
160
+ const payload = this.buildSpanPayload(span);
161
+ const braintrustSpan = braintrustParent.startSpan({
162
+ spanId: span.id,
163
+ name: span.name,
164
+ type: mapSpanType(span.type),
165
+ parentSpanIds: span.parentSpanId ? { spanId: span.parentSpanId, rootSpanId: span.traceId } : { spanId: span.traceId, rootSpanId: span.traceId },
166
+ startTime: span.startTime.getTime() / 1e3,
167
+ ...payload
168
+ });
169
+ braintrustSpan.end({ endTime: span.startTime.getTime() / 1e3 });
170
+ }
171
+ async initLogger(span) {
172
+ const logger = await braintrust.initLogger({
173
+ projectName: this.config.projectName ?? "mastra-tracing",
174
+ apiKey: this.config.apiKey,
175
+ appUrl: this.config.endpoint,
176
+ ...this.config.tuningParameters
177
+ });
178
+ this.traceMap.set(span.traceId, { logger, spans: /* @__PURE__ */ new Map(), activeIds: /* @__PURE__ */ new Set() });
179
+ }
180
+ getSpanData(options) {
181
+ const { span, method } = options;
182
+ if (this.traceMap.has(span.traceId)) {
183
+ return this.traceMap.get(span.traceId);
184
+ }
185
+ this.logger.warn("Braintrust exporter: No span data found for span", {
186
+ traceId: span.traceId,
187
+ spanId: span.id,
188
+ spanName: span.name,
189
+ spanType: span.type,
190
+ isRootSpan: span.isRootSpan,
191
+ parentSpanId: span.parentSpanId,
192
+ method
193
+ });
194
+ }
195
+ getBraintrustParent(options) {
196
+ const { spanData, span, method } = options;
197
+ const parentId = span.parentSpanId;
198
+ if (!parentId) {
199
+ return spanData.logger;
200
+ }
201
+ if (spanData.spans.has(parentId)) {
202
+ return spanData.spans.get(parentId);
203
+ }
204
+ if (parentId && !spanData.spans.has(parentId)) {
205
+ return spanData.logger;
206
+ }
207
+ this.logger.warn("Braintrust exporter: No parent data found for span", {
208
+ traceId: span.traceId,
209
+ spanId: span.id,
210
+ spanName: span.name,
211
+ spanType: span.type,
212
+ isRootSpan: span.isRootSpan,
213
+ parentSpanId: span.parentSpanId,
214
+ method
215
+ });
216
+ }
217
+ buildSpanPayload(span) {
218
+ const payload = {};
219
+ if (span.input !== void 0) {
220
+ payload.input = span.input;
221
+ }
222
+ if (span.output !== void 0) {
223
+ payload.output = span.output;
224
+ }
225
+ payload.metrics = {};
226
+ payload.metadata = {
227
+ spanType: span.type,
228
+ ...span.metadata
229
+ };
230
+ const attributes = span.attributes ?? {};
231
+ if (span.type === observability$1.SpanType.MODEL_GENERATION) {
232
+ const modelAttr = attributes;
233
+ if (modelAttr.model !== void 0) {
234
+ payload.metadata.model = modelAttr.model;
235
+ }
236
+ if (modelAttr.provider !== void 0) {
237
+ payload.metadata.provider = modelAttr.provider;
238
+ }
239
+ payload.metrics = normalizeUsageMetrics(modelAttr);
240
+ if (modelAttr.parameters !== void 0) {
241
+ payload.metadata.modelParameters = modelAttr.parameters;
242
+ }
243
+ const otherAttributes = utils.omitKeys(attributes, ["model", "usage", "parameters"]);
244
+ payload.metadata = {
245
+ ...payload.metadata,
246
+ ...otherAttributes
247
+ };
248
+ } else {
249
+ payload.metadata = {
250
+ ...payload.metadata,
251
+ ...attributes
252
+ };
253
+ }
254
+ if (span.errorInfo) {
255
+ payload.error = span.errorInfo.message;
256
+ payload.metadata.errorDetails = span.errorInfo;
257
+ }
258
+ if (Object.keys(payload.metrics).length === 0) {
259
+ delete payload.metrics;
260
+ }
261
+ return payload;
262
+ }
263
+ async shutdown() {
264
+ if (!this.config) {
265
+ return;
266
+ }
267
+ for (const [_traceId, spanData] of this.traceMap) {
268
+ for (const [_spanId, span] of spanData.spans) {
269
+ span.end();
270
+ }
271
+ }
272
+ this.traceMap.clear();
273
+ await super.shutdown();
274
+ }
275
+ };
276
+
277
+ exports.BraintrustExporter = BraintrustExporter;
278
+ //# sourceMappingURL=index.cjs.map
279
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1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CAAQ,QAAA,GAAW;AAAA,QACjB,GAAG,OAAA,CAAQ,QAAA;AAAA,QACX,GAAG;AAAA,OACL;AAAA,IACF;AAGA,IAAA,IAAI,KAAK,SAAA,EAAW;AAClB,MAAA,OAAA,CAAQ,KAAA,GAAQ,KAAK,SAAA,CAAU,OAAA;AAC/B,MAAA,OAAA,CAAQ,QAAA,CAAS,eAAe,IAAA,CAAK,SAAA;AAAA,IACvC;AAGA,IAAA,IAAI,OAAO,IAAA,CAAK,OAAA,CAAQ,OAAO,CAAA,CAAE,WAAW,CAAA,EAAG;AAC7C,MAAA,OAAO,OAAA,CAAQ,OAAA;AAAA,IACjB;AAEA,IAAA,OAAO,OAAA;AAAA,EACT;AAAA,EAEA,MAAM,QAAA,GAA0B;AAC9B,IAAA,IAAI,CAAC,KAAK,MAAA,EAAQ;AAChB,MAAA;AAAA,IACF;AAGA,IAAA,KAAA,MAAW,CAAC,QAAA,EAAU,QAAQ,CAAA,IAAK,KAAK,QAAA,EAAU;AAChD,MAAA,KAAA,MAAW,CAAC,OAAA,EAAS,IAAI,CAAA,IAAK,SAAS,KAAA,EAAO;AAC5C,QAAA,IAAA,CAAK,GAAA,EAAI;AAAA,MACX;AAAA,IAEF;AACA,IAAA,IAAA,CAAK,SAAS,KAAA,EAAM;AACpB,IAAA,MAAM,MAAM,QAAA,EAAS;AAAA,EACvB;AACF","file":"index.cjs","sourcesContent":["import type { ModelGenerationAttributes } from '@mastra/core/observability';\n/**\n * BraintrustUsageMetrics\n *\n * Canonical metric keys expected by Braintrust for LLM usage accounting.\n * These map various provider/SDK-specific usage fields to a common schema.\n * - prompt_tokens: input-side tokens (aka inputTokens/promptTokens)\n * - completion_tokens: output-side tokens (aka outputTokens/completionTokens)\n * - tokens: total tokens (provided or derived)\n * - completion_reasoning_tokens: reasoning tokens, when available\n * - prompt_cached_tokens: tokens served from cache (provider-specific)\n * - prompt_cache_creation_tokens: tokens used to create cache (provider-specific)\n */\nexport interface BraintrustUsageMetrics {\n prompt_tokens?: number;\n completion_tokens?: number;\n tokens?: number;\n completion_reasoning_tokens?: number;\n prompt_cached_tokens?: number;\n prompt_cache_creation_tokens?: number;\n [key: string]: number | undefined;\n}\n\nexport function normalizeUsageMetrics(modelAttr: ModelGenerationAttributes): BraintrustUsageMetrics {\n const metrics: BraintrustUsageMetrics = {};\n\n if (modelAttr.usage?.inputTokens !== undefined) {\n metrics.prompt_tokens = modelAttr.usage?.inputTokens;\n } else if (modelAttr.usage?.promptTokens !== undefined) {\n metrics.prompt_tokens = modelAttr.usage?.promptTokens;\n }\n\n if (modelAttr.usage?.outputTokens !== undefined) {\n metrics.completion_tokens = modelAttr.usage?.outputTokens;\n } else if (modelAttr.usage?.completionTokens !== undefined) {\n metrics.completion_tokens = modelAttr.usage?.completionTokens;\n }\n\n if (modelAttr.usage?.totalTokens !== undefined) {\n metrics.tokens = modelAttr.usage?.totalTokens;\n }\n if (modelAttr.usage?.reasoningTokens !== undefined) {\n metrics.completion_reasoning_tokens = modelAttr.usage?.reasoningTokens;\n }\n if (modelAttr.usage?.promptCacheHitTokens !== undefined) {\n metrics.prompt_cached_tokens = modelAttr.usage?.promptCacheHitTokens;\n }\n if (modelAttr.usage?.promptCacheMissTokens !== undefined) {\n metrics.prompt_cache_creation_tokens = modelAttr.usage?.promptCacheMissTokens;\n }\n\n return metrics;\n}\n","/**\n * Braintrust Exporter for Mastra Observability\n *\n * This exporter sends observability data to Braintrust.\n * Root spans become top-level Braintrust spans (no trace wrapper).\n * Events are handled as zero-duration spans with matching start/end times.\n */\n\nimport type { TracingEvent, AnyExportedSpan, ModelGenerationAttributes } from '@mastra/core/observability';\nimport { SpanType } from '@mastra/core/observability';\nimport { omitKeys } from '@mastra/core/utils';\nimport { BaseExporter } from '@mastra/observability';\nimport type { BaseExporterConfig } from '@mastra/observability';\nimport { initLogger } from 'braintrust';\nimport type { Span, Logger } from 'braintrust';\nimport { normalizeUsageMetrics } from './metrics';\n\nexport interface BraintrustExporterConfig extends BaseExporterConfig {\n /** Braintrust API key */\n apiKey?: string;\n /** Optional custom endpoint */\n endpoint?: string;\n /** Braintrust project name (default: 'mastra-tracing') */\n projectName?: string;\n /** Support tuning parameters */\n tuningParameters?: Record<string, any>;\n}\n\ntype SpanData = {\n logger: Logger<true>; // Braintrust logger (for root spans)\n spans: Map<string, Span>; // Maps span.id to Braintrust span\n activeIds: Set<string>; // Tracks started (non-event) spans not yet ended, including root\n};\n\n// Default span type for all spans\nconst DEFAULT_SPAN_TYPE = 'task';\n\n// Exceptions to the default mapping\nconst SPAN_TYPE_EXCEPTIONS: Partial<Record<SpanType, string>> = {\n [SpanType.MODEL_GENERATION]: 'llm',\n [SpanType.MODEL_CHUNK]: 'llm',\n [SpanType.TOOL_CALL]: 'tool',\n [SpanType.MCP_TOOL_CALL]: 'tool',\n [SpanType.WORKFLOW_CONDITIONAL_EVAL]: 'function',\n [SpanType.WORKFLOW_WAIT_EVENT]: 'function',\n};\n\n// Mapping function - returns valid Braintrust span types\nfunction mapSpanType(spanType: SpanType): 'llm' | 'score' | 'function' | 'eval' | 'task' | 'tool' {\n return (SPAN_TYPE_EXCEPTIONS[spanType] as any) ?? DEFAULT_SPAN_TYPE;\n}\n\nexport class BraintrustExporter extends BaseExporter {\n name = 'braintrust';\n private traceMap = new Map<string, SpanData>();\n private config: BraintrustExporterConfig;\n\n constructor(config: BraintrustExporterConfig) {\n super(config);\n\n if (!config.apiKey) {\n this.setDisabled(`Missing required credentials (apiKey: ${!!config.apiKey})`);\n this.config = null as any;\n return;\n }\n\n this.config = config;\n }\n\n protected async _exportTracingEvent(event: TracingEvent): Promise<void> {\n if (event.exportedSpan.isEvent) {\n await this.handleEventSpan(event.exportedSpan);\n return;\n }\n\n switch (event.type) {\n case 'span_started':\n await this.handleSpanStarted(event.exportedSpan);\n break;\n case 'span_updated':\n await this.handleSpanUpdateOrEnd(event.exportedSpan, false);\n break;\n case 'span_ended':\n await this.handleSpanUpdateOrEnd(event.exportedSpan, true);\n break;\n }\n }\n\n private async handleSpanStarted(span: AnyExportedSpan): Promise<void> {\n if (span.isRootSpan) {\n await this.initLogger(span);\n }\n\n const method = 'handleSpanStarted';\n const spanData = this.getSpanData({ span, method });\n if (!spanData) {\n return;\n }\n\n // Refcount: track active non-event spans (including root)\n if (!span.isEvent) {\n spanData.activeIds.add(span.id);\n }\n\n const braintrustParent = this.getBraintrustParent({ spanData, span, method });\n if (!braintrustParent) {\n return;\n }\n\n const payload = this.buildSpanPayload(span);\n\n const braintrustSpan = braintrustParent.startSpan({\n spanId: span.id,\n name: span.name,\n type: mapSpanType(span.type),\n parentSpanIds: span.parentSpanId\n ? { spanId: span.parentSpanId, rootSpanId: span.traceId }\n : { spanId: span.traceId, rootSpanId: span.traceId },\n ...payload,\n });\n\n spanData.spans.set(span.id, braintrustSpan);\n }\n\n private async handleSpanUpdateOrEnd(span: AnyExportedSpan, isEnd: boolean): Promise<void> {\n const method = isEnd ? 'handleSpanEnd' : 'handleSpanUpdate';\n\n const spanData = this.getSpanData({ span, method });\n if (!spanData) {\n return;\n }\n\n const braintrustSpan = spanData.spans.get(span.id);\n if (!braintrustSpan) {\n this.logger.warn('Braintrust exporter: No Braintrust span found for span update/end', {\n traceId: span.traceId,\n spanId: span.id,\n spanName: span.name,\n spanType: span.type,\n isRootSpan: span.isRootSpan,\n parentSpanId: span.parentSpanId,\n method,\n });\n return;\n }\n\n braintrustSpan.log(this.buildSpanPayload(span));\n\n if (isEnd) {\n // End the span with the correct endTime (convert milliseconds to seconds)\n if (span.endTime) {\n braintrustSpan.end({ endTime: span.endTime.getTime() / 1000 });\n } else {\n braintrustSpan.end();\n }\n\n // Refcount: mark this span as ended\n if (!span.isEvent) {\n spanData.activeIds.delete(span.id);\n }\n\n // If no more active spans remain for this trace, clean up the trace entry\n if (spanData.activeIds.size === 0) {\n this.traceMap.delete(span.traceId);\n }\n }\n }\n\n private async handleEventSpan(span: AnyExportedSpan): Promise<void> {\n if (span.isRootSpan) {\n this.logger.debug('Braintrust exporter: Creating logger for event', {\n traceId: span.traceId,\n spanId: span.id,\n spanName: span.name,\n method: 'handleEventSpan',\n });\n await this.initLogger(span);\n }\n\n const method = 'handleEventSpan';\n const spanData = this.getSpanData({ span, method });\n if (!spanData) {\n return;\n }\n\n const braintrustParent = this.getBraintrustParent({ spanData, span, method });\n if (!braintrustParent) {\n return;\n }\n\n const payload = this.buildSpanPayload(span);\n\n // Create zero-duration span for event (convert milliseconds to seconds)\n const braintrustSpan = braintrustParent.startSpan({\n spanId: span.id,\n name: span.name,\n type: mapSpanType(span.type),\n parentSpanIds: span.parentSpanId\n ? { spanId: span.parentSpanId, rootSpanId: span.traceId }\n : { spanId: span.traceId, rootSpanId: span.traceId },\n startTime: span.startTime.getTime() / 1000,\n ...payload,\n });\n\n braintrustSpan.end({ endTime: span.startTime.getTime() / 1000 });\n }\n\n private async initLogger(span: AnyExportedSpan): Promise<void> {\n const logger = await initLogger({\n projectName: this.config.projectName ?? 'mastra-tracing',\n apiKey: this.config.apiKey,\n appUrl: this.config.endpoint,\n ...this.config.tuningParameters,\n });\n\n this.traceMap.set(span.traceId, { logger, spans: new Map(), activeIds: new Set() });\n }\n\n private getSpanData(options: { span: AnyExportedSpan; method: string }): SpanData | undefined {\n const { span, method } = options;\n if (this.traceMap.has(span.traceId)) {\n return this.traceMap.get(span.traceId);\n }\n\n this.logger.warn('Braintrust exporter: No span data found for span', {\n traceId: span.traceId,\n spanId: span.id,\n spanName: span.name,\n spanType: span.type,\n isRootSpan: span.isRootSpan,\n parentSpanId: span.parentSpanId,\n method,\n });\n }\n\n private getBraintrustParent(options: {\n spanData: SpanData;\n span: AnyExportedSpan;\n method: string;\n }): Logger<true> | Span | undefined {\n const { spanData, span, method } = options;\n\n const parentId = span.parentSpanId;\n if (!parentId) {\n return spanData.logger;\n }\n\n if (spanData.spans.has(parentId)) {\n return spanData.spans.get(parentId);\n }\n\n // If the parent exists but is the root span (not represented as a Braintrust\n // span because we use the logger as the root), attach to the logger so the\n // span is not orphaned. We need to check if parentSpanId exists but the\n // parent span is not in our spans map (indicating it's the root span).\n if (parentId && !spanData.spans.has(parentId)) {\n // This means the parent exists but isn't tracked as a Braintrust span,\n // which happens when the parent is the root span (we use logger as root)\n return spanData.logger;\n }\n\n this.logger.warn('Braintrust exporter: No parent data found for span', {\n traceId: span.traceId,\n spanId: span.id,\n spanName: span.name,\n spanType: span.type,\n isRootSpan: span.isRootSpan,\n parentSpanId: span.parentSpanId,\n method,\n });\n }\n\n private buildSpanPayload(span: AnyExportedSpan): Record<string, any> {\n const payload: Record<string, any> = {};\n\n // Core span data\n if (span.input !== undefined) {\n payload.input = span.input;\n }\n\n if (span.output !== undefined) {\n payload.output = span.output;\n }\n\n // Initialize metrics and metadata objects\n payload.metrics = {};\n payload.metadata = {\n spanType: span.type,\n ...span.metadata,\n };\n\n const attributes = (span.attributes ?? {}) as Record<string, any>;\n\n if (span.type === SpanType.MODEL_GENERATION) {\n const modelAttr = attributes as ModelGenerationAttributes;\n\n // Model goes to metadata\n if (modelAttr.model !== undefined) {\n payload.metadata.model = modelAttr.model;\n }\n\n // Provider goes to metadata (if provided by attributes)\n if (modelAttr.provider !== undefined) {\n payload.metadata.provider = modelAttr.provider;\n }\n\n // Usage/token info goes to metrics\n payload.metrics = normalizeUsageMetrics(modelAttr);\n\n // Model parameters go to metadata\n if (modelAttr.parameters !== undefined) {\n payload.metadata.modelParameters = modelAttr.parameters;\n }\n\n // Other LLM attributes go to metadata\n const otherAttributes = omitKeys(attributes, ['model', 'usage', 'parameters']);\n payload.metadata = {\n ...payload.metadata,\n ...otherAttributes,\n };\n } else {\n // For non-LLM spans, put all attributes in metadata\n payload.metadata = {\n ...payload.metadata,\n ...attributes,\n };\n }\n\n // Handle errors\n if (span.errorInfo) {\n payload.error = span.errorInfo.message;\n payload.metadata.errorDetails = span.errorInfo;\n }\n\n // Clean up empty metrics object\n if (Object.keys(payload.metrics).length === 0) {\n delete payload.metrics;\n }\n\n return payload;\n }\n\n async shutdown(): Promise<void> {\n if (!this.config) {\n return;\n }\n\n // End all active spans\n for (const [_traceId, spanData] of this.traceMap) {\n for (const [_spanId, span] of spanData.spans) {\n span.end();\n }\n // Loggers don't have an explicit shutdown method\n }\n this.traceMap.clear();\n await super.shutdown();\n }\n}\n"]}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Braintrust Observability Provider for Mastra
3
+ *
4
+ * This package provides Braintrust-specific observability features for Mastra applications.
5
+ * Currently includes tracing support with plans for additional observability features.
6
+ */
7
+ export * from './tracing.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,WAAW,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,277 @@
1
+ import { SpanType } from '@mastra/core/observability';
2
+ import { omitKeys } from '@mastra/core/utils';
3
+ import { BaseExporter } from '@mastra/observability';
4
+ import { initLogger } from 'braintrust';
5
+
6
+ // src/tracing.ts
7
+
8
+ // src/metrics.ts
9
+ function normalizeUsageMetrics(modelAttr) {
10
+ const metrics = {};
11
+ if (modelAttr.usage?.inputTokens !== void 0) {
12
+ metrics.prompt_tokens = modelAttr.usage?.inputTokens;
13
+ } else if (modelAttr.usage?.promptTokens !== void 0) {
14
+ metrics.prompt_tokens = modelAttr.usage?.promptTokens;
15
+ }
16
+ if (modelAttr.usage?.outputTokens !== void 0) {
17
+ metrics.completion_tokens = modelAttr.usage?.outputTokens;
18
+ } else if (modelAttr.usage?.completionTokens !== void 0) {
19
+ metrics.completion_tokens = modelAttr.usage?.completionTokens;
20
+ }
21
+ if (modelAttr.usage?.totalTokens !== void 0) {
22
+ metrics.tokens = modelAttr.usage?.totalTokens;
23
+ }
24
+ if (modelAttr.usage?.reasoningTokens !== void 0) {
25
+ metrics.completion_reasoning_tokens = modelAttr.usage?.reasoningTokens;
26
+ }
27
+ if (modelAttr.usage?.promptCacheHitTokens !== void 0) {
28
+ metrics.prompt_cached_tokens = modelAttr.usage?.promptCacheHitTokens;
29
+ }
30
+ if (modelAttr.usage?.promptCacheMissTokens !== void 0) {
31
+ metrics.prompt_cache_creation_tokens = modelAttr.usage?.promptCacheMissTokens;
32
+ }
33
+ return metrics;
34
+ }
35
+
36
+ // src/tracing.ts
37
+ var DEFAULT_SPAN_TYPE = "task";
38
+ var SPAN_TYPE_EXCEPTIONS = {
39
+ [SpanType.MODEL_GENERATION]: "llm",
40
+ [SpanType.MODEL_CHUNK]: "llm",
41
+ [SpanType.TOOL_CALL]: "tool",
42
+ [SpanType.MCP_TOOL_CALL]: "tool",
43
+ [SpanType.WORKFLOW_CONDITIONAL_EVAL]: "function",
44
+ [SpanType.WORKFLOW_WAIT_EVENT]: "function"
45
+ };
46
+ function mapSpanType(spanType) {
47
+ return SPAN_TYPE_EXCEPTIONS[spanType] ?? DEFAULT_SPAN_TYPE;
48
+ }
49
+ var BraintrustExporter = class extends BaseExporter {
50
+ name = "braintrust";
51
+ traceMap = /* @__PURE__ */ new Map();
52
+ config;
53
+ constructor(config) {
54
+ super(config);
55
+ if (!config.apiKey) {
56
+ this.setDisabled(`Missing required credentials (apiKey: ${!!config.apiKey})`);
57
+ this.config = null;
58
+ return;
59
+ }
60
+ this.config = config;
61
+ }
62
+ async _exportTracingEvent(event) {
63
+ if (event.exportedSpan.isEvent) {
64
+ await this.handleEventSpan(event.exportedSpan);
65
+ return;
66
+ }
67
+ switch (event.type) {
68
+ case "span_started":
69
+ await this.handleSpanStarted(event.exportedSpan);
70
+ break;
71
+ case "span_updated":
72
+ await this.handleSpanUpdateOrEnd(event.exportedSpan, false);
73
+ break;
74
+ case "span_ended":
75
+ await this.handleSpanUpdateOrEnd(event.exportedSpan, true);
76
+ break;
77
+ }
78
+ }
79
+ async handleSpanStarted(span) {
80
+ if (span.isRootSpan) {
81
+ await this.initLogger(span);
82
+ }
83
+ const method = "handleSpanStarted";
84
+ const spanData = this.getSpanData({ span, method });
85
+ if (!spanData) {
86
+ return;
87
+ }
88
+ if (!span.isEvent) {
89
+ spanData.activeIds.add(span.id);
90
+ }
91
+ const braintrustParent = this.getBraintrustParent({ spanData, span, method });
92
+ if (!braintrustParent) {
93
+ return;
94
+ }
95
+ const payload = this.buildSpanPayload(span);
96
+ const braintrustSpan = braintrustParent.startSpan({
97
+ spanId: span.id,
98
+ name: span.name,
99
+ type: mapSpanType(span.type),
100
+ parentSpanIds: span.parentSpanId ? { spanId: span.parentSpanId, rootSpanId: span.traceId } : { spanId: span.traceId, rootSpanId: span.traceId },
101
+ ...payload
102
+ });
103
+ spanData.spans.set(span.id, braintrustSpan);
104
+ }
105
+ async handleSpanUpdateOrEnd(span, isEnd) {
106
+ const method = isEnd ? "handleSpanEnd" : "handleSpanUpdate";
107
+ const spanData = this.getSpanData({ span, method });
108
+ if (!spanData) {
109
+ return;
110
+ }
111
+ const braintrustSpan = spanData.spans.get(span.id);
112
+ if (!braintrustSpan) {
113
+ this.logger.warn("Braintrust exporter: No Braintrust span found for span update/end", {
114
+ traceId: span.traceId,
115
+ spanId: span.id,
116
+ spanName: span.name,
117
+ spanType: span.type,
118
+ isRootSpan: span.isRootSpan,
119
+ parentSpanId: span.parentSpanId,
120
+ method
121
+ });
122
+ return;
123
+ }
124
+ braintrustSpan.log(this.buildSpanPayload(span));
125
+ if (isEnd) {
126
+ if (span.endTime) {
127
+ braintrustSpan.end({ endTime: span.endTime.getTime() / 1e3 });
128
+ } else {
129
+ braintrustSpan.end();
130
+ }
131
+ if (!span.isEvent) {
132
+ spanData.activeIds.delete(span.id);
133
+ }
134
+ if (spanData.activeIds.size === 0) {
135
+ this.traceMap.delete(span.traceId);
136
+ }
137
+ }
138
+ }
139
+ async handleEventSpan(span) {
140
+ if (span.isRootSpan) {
141
+ this.logger.debug("Braintrust exporter: Creating logger for event", {
142
+ traceId: span.traceId,
143
+ spanId: span.id,
144
+ spanName: span.name,
145
+ method: "handleEventSpan"
146
+ });
147
+ await this.initLogger(span);
148
+ }
149
+ const method = "handleEventSpan";
150
+ const spanData = this.getSpanData({ span, method });
151
+ if (!spanData) {
152
+ return;
153
+ }
154
+ const braintrustParent = this.getBraintrustParent({ spanData, span, method });
155
+ if (!braintrustParent) {
156
+ return;
157
+ }
158
+ const payload = this.buildSpanPayload(span);
159
+ const braintrustSpan = braintrustParent.startSpan({
160
+ spanId: span.id,
161
+ name: span.name,
162
+ type: mapSpanType(span.type),
163
+ parentSpanIds: span.parentSpanId ? { spanId: span.parentSpanId, rootSpanId: span.traceId } : { spanId: span.traceId, rootSpanId: span.traceId },
164
+ startTime: span.startTime.getTime() / 1e3,
165
+ ...payload
166
+ });
167
+ braintrustSpan.end({ endTime: span.startTime.getTime() / 1e3 });
168
+ }
169
+ async initLogger(span) {
170
+ const logger = await initLogger({
171
+ projectName: this.config.projectName ?? "mastra-tracing",
172
+ apiKey: this.config.apiKey,
173
+ appUrl: this.config.endpoint,
174
+ ...this.config.tuningParameters
175
+ });
176
+ this.traceMap.set(span.traceId, { logger, spans: /* @__PURE__ */ new Map(), activeIds: /* @__PURE__ */ new Set() });
177
+ }
178
+ getSpanData(options) {
179
+ const { span, method } = options;
180
+ if (this.traceMap.has(span.traceId)) {
181
+ return this.traceMap.get(span.traceId);
182
+ }
183
+ this.logger.warn("Braintrust exporter: No span data found for span", {
184
+ traceId: span.traceId,
185
+ spanId: span.id,
186
+ spanName: span.name,
187
+ spanType: span.type,
188
+ isRootSpan: span.isRootSpan,
189
+ parentSpanId: span.parentSpanId,
190
+ method
191
+ });
192
+ }
193
+ getBraintrustParent(options) {
194
+ const { spanData, span, method } = options;
195
+ const parentId = span.parentSpanId;
196
+ if (!parentId) {
197
+ return spanData.logger;
198
+ }
199
+ if (spanData.spans.has(parentId)) {
200
+ return spanData.spans.get(parentId);
201
+ }
202
+ if (parentId && !spanData.spans.has(parentId)) {
203
+ return spanData.logger;
204
+ }
205
+ this.logger.warn("Braintrust exporter: No parent data found for span", {
206
+ traceId: span.traceId,
207
+ spanId: span.id,
208
+ spanName: span.name,
209
+ spanType: span.type,
210
+ isRootSpan: span.isRootSpan,
211
+ parentSpanId: span.parentSpanId,
212
+ method
213
+ });
214
+ }
215
+ buildSpanPayload(span) {
216
+ const payload = {};
217
+ if (span.input !== void 0) {
218
+ payload.input = span.input;
219
+ }
220
+ if (span.output !== void 0) {
221
+ payload.output = span.output;
222
+ }
223
+ payload.metrics = {};
224
+ payload.metadata = {
225
+ spanType: span.type,
226
+ ...span.metadata
227
+ };
228
+ const attributes = span.attributes ?? {};
229
+ if (span.type === SpanType.MODEL_GENERATION) {
230
+ const modelAttr = attributes;
231
+ if (modelAttr.model !== void 0) {
232
+ payload.metadata.model = modelAttr.model;
233
+ }
234
+ if (modelAttr.provider !== void 0) {
235
+ payload.metadata.provider = modelAttr.provider;
236
+ }
237
+ payload.metrics = normalizeUsageMetrics(modelAttr);
238
+ if (modelAttr.parameters !== void 0) {
239
+ payload.metadata.modelParameters = modelAttr.parameters;
240
+ }
241
+ const otherAttributes = omitKeys(attributes, ["model", "usage", "parameters"]);
242
+ payload.metadata = {
243
+ ...payload.metadata,
244
+ ...otherAttributes
245
+ };
246
+ } else {
247
+ payload.metadata = {
248
+ ...payload.metadata,
249
+ ...attributes
250
+ };
251
+ }
252
+ if (span.errorInfo) {
253
+ payload.error = span.errorInfo.message;
254
+ payload.metadata.errorDetails = span.errorInfo;
255
+ }
256
+ if (Object.keys(payload.metrics).length === 0) {
257
+ delete payload.metrics;
258
+ }
259
+ return payload;
260
+ }
261
+ async shutdown() {
262
+ if (!this.config) {
263
+ return;
264
+ }
265
+ for (const [_traceId, spanData] of this.traceMap) {
266
+ for (const [_spanId, span] of spanData.spans) {
267
+ span.end();
268
+ }
269
+ }
270
+ this.traceMap.clear();
271
+ await super.shutdown();
272
+ }
273
+ };
274
+
275
+ export { BraintrustExporter };
276
+ //# sourceMappingURL=index.js.map
277
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/metrics.ts","../src/tracing.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,IACF;AAGA,IAAA,IAAI,KAAK,SAAA,EAAW;AAClB,MAAA,OAAA,CAAQ,KAAA,GAAQ,KAAK,SAAA,CAAU,OAAA;AAC/B,MAAA,OAAA,CAAQ,QAAA,CAAS,eAAe,IAAA,CAAK,SAAA;AAAA,IACvC;AAGA,IAAA,IAAI,OAAO,IAAA,CAAK,OAAA,CAAQ,OAAO,CAAA,CAAE,WAAW,CAAA,EAAG;AAC7C,MAAA,OAAO,OAAA,CAAQ,OAAA;AAAA,IACjB;AAEA,IAAA,OAAO,OAAA;AAAA,EACT;AAAA,EAEA,MAAM,QAAA,GAA0B;AAC9B,IAAA,IAAI,CAAC,KAAK,MAAA,EAAQ;AAChB,MAAA;AAAA,IACF;AAGA,IAAA,KAAA,MAAW,CAAC,QAAA,EAAU,QAAQ,CAAA,IAAK,KAAK,QAAA,EAAU;AAChD,MAAA,KAAA,MAAW,CAAC,OAAA,EAAS,IAAI,CAAA,IAAK,SAAS,KAAA,EAAO;AAC5C,QAAA,IAAA,CAAK,GAAA,EAAI;AAAA,MACX;AAAA,IAEF;AACA,IAAA,IAAA,CAAK,SAAS,KAAA,EAAM;AACpB,IAAA,MAAM,MAAM,QAAA,EAAS;AAAA,EACvB;AACF","file":"index.js","sourcesContent":["import type { ModelGenerationAttributes } from '@mastra/core/observability';\n/**\n * BraintrustUsageMetrics\n *\n * Canonical metric keys expected by Braintrust for LLM usage accounting.\n * These map various provider/SDK-specific usage fields to a common schema.\n * - prompt_tokens: input-side tokens (aka inputTokens/promptTokens)\n * - completion_tokens: output-side tokens (aka outputTokens/completionTokens)\n * - tokens: total tokens (provided or derived)\n * - completion_reasoning_tokens: reasoning tokens, when available\n * - prompt_cached_tokens: tokens served from cache (provider-specific)\n * - prompt_cache_creation_tokens: tokens used to create cache (provider-specific)\n */\nexport interface BraintrustUsageMetrics {\n prompt_tokens?: number;\n completion_tokens?: number;\n tokens?: number;\n completion_reasoning_tokens?: number;\n prompt_cached_tokens?: number;\n prompt_cache_creation_tokens?: number;\n [key: string]: number | undefined;\n}\n\nexport function normalizeUsageMetrics(modelAttr: ModelGenerationAttributes): BraintrustUsageMetrics {\n const metrics: BraintrustUsageMetrics = {};\n\n if (modelAttr.usage?.inputTokens !== undefined) {\n metrics.prompt_tokens = modelAttr.usage?.inputTokens;\n } else if (modelAttr.usage?.promptTokens !== undefined) {\n metrics.prompt_tokens = modelAttr.usage?.promptTokens;\n }\n\n if (modelAttr.usage?.outputTokens !== undefined) {\n metrics.completion_tokens = modelAttr.usage?.outputTokens;\n } else if (modelAttr.usage?.completionTokens !== undefined) {\n metrics.completion_tokens = modelAttr.usage?.completionTokens;\n }\n\n if (modelAttr.usage?.totalTokens !== undefined) {\n metrics.tokens = modelAttr.usage?.totalTokens;\n }\n if (modelAttr.usage?.reasoningTokens !== undefined) {\n metrics.completion_reasoning_tokens = modelAttr.usage?.reasoningTokens;\n }\n if (modelAttr.usage?.promptCacheHitTokens !== undefined) {\n metrics.prompt_cached_tokens = modelAttr.usage?.promptCacheHitTokens;\n }\n if (modelAttr.usage?.promptCacheMissTokens !== undefined) {\n metrics.prompt_cache_creation_tokens = modelAttr.usage?.promptCacheMissTokens;\n }\n\n return metrics;\n}\n","/**\n * Braintrust Exporter for Mastra Observability\n *\n * This exporter sends observability data to Braintrust.\n * Root spans become top-level Braintrust spans (no trace wrapper).\n * Events are handled as zero-duration spans with matching start/end times.\n */\n\nimport type { TracingEvent, AnyExportedSpan, ModelGenerationAttributes } from '@mastra/core/observability';\nimport { SpanType } from '@mastra/core/observability';\nimport { omitKeys } from '@mastra/core/utils';\nimport { BaseExporter } from '@mastra/observability';\nimport type { BaseExporterConfig } from '@mastra/observability';\nimport { initLogger } from 'braintrust';\nimport type { Span, Logger } from 'braintrust';\nimport { normalizeUsageMetrics } from './metrics';\n\nexport interface BraintrustExporterConfig extends BaseExporterConfig {\n /** Braintrust API key */\n apiKey?: string;\n /** Optional custom endpoint */\n endpoint?: string;\n /** Braintrust project name (default: 'mastra-tracing') */\n projectName?: string;\n /** Support tuning parameters */\n tuningParameters?: Record<string, any>;\n}\n\ntype SpanData = {\n logger: Logger<true>; // Braintrust logger (for root spans)\n spans: Map<string, Span>; // Maps span.id to Braintrust span\n activeIds: Set<string>; // Tracks started (non-event) spans not yet ended, including root\n};\n\n// Default span type for all spans\nconst DEFAULT_SPAN_TYPE = 'task';\n\n// Exceptions to the default mapping\nconst SPAN_TYPE_EXCEPTIONS: Partial<Record<SpanType, string>> = {\n [SpanType.MODEL_GENERATION]: 'llm',\n [SpanType.MODEL_CHUNK]: 'llm',\n [SpanType.TOOL_CALL]: 'tool',\n [SpanType.MCP_TOOL_CALL]: 'tool',\n [SpanType.WORKFLOW_CONDITIONAL_EVAL]: 'function',\n [SpanType.WORKFLOW_WAIT_EVENT]: 'function',\n};\n\n// Mapping function - returns valid Braintrust span types\nfunction mapSpanType(spanType: SpanType): 'llm' | 'score' | 'function' | 'eval' | 'task' | 'tool' {\n return (SPAN_TYPE_EXCEPTIONS[spanType] as any) ?? DEFAULT_SPAN_TYPE;\n}\n\nexport class BraintrustExporter extends BaseExporter {\n name = 'braintrust';\n private traceMap = new Map<string, SpanData>();\n private config: BraintrustExporterConfig;\n\n constructor(config: BraintrustExporterConfig) {\n super(config);\n\n if (!config.apiKey) {\n this.setDisabled(`Missing required credentials (apiKey: ${!!config.apiKey})`);\n this.config = null as any;\n return;\n }\n\n this.config = config;\n }\n\n protected async _exportTracingEvent(event: TracingEvent): Promise<void> {\n if (event.exportedSpan.isEvent) {\n await this.handleEventSpan(event.exportedSpan);\n return;\n }\n\n switch (event.type) {\n case 'span_started':\n await this.handleSpanStarted(event.exportedSpan);\n break;\n case 'span_updated':\n await this.handleSpanUpdateOrEnd(event.exportedSpan, false);\n break;\n case 'span_ended':\n await this.handleSpanUpdateOrEnd(event.exportedSpan, true);\n break;\n }\n }\n\n private async handleSpanStarted(span: AnyExportedSpan): Promise<void> {\n if (span.isRootSpan) {\n await this.initLogger(span);\n }\n\n const method = 'handleSpanStarted';\n const spanData = this.getSpanData({ span, method });\n if (!spanData) {\n return;\n }\n\n // Refcount: track active non-event spans (including root)\n if (!span.isEvent) {\n spanData.activeIds.add(span.id);\n }\n\n const braintrustParent = this.getBraintrustParent({ spanData, span, method });\n if (!braintrustParent) {\n return;\n }\n\n const payload = this.buildSpanPayload(span);\n\n const braintrustSpan = braintrustParent.startSpan({\n spanId: span.id,\n name: span.name,\n type: mapSpanType(span.type),\n parentSpanIds: span.parentSpanId\n ? { spanId: span.parentSpanId, rootSpanId: span.traceId }\n : { spanId: span.traceId, rootSpanId: span.traceId },\n ...payload,\n });\n\n spanData.spans.set(span.id, braintrustSpan);\n }\n\n private async handleSpanUpdateOrEnd(span: AnyExportedSpan, isEnd: boolean): Promise<void> {\n const method = isEnd ? 'handleSpanEnd' : 'handleSpanUpdate';\n\n const spanData = this.getSpanData({ span, method });\n if (!spanData) {\n return;\n }\n\n const braintrustSpan = spanData.spans.get(span.id);\n if (!braintrustSpan) {\n this.logger.warn('Braintrust exporter: No Braintrust span found for span update/end', {\n traceId: span.traceId,\n spanId: span.id,\n spanName: span.name,\n spanType: span.type,\n isRootSpan: span.isRootSpan,\n parentSpanId: span.parentSpanId,\n method,\n });\n return;\n }\n\n braintrustSpan.log(this.buildSpanPayload(span));\n\n if (isEnd) {\n // End the span with the correct endTime (convert milliseconds to seconds)\n if (span.endTime) {\n braintrustSpan.end({ endTime: span.endTime.getTime() / 1000 });\n } else {\n braintrustSpan.end();\n }\n\n // Refcount: mark this span as ended\n if (!span.isEvent) {\n spanData.activeIds.delete(span.id);\n }\n\n // If no more active spans remain for this trace, clean up the trace entry\n if (spanData.activeIds.size === 0) {\n this.traceMap.delete(span.traceId);\n }\n }\n }\n\n private async handleEventSpan(span: AnyExportedSpan): Promise<void> {\n if (span.isRootSpan) {\n this.logger.debug('Braintrust exporter: Creating logger for event', {\n traceId: span.traceId,\n spanId: span.id,\n spanName: span.name,\n method: 'handleEventSpan',\n });\n await this.initLogger(span);\n }\n\n const method = 'handleEventSpan';\n const spanData = this.getSpanData({ span, method });\n if (!spanData) {\n return;\n }\n\n const braintrustParent = this.getBraintrustParent({ spanData, span, method });\n if (!braintrustParent) {\n return;\n }\n\n const payload = this.buildSpanPayload(span);\n\n // Create zero-duration span for event (convert milliseconds to seconds)\n const braintrustSpan = braintrustParent.startSpan({\n spanId: span.id,\n name: span.name,\n type: mapSpanType(span.type),\n parentSpanIds: span.parentSpanId\n ? { spanId: span.parentSpanId, rootSpanId: span.traceId }\n : { spanId: span.traceId, rootSpanId: span.traceId },\n startTime: span.startTime.getTime() / 1000,\n ...payload,\n });\n\n braintrustSpan.end({ endTime: span.startTime.getTime() / 1000 });\n }\n\n private async initLogger(span: AnyExportedSpan): Promise<void> {\n const logger = await initLogger({\n projectName: this.config.projectName ?? 'mastra-tracing',\n apiKey: this.config.apiKey,\n appUrl: this.config.endpoint,\n ...this.config.tuningParameters,\n });\n\n this.traceMap.set(span.traceId, { logger, spans: new Map(), activeIds: new Set() });\n }\n\n private getSpanData(options: { span: AnyExportedSpan; method: string }): SpanData | undefined {\n const { span, method } = options;\n if (this.traceMap.has(span.traceId)) {\n return this.traceMap.get(span.traceId);\n }\n\n this.logger.warn('Braintrust exporter: No span data found for span', {\n traceId: span.traceId,\n spanId: span.id,\n spanName: span.name,\n spanType: span.type,\n isRootSpan: span.isRootSpan,\n parentSpanId: span.parentSpanId,\n method,\n });\n }\n\n private getBraintrustParent(options: {\n spanData: SpanData;\n span: AnyExportedSpan;\n method: string;\n }): Logger<true> | Span | undefined {\n const { spanData, span, method } = options;\n\n const parentId = span.parentSpanId;\n if (!parentId) {\n return spanData.logger;\n }\n\n if (spanData.spans.has(parentId)) {\n return spanData.spans.get(parentId);\n }\n\n // If the parent exists but is the root span (not represented as a Braintrust\n // span because we use the logger as the root), attach to the logger so the\n // span is not orphaned. We need to check if parentSpanId exists but the\n // parent span is not in our spans map (indicating it's the root span).\n if (parentId && !spanData.spans.has(parentId)) {\n // This means the parent exists but isn't tracked as a Braintrust span,\n // which happens when the parent is the root span (we use logger as root)\n return spanData.logger;\n }\n\n this.logger.warn('Braintrust exporter: No parent data found for span', {\n traceId: span.traceId,\n spanId: span.id,\n spanName: span.name,\n spanType: span.type,\n isRootSpan: span.isRootSpan,\n parentSpanId: span.parentSpanId,\n method,\n });\n }\n\n private buildSpanPayload(span: AnyExportedSpan): Record<string, any> {\n const payload: Record<string, any> = {};\n\n // Core span data\n if (span.input !== undefined) {\n payload.input = span.input;\n }\n\n if (span.output !== undefined) {\n payload.output = span.output;\n }\n\n // Initialize metrics and metadata objects\n payload.metrics = {};\n payload.metadata = {\n spanType: span.type,\n ...span.metadata,\n };\n\n const attributes = (span.attributes ?? {}) as Record<string, any>;\n\n if (span.type === SpanType.MODEL_GENERATION) {\n const modelAttr = attributes as ModelGenerationAttributes;\n\n // Model goes to metadata\n if (modelAttr.model !== undefined) {\n payload.metadata.model = modelAttr.model;\n }\n\n // Provider goes to metadata (if provided by attributes)\n if (modelAttr.provider !== undefined) {\n payload.metadata.provider = modelAttr.provider;\n }\n\n // Usage/token info goes to metrics\n payload.metrics = normalizeUsageMetrics(modelAttr);\n\n // Model parameters go to metadata\n if (modelAttr.parameters !== undefined) {\n payload.metadata.modelParameters = modelAttr.parameters;\n }\n\n // Other LLM attributes go to metadata\n const otherAttributes = omitKeys(attributes, ['model', 'usage', 'parameters']);\n payload.metadata = {\n ...payload.metadata,\n ...otherAttributes,\n };\n } else {\n // For non-LLM spans, put all attributes in metadata\n payload.metadata = {\n ...payload.metadata,\n ...attributes,\n };\n }\n\n // Handle errors\n if (span.errorInfo) {\n payload.error = span.errorInfo.message;\n payload.metadata.errorDetails = span.errorInfo;\n }\n\n // Clean up empty metrics object\n if (Object.keys(payload.metrics).length === 0) {\n delete payload.metrics;\n }\n\n return payload;\n }\n\n async shutdown(): Promise<void> {\n if (!this.config) {\n return;\n }\n\n // End all active spans\n for (const [_traceId, spanData] of this.traceMap) {\n for (const [_spanId, span] of spanData.spans) {\n span.end();\n }\n // Loggers don't have an explicit shutdown method\n }\n this.traceMap.clear();\n await super.shutdown();\n }\n}\n"]}
@@ -0,0 +1,24 @@
1
+ import type { ModelGenerationAttributes } from '@mastra/core/observability';
2
+ /**
3
+ * BraintrustUsageMetrics
4
+ *
5
+ * Canonical metric keys expected by Braintrust for LLM usage accounting.
6
+ * These map various provider/SDK-specific usage fields to a common schema.
7
+ * - prompt_tokens: input-side tokens (aka inputTokens/promptTokens)
8
+ * - completion_tokens: output-side tokens (aka outputTokens/completionTokens)
9
+ * - tokens: total tokens (provided or derived)
10
+ * - completion_reasoning_tokens: reasoning tokens, when available
11
+ * - prompt_cached_tokens: tokens served from cache (provider-specific)
12
+ * - prompt_cache_creation_tokens: tokens used to create cache (provider-specific)
13
+ */
14
+ export interface BraintrustUsageMetrics {
15
+ prompt_tokens?: number;
16
+ completion_tokens?: number;
17
+ tokens?: number;
18
+ completion_reasoning_tokens?: number;
19
+ prompt_cached_tokens?: number;
20
+ prompt_cache_creation_tokens?: number;
21
+ [key: string]: number | undefined;
22
+ }
23
+ export declare function normalizeUsageMetrics(modelAttr: ModelGenerationAttributes): BraintrustUsageMetrics;
24
+ //# sourceMappingURL=metrics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../src/metrics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAC5E;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,sBAAsB;IACrC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2BAA2B,CAAC,EAAE,MAAM,CAAC;IACrC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,4BAA4B,CAAC,EAAE,MAAM,CAAC;IACtC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CACnC;AAED,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,yBAAyB,GAAG,sBAAsB,CA6BlG"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Braintrust Exporter for Mastra Observability
3
+ *
4
+ * This exporter sends observability data to Braintrust.
5
+ * Root spans become top-level Braintrust spans (no trace wrapper).
6
+ * Events are handled as zero-duration spans with matching start/end times.
7
+ */
8
+ import type { TracingEvent } from '@mastra/core/observability';
9
+ import { BaseExporter } from '@mastra/observability';
10
+ import type { BaseExporterConfig } from '@mastra/observability';
11
+ export interface BraintrustExporterConfig extends BaseExporterConfig {
12
+ /** Braintrust API key */
13
+ apiKey?: string;
14
+ /** Optional custom endpoint */
15
+ endpoint?: string;
16
+ /** Braintrust project name (default: 'mastra-tracing') */
17
+ projectName?: string;
18
+ /** Support tuning parameters */
19
+ tuningParameters?: Record<string, any>;
20
+ }
21
+ export declare class BraintrustExporter extends BaseExporter {
22
+ name: string;
23
+ private traceMap;
24
+ private config;
25
+ constructor(config: BraintrustExporterConfig);
26
+ protected _exportTracingEvent(event: TracingEvent): Promise<void>;
27
+ private handleSpanStarted;
28
+ private handleSpanUpdateOrEnd;
29
+ private handleEventSpan;
30
+ private initLogger;
31
+ private getSpanData;
32
+ private getBraintrustParent;
33
+ private buildSpanPayload;
34
+ shutdown(): Promise<void>;
35
+ }
36
+ //# sourceMappingURL=tracing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracing.d.ts","sourceRoot":"","sources":["../src/tracing.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAA8C,MAAM,4BAA4B,CAAC;AAG3G,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAKhE,MAAM,WAAW,wBAAyB,SAAQ,kBAAkB;IAClE,yBAAyB;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+BAA+B;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,0DAA0D;IAC1D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gCAAgC;IAChC,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACxC;AA0BD,qBAAa,kBAAmB,SAAQ,YAAY;IAClD,IAAI,SAAgB;IACpB,OAAO,CAAC,QAAQ,CAA+B;IAC/C,OAAO,CAAC,MAAM,CAA2B;gBAE7B,MAAM,EAAE,wBAAwB;cAY5B,mBAAmB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;YAmBzD,iBAAiB;YAoCjB,qBAAqB;YA4CrB,eAAe;YAuCf,UAAU;IAWxB,OAAO,CAAC,WAAW;IAiBnB,OAAO,CAAC,mBAAmB;IAqC3B,OAAO,CAAC,gBAAgB;IAsElB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAehC"}
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@mastra/braintrust",
3
+ "version": "0.0.0-1.x-tester-20251106055847",
4
+ "description": "Braintrust observability provider for Mastra - includes tracing and future observability features",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "CHANGELOG.md"
11
+ ],
12
+ "exports": {
13
+ ".": {
14
+ "import": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ },
18
+ "require": {
19
+ "types": "./dist/index.d.ts",
20
+ "default": "./dist/index.cjs"
21
+ }
22
+ },
23
+ "./package.json": "./package.json"
24
+ },
25
+ "license": "Apache-2.0",
26
+ "dependencies": {
27
+ "braintrust": "^0.4.3",
28
+ "@mastra/observability": "0.0.0-1.x-tester-20251106055847"
29
+ },
30
+ "devDependencies": {
31
+ "@microsoft/api-extractor": "^7.52.8",
32
+ "@types/node": "^20.19.0",
33
+ "eslint": "^9.37.0",
34
+ "tsup": "^8.5.0",
35
+ "typescript": "^5.8.3",
36
+ "vitest": "^3.2.4",
37
+ "@internal/lint": "0.0.0-1.x-tester-20251106055847",
38
+ "@mastra/core": "0.0.0-1.x-tester-20251106055847",
39
+ "@internal/types-builder": "0.0.0-1.x-tester-20251106055847"
40
+ },
41
+ "peerDependencies": {
42
+ "@mastra/core": "0.0.0-1.x-tester-20251106055847"
43
+ },
44
+ "homepage": "https://mastra.ai",
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "git+https://github.com/mastra-ai/mastra.git",
48
+ "directory": "observability/braintrust"
49
+ },
50
+ "bugs": {
51
+ "url": "https://github.com/mastra-ai/mastra/issues"
52
+ },
53
+ "engines": {
54
+ "node": ">=22.13.0"
55
+ },
56
+ "scripts": {
57
+ "build": "tsup --silent --config tsup.config.ts",
58
+ "build:watch": "pnpm build --watch",
59
+ "test": "vitest run",
60
+ "test:watch": "vitest watch",
61
+ "lint": "eslint ."
62
+ }
63
+ }