@mastra/core 1.18.0 → 1.18.1-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/agent/agent.d.ts.map +1 -1
  3. package/dist/agent/index.cjs +8 -8
  4. package/dist/agent/index.js +1 -1
  5. package/dist/agent/workflows/prepare-stream/map-results-step.d.ts.map +1 -1
  6. package/dist/{chunk-KLVNQDUR.cjs → chunk-2W7R236U.cjs} +3 -3
  7. package/dist/chunk-2W7R236U.cjs.map +1 -0
  8. package/dist/{chunk-V2NQOABM.cjs → chunk-5ANYSU2W.cjs} +9 -9
  9. package/dist/{chunk-V2NQOABM.cjs.map → chunk-5ANYSU2W.cjs.map} +1 -1
  10. package/dist/{chunk-KOTSKPTF.cjs → chunk-6R5PT6ZP.cjs} +5 -5
  11. package/dist/{chunk-KOTSKPTF.cjs.map → chunk-6R5PT6ZP.cjs.map} +1 -1
  12. package/dist/{chunk-LKZQG2ZZ.cjs → chunk-6VRSFFQ4.cjs} +7 -6
  13. package/dist/chunk-6VRSFFQ4.cjs.map +1 -0
  14. package/dist/{chunk-2M3HWTRI.js → chunk-7IE4K74P.js} +4 -4
  15. package/dist/{chunk-2M3HWTRI.js.map → chunk-7IE4K74P.js.map} +1 -1
  16. package/dist/{chunk-I4ZSA3XJ.js → chunk-7V3UNILV.js} +4 -4
  17. package/dist/{chunk-I4ZSA3XJ.js.map → chunk-7V3UNILV.js.map} +1 -1
  18. package/dist/{chunk-ZRLAR66M.js → chunk-AJZQPWAV.js} +59 -19
  19. package/dist/chunk-AJZQPWAV.js.map +1 -0
  20. package/dist/{chunk-XOBRMYFA.js → chunk-BZ2MSXOF.js} +3 -3
  21. package/dist/chunk-BZ2MSXOF.js.map +1 -0
  22. package/dist/{chunk-HRT662B6.js → chunk-EAJDF6UV.js} +12 -7
  23. package/dist/chunk-EAJDF6UV.js.map +1 -0
  24. package/dist/{chunk-PWFPYJGG.cjs → chunk-EXDBQKH4.cjs} +15 -15
  25. package/dist/{chunk-PWFPYJGG.cjs.map → chunk-EXDBQKH4.cjs.map} +1 -1
  26. package/dist/{chunk-GJ62FP5X.js → chunk-HQCBFWL2.js} +18 -35
  27. package/dist/chunk-HQCBFWL2.js.map +1 -0
  28. package/dist/{chunk-UPBMT3QM.js → chunk-JTJCFEIY.js} +8 -8
  29. package/dist/{chunk-UPBMT3QM.js.map → chunk-JTJCFEIY.js.map} +1 -1
  30. package/dist/{chunk-GJIN53S6.cjs → chunk-L2GYXPJJ.cjs} +9 -9
  31. package/dist/{chunk-GJIN53S6.cjs.map → chunk-L2GYXPJJ.cjs.map} +1 -1
  32. package/dist/{chunk-2H53MD2U.cjs → chunk-LVZKPNQO.cjs} +50 -50
  33. package/dist/{chunk-2H53MD2U.cjs.map → chunk-LVZKPNQO.cjs.map} +1 -1
  34. package/dist/{chunk-MJF7NZEF.js → chunk-OLHODPXN.js} +3 -3
  35. package/dist/{chunk-MJF7NZEF.js.map → chunk-OLHODPXN.js.map} +1 -1
  36. package/dist/{chunk-6Z4GSLLO.js → chunk-OTJAMDX5.js} +3 -3
  37. package/dist/{chunk-6Z4GSLLO.js.map → chunk-OTJAMDX5.js.map} +1 -1
  38. package/dist/{chunk-EKFG6JWW.js → chunk-PB3KXPNE.js} +8 -7
  39. package/dist/chunk-PB3KXPNE.js.map +1 -0
  40. package/dist/{chunk-TVZCMQTV.cjs → chunk-QADPCUBX.cjs} +83 -82
  41. package/dist/chunk-QADPCUBX.cjs.map +1 -0
  42. package/dist/{chunk-RTBZOGTO.js → chunk-QNNFMCSE.js} +3 -3
  43. package/dist/{chunk-RTBZOGTO.js.map → chunk-QNNFMCSE.js.map} +1 -1
  44. package/dist/{chunk-7GLVV6CZ.js → chunk-RF4TETYQ.js} +4 -4
  45. package/dist/{chunk-7GLVV6CZ.js.map → chunk-RF4TETYQ.js.map} +1 -1
  46. package/dist/{chunk-XQN3BKCI.js → chunk-UJX2TJIF.js} +3 -3
  47. package/dist/{chunk-XQN3BKCI.js.map → chunk-UJX2TJIF.js.map} +1 -1
  48. package/dist/{chunk-XQRTJIC7.cjs → chunk-VEP4CV7E.cjs} +32 -3
  49. package/dist/chunk-VEP4CV7E.cjs.map +1 -0
  50. package/dist/{chunk-K7AE4BHR.js → chunk-VMBWVH4B.js} +4 -3
  51. package/dist/chunk-VMBWVH4B.js.map +1 -0
  52. package/dist/{chunk-J47RNLSY.cjs → chunk-WLNT3YJ7.cjs} +95 -55
  53. package/dist/chunk-WLNT3YJ7.cjs.map +1 -0
  54. package/dist/{chunk-L3X22YTN.cjs → chunk-WMF4CWAL.cjs} +185 -185
  55. package/dist/{chunk-L3X22YTN.cjs.map → chunk-WMF4CWAL.cjs.map} +1 -1
  56. package/dist/{chunk-4FMKWOPC.js → chunk-X4Q4KB6C.js} +31 -4
  57. package/dist/chunk-X4Q4KB6C.js.map +1 -0
  58. package/dist/{chunk-RTXCZT3M.cjs → chunk-XDZOEUNU.cjs} +19 -36
  59. package/dist/chunk-XDZOEUNU.cjs.map +1 -0
  60. package/dist/{chunk-GXXNF6NF.cjs → chunk-XNBGNCVV.cjs} +15 -10
  61. package/dist/chunk-XNBGNCVV.cjs.map +1 -0
  62. package/dist/{chunk-ZVGS2O2W.cjs → chunk-YCT2YQDL.cjs} +6 -6
  63. package/dist/{chunk-ZVGS2O2W.cjs.map → chunk-YCT2YQDL.cjs.map} +1 -1
  64. package/dist/{chunk-ZQE2VUYD.cjs → chunk-YMPV2RMB.cjs} +7 -7
  65. package/dist/{chunk-ZQE2VUYD.cjs.map → chunk-YMPV2RMB.cjs.map} +1 -1
  66. package/dist/datasets/index.cjs +17 -17
  67. package/dist/datasets/index.js +2 -2
  68. package/dist/docs/SKILL.md +8 -18
  69. package/dist/docs/assets/SOURCE_MAP.json +254 -254
  70. package/dist/docs/references/docs-agents-overview.md +4 -4
  71. package/dist/docs/references/docs-agents-processors.md +1 -1
  72. package/dist/docs/references/{docs-observability-datasets-overview.md → docs-evals-datasets-overview.md} +12 -12
  73. package/dist/docs/references/{docs-observability-datasets-running-experiments.md → docs-evals-datasets-running-experiments.md} +9 -9
  74. package/dist/docs/references/docs-evals-overview.md +8 -9
  75. package/dist/docs/references/docs-memory-observational-memory.md +20 -11
  76. package/dist/docs/references/docs-memory-overview.md +4 -4
  77. package/dist/docs/references/docs-memory-semantic-recall.md +28 -19
  78. package/dist/docs/references/docs-memory-storage.md +4 -4
  79. package/dist/docs/references/docs-rag-chunking-and-embedding.md +2 -2
  80. package/dist/docs/references/docs-server-auth-composite-auth.md +1 -7
  81. package/dist/docs/references/docs-server-auth-custom-auth-provider.md +2 -4
  82. package/dist/docs/references/docs-server-auth-jwt.md +1 -1
  83. package/dist/docs/references/docs-server-auth-simple-auth.md +1 -7
  84. package/dist/docs/references/docs-server-custom-adapters.md +3 -1
  85. package/dist/docs/references/docs-server-custom-api-routes.md +1 -1
  86. package/dist/docs/references/docs-server-mastra-client.md +1 -3
  87. package/dist/docs/references/docs-server-mastra-server.md +8 -0
  88. package/dist/docs/references/docs-server-request-context.md +17 -17
  89. package/dist/docs/references/docs-streaming-events.md +1 -90
  90. package/dist/docs/references/docs-studio-auth.md +142 -0
  91. package/dist/docs/references/docs-studio-deployment.md +260 -0
  92. package/dist/docs/references/docs-studio-observability.md +98 -0
  93. package/dist/docs/references/docs-studio-overview.md +127 -0
  94. package/dist/docs/references/docs-workflows-agents-and-tools.md +7 -10
  95. package/dist/docs/references/docs-workflows-control-flow.md +1 -1
  96. package/dist/docs/references/docs-workflows-overview.md +12 -7
  97. package/dist/docs/references/docs-workflows-suspend-and-resume.md +1 -1
  98. package/dist/docs/references/guides-concepts-multi-agent-systems.md +4 -4
  99. package/dist/docs/references/reference-agents-agent.md +1 -1
  100. package/dist/docs/references/reference-configuration.md +4 -4
  101. package/dist/docs/references/reference-memory-observational-memory.md +1 -1
  102. package/dist/docs/references/reference-storage-cloudflare-d1.md +1 -1
  103. package/dist/docs/references/reference-storage-lance.md +1 -1
  104. package/dist/docs/references/reference-storage-upstash.md +1 -1
  105. package/dist/docs/references/reference.md +16 -14
  106. package/dist/evals/index.cjs +5 -5
  107. package/dist/evals/index.js +2 -2
  108. package/dist/evals/scoreTraces/index.cjs +3 -3
  109. package/dist/evals/scoreTraces/index.js +1 -1
  110. package/dist/harness/harness.d.ts.map +1 -1
  111. package/dist/harness/index.cjs +13 -12
  112. package/dist/harness/index.cjs.map +1 -1
  113. package/dist/harness/index.js +8 -7
  114. package/dist/harness/index.js.map +1 -1
  115. package/dist/index.cjs +2 -2
  116. package/dist/index.js +1 -1
  117. package/dist/llm/index.cjs +16 -16
  118. package/dist/llm/index.js +5 -5
  119. package/dist/llm/model/aisdk/v5/model.d.ts +5 -0
  120. package/dist/llm/model/aisdk/v5/model.d.ts.map +1 -1
  121. package/dist/llm/model/aisdk/v6/model.d.ts +5 -0
  122. package/dist/llm/model/aisdk/v6/model.d.ts.map +1 -1
  123. package/dist/llm/model/provider-types.generated.d.ts +5 -13
  124. package/dist/loop/index.cjs +14 -14
  125. package/dist/loop/index.js +1 -1
  126. package/dist/loop/network/validation.d.ts.map +1 -1
  127. package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts.map +1 -1
  128. package/dist/mastra/index.cjs +2 -2
  129. package/dist/mastra/index.js +1 -1
  130. package/dist/memory/index.cjs +14 -14
  131. package/dist/memory/index.js +1 -1
  132. package/dist/models-dev-WD6XLSFC.cjs +12 -0
  133. package/dist/{models-dev-5WY37RVC.cjs.map → models-dev-WD6XLSFC.cjs.map} +1 -1
  134. package/dist/models-dev-XG4KIUFT.js +3 -0
  135. package/dist/{models-dev-Y2UFJEOO.js.map → models-dev-XG4KIUFT.js.map} +1 -1
  136. package/dist/netlify-FMBBUFKT.cjs +12 -0
  137. package/dist/{netlify-ADZQ5ZNY.cjs.map → netlify-FMBBUFKT.cjs.map} +1 -1
  138. package/dist/netlify-NDOVF45T.js +3 -0
  139. package/dist/{netlify-I4AUVRO2.js.map → netlify-NDOVF45T.js.map} +1 -1
  140. package/dist/processor-provider/index.cjs +10 -10
  141. package/dist/processor-provider/index.js +1 -1
  142. package/dist/processors/index.cjs +44 -44
  143. package/dist/processors/index.js +1 -1
  144. package/dist/provider-registry-KHXFOGCK.js +3 -0
  145. package/dist/{provider-registry-C7SZ5ZT4.js.map → provider-registry-KHXFOGCK.js.map} +1 -1
  146. package/dist/provider-registry-VUG7E4SG.cjs +40 -0
  147. package/dist/{provider-registry-I5RW3MEE.cjs.map → provider-registry-VUG7E4SG.cjs.map} +1 -1
  148. package/dist/provider-registry.json +14 -31
  149. package/dist/relevance/index.cjs +3 -3
  150. package/dist/relevance/index.js +1 -1
  151. package/dist/storage/index.cjs +74 -74
  152. package/dist/storage/index.js +1 -1
  153. package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts.map +1 -1
  154. package/dist/stream/index.cjs +8 -8
  155. package/dist/stream/index.js +1 -1
  156. package/dist/test-utils/llm-mock.cjs +4 -4
  157. package/dist/test-utils/llm-mock.js +1 -1
  158. package/dist/tool-loop-agent/index.cjs +4 -4
  159. package/dist/tool-loop-agent/index.js +1 -1
  160. package/dist/tools/tool-builder/builder.d.ts.map +1 -1
  161. package/dist/utils.cjs +31 -23
  162. package/dist/utils.d.ts +10 -0
  163. package/dist/utils.d.ts.map +1 -1
  164. package/dist/utils.js +1 -1
  165. package/dist/vector/index.cjs +7 -7
  166. package/dist/vector/index.js +1 -1
  167. package/dist/workflows/evented/index.cjs +10 -10
  168. package/dist/workflows/evented/index.js +1 -1
  169. package/dist/workflows/index.cjs +24 -24
  170. package/dist/workflows/index.js +1 -1
  171. package/dist/workflows/workflow.d.ts.map +1 -1
  172. package/dist/workspace/index.cjs +68 -68
  173. package/dist/workspace/index.js +1 -1
  174. package/dist/workspace/workspace.d.ts +1 -0
  175. package/dist/workspace/workspace.d.ts.map +1 -1
  176. package/package.json +2 -2
  177. package/src/llm/model/provider-types.generated.d.ts +5 -13
  178. package/dist/chunk-4FMKWOPC.js.map +0 -1
  179. package/dist/chunk-EKFG6JWW.js.map +0 -1
  180. package/dist/chunk-GJ62FP5X.js.map +0 -1
  181. package/dist/chunk-GXXNF6NF.cjs.map +0 -1
  182. package/dist/chunk-HRT662B6.js.map +0 -1
  183. package/dist/chunk-J47RNLSY.cjs.map +0 -1
  184. package/dist/chunk-K7AE4BHR.js.map +0 -1
  185. package/dist/chunk-KLVNQDUR.cjs.map +0 -1
  186. package/dist/chunk-LKZQG2ZZ.cjs.map +0 -1
  187. package/dist/chunk-RTXCZT3M.cjs.map +0 -1
  188. package/dist/chunk-TVZCMQTV.cjs.map +0 -1
  189. package/dist/chunk-XOBRMYFA.js.map +0 -1
  190. package/dist/chunk-XQRTJIC7.cjs.map +0 -1
  191. package/dist/chunk-ZRLAR66M.js.map +0 -1
  192. package/dist/docs/references/docs-observability-logging.md +0 -99
  193. package/dist/docs/references/docs-observability-overview.md +0 -70
  194. package/dist/docs/references/docs-observability-tracing-bridges-otel.md +0 -209
  195. package/dist/docs/references/docs-observability-tracing-exporters-arize.md +0 -272
  196. package/dist/docs/references/docs-observability-tracing-exporters-braintrust.md +0 -126
  197. package/dist/docs/references/docs-observability-tracing-exporters-cloud.md +0 -127
  198. package/dist/docs/references/docs-observability-tracing-exporters-datadog.md +0 -317
  199. package/dist/docs/references/docs-observability-tracing-exporters-default.md +0 -209
  200. package/dist/docs/references/docs-observability-tracing-exporters-laminar.md +0 -100
  201. package/dist/docs/references/docs-observability-tracing-exporters-langfuse.md +0 -213
  202. package/dist/docs/references/docs-observability-tracing-exporters-langsmith.md +0 -198
  203. package/dist/docs/references/docs-observability-tracing-exporters-otel.md +0 -476
  204. package/dist/docs/references/docs-observability-tracing-exporters-posthog.md +0 -148
  205. package/dist/docs/references/docs-observability-tracing-overview.md +0 -1112
  206. package/dist/models-dev-5WY37RVC.cjs +0 -12
  207. package/dist/models-dev-Y2UFJEOO.js +0 -3
  208. package/dist/netlify-ADZQ5ZNY.cjs +0 -12
  209. package/dist/netlify-I4AUVRO2.js +0 -3
  210. package/dist/provider-registry-C7SZ5ZT4.js +0 -3
  211. package/dist/provider-registry-I5RW3MEE.cjs +0 -40
