@mastra/mcp-docs-server 0.13.24 → 0.13.25-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/organized/changelogs/%40internal%2Fstorage-test-utils.md +8 -8
- package/.docs/organized/changelogs/%40internal%2Ftypes-builder.md +2 -0
- package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +12 -0
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +11 -0
- package/.docs/organized/changelogs/%40mastra%2Fastra.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +29 -29
- package/.docs/organized/changelogs/%40mastra%2Fcloud.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +70 -70
- package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +23 -23
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +30 -30
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +15 -15
- package/.docs/organized/changelogs/%40mastra%2Flance.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +18 -18
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +16 -16
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +50 -50
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Frag.md +13 -13
- package/.docs/organized/changelogs/%40mastra%2Freact-hooks.md +8 -0
- package/.docs/organized/changelogs/%40mastra%2Fs3vectors.md +9 -0
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +36 -36
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +13 -13
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-gladia.md +9 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google-gemini-live.md +9 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +10 -10
- package/.docs/organized/changelogs/create-mastra.md +22 -22
- package/.docs/organized/changelogs/mastra.md +46 -46
- package/.docs/raw/index.mdx +1 -0
- package/.docs/raw/observability/ai-tracing/exporters/braintrust.mdx +81 -0
- package/.docs/raw/observability/ai-tracing/exporters/cloud.mdx +120 -0
- package/.docs/raw/observability/ai-tracing/exporters/default.mdx +167 -0
- package/.docs/raw/observability/ai-tracing/exporters/langfuse.mdx +121 -0
- package/.docs/raw/observability/ai-tracing/overview.mdx +565 -0
- package/.docs/raw/observability/ai-tracing/processors/sensitive-data-filter.mdx +274 -0
- package/.docs/raw/observability/{tracing.mdx → otel-tracing.mdx} +2 -2
- package/.docs/raw/observability/overview.mdx +66 -0
- package/.docs/raw/reference/agents/generate.mdx +39 -1
- package/.docs/raw/reference/agents/generateVNext.mdx +34 -2
- package/.docs/raw/reference/agents/network.mdx +34 -2
- package/.docs/raw/reference/observability/ai-tracing/ai-tracing.mdx +181 -0
- package/.docs/raw/reference/observability/ai-tracing/configuration.mdx +233 -0
- package/.docs/raw/reference/observability/ai-tracing/exporters/braintrust.mdx +112 -0
- package/.docs/raw/reference/observability/ai-tracing/exporters/cloud-exporter.mdx +176 -0
- package/.docs/raw/reference/observability/ai-tracing/exporters/console-exporter.mdx +148 -0
- package/.docs/raw/reference/observability/ai-tracing/exporters/default-exporter.mdx +196 -0
- package/.docs/raw/reference/observability/ai-tracing/exporters/langfuse.mdx +116 -0
- package/.docs/raw/reference/observability/ai-tracing/interfaces.mdx +651 -0
- package/.docs/raw/reference/observability/ai-tracing/processors/sensitive-data-filter.mdx +178 -0
- package/.docs/raw/reference/observability/ai-tracing/span.mdx +371 -0
- package/.docs/raw/reference/observability/otel-tracing/providers/index.mdx +22 -0
- package/.docs/raw/reference/streaming/agents/stream.mdx +39 -1
- package/.docs/raw/reference/streaming/agents/streamVNext.mdx +34 -2
- package/.docs/raw/reference/streaming/workflows/stream.mdx +38 -0
- package/.docs/raw/reference/streaming/workflows/streamVNext.mdx +38 -0
- package/.docs/raw/reference/tools/create-tool.mdx +34 -1
- package/.docs/raw/reference/workflows/run-methods/resume.mdx +38 -0
- package/.docs/raw/reference/workflows/run-methods/start.mdx +38 -0
- package/CHANGELOG.md +7 -0
- package/package.json +3 -3
- package/.docs/raw/observability/ai-tracing.mdx +0 -597
- package/.docs/raw/reference/observability/providers/index.mdx +0 -20
- /package/.docs/raw/reference/observability/{logger.mdx → logging/pino-logger.mdx} +0 -0
- /package/.docs/raw/reference/observability/{otel-config.mdx → otel-tracing/otel-config.mdx} +0 -0
- /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/arize-ax.mdx +0 -0
- /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/arize-phoenix.mdx +0 -0
- /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/braintrust.mdx +0 -0
- /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/dash0.mdx +0 -0
- /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/keywordsai.mdx +0 -0
- /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/laminar.mdx +0 -0
- /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/langfuse.mdx +0 -0
- /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/langsmith.mdx +0 -0
- /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/langwatch.mdx +0 -0
- /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/new-relic.mdx +0 -0
- /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/signoz.mdx +0 -0
- /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/traceloop.mdx +0 -0
|
@@ -1,597 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: "AI Tracing | Mastra Observability Documentation"
|
|
3
|
-
description: "Set up AI tracing for Mastra applications"
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
import { Callout } from "nextra/components";
|
|
7
|
-
|
|
8
|
-
# AI Tracing
|
|
9
|
-
|
|
10
|
-
AI Tracing provides specialized monitoring and debugging for the AI-related operations in your application. When enabled, Mastra automatically creates traces for agent runs, LLM generations, tool calls, and workflow steps with AI-specific context and metadata.
|
|
11
|
-
|
|
12
|
-
Unlike traditional application tracing, AI Tracing focuses specifically on understanding your AI pipeline — capturing token usage, model parameters, tool execution details, and conversation flows. This makes it easier to debug issues, optimize performance, and understand how your AI systems behave in production.
|
|
13
|
-
|
|
14
|
-
You create AI traces by:
|
|
15
|
-
|
|
16
|
-
- **Configuring exporters** to send trace data to observability platforms like Langfuse
|
|
17
|
-
- **Setting sampling strategies** to control which traces are collected
|
|
18
|
-
- **Running agents and workflows** — Mastra automatically instruments them with detailed AI tracing
|
|
19
|
-
|
|
20
|
-
This provides full visibility into your AI operations with minimal setup, helping you build more reliable and observable AI applications.
|
|
21
|
-
|
|
22
|
-
<Callout type="warning">
|
|
23
|
-
**Experimental Feature**
|
|
24
|
-
|
|
25
|
-
AI Tracing is available as of `@mastra/core 0.14.0` and is currently experimental. The API may change in future releases.
|
|
26
|
-
</Callout>
|
|
27
|
-
|
|
28
|
-
## How It Differs from Standard Tracing
|
|
29
|
-
|
|
30
|
-
AI Tracing complements Mastra's existing [OpenTelemetry-based tracing](./tracing.mdx) but serves a different purpose:
|
|
31
|
-
|
|
32
|
-
| Feature | Standard Tracing | AI Tracing |
|
|
33
|
-
|---------|-----------------|------------|
|
|
34
|
-
| **Focus** | Application infrastructure | AI operations only |
|
|
35
|
-
| **Data Format** | OpenTelemetry standard | Provider-native (Langfuse, etc.) |
|
|
36
|
-
| **Timing** | Batch export | Real-time option for debugging |
|
|
37
|
-
| **Metadata** | Generic span attributes | AI-specific (tokens, models, tools) |
|
|
38
|
-
|
|
39
|
-
## Current Status
|
|
40
|
-
|
|
41
|
-
**Supported Exporters:**
|
|
42
|
-
- ✅ [Langfuse](https://langfuse.com/) - Full support with real-time mode
|
|
43
|
-
- ✅ [Braintrust](https://www.braintrust.dev/home) - Initial release
|
|
44
|
-
- 🔄 [OpenTelemetry](https://opentelemetry.io/) - Coming soon
|
|
45
|
-
|
|
46
|
-
**Known Limitations:**
|
|
47
|
-
- Mastra playground traces still use the legacy tracing system
|
|
48
|
-
- API is experimental and may change
|
|
49
|
-
|
|
50
|
-
For the latest updates, see [GitHub issue #6773](https://github.com/mastra-ai/mastra/issues/6773).
|
|
51
|
-
|
|
52
|
-
## Basic Configuration
|
|
53
|
-
|
|
54
|
-
```ts filename="src/mastra/index.ts" showLineNumbers copy
|
|
55
|
-
export const mastra = new Mastra({
|
|
56
|
-
// ... other config
|
|
57
|
-
observability: {
|
|
58
|
-
default: { enabled: true }, // Enables DefaultExporter and CloudExporter
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
## Configuration Options
|
|
64
|
-
|
|
65
|
-
The AI tracing config accepts these properties:
|
|
66
|
-
|
|
67
|
-
```ts
|
|
68
|
-
type AITracingConfig = {
|
|
69
|
-
// Enable default configuration with built-in exporters
|
|
70
|
-
default?: {
|
|
71
|
-
enabled?: boolean;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
// Map of tracing instance names to their configurations
|
|
75
|
-
configs?: Record<string, AITracingInstanceConfig | MastraAITracing>;
|
|
76
|
-
|
|
77
|
-
// Optional function to select which tracing instance to use
|
|
78
|
-
configSelector?: TracingSelector;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
type AITracingInstanceConfig = {
|
|
82
|
-
// Name to identify your service in traces
|
|
83
|
-
serviceName: string;
|
|
84
|
-
|
|
85
|
-
// Control how many traces are sampled
|
|
86
|
-
sampling?: {
|
|
87
|
-
type: "always" | "never" | "ratio" | "custom";
|
|
88
|
-
probability?: number; // For ratio sampling (0.0 to 1.0)
|
|
89
|
-
sampler?: (context: TraceContext) => boolean; // For custom sampling
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
// Array of exporters to send trace data to
|
|
93
|
-
exporters?: AITracingExporter[];
|
|
94
|
-
|
|
95
|
-
// Array of processors to transform spans before export
|
|
96
|
-
processors?: AISpanProcessor[];
|
|
97
|
-
};
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
### Default Configuration
|
|
101
|
-
|
|
102
|
-
When `default.enabled` is set to `true`, Mastra automatically configures AI tracing with sensible defaults:
|
|
103
|
-
|
|
104
|
-
```ts filename="src/mastra/index.ts" showLineNumbers copy
|
|
105
|
-
export const mastra = new Mastra({
|
|
106
|
-
observability: {
|
|
107
|
-
default: { enabled: true },
|
|
108
|
-
configs: {
|
|
109
|
-
// Your custom configs can coexist with the default
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
The default configuration includes:
|
|
116
|
-
- **Service Name**: `"mastra"`
|
|
117
|
-
- **Sampling**: Always sample (100% of traces)
|
|
118
|
-
- **Exporters**:
|
|
119
|
-
- `DefaultExporter` - Persists traces to your configured storage
|
|
120
|
-
- `CloudExporter` - Sends traces to Mastra Cloud (requires `MASTRA_CLOUD_ACCESS_TOKEN`)
|
|
121
|
-
- **Processors**: `SensitiveDataFilter` - Automatically redacts sensitive fields
|
|
122
|
-
|
|
123
|
-
<Callout type="info">
|
|
124
|
-
**Note**: You cannot name a custom config `"default"` when the default configuration is enabled. This will throw an error to prevent naming conflicts.
|
|
125
|
-
</Callout>
|
|
126
|
-
|
|
127
|
-
### Sampling Configuration
|
|
128
|
-
|
|
129
|
-
Control which traces are collected and exported:
|
|
130
|
-
|
|
131
|
-
```ts filename="src/mastra/index.ts" showLineNumbers copy
|
|
132
|
-
export const mastra = new Mastra({
|
|
133
|
-
observability: {
|
|
134
|
-
configs: {
|
|
135
|
-
langfuse: {
|
|
136
|
-
serviceName: 'my-service',
|
|
137
|
-
// Sample all traces (default)
|
|
138
|
-
sampling: { type: 'always' },
|
|
139
|
-
exporters: [langfuseExporter],
|
|
140
|
-
},
|
|
141
|
-
|
|
142
|
-
development: {
|
|
143
|
-
serviceName: 'dev-service',
|
|
144
|
-
// Sample 10% of traces
|
|
145
|
-
sampling: {
|
|
146
|
-
type: 'ratio',
|
|
147
|
-
probability: 0.1
|
|
148
|
-
},
|
|
149
|
-
exporters: [langfuseExporter],
|
|
150
|
-
},
|
|
151
|
-
|
|
152
|
-
custom: {
|
|
153
|
-
serviceName: 'custom-service',
|
|
154
|
-
// Custom sampling logic
|
|
155
|
-
sampling: {
|
|
156
|
-
type: 'custom',
|
|
157
|
-
sampler: (context) => {
|
|
158
|
-
// Only trace requests from specific users
|
|
159
|
-
return context.metadata?.userId === 'debug-user';
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
exporters: [langfuseExporter],
|
|
163
|
-
},
|
|
164
|
-
},
|
|
165
|
-
},
|
|
166
|
-
});
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
## Exporters
|
|
170
|
-
|
|
171
|
-
### Built-in Exporters
|
|
172
|
-
|
|
173
|
-
Mastra includes two built-in exporters that are automatically configured when using the default configuration:
|
|
174
|
-
|
|
175
|
-
#### DefaultExporter
|
|
176
|
-
|
|
177
|
-
The `DefaultExporter` persists traces to your configured Mastra storage backend. It handles batching and retry logic automatically.
|
|
178
|
-
|
|
179
|
-
**Features:**
|
|
180
|
-
- Automatic batching with configurable batch size
|
|
181
|
-
- Retry logic for failed exports
|
|
182
|
-
- Strategy selection based on storage capabilities
|
|
183
|
-
- No external dependencies required
|
|
184
|
-
|
|
185
|
-
**Configuration:**
|
|
186
|
-
```ts
|
|
187
|
-
import { DefaultExporter } from '@mastra/core';
|
|
188
|
-
|
|
189
|
-
new DefaultExporter({
|
|
190
|
-
maxBatchSize: 1000, // Maximum spans per batch
|
|
191
|
-
maxBatchWaitMs: 5000, // Maximum wait time before flushing
|
|
192
|
-
maxRetries: 4, // Number of retry attempts
|
|
193
|
-
strategy: 'auto', // 'auto' | 'realtime' | 'batch-with-updates' | 'insert-only'
|
|
194
|
-
});
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
<Callout type="info">
|
|
198
|
-
If storage is not configured, the DefaultExporter will log a warning and operate as a no-op, allowing your application to continue without errors.
|
|
199
|
-
</Callout>
|
|
200
|
-
|
|
201
|
-
#### CloudExporter
|
|
202
|
-
|
|
203
|
-
The `CloudExporter` sends traces to Mastra Cloud for online visualization and analysis.
|
|
204
|
-
|
|
205
|
-
**Features:**
|
|
206
|
-
- Real-time trace visualization in Mastra Cloud dashboard
|
|
207
|
-
- Automatic batching and compression
|
|
208
|
-
- Secure token-based authentication
|
|
209
|
-
- Graceful fallback when token is not configured
|
|
210
|
-
|
|
211
|
-
**Configuration:**
|
|
212
|
-
```ts
|
|
213
|
-
import { CloudExporter } from '@mastra/core';
|
|
214
|
-
|
|
215
|
-
new CloudExporter({
|
|
216
|
-
accessToken: process.env.MASTRA_CLOUD_ACCESS_TOKEN, // Required (but can be pulled directly from the environment)
|
|
217
|
-
endpoint: 'https://api.mastra.ai/ai/spans/publish', // Optional custom endpoint
|
|
218
|
-
maxBatchSize: 1000, // Maximum spans per batch
|
|
219
|
-
maxBatchWaitMs: 5000, // Maximum wait time before flushing
|
|
220
|
-
});
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
**Environment Variables:**
|
|
224
|
-
- `MASTRA_CLOUD_ACCESS_TOKEN` - Your Mastra Cloud access token
|
|
225
|
-
- `MASTRA_CLOUD_AI_TRACES_ENDPOINT` - Optional custom endpoint URL
|
|
226
|
-
|
|
227
|
-
<Callout type="warning">
|
|
228
|
-
If `MASTRA_CLOUD_ACCESS_TOKEN` is not set, the CloudExporter will log a message directing you to sign up at [mastra.ai](https://mastra.ai) and operate as a no-op.
|
|
229
|
-
</Callout>
|
|
230
|
-
|
|
231
|
-
### Langfuse Exporter
|
|
232
|
-
|
|
233
|
-
#### Installation
|
|
234
|
-
|
|
235
|
-
```bash
|
|
236
|
-
npm install @mastra/langfuse
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
#### Configuration
|
|
240
|
-
|
|
241
|
-
The Langfuse exporter accepts these options:
|
|
242
|
-
|
|
243
|
-
```ts
|
|
244
|
-
type LangfuseExporterConfig = {
|
|
245
|
-
// Langfuse API credentials (required)
|
|
246
|
-
publicKey?: string;
|
|
247
|
-
secretKey?: string;
|
|
248
|
-
|
|
249
|
-
// Langfuse host URL (optional - defaults to Langfuse cloud)
|
|
250
|
-
baseUrl?: string;
|
|
251
|
-
|
|
252
|
-
// Enable realtime mode for immediate trace visibility
|
|
253
|
-
realtime?: boolean; // defaults to false
|
|
254
|
-
|
|
255
|
-
// Additional options passed to Langfuse client
|
|
256
|
-
options?: any;
|
|
257
|
-
};
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
#### Basic Setup
|
|
261
|
-
|
|
262
|
-
```ts filename="mastra.config.ts" showLineNumbers copy
|
|
263
|
-
import { LangfuseExporter } from '@mastra/langfuse';
|
|
264
|
-
|
|
265
|
-
export const mastra = new Mastra({
|
|
266
|
-
observability: {
|
|
267
|
-
configs: {
|
|
268
|
-
langfuse: {
|
|
269
|
-
serviceName: process.env.SERVICE_NAME || 'mastra-app',
|
|
270
|
-
sampling: { type: 'always' },
|
|
271
|
-
exporters: [
|
|
272
|
-
new LangfuseExporter({
|
|
273
|
-
publicKey: process.env.LANGFUSE_PUBLIC_KEY,
|
|
274
|
-
secretKey: process.env.LANGFUSE_SECRET_KEY,
|
|
275
|
-
baseUrl: process.env.LANGFUSE_BASE_URL, // Optional
|
|
276
|
-
realtime: process.env.NODE_ENV === 'development',
|
|
277
|
-
}),
|
|
278
|
-
],
|
|
279
|
-
},
|
|
280
|
-
},
|
|
281
|
-
},
|
|
282
|
-
});
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
#### Real-time vs Batch Mode
|
|
286
|
-
|
|
287
|
-
The Langfuse exporter supports two modes:
|
|
288
|
-
|
|
289
|
-
**Batch Mode (default)**
|
|
290
|
-
- Traces are buffered and sent periodically
|
|
291
|
-
- Better performance for production
|
|
292
|
-
- Traces may appear with slight delay
|
|
293
|
-
|
|
294
|
-
**Real-time Mode**
|
|
295
|
-
- Each trace event is immediately flushed
|
|
296
|
-
- Ideal for development and debugging
|
|
297
|
-
- Immediate visibility in Langfuse dashboard
|
|
298
|
-
|
|
299
|
-
```ts
|
|
300
|
-
new LangfuseExporter({
|
|
301
|
-
// ... other config
|
|
302
|
-
realtime: process.env.NODE_ENV === 'development',
|
|
303
|
-
})
|
|
304
|
-
```
|
|
305
|
-
|
|
306
|
-
### Braintrust Exporter
|
|
307
|
-
|
|
308
|
-
The Braintrust exporter sends trace data to [Braintrust](https://www.braintrust.dev/) for AI evaluation and monitoring.
|
|
309
|
-
|
|
310
|
-
#### Installation
|
|
311
|
-
|
|
312
|
-
```bash
|
|
313
|
-
npm install @mastra/braintrust
|
|
314
|
-
```
|
|
315
|
-
|
|
316
|
-
#### Configuration
|
|
317
|
-
|
|
318
|
-
```ts
|
|
319
|
-
type BraintrustExporterConfig = {
|
|
320
|
-
// Braintrust API key (required)
|
|
321
|
-
apiKey?: string;
|
|
322
|
-
|
|
323
|
-
// Optional custom endpoint
|
|
324
|
-
endpoint?: string;
|
|
325
|
-
|
|
326
|
-
// Logger level for diagnostic messages (default: 'warn')
|
|
327
|
-
logLevel?: 'debug' | 'info' | 'warn' | 'error';
|
|
328
|
-
|
|
329
|
-
// Additional tuning parameters passed to Braintrust
|
|
330
|
-
tuningParameters?: Record<string, any>;
|
|
331
|
-
};
|
|
332
|
-
```
|
|
333
|
-
|
|
334
|
-
#### Basic Setup
|
|
335
|
-
|
|
336
|
-
```ts filename="src/mastra/index.ts" showLineNumbers copy
|
|
337
|
-
import { BraintrustExporter } from '@mastra/braintrust';
|
|
338
|
-
|
|
339
|
-
export const mastra = new Mastra({
|
|
340
|
-
observability: {
|
|
341
|
-
configs: {
|
|
342
|
-
braintrust: {
|
|
343
|
-
serviceName: 'my-service',
|
|
344
|
-
exporters: [
|
|
345
|
-
new BraintrustExporter({
|
|
346
|
-
apiKey: process.env.BRAINTRUST_API_KEY,
|
|
347
|
-
endpoint: process.env.BRAINTRUST_ENDPOINT, // optional
|
|
348
|
-
}),
|
|
349
|
-
],
|
|
350
|
-
},
|
|
351
|
-
},
|
|
352
|
-
},
|
|
353
|
-
});
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
### Multi-Instance Configuration
|
|
357
|
-
|
|
358
|
-
You can configure multiple tracing instances and use a selector to choose which one to use:
|
|
359
|
-
|
|
360
|
-
```ts filename="mastra.config.ts" showLineNumbers copy
|
|
361
|
-
export const mastra = new Mastra({
|
|
362
|
-
observability: {
|
|
363
|
-
configs: {
|
|
364
|
-
production: {
|
|
365
|
-
serviceName: 'prod-service',
|
|
366
|
-
sampling: { type: 'ratio', probability: 0.1 },
|
|
367
|
-
exporters: [prodLangfuseExporter],
|
|
368
|
-
},
|
|
369
|
-
development: {
|
|
370
|
-
serviceName: 'dev-service',
|
|
371
|
-
sampling: { type: 'always' },
|
|
372
|
-
exporters: [devLangfuseExporter],
|
|
373
|
-
},
|
|
374
|
-
},
|
|
375
|
-
configSelector: (context, availableTracers) => {
|
|
376
|
-
// Use development tracer for debug sessions
|
|
377
|
-
if (context.runtimeContext?.get('debug') === 'true') {
|
|
378
|
-
return 'development';
|
|
379
|
-
}
|
|
380
|
-
return 'production';
|
|
381
|
-
},
|
|
382
|
-
},
|
|
383
|
-
});
|
|
384
|
-
```
|
|
385
|
-
|
|
386
|
-
You can also combine the default configuration with custom configs:
|
|
387
|
-
|
|
388
|
-
```ts filename="mastra.config.ts" showLineNumbers copy
|
|
389
|
-
export const mastra = new Mastra({
|
|
390
|
-
observability: {
|
|
391
|
-
default: { enabled: true }, // Provides 'default' instance
|
|
392
|
-
configs: {
|
|
393
|
-
langfuse: {
|
|
394
|
-
serviceName: 'langfuse-service',
|
|
395
|
-
exporters: [langfuseExporter],
|
|
396
|
-
},
|
|
397
|
-
},
|
|
398
|
-
configSelector: (context, availableTracers) => {
|
|
399
|
-
// Route specific requests to langfuse, others to default
|
|
400
|
-
if (context.runtimeContext?.get('useExternalTracing')) {
|
|
401
|
-
return 'langfuse';
|
|
402
|
-
}
|
|
403
|
-
return 'default';
|
|
404
|
-
},
|
|
405
|
-
},
|
|
406
|
-
});
|
|
407
|
-
```
|
|
408
|
-
|
|
409
|
-
## Span Types and Attributes
|
|
410
|
-
|
|
411
|
-
AI Tracing automatically creates spans for different AI operations. Mastra supports the following span types:
|
|
412
|
-
|
|
413
|
-
### Agent Operation Types
|
|
414
|
-
- **`AGENT_RUN`** - Agent execution from start to finish
|
|
415
|
-
- **`LLM_GENERATION`** - Individual model calls with prompts and completions
|
|
416
|
-
- **`TOOL_CALL`** - Function/tool executions with inputs and outputs
|
|
417
|
-
- **`MCP_TOOL_CALL`** - Model Context Protocol tool executions
|
|
418
|
-
- **`GENERIC`** - Custom operations
|
|
419
|
-
|
|
420
|
-
### Workflow Operation Types
|
|
421
|
-
- **`WORKFLOW_RUN`** - Workflow execution from start to finish
|
|
422
|
-
- **`WORKFLOW_STEP`** - Individual step processing
|
|
423
|
-
- **`WORKFLOW_CONDITIONAL`** - Conditional execution blocks
|
|
424
|
-
- **`WORKFLOW_CONDITIONAL_EVAL`** - Individual condition evaluations
|
|
425
|
-
- **`WORKFLOW_PARALLEL`** - Parallel execution blocks
|
|
426
|
-
- **`WORKFLOW_LOOP`** - Loop execution blocks
|
|
427
|
-
- **`WORKFLOW_SLEEP`** - Sleep/delay operations
|
|
428
|
-
- **`WORKFLOW_WAIT_EVENT`** - Event waiting operations
|
|
429
|
-
|
|
430
|
-
### Key Attributes
|
|
431
|
-
Each span type includes relevant attributes:
|
|
432
|
-
- **Agent spans**: Agent ID, instructions, available tools, max steps
|
|
433
|
-
- **LLM spans**: Model name, provider, token usage, parameters, finish reason
|
|
434
|
-
- **Tool spans**: Tool ID, tool type, success status
|
|
435
|
-
- **Workflow spans**: Step/workflow IDs, status information
|
|
436
|
-
|
|
437
|
-
## Adding Custom Metadata to Spans
|
|
438
|
-
|
|
439
|
-
You can add custom metadata to spans using the `tracingContext.currentSpan` available in workflow steps and tool calls. This is useful for tracking additional context like API status codes, user IDs, or performance metrics.
|
|
440
|
-
|
|
441
|
-
```ts showLineNumbers copy
|
|
442
|
-
execute: async ({ inputData, tracingContext }) => {
|
|
443
|
-
const response = await fetch(inputData.endpoint, {
|
|
444
|
-
method: 'POST',
|
|
445
|
-
body: JSON.stringify(inputData.payload),
|
|
446
|
-
});
|
|
447
|
-
|
|
448
|
-
// Add custom metadata to the current span
|
|
449
|
-
tracingContext.currentSpan?.update({
|
|
450
|
-
metadata: {
|
|
451
|
-
apiStatusCode: response.status,
|
|
452
|
-
responseHeaders: Object.fromEntries(response.headers.entries()),
|
|
453
|
-
endpoint: inputData.endpoint,
|
|
454
|
-
}
|
|
455
|
-
});
|
|
456
|
-
|
|
457
|
-
const data = await response.json();
|
|
458
|
-
return { data, statusCode: response.status };
|
|
459
|
-
}
|
|
460
|
-
```
|
|
461
|
-
|
|
462
|
-
## Creating Child Spans
|
|
463
|
-
|
|
464
|
-
You can create child spans to track specific operations within your workflow steps or tools. This provides more granular visibility into what's happening during execution.
|
|
465
|
-
|
|
466
|
-
```ts showLineNumbers copy
|
|
467
|
-
execute: async ({ input, tracingContext }) => {
|
|
468
|
-
// Create a child span for the database query
|
|
469
|
-
const querySpan = tracingContext.currentSpan?.createChildSpan({
|
|
470
|
-
type: 'generic',
|
|
471
|
-
name: 'database-query',
|
|
472
|
-
input: {
|
|
473
|
-
query: input.query,
|
|
474
|
-
params: input.params,
|
|
475
|
-
}
|
|
476
|
-
});
|
|
477
|
-
|
|
478
|
-
try {
|
|
479
|
-
const results = await db.query(input.query, input.params);
|
|
480
|
-
|
|
481
|
-
// Update child span with results and end it
|
|
482
|
-
querySpan?.end({
|
|
483
|
-
output: results.data,
|
|
484
|
-
metadata: {
|
|
485
|
-
rowsReturned: results.length,
|
|
486
|
-
success: true,
|
|
487
|
-
}
|
|
488
|
-
});
|
|
489
|
-
|
|
490
|
-
return { results, rowCount: results.length };
|
|
491
|
-
} catch (error) {
|
|
492
|
-
// Record error on child span
|
|
493
|
-
querySpan?.error({error});
|
|
494
|
-
throw error;
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
```
|
|
498
|
-
|
|
499
|
-
## Span Processors and Data Filtering
|
|
500
|
-
|
|
501
|
-
Span processors allow you to modify or filter span data before it's exported to observability platforms. This is useful for adding computed fields, redacting sensitive information, or transforming data formats.
|
|
502
|
-
|
|
503
|
-
### Built-in SensitiveDataFilter
|
|
504
|
-
|
|
505
|
-
Mastra includes a `SensitiveDataFilter` processor that automatically redacts sensitive fields from span data. It's enabled by default and scans for common sensitive field names:
|
|
506
|
-
|
|
507
|
-
```ts filename="src/mastra/index.ts" showLineNumbers copy
|
|
508
|
-
import { LangfuseExporter } from '@mastra/langfuse';
|
|
509
|
-
import { SensitiveDataFilter } from '@mastra/core/ai-tracing';
|
|
510
|
-
|
|
511
|
-
export const mastra = new Mastra({
|
|
512
|
-
observability: {
|
|
513
|
-
instances: {
|
|
514
|
-
langfuse: {
|
|
515
|
-
serviceName: 'my-service',
|
|
516
|
-
exporters: [new LangfuseExporter({ /* config */ })],
|
|
517
|
-
// SensitiveDataFilter is included by default, but you can customize it
|
|
518
|
-
processors: [
|
|
519
|
-
new SensitiveDataFilter([
|
|
520
|
-
'password', 'token', 'secret', 'key', 'apiKey',
|
|
521
|
-
'auth', 'authorization', 'bearer', 'jwt',
|
|
522
|
-
'credential', 'sessionId',
|
|
523
|
-
// Add your custom sensitive fields
|
|
524
|
-
'ssn', 'creditCard', 'bankAccount'
|
|
525
|
-
])
|
|
526
|
-
],
|
|
527
|
-
},
|
|
528
|
-
},
|
|
529
|
-
},
|
|
530
|
-
});
|
|
531
|
-
```
|
|
532
|
-
|
|
533
|
-
The `SensitiveDataFilter` automatically redacts matching fields in:
|
|
534
|
-
- Span attributes
|
|
535
|
-
- Span metadata
|
|
536
|
-
- Input/output data
|
|
537
|
-
- Error information
|
|
538
|
-
|
|
539
|
-
Fields are matched case-insensitively, and nested objects are processed recursively.
|
|
540
|
-
|
|
541
|
-
### Custom Processors
|
|
542
|
-
|
|
543
|
-
You can create custom processors to implement your own span transformation logic:
|
|
544
|
-
|
|
545
|
-
```ts showLineNumbers copy
|
|
546
|
-
import type { AISpanProcessor, AnyAISpan } from '@mastra/core/ai-tracing';
|
|
547
|
-
|
|
548
|
-
export class PerformanceEnrichmentProcessor implements AISpanProcessor {
|
|
549
|
-
name = 'performance-enrichment';
|
|
550
|
-
|
|
551
|
-
process(span: AnyAISpan): AnyAISpan | null {
|
|
552
|
-
const modifiedSpan = { ...span };
|
|
553
|
-
|
|
554
|
-
// Add computed performance metrics
|
|
555
|
-
if (span.startTime && span.endTime) {
|
|
556
|
-
const duration = span.endTime.getTime() - span.startTime.getTime();
|
|
557
|
-
|
|
558
|
-
modifiedSpan.metadata = {
|
|
559
|
-
...span.metadata,
|
|
560
|
-
durationMs: duration,
|
|
561
|
-
performanceCategory: duration < 100 ? 'fast' : duration < 1000 ? 'medium' : 'slow',
|
|
562
|
-
};
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
// Add environment context
|
|
566
|
-
modifiedSpan.metadata = {
|
|
567
|
-
...modifiedSpan.metadata,
|
|
568
|
-
environment: process.env.NODE_ENV || 'unknown',
|
|
569
|
-
region: process.env.AWS_REGION || 'unknown',
|
|
570
|
-
};
|
|
571
|
-
|
|
572
|
-
return modifiedSpan;
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
async shutdown(): Promise<void> {
|
|
576
|
-
// Cleanup if needed
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
// Use in your Mastra configuration
|
|
581
|
-
export const mastra = new Mastra({
|
|
582
|
-
observability: {
|
|
583
|
-
instances: {
|
|
584
|
-
langfuse: {
|
|
585
|
-
serviceName: 'my-service',
|
|
586
|
-
exporters: [new LangfuseExporter({ /* config */ })],
|
|
587
|
-
processors: [
|
|
588
|
-
new SensitiveDataFilter(),
|
|
589
|
-
new PerformanceEnrichmentProcessor(),
|
|
590
|
-
],
|
|
591
|
-
},
|
|
592
|
-
},
|
|
593
|
-
},
|
|
594
|
-
});
|
|
595
|
-
```
|
|
596
|
-
|
|
597
|
-
Processors are executed in the order they're defined, and each processor receives the output of the previous one.
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: "Reference: Provider List | Observability | Mastra Docs"
|
|
3
|
-
description: Overview of observability providers supported by Mastra, including Arize AX, Arize Phoenix, Dash0, SigNoz, Braintrust, Langfuse, and more.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Observability Providers
|
|
7
|
-
|
|
8
|
-
Observability providers include:
|
|
9
|
-
|
|
10
|
-
- [Arize AX](./providers/arize-ax.mdx)
|
|
11
|
-
- [Arize Phoenix](./providers/arize-phoenix.mdx)
|
|
12
|
-
- [Braintrust](./providers/braintrust.mdx)
|
|
13
|
-
- [Dash0](./providers/dash0.mdx)
|
|
14
|
-
- [Laminar](./providers/laminar.mdx)
|
|
15
|
-
- [Langfuse](./providers/langfuse.mdx)
|
|
16
|
-
- [Langsmith](./providers/langsmith.mdx)
|
|
17
|
-
- [LangWatch](./providers/langwatch.mdx)
|
|
18
|
-
- [New Relic](./providers/new-relic.mdx)
|
|
19
|
-
- [SigNoz](./providers/signoz.mdx)
|
|
20
|
-
- [Traceloop](./providers/traceloop.mdx)
|
|
File without changes
|
|
File without changes
|
/package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/arize-ax.mdx
RENAMED
|
File without changes
|
/package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/arize-phoenix.mdx
RENAMED
|
File without changes
|
/package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/braintrust.mdx
RENAMED
|
File without changes
|
|
File without changes
|
/package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/keywordsai.mdx
RENAMED
|
File without changes
|
|
File without changes
|
/package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/langfuse.mdx
RENAMED
|
File without changes
|
/package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/langsmith.mdx
RENAMED
|
File without changes
|
/package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/langwatch.mdx
RENAMED
|
File without changes
|
/package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/new-relic.mdx
RENAMED
|
File without changes
|
|
File without changes
|
/package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/traceloop.mdx
RENAMED
|
File without changes
|