@mastra/mcp-docs-server 0.13.20 → 0.13.21-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.
- 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 +8 -0
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +30 -30
- package/.docs/organized/changelogs/%40mastra%2Fcloud.md +13 -13
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +51 -51
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +29 -29
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +32 -32
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +30 -30
- package/.docs/organized/changelogs/create-mastra.md +11 -11
- package/.docs/organized/changelogs/mastra.md +31 -31
- package/.docs/organized/code-examples/agent.md +34 -9
- package/.docs/organized/code-examples/ai-sdk-v5.md +16 -14
- package/.docs/organized/code-examples/heads-up-game.md +3 -3
- package/.docs/raw/auth/clerk.mdx +142 -0
- package/.docs/raw/getting-started/installation.mdx +3 -1
- package/.docs/raw/getting-started/model-providers.mdx +31 -31
- package/.docs/raw/observability/ai-tracing.mdx +123 -24
- package/.docs/raw/reference/agents/ChunkType.mdx +857 -0
- package/.docs/raw/reference/agents/MastraModelOutput.mdx +321 -0
- package/.docs/raw/reference/agents/generateVNext.mdx +519 -0
- package/.docs/raw/reference/agents/streamVNext.mdx +6 -20
- package/.docs/raw/reference/auth/clerk.mdx +71 -0
- package/.docs/raw/reference/scorers/answer-similarity.mdx +179 -0
- package/.docs/raw/scorers/off-the-shelf-scorers.mdx +1 -0
- package/.docs/raw/server-db/production-server.mdx +27 -2
- package/.docs/raw/tools-mcp/mcp-overview.mdx +144 -159
- package/.docs/raw/workflows/control-flow.mdx +1 -1
- package/.docs/raw/workflows/suspend-and-resume.mdx +5 -0
- package/CHANGELOG.md +16 -0
- package/dist/stdio.js +11 -4
- package/dist/tools/docs.d.ts.map +1 -1
- package/package.json +4 -4
- /package/.docs/raw/reference/{templates.mdx → templates/overview.mdx} +0 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "MastraAuthClerk Class"
|
|
3
|
+
description: "Documentation for the MastraAuthClerk class, which authenticates Mastra applications using Clerk authentication."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { Tabs, Tab } from "@/components/tabs";
|
|
7
|
+
|
|
8
|
+
# MastraAuthClerk Class
|
|
9
|
+
|
|
10
|
+
The `MastraAuthClerk` class provides authentication for Mastra using Clerk. It verifies incoming requests using Clerk's authentication system and integrates with the Mastra server using the `experimental_auth` option.
|
|
11
|
+
|
|
12
|
+
## Prerequisites
|
|
13
|
+
|
|
14
|
+
This example uses Clerk authentication. Make sure to add your Clerk credentials to your `.env` file and ensure your Clerk project is properly configured.
|
|
15
|
+
|
|
16
|
+
```env filename=".env" copy
|
|
17
|
+
CLERK_PUBLISHABLE_KEY=pk_test_...
|
|
18
|
+
CLERK_SECRET_KEY=sk_test_...
|
|
19
|
+
CLERK_JWKS_URI=https://your-clerk-domain.clerk.accounts.dev/.well-known/jwks.json
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
> **Note:** You can find these keys in your Clerk Dashboard under "API Keys".
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
Before you can use the `MastraAuthClerk` class you have to install the `@mastra/clerk-auth` package.
|
|
27
|
+
|
|
28
|
+
```bash copy
|
|
29
|
+
npm install @mastra/clerk-auth@latest
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Usage example
|
|
33
|
+
|
|
34
|
+
```typescript {2,7-11} filename="src/mastra/index.ts" showLineNumbers copy
|
|
35
|
+
import { Mastra } from "@mastra/core/mastra";
|
|
36
|
+
import { MastraAuthClerk } from '@mastra/clerk-auth';
|
|
37
|
+
|
|
38
|
+
export const mastra = new Mastra({
|
|
39
|
+
// ..
|
|
40
|
+
server: {
|
|
41
|
+
experimental_auth: new MastraAuthClerk({
|
|
42
|
+
publishableKey: process.env.CLERK_PUBLISHABLE_KEY,
|
|
43
|
+
secretKey: process.env.CLERK_SECRET_KEY,
|
|
44
|
+
jwksUri: process.env.CLERK_JWKS_URI
|
|
45
|
+
}),
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
> **Note:** The default `authorizeUser` method allows all authenticated users. To customize user authorization, provide a custom `authorizeUser` function when constructing the provider.
|
|
51
|
+
|
|
52
|
+
> See the [MastraAuthClerk](/reference/auth/clerk.mdx) API reference for all available configuration options.
|
|
53
|
+
|
|
54
|
+
## Client-side setup
|
|
55
|
+
|
|
56
|
+
When using Clerk auth, you'll need to retrieve the access token from Clerk on the client side and pass it to your Mastra requests.
|
|
57
|
+
|
|
58
|
+
### Retrieving the access token
|
|
59
|
+
|
|
60
|
+
Use the Clerk React hooks to authenticate users and retrieve their access token:
|
|
61
|
+
|
|
62
|
+
```typescript filename="lib/auth.ts" showLineNumbers copy
|
|
63
|
+
import { useAuth } from "@clerk/nextjs";
|
|
64
|
+
|
|
65
|
+
export const useClerkAuth = () => {
|
|
66
|
+
const { getToken } = useAuth();
|
|
67
|
+
|
|
68
|
+
const getAccessToken = async () => {
|
|
69
|
+
const token = await getToken();
|
|
70
|
+
return token;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
return { getAccessToken };
|
|
74
|
+
};
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
> Refer to the [Clerk documentation](https://clerk.com/docs) for more information.
|
|
78
|
+
|
|
79
|
+
## Configuring `MastraClient`
|
|
80
|
+
|
|
81
|
+
When `experimental_auth` is enabled, all requests made with `MastraClient` must include a valid Clerk access token in the `Authorization` header:
|
|
82
|
+
|
|
83
|
+
```typescript {6} filename="lib/mastra/mastra-client.ts" showLineNumbers copy
|
|
84
|
+
import { MastraClient } from "@mastra/client-js";
|
|
85
|
+
|
|
86
|
+
export const mastraClient = new MastraClient({
|
|
87
|
+
baseUrl: "https://<mastra-api-url>",
|
|
88
|
+
headers: {
|
|
89
|
+
Authorization: `Bearer ${accessToken}`
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
> **Note:** The access token must be prefixed with `Bearer` in the Authorization header.
|
|
95
|
+
> See [Mastra Client SDK](/docs/server-db/mastra-client.mdx) for more configuration options.
|
|
96
|
+
|
|
97
|
+
### Making authenticated requests
|
|
98
|
+
|
|
99
|
+
Once `MastraClient` is configured with the Clerk access token, you can send authenticated requests:
|
|
100
|
+
|
|
101
|
+
<Tabs items={["MastraClient", "curl"]}>
|
|
102
|
+
<Tab>
|
|
103
|
+
```tsx filename="src/components/test-agent.tsx" showLineNumbers copy
|
|
104
|
+
"use client";
|
|
105
|
+
|
|
106
|
+
import { useAuth } from "@clerk/nextjs";
|
|
107
|
+
import { MastraClient } from "@mastra/client-js";
|
|
108
|
+
|
|
109
|
+
export const TestAgent = () => {
|
|
110
|
+
const { getToken } = useAuth();
|
|
111
|
+
|
|
112
|
+
async function handleClick() {
|
|
113
|
+
const token = await getToken();
|
|
114
|
+
|
|
115
|
+
const client = new MastraClient({
|
|
116
|
+
baseUrl: "http://localhost:4111",
|
|
117
|
+
headers: token ? { Authorization: `Bearer ${token}` } : undefined,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const weatherAgent = client.getAgent("weatherAgent");
|
|
121
|
+
const response = await weatherAgent.generate({
|
|
122
|
+
messages: "What's the weather like in New York",
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
console.log({ response });
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return <button onClick={handleClick}>Test Agent</button>;
|
|
129
|
+
};
|
|
130
|
+
```
|
|
131
|
+
</Tab>
|
|
132
|
+
<Tab>
|
|
133
|
+
```bash copy
|
|
134
|
+
curl -X POST http://localhost:4111/api/agents/weatherAgent/generate \
|
|
135
|
+
-H "Content-Type: application/json" \
|
|
136
|
+
-H "Authorization: Bearer <your-clerk-access-token>" \
|
|
137
|
+
-d '{
|
|
138
|
+
"messages": "Weather in London"
|
|
139
|
+
}'
|
|
140
|
+
```
|
|
141
|
+
</Tab>
|
|
142
|
+
</Tabs>
|
|
@@ -228,7 +228,9 @@ touch tsconfig.json
|
|
|
228
228
|
|
|
229
229
|
Add the following configuration:
|
|
230
230
|
|
|
231
|
-
|
|
231
|
+
Mastra requires `module` and `moduleResolution` values that support modern Node.js versions. Older settings like `CommonJS` or `node` are incompatible with Mastra’s packages and will cause resolution errors.
|
|
232
|
+
|
|
233
|
+
```json {4-5} filename="tsconfig.json" copy
|
|
232
234
|
{
|
|
233
235
|
"compilerOptions": {
|
|
234
236
|
"target": "ES2022",
|
|
@@ -3,7 +3,7 @@ title: "Model Providers | Getting Started | Mastra Docs"
|
|
|
3
3
|
description: "Learn how to configure and use different model providers with Mastra."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
import { Callout } from
|
|
6
|
+
import { Callout } from "nextra/components"
|
|
7
7
|
|
|
8
8
|
# Model Providers
|
|
9
9
|
|
|
@@ -62,18 +62,18 @@ Here's an example using the OpenAI provider:
|
|
|
62
62
|
|
|
63
63
|
```typescript showLineNumbers copy filename="src/mastra/agents/weather-agent.ts" {1,4-8,13}
|
|
64
64
|
import { createOpenAI } from "@ai-sdk/openai";
|
|
65
|
-
import { Agent } from "@mastra/core/agent"
|
|
65
|
+
import { Agent } from "@mastra/core/agent";
|
|
66
66
|
|
|
67
67
|
const openai = createOpenAI({
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
baseUrl: "<your-custom-base-url>",
|
|
69
|
+
apiKey: "<your-custom-api-key>",
|
|
70
|
+
...otherOptions,
|
|
71
71
|
});
|
|
72
72
|
|
|
73
73
|
const agent = new Agent({
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
name: "WeatherAgent",
|
|
75
|
+
instructions: "Instructions for the agent...",
|
|
76
|
+
model: openai("<model-name>"),
|
|
77
77
|
});
|
|
78
78
|
```
|
|
79
79
|
|
|
@@ -88,21 +88,21 @@ import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
|
88
88
|
import { Agent } from "@mastra/core/agent";
|
|
89
89
|
|
|
90
90
|
const openaiCompatible = createOpenAICompatible({
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
91
|
+
name: "<model-name>",
|
|
92
|
+
baseUrl: "<base-url>",
|
|
93
|
+
apiKey: "<api-key>",
|
|
94
|
+
headers: {},
|
|
95
|
+
queryParams: {},
|
|
96
|
+
fetch: async (url, options) => {
|
|
97
|
+
// custom fetch logic
|
|
98
|
+
return fetch(url, options);
|
|
99
|
+
},
|
|
100
100
|
});
|
|
101
101
|
|
|
102
102
|
const agent = new Agent({
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
name: "WeatherAgent",
|
|
104
|
+
instructions: "Instructions for the agent...",
|
|
105
|
+
model: openaiCompatible("<model-name>"),
|
|
106
106
|
});
|
|
107
107
|
```
|
|
108
108
|
|
|
@@ -114,36 +114,36 @@ The AI SDK provides a [Language Model Specification](https://github.com/vercel/a
|
|
|
114
114
|
Following this specification, you can create your own model provider compatible with the AI SDK.
|
|
115
115
|
|
|
116
116
|
Some community providers have implemented this specification and are compatible with the AI SDK.
|
|
117
|
-
We will look at one such provider, the Ollama provider available in the [`ollama-ai-provider`](https://github.com/
|
|
117
|
+
We will look at one such provider, the Ollama provider available in the [`ollama-ai-provider-v2`](https://github.com/nordwestt/ollama-ai-provider-v2) package.
|
|
118
118
|
|
|
119
119
|
Here's an example:
|
|
120
120
|
|
|
121
121
|
```typescript showLineNumbers copy filename="src/mastra/agents/weather-agent.ts" {1,7}
|
|
122
|
-
import { ollama } from "ollama-ai-provider";
|
|
122
|
+
import { ollama } from "ollama-ai-provider-v2";
|
|
123
123
|
import { Agent } from "@mastra/core/agent";
|
|
124
124
|
|
|
125
125
|
const agent = new Agent({
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
name: "WeatherAgent",
|
|
127
|
+
instructions: "Instructions for the agent...",
|
|
128
|
+
model: ollama("llama3.2:latest"),
|
|
129
129
|
});
|
|
130
130
|
```
|
|
131
131
|
|
|
132
132
|
You can also configure the Ollama provider like so:
|
|
133
133
|
|
|
134
134
|
```typescript showLineNumbers copy filename="src/mastra/agents/weather-agent.ts" {1,4-7,12}
|
|
135
|
-
import { createOllama } from "ollama-ai-provider";
|
|
135
|
+
import { createOllama } from "ollama-ai-provider-v2";
|
|
136
136
|
import { Agent } from "@mastra/core/agent";
|
|
137
137
|
|
|
138
138
|
const ollama = createOllama({
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
baseUrl: "<your-custom-base-url>",
|
|
140
|
+
...otherOptions,
|
|
141
141
|
});
|
|
142
142
|
|
|
143
143
|
const agent = new Agent({
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
144
|
+
name: "WeatherAgent",
|
|
145
|
+
instructions: "Instructions for the agent...",
|
|
146
|
+
model: ollama("llama3.2:latest"),
|
|
147
147
|
});
|
|
148
148
|
```
|
|
149
149
|
|
|
@@ -51,27 +51,11 @@ For the latest updates, see [GitHub issue #6773](https://github.com/mastra-ai/ma
|
|
|
51
51
|
|
|
52
52
|
## Basic Configuration
|
|
53
53
|
|
|
54
|
-
Here's a simple example of enabling AI Tracing:
|
|
55
|
-
|
|
56
54
|
```ts filename="src/mastra/index.ts" showLineNumbers copy
|
|
57
|
-
import { LangfuseExporter } from '@mastra/langfuse';
|
|
58
|
-
|
|
59
55
|
export const mastra = new Mastra({
|
|
60
56
|
// ... other config
|
|
61
57
|
observability: {
|
|
62
|
-
|
|
63
|
-
langfuse: {
|
|
64
|
-
serviceName: 'my-service',
|
|
65
|
-
exporters: [
|
|
66
|
-
new LangfuseExporter({
|
|
67
|
-
publicKey: process.env.LANGFUSE_PUBLIC_KEY,
|
|
68
|
-
secretKey: process.env.LANGFUSE_SECRET_KEY,
|
|
69
|
-
baseUrl: process.env.LANGFUSE_BASE_URL, // Optional - defaults to Langfuse cloud
|
|
70
|
-
realtime: true,
|
|
71
|
-
}),
|
|
72
|
-
],
|
|
73
|
-
},
|
|
74
|
-
},
|
|
58
|
+
default: { enabled: true }, // Enables DefaultExporter and CloudExporter
|
|
75
59
|
},
|
|
76
60
|
});
|
|
77
61
|
```
|
|
@@ -82,11 +66,16 @@ The AI tracing config accepts these properties:
|
|
|
82
66
|
|
|
83
67
|
```ts
|
|
84
68
|
type AITracingConfig = {
|
|
69
|
+
// Enable default configuration with built-in exporters
|
|
70
|
+
default?: {
|
|
71
|
+
enabled?: boolean;
|
|
72
|
+
};
|
|
73
|
+
|
|
85
74
|
// Map of tracing instance names to their configurations
|
|
86
|
-
|
|
75
|
+
configs?: Record<string, AITracingInstanceConfig | MastraAITracing>;
|
|
87
76
|
|
|
88
77
|
// Optional function to select which tracing instance to use
|
|
89
|
-
|
|
78
|
+
configSelector?: TracingSelector;
|
|
90
79
|
};
|
|
91
80
|
|
|
92
81
|
type AITracingInstanceConfig = {
|
|
@@ -108,6 +97,33 @@ type AITracingInstanceConfig = {
|
|
|
108
97
|
};
|
|
109
98
|
```
|
|
110
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
|
+
|
|
111
127
|
### Sampling Configuration
|
|
112
128
|
|
|
113
129
|
Control which traces are collected and exported:
|
|
@@ -115,7 +131,7 @@ Control which traces are collected and exported:
|
|
|
115
131
|
```ts filename="src/mastra/index.ts" showLineNumbers copy
|
|
116
132
|
export const mastra = new Mastra({
|
|
117
133
|
observability: {
|
|
118
|
-
|
|
134
|
+
configs: {
|
|
119
135
|
langfuse: {
|
|
120
136
|
serviceName: 'my-service',
|
|
121
137
|
// Sample all traces (default)
|
|
@@ -152,6 +168,66 @@ export const mastra = new Mastra({
|
|
|
152
168
|
|
|
153
169
|
## Exporters
|
|
154
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
|
+
|
|
155
231
|
### Langfuse Exporter
|
|
156
232
|
|
|
157
233
|
#### Installation
|
|
@@ -188,7 +264,7 @@ import { LangfuseExporter } from '@mastra/langfuse';
|
|
|
188
264
|
|
|
189
265
|
export const mastra = new Mastra({
|
|
190
266
|
observability: {
|
|
191
|
-
|
|
267
|
+
configs: {
|
|
192
268
|
langfuse: {
|
|
193
269
|
serviceName: process.env.SERVICE_NAME || 'mastra-app',
|
|
194
270
|
sampling: { type: 'always' },
|
|
@@ -262,7 +338,7 @@ import { BraintrustExporter } from '@mastra/braintrust';
|
|
|
262
338
|
|
|
263
339
|
export const mastra = new Mastra({
|
|
264
340
|
observability: {
|
|
265
|
-
|
|
341
|
+
configs: {
|
|
266
342
|
braintrust: {
|
|
267
343
|
serviceName: 'my-service',
|
|
268
344
|
exporters: [
|
|
@@ -284,7 +360,7 @@ You can configure multiple tracing instances and use a selector to choose which
|
|
|
284
360
|
```ts filename="mastra.config.ts" showLineNumbers copy
|
|
285
361
|
export const mastra = new Mastra({
|
|
286
362
|
observability: {
|
|
287
|
-
|
|
363
|
+
configs: {
|
|
288
364
|
production: {
|
|
289
365
|
serviceName: 'prod-service',
|
|
290
366
|
sampling: { type: 'ratio', probability: 0.1 },
|
|
@@ -296,7 +372,7 @@ export const mastra = new Mastra({
|
|
|
296
372
|
exporters: [devLangfuseExporter],
|
|
297
373
|
},
|
|
298
374
|
},
|
|
299
|
-
|
|
375
|
+
configSelector: (context, availableTracers) => {
|
|
300
376
|
// Use development tracer for debug sessions
|
|
301
377
|
if (context.runtimeContext?.get('debug') === 'true') {
|
|
302
378
|
return 'development';
|
|
@@ -307,6 +383,29 @@ export const mastra = new Mastra({
|
|
|
307
383
|
});
|
|
308
384
|
```
|
|
309
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
|
+
|
|
310
409
|
## Span Types and Attributes
|
|
311
410
|
|
|
312
411
|
AI Tracing automatically creates spans for different AI operations. Mastra supports the following span types:
|