@mastra/mcp-docs-server 0.13.24-alpha.3 → 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.
Files changed (105) hide show
  1. package/.docs/organized/changelogs/%40internal%2Fstorage-test-utils.md +8 -8
  2. package/.docs/organized/changelogs/%40internal%2Ftypes-builder.md +2 -0
  3. package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +12 -0
  4. package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +11 -0
  5. package/.docs/organized/changelogs/%40mastra%2Fastra.md +10 -10
  6. package/.docs/organized/changelogs/%40mastra%2Fchroma.md +10 -10
  7. package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +10 -10
  8. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +29 -29
  9. package/.docs/organized/changelogs/%40mastra%2Fcloud.md +10 -10
  10. package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +10 -10
  11. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +11 -11
  12. package/.docs/organized/changelogs/%40mastra%2Fcore.md +70 -70
  13. package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +10 -10
  14. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +25 -25
  15. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +23 -23
  16. package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +24 -24
  17. package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +24 -24
  18. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +30 -30
  19. package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +10 -10
  20. package/.docs/organized/changelogs/%40mastra%2Fevals.md +21 -21
  21. package/.docs/organized/changelogs/%40mastra%2Flance.md +11 -11
  22. package/.docs/organized/changelogs/%40mastra%2Flibsql.md +10 -10
  23. package/.docs/organized/changelogs/%40mastra%2Floggers.md +10 -10
  24. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +17 -17
  25. package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +10 -10
  26. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +10 -10
  27. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +18 -18
  28. package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +10 -10
  29. package/.docs/organized/changelogs/%40mastra%2Fmssql.md +10 -10
  30. package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +11 -11
  31. package/.docs/organized/changelogs/%40mastra%2Fpg.md +16 -16
  32. package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +10 -10
  33. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +56 -56
  34. package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +11 -11
  35. package/.docs/organized/changelogs/%40mastra%2Frag.md +13 -13
  36. package/.docs/organized/changelogs/%40mastra%2Freact-hooks.md +8 -0
  37. package/.docs/organized/changelogs/%40mastra%2Fs3vectors.md +9 -0
  38. package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -0
  39. package/.docs/organized/changelogs/%40mastra%2Fserver.md +36 -36
  40. package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +10 -10
  41. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +13 -13
  42. package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +10 -10
  43. package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +10 -10
  44. package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +10 -10
  45. package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +10 -10
  46. package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +10 -10
  47. package/.docs/organized/changelogs/%40mastra%2Fvoice-gladia.md +9 -0
  48. package/.docs/organized/changelogs/%40mastra%2Fvoice-google-gemini-live.md +9 -0
  49. package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +11 -11
  50. package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +11 -11
  51. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +11 -11
  52. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +11 -11
  53. package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +10 -10
  54. package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +10 -10
  55. package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +10 -10
  56. package/.docs/organized/changelogs/create-mastra.md +28 -28
  57. package/.docs/organized/changelogs/mastra.md +52 -52
  58. package/.docs/raw/index.mdx +1 -0
  59. package/.docs/raw/observability/ai-tracing/exporters/braintrust.mdx +81 -0
  60. package/.docs/raw/observability/ai-tracing/exporters/cloud.mdx +120 -0
  61. package/.docs/raw/observability/ai-tracing/exporters/default.mdx +167 -0
  62. package/.docs/raw/observability/ai-tracing/exporters/langfuse.mdx +121 -0
  63. package/.docs/raw/observability/ai-tracing/overview.mdx +565 -0
  64. package/.docs/raw/observability/ai-tracing/processors/sensitive-data-filter.mdx +274 -0
  65. package/.docs/raw/observability/{tracing.mdx → otel-tracing.mdx} +2 -2
  66. package/.docs/raw/observability/overview.mdx +66 -0
  67. package/.docs/raw/reference/agents/generate.mdx +39 -1
  68. package/.docs/raw/reference/agents/generateVNext.mdx +34 -2
  69. package/.docs/raw/reference/agents/network.mdx +34 -2
  70. package/.docs/raw/reference/observability/ai-tracing/ai-tracing.mdx +181 -0
  71. package/.docs/raw/reference/observability/ai-tracing/configuration.mdx +233 -0
  72. package/.docs/raw/reference/observability/ai-tracing/exporters/braintrust.mdx +112 -0
  73. package/.docs/raw/reference/observability/ai-tracing/exporters/cloud-exporter.mdx +176 -0
  74. package/.docs/raw/reference/observability/ai-tracing/exporters/console-exporter.mdx +148 -0
  75. package/.docs/raw/reference/observability/ai-tracing/exporters/default-exporter.mdx +196 -0
  76. package/.docs/raw/reference/observability/ai-tracing/exporters/langfuse.mdx +116 -0
  77. package/.docs/raw/reference/observability/ai-tracing/interfaces.mdx +651 -0
  78. package/.docs/raw/reference/observability/ai-tracing/processors/sensitive-data-filter.mdx +178 -0
  79. package/.docs/raw/reference/observability/ai-tracing/span.mdx +371 -0
  80. package/.docs/raw/reference/observability/otel-tracing/providers/index.mdx +22 -0
  81. package/.docs/raw/reference/streaming/agents/stream.mdx +39 -1
  82. package/.docs/raw/reference/streaming/agents/streamVNext.mdx +34 -2
  83. package/.docs/raw/reference/streaming/workflows/stream.mdx +38 -0
  84. package/.docs/raw/reference/streaming/workflows/streamVNext.mdx +38 -0
  85. package/.docs/raw/reference/tools/create-tool.mdx +34 -1
  86. package/.docs/raw/reference/workflows/run-methods/resume.mdx +38 -0
  87. package/.docs/raw/reference/workflows/run-methods/start.mdx +38 -0
  88. package/CHANGELOG.md +15 -0
  89. package/package.json +5 -5
  90. package/.docs/raw/observability/ai-tracing.mdx +0 -597
  91. package/.docs/raw/reference/observability/providers/index.mdx +0 -20
  92. /package/.docs/raw/reference/observability/{logger.mdx → logging/pino-logger.mdx} +0 -0
  93. /package/.docs/raw/reference/observability/{otel-config.mdx → otel-tracing/otel-config.mdx} +0 -0
  94. /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/arize-ax.mdx +0 -0
  95. /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/arize-phoenix.mdx +0 -0
  96. /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/braintrust.mdx +0 -0
  97. /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/dash0.mdx +0 -0
  98. /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/keywordsai.mdx +0 -0
  99. /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/laminar.mdx +0 -0
  100. /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/langfuse.mdx +0 -0
  101. /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/langsmith.mdx +0 -0
  102. /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/langwatch.mdx +0 -0
  103. /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/new-relic.mdx +0 -0
  104. /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/signoz.mdx +0 -0
  105. /package/.docs/raw/reference/observability/{providers → otel-tracing/providers}/traceloop.mdx +0 -0