@@ -1,99 +0,0 @@
1
- # Logging
2
-
3
- Mastra's logging system captures function execution, input data, and output responses in a structured format.
4
-
5
- When deploying to Mastra Cloud, logs are shown on the [Logs](https://mastra.ai/docs/mastra-cloud/observability) page. In self-hosted or custom environments, logs can be directed to files or external services depending on the configured transports.
6
-
7
- ## Configuring logs with `PinoLogger`
8
-
9
- When [initializing a new Mastra project](https://mastra.ai/guides/getting-started/quickstart) using the CLI, `PinoLogger` is included by default.
10
-
11
- ```typescript
12
- import { Mastra } from '@mastra/core/mastra'
13
- import { PinoLogger } from '@mastra/loggers'
14
-
15
- export const mastra = new Mastra({
16
- logger: new PinoLogger({
17
- name: 'Mastra',
18
- level: 'info',
19
- }),
20
- })
21
- ```
22
-
23
- > **Info:** Visit [PinoLogger](https://mastra.ai/reference/logging/pino-logger) for all available configuration options.
24
-
25
- ## Customizing logs
26
-
27
- Mastra provides access to a logger instance via the `mastra.getLogger()` method, available inside both workflow steps and tools. The logger supports standard severity levels: `debug`, `info`, `warn`, and `error`.
28
-
29
- ### Logging from workflow steps
30
-
31
- Within a workflow step, access the logger via the `mastra` parameter inside the `execute` function. This allows you to log messages relevant to the step’s execution.
32
-
33
- ```typescript
34
- import { createWorkflow, createStep } from "@mastra/core/workflows";
35
- import { z } from "zod";
36
-
37
- const step1 = createStep({
38
- execute: async ({ mastra }) => {
39
- const logger = mastra.getLogger();
40
- logger.info("workflow info log");
41
-
42
- return {
43
- output: ""
44
- };
45
- }
46
- });
47
-
48
- export const testWorkflow = createWorkflow({...})
49
- .then(step1)
50
- .commit();
51
- ```
52
-
53
- ### Logging from tools
54
-
55
- Similarly, tools have access to the logger instance via the `mastra` parameter. Use this to log tool specific activity during execution.
56
-
57
- ```typescript
58
- import { createTool } from '@mastra/core/tools'
59
- import { z } from 'zod'
60
-
61
- export const testTool = createTool({
62
- execute: async (inputData, context) => {
63
- const logger = context?.mastra.getLogger()
64
- logger?.info('tool info log')
65
-
66
- return {
67
- output: '',
68
- }
69
- },
70
- })
71
- ```
72
-
73
- ### Logging with additional data
74
-
75
- Logger methods accept an optional second argument for additional data. This can be any value, such as an object, string, or number.
76
-
77
- In this example, the log message includes an object with a key of `agent` and a value of the `testAgent` instance.
78
-
79
- ```typescript
80
- import { createWorkflow, createStep } from "@mastra/core/workflows";
81
- import { z } from "zod";
82
-
83
- const step1 = createStep({
84
- execute: async ({ mastra }) => {
85
- const testAgent = mastra.getAgent("testAgent");
86
- const logger = mastra.getLogger();
87
-
88
- logger.info("workflow info log", { agent: testAgent });
89
-
90
- return {
91
- output: ""
92
- };
93
- }
94
- });
95
-
96
- export const testWorkflow = createWorkflow({...})
97
- .then(step1)
98
- .commit();
99
- ```
@@ -1,70 +0,0 @@
1
- # Observability overview
2
-
3
- Mastra provides observability features for AI applications. Monitor LLM operations, trace agent decisions, and debug complex workflows with tools that understand AI-specific patterns.
4
-
5
- ## Key features
6
-
7
- ### Tracing
8
-
9
- Specialized tracing for AI operations that captures:
10
-
11
- - **Model interactions**: Token usage, latency, prompts, and completions
12
- - **Agent execution**: Decision paths, tool calls, and memory operations
13
- - **Workflow steps**: Branching logic, parallel execution, and step outputs
14
- - **Automatic instrumentation**: Tracing with decorators
15
-
16
- ## Storage requirements
17
-
18
- The `DefaultExporter` persists traces to your configured storage backend. Not all storage providers support observability—for the full list, see [Storage Provider Support](https://mastra.ai/docs/observability/tracing/exporters/default).
19
-
20
- For production environments with high traffic, we recommend using **ClickHouse** for the observability domain via [composite storage](https://mastra.ai/reference/storage/composite). See [Production Recommendations](https://mastra.ai/docs/observability/tracing/exporters/default) for details.
21
-
22
- ## Quickstart
23
-
24
- Configure Observability in your Mastra instance:
25
-
26
- ```typescript
27
- import { Mastra } from '@mastra/core'
28
- import { PinoLogger } from '@mastra/loggers'
29
- import { LibSQLStore } from '@mastra/libsql'
30
- import {
31
- Observability,
32
- DefaultExporter,
33
- CloudExporter,
34
- SensitiveDataFilter,
35
- } from '@mastra/observability'
36
-
37
- export const mastra = new Mastra({
38
- logger: new PinoLogger(),
39
- storage: new LibSQLStore({
40
- id: 'mastra-storage',
41
- url: 'file:./mastra.db', // Storage is required for tracing
42
- }),
43
- observability: new Observability({
44
- configs: {
45
- default: {
46
- serviceName: 'mastra',
47
- exporters: [
48
- new DefaultExporter(), // Persists traces to storage for Mastra Studio
49
- new CloudExporter(), // Sends traces to Mastra Cloud (if MASTRA_CLOUD_ACCESS_TOKEN is set)
50
- ],
51
- spanOutputProcessors: [
52
- new SensitiveDataFilter(), // Redacts sensitive data like passwords, tokens, keys
53
- ],
54
- },
55
- },
56
- }),
57
- })
58
- ```
59
-
60
- > **Serverless environments:** The `file:./mastra.db` storage URL uses the local filesystem, which doesn't work in serverless environments like Vercel, AWS Lambda, or Cloudflare Workers. For serverless deployments, use external storage. See the [Vercel deployment guide](https://mastra.ai/guides/deployment/vercel) for a complete example.
61
-
62
- With this basic setup, you will see Traces and Logs in both Studio and in Mastra Cloud.
63
-
64
- We also support various external tracing providers like MLflow, Langfuse, Braintrust, and any OpenTelemetry-compatible platform (Datadog, New Relic, SigNoz, etc.). See more about this in the [Tracing](https://mastra.ai/docs/observability/tracing/overview) documentation.
65
-
66
- ## What's next?
67
-
68
- - **[Set up Tracing](https://mastra.ai/docs/observability/tracing/overview)**: Configure tracing for your application
69
- - **[Configure Logging](https://mastra.ai/docs/observability/logging)**: Add structured logging
70
- - **[API Reference](https://mastra.ai/reference/observability/tracing/instances)**: Detailed configuration options
@@ -1,209 +0,0 @@
1
- # OpenTelemetry bridge
2
-
3
- > **Warning:** The OpenTelemetry Bridge is currently **experimental**. APIs and configuration options may change in future releases.
4
-
5
- The OpenTelemetry (OTEL) Bridge enables bidirectional integration between Mastra's tracing system and existing OpenTelemetry infrastructure. Unlike exporters that send trace data to external platforms, the bridge creates native OTEL spans that participate in your distributed tracing context.
6
-
7
- > **Looking to send traces without existing OTEL infrastructure?:** If you don't have existing OpenTelemetry instrumentation, the [OpenTelemetry Exporter](https://mastra.ai/docs/observability/tracing/exporters/otel) may be simpler — it sends traces directly without requiring an OTEL SDK setup.
8
-
9
- ## When to use the bridge
10
-
11
- Use the OtelBridge when you:
12
-
13
- - Have existing OTEL instrumentation in your application (HTTP servers, database clients, etc.)
14
- - Want Mastra operations to appear as child spans of your existing OTEL traces
15
- - Need OTEL-instrumented code inside Mastra tools to maintain proper parent-child relationships
16
- - Are building a distributed system where trace context must propagate across services
17
-
18
- ## How it works
19
-
20
- The OtelBridge provides two-way integration:
21
-
22
- **From OTEL to Mastra:**
23
-
24
- - Reads from OTEL ambient context (AsyncLocalStorage) automatically
25
- - Inherits trace ID and parent span ID from active OTEL spans
26
- - Respects OTEL sampling decisions — if a trace isn't sampled, Mastra won't create spans for it
27
- - No manual trace ID passing required when OTEL auto-instrumentation is active
28
-
29
- **From Mastra to OTEL:**
30
-
31
- - Creates native OTEL spans for Mastra operations (agents, LLM calls, tools, workflows)
32
- - Maintains proper parent-child relationships in distributed traces
33
- - Allows OTEL-instrumented code (HTTP clients, database calls) within Mastra operations to nest correctly
34
-
35
- ## Installation
36
-
37
- **npm**:
38
-
39
- ```bash
40
- npm install @mastra/otel-bridge
41
- ```
42
-
43
- **pnpm**:
44
-
45
- ```bash
46
- pnpm add @mastra/otel-bridge
47
- ```
48
-
49
- **Yarn**:
50
-
51
- ```bash
52
- yarn add @mastra/otel-bridge
53
- ```
54
-
55
- **Bun**:
56
-
57
- ```bash
58
- bun add @mastra/otel-bridge
59
- ```
60
-
61
- The bridge works with your existing OpenTelemetry setup. Depending on your configuration, you may also need some of these packages:
62
-
63
- - `@opentelemetry/sdk-node` - Core Node.js SDK for OTEL
64
- - `@opentelemetry/auto-instrumentations-node` - Auto-instrumentation for common libraries
65
- - `@opentelemetry/exporter-trace-otlp-proto` - OTLP exporter (Protobuf over HTTP)
66
- - `@opentelemetry/exporter-trace-otlp-http` - OTLP exporter (JSON over HTTP)
67
- - `@opentelemetry/exporter-trace-otlp-grpc` - OTLP exporter (gRPC)
68
- - `@opentelemetry/sdk-trace-base` - Base tracing SDK (for BatchSpanProcessor, etc.)
69
- - `@opentelemetry/core` - Core utilities (for W3CTraceContextPropagator, etc.)
70
-
71
- ## Configuration
72
-
73
- Using the OtelBridge requires two steps:
74
-
75
- 1. Configure OpenTelemetry instrumentation in your application
76
- 2. Add the OtelBridge to your Mastra observability config
77
-
78
- ### Step 1: OpenTelemetry Instrumentation
79
-
80
- Create an instrumentation file that initializes OTEL. This must run before your application code:
81
-
82
- ```typescript
83
- import { NodeSDK } from '@opentelemetry/sdk-node'
84
- import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node'
85
- import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto'
86
- import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base'
87
- import { W3CTraceContextPropagator } from '@opentelemetry/core'
88
-
89
- const sdk = new NodeSDK({
90
- serviceName: 'my-service',
91
- spanProcessors: [
92
- new BatchSpanProcessor(
93
- new OTLPTraceExporter({
94
- url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'http://localhost:4318/v1/traces',
95
- }),
96
- ),
97
- ],
98
- instrumentations: [getNodeAutoInstrumentations()],
99
- textMapPropagator: new W3CTraceContextPropagator(),
100
- })
101
-
102
- sdk.start()
103
-
104
- export { sdk }
105
- ```
106
-
107
- ### Step 2: Mastra Configuration
108
-
109
- Add the OtelBridge to your Mastra observability config:
110
-
111
- ```typescript
112
- import { Mastra } from '@mastra/core'
113
- import { Observability } from '@mastra/observability'
114
- import { OtelBridge } from '@mastra/otel-bridge'
115
-
116
- export const mastra = new Mastra({
117
- observability: new Observability({
118
- configs: {
119
- default: {
120
- serviceName: 'my-service',
121
- bridge: new OtelBridge(),
122
- },
123
- },
124
- }),
125
- agents: {
126
- /* your agents */
127
- },
128
- })
129
- ```
130
-
131
- No Mastra exporters are required when using the bridge — traces are sent via your OTEL SDK configuration. You can optionally add Mastra exporters if you want to send traces to additional destinations.
132
-
133
- ### Running Your Application
134
-
135
- Use the `--import` flag to ensure instrumentation loads before your application:
136
-
137
- ```bash
138
- tsx --import ./instrumentation.ts ./src/index.ts
139
- ```
140
-
141
- ## Semantic conventions
142
-
143
- The OtelBridge exports Mastra spans using [OpenTelemetry Semantic Conventions for GenAI v1.38.0](https://github.com/open-telemetry/semantic-conventions/tree/v1.38.0/docs/gen-ai). This includes standardized span names (`chat {model}`, `execute_tool {tool_name}`, etc.) and attributes (`gen_ai.usage.input_tokens`, `gen_ai.request.model`, etc.).
144
-
145
- For details on span naming and attributes, see the [OpenTelemetry Exporter semantic conventions](https://mastra.ai/docs/observability/tracing/exporters/otel).
146
-
147
- ## Trace hierarchy
148
-
149
- With the OtelBridge, your traces maintain proper hierarchy across OTEL and Mastra boundaries:
150
-
151
- ```text
152
- HTTP POST /api/chat (from Hono middleware)
153
- └── agent.assistant (from Mastra via OtelBridge)
154
- ├── chat gpt-5.4 (LLM call)
155
- ├── tool.execute search (tool execution)
156
- │ └── HTTP GET api.example.com (from OTEL auto-instrumentation)
157
- └── chat gpt-5.4 (follow-up LLM call)
158
- ```
159
-
160
- ## Multi-service distributed tracing
161
-
162
- The OtelBridge enables trace propagation across service boundaries. When Service A calls Service B via HTTP, trace context propagates automatically:
163
-
164
- ```text
165
- Service A: HTTP POST /api/process
166
- └── HTTP POST service-b/api/analyze (outgoing call)
167
-
168
- Service B: HTTP POST /api/analyze (incoming call - same trace!)
169
- └── agent.analyzer (Mastra agent inherits trace context)
170
- └── chat gpt-5.4
171
- ```
172
-
173
- Both services must have:
174
-
175
- 1. OTEL instrumentation configured
176
- 2. W3C Trace Context propagator enabled
177
- 3. Mastra with OtelBridge configured
178
-
179
- ## Using tags
180
-
181
- Tags help you categorize and filter traces in your OTEL backend. Add tags when executing agents or workflows:
182
-
183
- ```typescript
184
- const result = await agent.generate('Hello', {
185
- tracingOptions: {
186
- tags: ['production', 'experiment-v2', 'user-request'],
187
- },
188
- })
189
- ```
190
-
191
- Tags are exported as a JSON string in the `mastra.tags` span attribute for broad backend compatibility. Common use cases include:
192
-
193
- - Environment labels: `"production"`, `"staging"`
194
- - Experiment tracking: `"experiment-v1"`, `"control-group"`
195
- - Priority levels: `"priority-high"`, `"batch-job"`
196
-
197
- ## Troubleshooting
198
-
199
- If traces aren't displaying or connecting as expected:
200
-
201
- - Verify OTEL SDK is initialized before Mastra (use `--import` flag or import at top of entry point)
202
- - Ensure the OtelBridge is added to your observability config
203
- - Check that your OTEL backend is running and accessible
204
-
205
- ## Related
206
-
207
- - [Tracing Overview](https://mastra.ai/docs/observability/tracing/overview)
208
- - [OpenTelemetry Exporter](https://mastra.ai/docs/observability/tracing/exporters/otel) - For sending traces to OTEL backends
209
- - [OtelBridge Reference](https://mastra.ai/reference/observability/tracing/bridges/otel) - API documentation
@@ -1,272 +0,0 @@
1
- # Arize exporter
2
-
3
- [Arize](https://arize.com/) provides observability platforms for AI applications through [Phoenix](https://phoenix.arize.com/) (open-source) and [Arize AX](https://arize.com/generative-ai/) (enterprise). The Arize exporter sends traces using OpenTelemetry and [OpenInference](https://github.com/Arize-ai/openinference/tree/main/spec) semantic conventions, compatible with any OpenTelemetry platform that supports OpenInference.
4
-
5
- ## Installation
6
-
7
- **npm**:
8
-
9
- ```bash
10
- npm install @mastra/arize@latest
11
- ```
12
-
13
- **pnpm**:
14
-
15
- ```bash
16
- pnpm add @mastra/arize@latest
17
- ```
18
-
19
- **Yarn**:
20
-
21
- ```bash
22
- yarn add @mastra/arize@latest
23
- ```
24
-
25
- **Bun**:
26
-
27
- ```bash
28
- bun add @mastra/arize@latest
29
- ```
30
-
31
- ## Configuration
32
-
33
- ### Phoenix Setup
34
-
35
- Phoenix is an open-source observability platform that can be self-hosted or used via Phoenix Cloud.
36
-
37
- #### Prerequisites
38
-
39
- 1. **Phoenix Instance**: Deploy using Docker or sign up at [Phoenix Cloud](https://app.phoenix.arize.com/login)
40
- 2. **Endpoint**: Your Phoenix endpoint URL (ends in `/v1/traces`)
41
- 3. **API Key**: Optional for unauthenticated instances, required for Phoenix Cloud
42
- 4. **Environment Variables**: Set your configuration
43
-
44
- ```bash
45
- # Required
46
- PHOENIX_ENDPOINT=http://localhost:6006/v1/traces # Or your Phoenix Cloud URL
47
-
48
- # Optional
49
- PHOENIX_API_KEY=your-api-key # For authenticated Phoenix instances
50
- PHOENIX_PROJECT_NAME=mastra-service # Defaults to 'mastra-service'
51
- ```
52
-
53
- #### Zero-Config Setup
54
-
55
- With environment variables set, use the exporter with no configuration:
56
-
57
- ```typescript
58
- import { Mastra } from '@mastra/core'
59
- import { Observability } from '@mastra/observability'
60
- import { ArizeExporter } from '@mastra/arize'
61
-
62
- export const mastra = new Mastra({
63
- observability: new Observability({
64
- configs: {
65
- arize: {
66
- serviceName: 'mastra-service',
67
- exporters: [new ArizeExporter()],
68
- },
69
- },
70
- }),
71
- })
72
- ```
73
-
74
- #### Explicit Configuration
75
-
76
- You can also pass credentials directly (takes precedence over environment variables):
77
-
78
- ```typescript
79
- import { Mastra } from '@mastra/core'
80
- import { Observability } from '@mastra/observability'
81
- import { ArizeExporter } from '@mastra/arize'
82
-
83
- export const mastra = new Mastra({
84
- observability: new Observability({
85
- configs: {
86
- arize: {
87
- serviceName: process.env.PHOENIX_PROJECT_NAME || 'mastra-service',
88
- exporters: [
89
- new ArizeExporter({
90
- endpoint: process.env.PHOENIX_ENDPOINT!,
91
- apiKey: process.env.PHOENIX_API_KEY,
92
- projectName: process.env.PHOENIX_PROJECT_NAME,
93
- }),
94
- ],
95
- },
96
- },
97
- }),
98
- })
99
- ```
100
-
101
- > **Quickstart with Docker:** Test locally with an in-memory Phoenix instance:
102
- >
103
- > ```bash
104
- > docker run --pull=always -d --name arize-phoenix -p 6006:6006 \
105
- > -e PHOENIX_SQL_DATABASE_URL="sqlite:///:memory:" \
106
- > arizephoenix/phoenix:latest
107
- > ```
108
- >
109
- > Set `PHOENIX_ENDPOINT=http://localhost:6006/v1/traces` and run your Mastra agent to see traces at [localhost:6006](http://localhost:6006).
110
-
111
- ### Arize AX Setup
112
-
113
- Arize AX is an enterprise observability platform with advanced features for production AI systems.
114
-
115
- #### Prerequisites
116
-
117
- 1. **Arize AX Account**: Sign up at [app.arize.com](https://app.arize.com/)
118
- 2. **Space ID**: Your organization's space identifier
119
- 3. **API Key**: Generate in Arize AX settings
120
- 4. **Environment Variables**: Set your credentials
121
-
122
- ```bash
123
- # Required
124
- ARIZE_SPACE_ID=your-space-id
125
- ARIZE_API_KEY=your-api-key
126
-
127
- # Optional
128
- ARIZE_PROJECT_NAME=mastra-service
129
- ```
130
-
131
- #### Zero-Config Setup
132
-
133
- With environment variables set, use the exporter with no configuration:
134
-
135
- ```typescript
136
- import { Mastra } from '@mastra/core'
137
- import { Observability } from '@mastra/observability'
138
- import { ArizeExporter } from '@mastra/arize'
139
-
140
- export const mastra = new Mastra({
141
- observability: new Observability({
142
- configs: {
143
- arize: {
144
- serviceName: 'mastra-service',
145
- exporters: [new ArizeExporter()],
146
- },
147
- },
148
- }),
149
- })
150
- ```
151
-
152
- #### Explicit Configuration
153
-
154
- You can also pass credentials directly (takes precedence over environment variables):
155
-
156
- ```typescript
157
- import { Mastra } from '@mastra/core'
158
- import { Observability } from '@mastra/observability'
159
- import { ArizeExporter } from '@mastra/arize'
160
-
161
- export const mastra = new Mastra({
162
- observability: new Observability({
163
- configs: {
164
- arize: {
165
- serviceName: process.env.ARIZE_PROJECT_NAME || 'mastra-service',
166
- exporters: [
167
- new ArizeExporter({
168
- apiKey: process.env.ARIZE_API_KEY!,
169
- spaceId: process.env.ARIZE_SPACE_ID!,
170
- projectName: process.env.ARIZE_PROJECT_NAME,
171
- }),
172
- ],
173
- },
174
- },
175
- }),
176
- })
177
- ```
178
-
179
- ## Configuration options
180
-
181
- The Arize exporter supports advanced configuration for fine-tuning OpenTelemetry behavior:
182
-
183
- ### Complete Configuration
184
-
185
- ```typescript
186
- new ArizeExporter({
187
- // Phoenix Configuration
188
- endpoint: 'https://your-collector.example.com/v1/traces', // Required for Phoenix
189
-
190
- // Arize AX Configuration
191
- spaceId: 'your-space-id', // Required for Arize AX
192
-
193
- // Shared Configuration
194
- apiKey: 'your-api-key', // Required for authenticated endpoints
195
- projectName: 'mastra-service', // Optional project name
196
-
197
- // Optional OTLP settings
198
- headers: {
199
- 'x-custom-header': 'value', // Additional headers for OTLP requests
200
- },
201
-
202
- // Debug and performance tuning
203
- logLevel: 'debug', // Logging: debug | info | warn | error
204
- batchSize: 512, // Batch size before exporting spans
205
- timeout: 30000, // Timeout in ms before exporting spans
206
-
207
- // Custom resource attributes
208
- resourceAttributes: {
209
- 'deployment.environment': process.env.NODE_ENV,
210
- 'service.version': process.env.APP_VERSION,
211
- },
212
- })
213
- ```
214
-
215
- ### Batch Processing Options
216
-
217
- Control how traces are batched and exported:
218
-
219
- ```typescript
220
- new ArizeExporter({
221
- endpoint: process.env.PHOENIX_ENDPOINT!,
222
- apiKey: process.env.PHOENIX_API_KEY,
223
-
224
- // Batch processing configuration
225
- batchSize: 512, // Number of spans to batch (default: 512)
226
- timeout: 30000, // Max time in ms to wait before export (default: 30000)
227
- })
228
- ```
229
-
230
- ### Resource Attributes
231
-
232
- Add custom attributes to all exported spans:
233
-
234
- ```typescript
235
- new ArizeExporter({
236
- endpoint: process.env.PHOENIX_ENDPOINT!,
237
- resourceAttributes: {
238
- 'deployment.environment': process.env.NODE_ENV,
239
- 'service.namespace': 'production',
240
- 'service.instance.id': process.env.HOSTNAME,
241
- 'custom.attribute': 'value',
242
- },
243
- })
244
- ```
245
-
246
- ### Custom metadata
247
-
248
- Non-reserved span attributes are serialized into the OpenInference `metadata` payload and surface in Arize/Phoenix. You can add them via `tracingOptions.metadata`:
249
-
250
- ```ts
251
- await agent.generate(input, {
252
- tracingOptions: {
253
- metadata: {
254
- companyId: 'acme-co',
255
- tier: 'enterprise',
256
- },
257
- },
258
- })
259
- ```
260
-
261
- Reserved fields such as `input`, `output`, `sessionId`, thread/user IDs, and OpenInference IDs are excluded automatically.
262
-
263
- ## OpenInference semantic conventions
264
-
265
- This exporter implements the [OpenInference Semantic Conventions](https://github.com/Arize-ai/openinference/tree/main/spec) for generative AI applications, providing standardized trace structure across different observability platforms.
266
-
267
- ## Related
268
-
269
- - [Tracing Overview](https://mastra.ai/docs/observability/tracing/overview)
270
- - [Phoenix Documentation](https://docs.arize.com/phoenix)
271
- - [Arize AX Documentation](https://docs.arize.com/)
272
- - [OpenInference Specification](https://github.com/Arize-ai/openinference/tree/main/spec)