@@ -0,0 +1,81 @@
1
+ ---
2
+ title: "Braintrust Exporter | AI Tracing | Observability | Mastra Docs"
3
+ description: "Send AI traces to Braintrust for evaluation and monitoring"
4
+ ---
5
+
6
+ import { Callout } from "nextra/components";
7
+
8
+ # Braintrust Exporter
9
+
10
+ [Braintrust](https://www.braintrust.dev/) is an evaluation and monitoring platform that helps you measure and improve LLM application quality. The Braintrust exporter sends your AI traces to Braintrust, enabling systematic evaluation, scoring, and experimentation.
11
+
12
+ ## When to Use Braintrust
13
+
14
+ Braintrust excels at:
15
+ - **Evaluation workflows** - Systematic quality measurement
16
+ - **Experiment tracking** - Compare model versions and prompts
17
+ - **Dataset management** - Curate test cases and golden datasets
18
+ - **Regression testing** - Ensure improvements don't break existing functionality
19
+ - **Team collaboration** - Share experiments and insights
20
+
21
+ ## Installation
22
+
23
+ ```bash npm2yarn
24
+ npm install @mastra/braintrust
25
+ ```
26
+
27
+ ## Configuration
28
+
29
+ ### Prerequisites
30
+
31
+ 1. **Braintrust Account**: Sign up at [braintrust.dev](https://www.braintrust.dev/)
32
+ 2. **Project**: Create or select a project for your traces
33
+ 3. **API Key**: Generate in Braintrust Settings → API Keys
34
+ 4. **Environment Variables**: Set your credentials:
35
+
36
+ ```bash filename=".env"
37
+ BRAINTRUST_API_KEY=sk-xxxxxxxxxxxxxxxx
38
+ BRAINTRUST_PROJECT_NAME=my-project # Optional, defaults to 'mastra-tracing'
39
+ ```
40
+
41
+ ### Basic Setup
42
+
43
+ ```typescript filename="src/mastra/index.ts"
44
+ import { Mastra } from "@mastra/core";
45
+ import { BraintrustExporter } from "@mastra/braintrust";
46
+
47
+ export const mastra = new Mastra({
48
+ observability: {
49
+ configs: {
50
+ braintrust: {
51
+ serviceName: 'my-service',
52
+ exporters: [
53
+ new BraintrustExporter({
54
+ apiKey: process.env.BRAINTRUST_API_KEY,
55
+ projectName: process.env.BRAINTRUST_PROJECT_NAME,
56
+ }),
57
+ ],
58
+ },
59
+ },
60
+ },
61
+ });
62
+ ```
63
+
64
+ ### Complete Configuration
65
+
66
+ ```typescript
67
+ new BraintrustExporter({
68
+ // Required
69
+ apiKey: process.env.BRAINTRUST_API_KEY!,
70
+
71
+ // Optional settings
72
+ projectName: 'my-project', // Default: 'mastra-tracing'
73
+ endpoint: 'https://api.braintrust.dev', // Custom endpoint if needed
74
+ logLevel: 'info', // Diagnostic logging: debug | info | warn | error
75
+ })
76
+ ```
77
+
78
+ ## Related
79
+
80
+ - [AI Tracing Overview](/docs/observability/ai-tracing/overview)
81
+ - [Braintrust Documentation](https://www.braintrust.dev/docs)
@@ -0,0 +1,120 @@
1
+ ---
2
+ title: "Cloud Exporter | AI Tracing | Observability | Mastra Docs"
3
+ description: "Send traces to Mastra Cloud for production monitoring"
4
+ ---
5
+
6
+ import { Callout } from "nextra/components";
7
+
8
+ # Cloud Exporter
9
+
10
+ The `CloudExporter` sends traces to Mastra Cloud for centralized monitoring and team collaboration. It's automatically enabled when using the default observability configuration with a valid access token.
11
+
12
+ ## When to Use CloudExporter
13
+
14
+ CloudExporter is ideal for:
15
+ - **Production monitoring** - Centralized trace visualization
16
+ - **Team collaboration** - Share traces across your organization
17
+ - **Advanced analytics** - Insights and performance metrics
18
+ - **Zero maintenance** - No infrastructure to manage
19
+
20
+ ## Configuration
21
+
22
+ ### Prerequisites
23
+
24
+ 1. **Mastra Cloud Account**: Sign up at [cloud.mastra.ai](https://cloud.mastra.ai)
25
+ 2. **Access Token**: Generate in Mastra Cloud → Settings → API Tokens
26
+ 3. **Environment Variables**: Set your credentials:
27
+
28
+ ```bash filename=".env"
29
+ MASTRA_CLOUD_ACCESS_TOKEN=mst_xxxxxxxxxxxxxxxx
30
+ ```
31
+
32
+ ### Basic Setup
33
+
34
+ ```typescript filename="src/mastra/index.ts"
35
+ import { Mastra } from "@mastra/core";
36
+ import { CloudExporter } from "@mastra/core/ai-tracing";
37
+
38
+ export const mastra = new Mastra({
39
+ observability: {
40
+ configs: {
41
+ production: {
42
+ serviceName: 'my-service',
43
+ exporters: [
44
+ new CloudExporter(), // Uses MASTRA_CLOUD_ACCESS_TOKEN env var
45
+ ],
46
+ },
47
+ },
48
+ },
49
+ });
50
+ ```
51
+
52
+ ### Automatic Configuration
53
+
54
+ When using the default observability configuration, CloudExporter is automatically included if the access token is set:
55
+
56
+ ```typescript
57
+ export const mastra = new Mastra({
58
+ observability: {
59
+ default: { enabled: true }, // Automatically includes CloudExporter if token exists
60
+ },
61
+ });
62
+ ```
63
+
64
+ ### Complete Configuration
65
+
66
+ ```typescript
67
+ new CloudExporter({
68
+ // Optional - defaults to env var
69
+ accessToken: process.env.MASTRA_CLOUD_ACCESS_TOKEN,
70
+
71
+ // Optional - for self-hosted Mastra Cloud
72
+ endpoint: 'https://cloud.your-domain.com',
73
+
74
+ // Batching configuration
75
+ maxBatchSize: 1000, // Max spans per batch
76
+ maxBatchWaitMs: 5000, // Max wait before sending batch
77
+
78
+ // Diagnostic logging
79
+ logLevel: 'info', // debug | info | warn | error
80
+ })
81
+ ```
82
+
83
+ ## Viewing Traces
84
+
85
+ ### Mastra Cloud Dashboard
86
+
87
+ 1. Navigate to [cloud.mastra.ai](https://cloud.mastra.ai)
88
+ 2. Select your project
89
+ 3. Go to Observability → Traces
90
+ 4. Use filters to find specific traces:
91
+ - Service name
92
+ - Time range
93
+ - Trace ID
94
+ - Error status
95
+
96
+ ### Features
97
+
98
+ - **Trace Timeline** - Visual execution flow
99
+ - **Span Details** - Inputs, outputs, metadata
100
+ - **Performance Metrics** - Latency, token usage
101
+ - **Team Collaboration** - Share trace links
102
+
103
+ ## Performance
104
+
105
+ <Callout type="info">
106
+ CloudExporter uses intelligent batching to optimize network usage. Traces are buffered and sent in batches, reducing overhead while maintaining near real-time visibility.
107
+ </Callout>
108
+
109
+ ### Batching Behavior
110
+
111
+ - Traces are batched up to `maxBatchSize` (default: 1000)
112
+ - Batches are sent when full or after `maxBatchWaitMs` (default: 5 seconds)
113
+ - Failed batches are retried with exponential backoff
114
+ - Graceful degradation if Mastra Cloud is unreachable
115
+
116
+ ## Related
117
+
118
+ - [AI Tracing Overview](/docs/observability/ai-tracing/overview)
119
+ - [DefaultExporter](/docs/observability/ai-tracing/exporters/default)
120
+ - [Mastra Cloud Documentation](https://cloud.mastra.ai/docs)
@@ -0,0 +1,167 @@
1
+ ---
2
+ title: "Default Exporter | AI Tracing | Observability | Mastra Docs"
3
+ description: "Store traces locally for development and debugging"
4
+ ---
5
+
6
+ # Default Exporter
7
+
8
+ The `DefaultExporter` persists traces to your configured storage backend, making them accessible through the Mastra Playground. It's automatically enabled when using the default observability configuration and requires no external services.
9
+
10
+ ## When to Use DefaultExporter
11
+
12
+ DefaultExporter is ideal for:
13
+ - **Local development** - Debug and analyze traces offline
14
+ - **Data ownership** - Complete control over your trace data
15
+ - **Zero dependencies** - No external services required
16
+ - **Playground integration** - View traces in Mastra Playground UI
17
+
18
+ ## Configuration
19
+
20
+ ### Prerequisites
21
+
22
+ 1. **Storage Backend**: Configure a storage provider (LibSQL, PostgreSQL, etc.)
23
+ 2. **Mastra Playground**: Install for viewing traces locally
24
+
25
+ ### Basic Setup
26
+
27
+ ```typescript filename="src/mastra/index.ts"
28
+ import { Mastra } from "@mastra/core";
29
+ import { DefaultExporter } from "@mastra/core/ai-tracing";
30
+ import { LibSQLStore } from "@mastra/libsql";
31
+
32
+ export const mastra = new Mastra({
33
+ storage: new LibSQLStore({
34
+ url: "file:./mastra.db", // Required for trace persistence
35
+ }),
36
+ observability: {
37
+ configs: {
38
+ local: {
39
+ serviceName: 'my-service',
40
+ exporters: [
41
+ new DefaultExporter(),
42
+ ],
43
+ },
44
+ },
45
+ },
46
+ });
47
+ ```
48
+
49
+ ### Automatic Configuration
50
+
51
+ When using the default observability configuration, DefaultExporter is automatically included:
52
+
53
+ ```typescript
54
+ export const mastra = new Mastra({
55
+ storage: new LibSQLStore({
56
+ url: "file:./mastra.db",
57
+ }),
58
+ observability: {
59
+ default: { enabled: true }, // Automatically includes DefaultExporter
60
+ },
61
+ });
62
+ ```
63
+
64
+ ## Viewing Traces
65
+
66
+ ### Mastra Playground
67
+
68
+ Access your traces through the local Playground:
69
+
70
+ 1. Start the Playground
71
+ 2. Navigate to Observability
72
+ 3. Filter and search your local traces
73
+ 4. Inspect detailed span information
74
+
75
+ ## Tracing Strategies
76
+
77
+ DefaultExporter automatically selects the optimal tracing strategy based on your storage provider. You can also override this selection if needed.
78
+
79
+ ### Available Strategies
80
+
81
+ | Strategy | Description | Use Case |
82
+ |----------|-------------|----------|
83
+ | **realtime** | Process each event immediately | Development, debugging, low traffic |
84
+ | **batch-with-updates** | Buffer events and batch write with full lifecycle support | Low volume Production |
85
+ | **insert-only** | Only process completed spans, ignore updates | High volume Production |
86
+
87
+ ### Strategy Configuration
88
+
89
+ ```typescript
90
+ new DefaultExporter({
91
+ strategy: 'auto', // Default - let storage provider decide
92
+ // or explicitly set:
93
+ // strategy: 'realtime' | 'batch-with-updates' | 'insert-only'
94
+
95
+ // Batching configuration (applies to both batch-with-updates and insert-only)
96
+ maxBatchSize: 1000, // Max spans per batch
97
+ maxBatchWaitMs: 5000, // Max wait before flushing
98
+ maxBufferSize: 10000, // Max spans to buffer
99
+ })
100
+ ```
101
+
102
+ ## Storage Provider Support
103
+
104
+ Different storage providers support different tracing strategies.
105
+
106
+ If you set the strategy to `'auto'`, the `DefaultExporter` automatically selects the optimal strategy for the storage provider. If you set the strategy to a mode that the storage provider doesn't support, you will get an error message.
107
+
108
+ | Storage Provider | Preferred Strategy | Supported Strategies | Notes |
109
+ |-----------------|-------------------|---------------------|--------|
110
+ | **[LibSQL](/reference/storage/libsql)** | batch-with-updates | realtime, batch-with-updates, insert-only | Default storage, good for development |
111
+
112
+ ### Strategy Benefits
113
+
114
+ - **realtime**: Immediate visibility, best for debugging
115
+ - **batch-with-updates**: 10-100x throughput improvement, full span lifecycle
116
+ - **insert-only**: Additional 70% reduction in database operations, perfect for analytics
117
+
118
+ ## Batching Behavior
119
+
120
+ ### Flush Triggers
121
+
122
+ For both batch strategies (`batch-with-updates` and `insert-only`), traces are flushed to storage when any of these conditions are met:
123
+
124
+ 1. **Size trigger**: Buffer reaches `maxBatchSize` spans
125
+ 2. **Time trigger**: `maxBatchWaitMs` elapsed since first event
126
+ 3. **Emergency flush**: Buffer approaches `maxBufferSize` limit
127
+ 4. **Shutdown**: Force flush all pending events
128
+
129
+ ### Error Handling
130
+
131
+ The DefaultExporter includes robust error handling for production use:
132
+
133
+ - **Retry Logic**: Exponential backoff (500ms, 1s, 2s, 4s)
134
+ - **Transient Failures**: Automatic retry with backoff
135
+ - **Persistent Failures**: Drop batch after 4 failed attempts
136
+ - **Buffer Overflow**: Prevent memory issues during storage outages
137
+
138
+ ### Configuration Examples
139
+
140
+ ```typescript
141
+ // Zero config - recommended for most users
142
+ new DefaultExporter()
143
+
144
+ // Development override
145
+ new DefaultExporter({
146
+ strategy: 'realtime', // Immediate visibility for debugging
147
+ })
148
+
149
+ // High-throughput production
150
+ new DefaultExporter({
151
+ maxBatchSize: 2000, // Larger batches
152
+ maxBatchWaitMs: 10000, // Wait longer to fill batches
153
+ maxBufferSize: 50000, // Handle longer outages
154
+ })
155
+
156
+ // Low-latency production
157
+ new DefaultExporter({
158
+ maxBatchSize: 100, // Smaller batches
159
+ maxBatchWaitMs: 1000, // Flush quickly
160
+ })
161
+ ```
162
+
163
+ ## Related
164
+
165
+ - [AI Tracing Overview](/docs/observability/ai-tracing/overview)
166
+ - [CloudExporter](/docs/observability/ai-tracing/exporters/cloud)
167
+ - [Storage Configuration](/docs/storage/overview)
@@ -0,0 +1,121 @@
1
+ ---
2
+ title: "Langfuse Exporter | AI Tracing | Observability | Mastra Docs"
3
+ description: "Send AI traces to Langfuse for LLM observability and analytics"
4
+ ---
5
+
6
+ import { Callout } from "nextra/components";
7
+
8
+ # Langfuse Exporter
9
+
10
+ [Langfuse](https://langfuse.com/) is an open-source observability platform specifically designed for LLM applications. The Langfuse exporter sends your AI traces to Langfuse, providing detailed insights into model performance, token usage, and conversation flows.
11
+
12
+ ## When to Use Langfuse
13
+
14
+ Langfuse is ideal when you need:
15
+ - **LLM-specific analytics** - Token usage, costs, latency breakdown
16
+ - **Conversation tracking** - Session-based trace grouping
17
+ - **Quality scoring** - Manual and automated evaluation scores
18
+ - **Model comparison** - A/B testing and version comparisons
19
+ - **Self-hosted option** - Deploy on your own infrastructure
20
+
21
+ ## Installation
22
+
23
+ ```bash npm2yarn
24
+ npm install @mastra/langfuse
25
+ ```
26
+
27
+ ## Configuration
28
+
29
+ ### Prerequisites
30
+
31
+ 1. **Langfuse Account**: Sign up at [cloud.langfuse.com](https://cloud.langfuse.com) or deploy self-hosted
32
+ 2. **API Keys**: Create public/secret key pair in Langfuse Settings → API Keys
33
+ 3. **Environment Variables**: Set your credentials
34
+
35
+ ```bash filename=".env"
36
+ LANGFUSE_PUBLIC_KEY=pk-lf-xxxxxxxxxxxx
37
+ LANGFUSE_SECRET_KEY=sk-lf-xxxxxxxxxxxx
38
+ LANGFUSE_BASE_URL=https://cloud.langfuse.com # Or your self-hosted URL
39
+ ```
40
+
41
+ ### Basic Setup
42
+
43
+ ```typescript filename="src/mastra/index.ts"
44
+ import { Mastra } from "@mastra/core";
45
+ import { LangfuseExporter } from "@mastra/langfuse";
46
+
47
+ export const mastra = new Mastra({
48
+ observability: {
49
+ configs: {
50
+ langfuse: {
51
+ serviceName: 'my-service',
52
+ exporters: [
53
+ new LangfuseExporter({
54
+ publicKey: process.env.LANGFUSE_PUBLIC_KEY!,
55
+ secretKey: process.env.LANGFUSE_SECRET_KEY!,
56
+ baseUrl: process.env.LANGFUSE_BASE_URL,
57
+ options: {
58
+ environment: process.env.NODE_ENV,
59
+ },
60
+ }),
61
+ ],
62
+ },
63
+ },
64
+ },
65
+ });
66
+ ```
67
+
68
+ ## Configuration Options
69
+
70
+ ### Realtime vs Batch Mode
71
+
72
+ The Langfuse exporter supports two modes for sending traces:
73
+
74
+ #### Realtime Mode (Development)
75
+ Traces appear immediately in Langfuse dashboard, ideal for debugging:
76
+
77
+ ```typescript
78
+ new LangfuseExporter({
79
+ publicKey: process.env.LANGFUSE_PUBLIC_KEY!,
80
+ secretKey: process.env.LANGFUSE_SECRET_KEY!,
81
+ realtime: true, // Flush after each event
82
+ })
83
+ ```
84
+
85
+ #### Batch Mode (Production)
86
+ Better performance with automatic batching:
87
+
88
+ ```typescript
89
+ new LangfuseExporter({
90
+ publicKey: process.env.LANGFUSE_PUBLIC_KEY!,
91
+ secretKey: process.env.LANGFUSE_SECRET_KEY!,
92
+ realtime: false, // Default - batch traces
93
+ })
94
+ ```
95
+
96
+ ### Complete Configuration
97
+
98
+ ```typescript
99
+ new LangfuseExporter({
100
+ // Required credentials
101
+ publicKey: process.env.LANGFUSE_PUBLIC_KEY!,
102
+ secretKey: process.env.LANGFUSE_SECRET_KEY!,
103
+
104
+ // Optional settings
105
+ baseUrl: process.env.LANGFUSE_BASE_URL, // Default: https://cloud.langfuse.com
106
+ realtime: process.env.NODE_ENV === 'development', // Dynamic mode selection
107
+ logLevel: 'info', // Diagnostic logging: debug | info | warn | error
108
+
109
+ // Langfuse-specific options
110
+ options: {
111
+ environment: process.env.NODE_ENV, // Shows in UI for filtering
112
+ version: process.env.APP_VERSION, // Track different versions
113
+ release: process.env.GIT_COMMIT, // Git commit hash
114
+ },
115
+ })
116
+ ```
117
+
118
+ ## Related
119
+
120
+ - [AI Tracing Overview](/docs/observability/ai-tracing/overview)
121
+ - [Langfuse Documentation](https://langfuse.com/docs)