@mastra/observability 1.24.1 → 1.24.2-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/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-observability-integrations-exporters-mastra-storage.md +12 -12
- package/dist/docs/references/docs-observability-tracing-overview.md +4 -2
- package/dist/docs/references/docs-studio-observability.md +1 -1
- package/dist/docs/references/integrations-observability-arize.md +9 -9
- package/dist/docs/references/integrations-observability-arthur.md +3 -3
- package/dist/docs/references/integrations-observability-braintrust.md +3 -3
- package/dist/docs/references/integrations-observability-confident-ai.md +5 -5
- package/dist/docs/references/integrations-observability-datadog.md +9 -9
- package/dist/docs/references/integrations-observability-laminar.md +2 -2
- package/dist/docs/references/integrations-observability-langfuse.md +13 -13
- package/dist/docs/references/integrations-observability-langsmith.md +9 -9
- package/dist/docs/references/integrations-observability-opentelemetry.md +23 -23
- package/dist/docs/references/integrations-observability-sentry.md +4 -4
- package/dist/docs/references/reference-observability-tracing-bridges-datadog.md +4 -4
- package/dist/docs/references/reference-observability-tracing-bridges-otel.md +4 -4
- package/dist/docs/references/reference-observability-tracing-exporters-cloud-exporter.md +2 -2
- package/dist/docs/references/reference-observability-tracing-exporters-console-exporter.md +1 -1
- package/dist/docs/references/reference-observability-tracing-exporters-datadog.md +3 -3
- package/dist/docs/references/reference-observability-tracing-exporters-default-exporter.md +5 -5
- package/dist/docs/references/reference-observability-tracing-exporters-langfuse.md +3 -3
- package/dist/docs/references/reference-observability-tracing-exporters-mastra-platform-exporter.md +1 -1
- package/dist/docs/references/reference-observability-tracing-exporters-mastra-storage-exporter.md +5 -5
- package/dist/docs/references/reference-observability-tracing-exporters-sentry.md +4 -4
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/instances/base.d.ts.map +1 -1
- package/dist/metrics/pricing-data.json +13587 -4600
- package/package.json +3 -3
package/dist/docs/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: mastra-observability
|
|
|
3
3
|
description: Documentation for @mastra/observability. Use when working with @mastra/observability APIs, configuration, or implementation.
|
|
4
4
|
metadata:
|
|
5
5
|
package: "@mastra/observability"
|
|
6
|
-
version: "1.24.
|
|
6
|
+
version: "1.24.2-alpha.0"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -8,7 +8,7 @@ The `MastraStorageExporter` persists traces to your configured storage backend,
|
|
|
8
8
|
|
|
9
9
|
> **Note:** `MastraStorageExporter` was previously called `DefaultExporter`. The original `DefaultExporter` class is still exported from `@mastra/observability` for backward compatibility, but it's deprecated. New code should use `MastraStorageExporter`.
|
|
10
10
|
|
|
11
|
-
> **Production Observability:** Observability data can
|
|
11
|
+
> **Production Observability:** Observability data can overwhelm general-purpose databases in production. For high-traffic applications, route the observability storage domain to [ClickHouse](https://mastra.ai/integrations/databases/clickhouse) through [composite storage](https://mastra.ai/reference/storage/composite). See [Production Recommendations](#production-recommendations) for details.
|
|
12
12
|
|
|
13
13
|
## Configuration
|
|
14
14
|
|
|
@@ -17,7 +17,7 @@ The `MastraStorageExporter` persists traces to your configured storage backend,
|
|
|
17
17
|
1. **Storage Backend**: Configure a storage provider (libSQL, PostgreSQL, etc.)
|
|
18
18
|
2. **Studio**: Install for viewing traces locally
|
|
19
19
|
|
|
20
|
-
### Basic
|
|
20
|
+
### Basic setup
|
|
21
21
|
|
|
22
22
|
```typescript
|
|
23
23
|
import { Mastra } from '@mastra/core'
|
|
@@ -40,7 +40,7 @@ export const mastra = new Mastra({
|
|
|
40
40
|
})
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
### Recommended
|
|
43
|
+
### Recommended configuration
|
|
44
44
|
|
|
45
45
|
Include MastraStorageExporter in your observability configuration:
|
|
46
46
|
|
|
@@ -128,7 +128,7 @@ Access your traces through Studio:
|
|
|
128
128
|
|
|
129
129
|
MastraStorageExporter automatically selects the optimal tracing strategy based on your storage provider. You can also override this selection if needed.
|
|
130
130
|
|
|
131
|
-
### Available
|
|
131
|
+
### Available strategies
|
|
132
132
|
|
|
133
133
|
| Strategy | Description | Use Case |
|
|
134
134
|
| ---------------------- | ------------------------------------------------------------------------------------- | ---------------------------------------------- |
|
|
@@ -139,7 +139,7 @@ MastraStorageExporter automatically selects the optimal tracing strategy based o
|
|
|
139
139
|
|
|
140
140
|
> **Note:** `realtime` assumes one process owns a span from start to end, so it isn't supported with durable execution (durable agents, and Inngest, Temporal, or evented workflows). When any of these is registered, the exporter logs one warning and runs `batch-with-updates`.
|
|
141
141
|
|
|
142
|
-
### Strategy
|
|
142
|
+
### Strategy configuration
|
|
143
143
|
|
|
144
144
|
```typescript
|
|
145
145
|
new MastraStorageExporter({
|
|
@@ -160,7 +160,7 @@ Different storage providers support different tracing strategies. Some providers
|
|
|
160
160
|
|
|
161
161
|
If you set the strategy to `'auto'`, the `MastraStorageExporter` automatically selects the optimal strategy for the storage provider. If you set an explicit strategy that the storage provider doesn't support, the exporter logs a warning and falls back to the provider's preferred strategy.
|
|
162
162
|
|
|
163
|
-
### Providers with
|
|
163
|
+
### Providers with observability support
|
|
164
164
|
|
|
165
165
|
| Storage Provider | Preferred Strategy | Supported Strategies | Recommended Use |
|
|
166
166
|
| ----------------------------------------------------------------------------- | ------------------ | ------------------------------- | ------------------------------------- |
|
|
@@ -174,7 +174,7 @@ If you set the strategy to `'auto'`, the `MastraStorageExporter` automatically s
|
|
|
174
174
|
|
|
175
175
|
> **Note:** Under `insert-only`, only completed spans are persisted, and span start and update events are ignored. A trace therefore becomes visible in Studio only after its root span ends, and filtering traces by `status: 'running'` returns no results. `PostgresStoreVNext` uses `event-sourced` tracing instead, so in-progress traces remain visible while preserving append-only writes.
|
|
176
176
|
|
|
177
|
-
### Providers without
|
|
177
|
+
### Providers without observability support
|
|
178
178
|
|
|
179
179
|
The following storage providers **don't support** the observability domain. If you're using one of these providers and need observability, use [composite storage](https://mastra.ai/reference/storage/composite) to route observability data to a supported provider:
|
|
180
180
|
|
|
@@ -185,7 +185,7 @@ The following storage providers **don't support** the observability domain. If y
|
|
|
185
185
|
- [Upstash](https://mastra.ai/integrations/databases/upstash)
|
|
186
186
|
- [LanceDB](https://mastra.ai/integrations/databases/lancedb)
|
|
187
187
|
|
|
188
|
-
### Strategy
|
|
188
|
+
### Strategy benefits
|
|
189
189
|
|
|
190
190
|
- **realtime**: Immediate visibility, best for debugging in a single process
|
|
191
191
|
- **batch-with-updates**: 10-100x throughput improvement, full span lifecycle
|
|
@@ -194,9 +194,9 @@ The following storage providers **don't support** the observability domain. If y
|
|
|
194
194
|
|
|
195
195
|
## Production recommendations
|
|
196
196
|
|
|
197
|
-
Observability data grows
|
|
197
|
+
Observability data grows fast in production environments. A single agent interaction can generate hundreds of spans, and high-traffic applications can produce thousands of traces per day. Most general-purpose databases aren't optimized for this write-heavy, append-only workload.
|
|
198
198
|
|
|
199
|
-
### Recommended: ClickHouse for
|
|
199
|
+
### Recommended: ClickHouse for high-volume production
|
|
200
200
|
|
|
201
201
|
[ClickHouse](https://mastra.ai/integrations/databases/clickhouse) is a columnar database designed for high-volume analytics workloads. It's the recommended choice for production observability because:
|
|
202
202
|
|
|
@@ -205,13 +205,13 @@ Observability data grows quickly in production environments. A single agent inte
|
|
|
205
205
|
- **Fast queries**: Columnar storage enables quick trace lookups and aggregations
|
|
206
206
|
- **Time-series native**: Built-in support for time-based data retention and partitioning
|
|
207
207
|
|
|
208
|
-
### Using
|
|
208
|
+
### Using composite storage
|
|
209
209
|
|
|
210
210
|
If you're using a provider without observability support (like Convex or DynamoDB) or want to optimize performance, use [composite storage](https://mastra.ai/reference/storage/composite) to route observability data to ClickHouse while keeping other data in your primary database.
|
|
211
211
|
|
|
212
212
|
## Batching behavior
|
|
213
213
|
|
|
214
|
-
### Flush
|
|
214
|
+
### Flush triggers
|
|
215
215
|
|
|
216
216
|
For both batch strategies (`batch-with-updates` and `insert-only`), traces are flushed to storage when any of these conditions are met:
|
|
217
217
|
|
|
@@ -62,6 +62,8 @@ If the configured failure policy lets the main execution continue, it can still
|
|
|
62
62
|
|
|
63
63
|
Model inference spans (`MODEL_INFERENCE`) measure provider execution and record usage. Model chunk spans (`MODEL_CHUNK`) capture content after output processors have accepted or transformed it. Chunks belong to the logical step (`MODEL_STEP`), so buffered output can arrive after provider execution ends without outliving its parent. In the agent streaming paths, inference spans no longer capture response output; use the processed chunk spans or the generation output instead.
|
|
64
64
|
|
|
65
|
+
A resumed workflow run continues the suspended run's trace on every engine: it keeps the original sampling decision and trace-level settings such as `hideInput`, except those the resume call sets itself, and it nests under the suspended run span. A run that wasn't sampled stays unrecorded when it resumes. Snapshots written by earlier versions carry only the trace and span IDs. Their resumes sample again.
|
|
66
|
+
|
|
65
67
|
## Sampling strategies
|
|
66
68
|
|
|
67
69
|
Sampling allows you to control which traces are collected, helping you balance between observability needs and resource costs.
|
|
@@ -111,7 +113,7 @@ The `sampling` option allows you to control which traces are collected, helping
|
|
|
111
113
|
}
|
|
112
114
|
```
|
|
113
115
|
|
|
114
|
-
3. **Ratio-Based Sampling**:
|
|
116
|
+
3. **Ratio-Based Sampling**: Samples a random percentage of traces. Ideal for production environments where you want statistical insights without the cost of full tracing. The probability value ranges from 0 (no traces) to 1 (all traces).
|
|
115
117
|
|
|
116
118
|
```ts
|
|
117
119
|
sampling: {
|
|
@@ -719,7 +721,7 @@ const exporter = new LangfuseExporter({
|
|
|
719
721
|
|
|
720
722
|
## Serialization options
|
|
721
723
|
|
|
722
|
-
Serialization options control how span data (input, output, and attributes) is truncated before export. This is useful when working with large payloads,
|
|
724
|
+
Serialization options control how span data (input, output, and attributes) is truncated before export. This is useful when working with large payloads, nested objects, or when you need to optimize trace storage.
|
|
723
725
|
|
|
724
726
|
### Configuration
|
|
725
727
|
|
|
@@ -14,7 +14,7 @@ All require an observability storage backend to be configured.
|
|
|
14
14
|
|
|
15
15
|
## Quickstart
|
|
16
16
|
|
|
17
|
-
For detailed instructions, follow the [observability instructions](https://mastra.ai/docs/observability/overview). To get
|
|
17
|
+
For detailed instructions, follow the [observability instructions](https://mastra.ai/docs/observability/overview). To get started fast, add the `@mastra/observability` package to your project and configure it with [LibSQL](https://mastra.ai/integrations/databases/libsql) and [DuckDB](https://mastra.ai/integrations/vectors/duckdb) for a local development setup that supports both traces and metrics.
|
|
18
18
|
|
|
19
19
|
**npm**:
|
|
20
20
|
|
|
@@ -36,7 +36,7 @@ bun add @mastra/arize@latest
|
|
|
36
36
|
|
|
37
37
|
## Configuration
|
|
38
38
|
|
|
39
|
-
### Phoenix
|
|
39
|
+
### Phoenix setup
|
|
40
40
|
|
|
41
41
|
Phoenix is an open-source observability platform that can run locally or be self-hosted.
|
|
42
42
|
|
|
@@ -56,7 +56,7 @@ PHOENIX_API_KEY=your-api-key # For authenticated Phoenix instances
|
|
|
56
56
|
PHOENIX_PROJECT_NAME=mastra-service # Defaults to 'mastra-service'
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
#### Zero-
|
|
59
|
+
#### Zero-config setup
|
|
60
60
|
|
|
61
61
|
With environment variables set, use the exporter with no configuration:
|
|
62
62
|
|
|
@@ -77,7 +77,7 @@ export const mastra = new Mastra({
|
|
|
77
77
|
})
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
-
#### Explicit
|
|
80
|
+
#### Explicit configuration
|
|
81
81
|
|
|
82
82
|
You can also pass credentials directly (takes precedence over environment variables):
|
|
83
83
|
|
|
@@ -114,7 +114,7 @@ export const mastra = new Mastra({
|
|
|
114
114
|
>
|
|
115
115
|
> Set `PHOENIX_COLLECTOR_ENDPOINT=http://localhost:6006/v1/traces` and run your Mastra agent to see traces at [localhost:6006](http://localhost:6006).
|
|
116
116
|
|
|
117
|
-
### Arize AX
|
|
117
|
+
### Arize AX setup
|
|
118
118
|
|
|
119
119
|
Arize AX is a managed cloud and enterprise self-hosted observability platform with advanced features for production AI systems.
|
|
120
120
|
|
|
@@ -134,7 +134,7 @@ ARIZE_API_KEY=your-api-key
|
|
|
134
134
|
ARIZE_PROJECT_NAME=mastra-service
|
|
135
135
|
```
|
|
136
136
|
|
|
137
|
-
#### Zero-
|
|
137
|
+
#### Zero-config setup
|
|
138
138
|
|
|
139
139
|
With environment variables set, use the exporter with no configuration:
|
|
140
140
|
|
|
@@ -155,7 +155,7 @@ export const mastra = new Mastra({
|
|
|
155
155
|
})
|
|
156
156
|
```
|
|
157
157
|
|
|
158
|
-
#### Explicit
|
|
158
|
+
#### Explicit configuration
|
|
159
159
|
|
|
160
160
|
You can also pass credentials directly (takes precedence over environment variables):
|
|
161
161
|
|
|
@@ -186,7 +186,7 @@ export const mastra = new Mastra({
|
|
|
186
186
|
|
|
187
187
|
The Arize exporter supports advanced configuration for fine-tuning OpenTelemetry behavior:
|
|
188
188
|
|
|
189
|
-
### Complete
|
|
189
|
+
### Complete configuration
|
|
190
190
|
|
|
191
191
|
```typescript
|
|
192
192
|
new ArizeExporter({
|
|
@@ -218,7 +218,7 @@ new ArizeExporter({
|
|
|
218
218
|
})
|
|
219
219
|
```
|
|
220
220
|
|
|
221
|
-
### Batch
|
|
221
|
+
### Batch processing options
|
|
222
222
|
|
|
223
223
|
Control how traces are batched and exported:
|
|
224
224
|
|
|
@@ -233,7 +233,7 @@ new ArizeExporter({
|
|
|
233
233
|
})
|
|
234
234
|
```
|
|
235
235
|
|
|
236
|
-
### Resource
|
|
236
|
+
### Resource attributes
|
|
237
237
|
|
|
238
238
|
Add custom attributes to all exported spans:
|
|
239
239
|
|
|
@@ -60,7 +60,7 @@ ARTHUR_BASE_URL=http://localhost:3030
|
|
|
60
60
|
ARTHUR_TASK_ID=your-task-id
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
-
### Zero-
|
|
63
|
+
### Zero-config setup
|
|
64
64
|
|
|
65
65
|
With environment variables set, use the exporter with no configuration:
|
|
66
66
|
|
|
@@ -81,7 +81,7 @@ export const mastra = new Mastra({
|
|
|
81
81
|
})
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
### Explicit
|
|
84
|
+
### Explicit configuration
|
|
85
85
|
|
|
86
86
|
You can also pass credentials directly (takes precedence over environment variables):
|
|
87
87
|
|
|
@@ -110,7 +110,7 @@ export const mastra = new Mastra({
|
|
|
110
110
|
|
|
111
111
|
## Configuration options
|
|
112
112
|
|
|
113
|
-
### Complete
|
|
113
|
+
### Complete configuration
|
|
114
114
|
|
|
115
115
|
```typescript
|
|
116
116
|
new ArthurExporter({
|
|
@@ -48,7 +48,7 @@ BRAINTRUST_API_KEY=sk-xxxxxxxxxxxxxxxx
|
|
|
48
48
|
BRAINTRUST_ENDPOINT=https://api.braintrust.dev # Custom endpoint if needed
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
### Zero-
|
|
51
|
+
### Zero-config setup
|
|
52
52
|
|
|
53
53
|
With environment variables set, use the exporter with no configuration:
|
|
54
54
|
|
|
@@ -69,7 +69,7 @@ export const mastra = new Mastra({
|
|
|
69
69
|
})
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
-
### Explicit
|
|
72
|
+
### Explicit configuration
|
|
73
73
|
|
|
74
74
|
You can also pass credentials directly (takes precedence over environment variables):
|
|
75
75
|
|
|
@@ -95,7 +95,7 @@ export const mastra = new Mastra({
|
|
|
95
95
|
})
|
|
96
96
|
```
|
|
97
97
|
|
|
98
|
-
### Complete
|
|
98
|
+
### Complete configuration
|
|
99
99
|
|
|
100
100
|
```typescript
|
|
101
101
|
new BraintrustExporter({
|
|
@@ -49,7 +49,7 @@ CONFIDENT_API_KEY=confident_proj_xxxxxxxxxxxxx
|
|
|
49
49
|
CONFIDENT_OTEL_ENDPOINT=https://eu.otel.confident-ai.com/v1/traces
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
### Zero-
|
|
52
|
+
### Zero-config setup
|
|
53
53
|
|
|
54
54
|
With environment variables set, use the exporter with no configuration:
|
|
55
55
|
|
|
@@ -70,7 +70,7 @@ export const mastra = new Mastra({
|
|
|
70
70
|
})
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
### Explicit
|
|
73
|
+
### Explicit configuration
|
|
74
74
|
|
|
75
75
|
You can also pass credentials directly (takes precedence over environment variables):
|
|
76
76
|
|
|
@@ -136,7 +136,7 @@ const result = await mastra.getAgent('assistant').generate('How do you make the
|
|
|
136
136
|
})
|
|
137
137
|
```
|
|
138
138
|
|
|
139
|
-
Your metadata is merged with the fields Mastra sets itself, such as `runId`. Tags apply to the root span,
|
|
139
|
+
Your metadata is merged with the fields Mastra sets itself, such as `runId`. Tags apply to the root span, which means they apply to the trace rather than to individual spans.
|
|
140
140
|
|
|
141
141
|
## Lifecycle
|
|
142
142
|
|
|
@@ -152,11 +152,11 @@ In a long-running server, shut down during graceful shutdown rather than per req
|
|
|
152
152
|
|
|
153
153
|
## Threads and trace properties
|
|
154
154
|
|
|
155
|
-
This exporter maps Mastra's own tracing surface, so trace metadata and tags come from `tracingOptions`
|
|
155
|
+
This exporter maps Mastra's own tracing surface, so trace metadata and tags come from the `tracingOptions` passed to the traced call.
|
|
156
156
|
|
|
157
157
|
Grouping turns into [threads](https://www.confident-ai.com/docs/llm-tracing/features/threads) and setting trace-level properties such as user IDs use `confident-trace`'s SDK instrumentation, which attaches to Mastra directly rather than through an exporter. See the [Mastra integration guide](https://www.confident-ai.com/docs/integrations/third-party/mastra) for that setup.
|
|
158
158
|
|
|
159
|
-
Choose one or the other.
|
|
159
|
+
Choose one or the other. Don't use both at once.
|
|
160
160
|
|
|
161
161
|
## Related
|
|
162
162
|
|
|
@@ -51,7 +51,7 @@ DD_SITE=datadoghq.com # Optional: defaults to datadoghq.com
|
|
|
51
51
|
DD_ENV=production # Optional: environment name
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
#### Zero-
|
|
54
|
+
#### Zero-config setup
|
|
55
55
|
|
|
56
56
|
With environment variables set, use the exporter with no configuration:
|
|
57
57
|
|
|
@@ -72,7 +72,7 @@ export const mastra = new Mastra({
|
|
|
72
72
|
})
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
#### Explicit
|
|
75
|
+
#### Explicit configuration
|
|
76
76
|
|
|
77
77
|
You can also pass credentials directly (takes precedence over environment variables):
|
|
78
78
|
|
|
@@ -100,7 +100,7 @@ export const mastra = new Mastra({
|
|
|
100
100
|
|
|
101
101
|
### Configuration options
|
|
102
102
|
|
|
103
|
-
#### Complete
|
|
103
|
+
#### Complete configuration
|
|
104
104
|
|
|
105
105
|
```typescript
|
|
106
106
|
new DatadogExporter({
|
|
@@ -122,7 +122,7 @@ new DatadogExporter({
|
|
|
122
122
|
})
|
|
123
123
|
```
|
|
124
124
|
|
|
125
|
-
#### With
|
|
125
|
+
#### With local Datadog agent
|
|
126
126
|
|
|
127
127
|
If you have a Datadog Agent running locally, you can route traces through it instead of direct HTTPS:
|
|
128
128
|
|
|
@@ -153,7 +153,7 @@ Mastra span types are automatically mapped to Datadog LLM Observability span kin
|
|
|
153
153
|
|
|
154
154
|
Other/future Mastra span types will default to 'task' when mapped unless specified.
|
|
155
155
|
|
|
156
|
-
### Application
|
|
156
|
+
### Application performance monitoring
|
|
157
157
|
|
|
158
158
|
The sections above cover Mastra's [LLM Observability](https://docs.datadoghq.com/llm_observability/) integration. To trace your Mastra HTTP server routes (request latency, error tracking, service maps), use `dd-trace` directly for Datadog Application Performance Monitoring (APM).
|
|
159
159
|
|
|
@@ -227,7 +227,7 @@ DD_VERSION=1.0.0
|
|
|
227
227
|
|
|
228
228
|
`dd-trace` auto-instruments popular HTTP frameworks, including those supported by Mastra's [server adapters](https://mastra.ai/docs/server/server-adapters). Inbound requests, outbound HTTP calls, and database queries appear as APM traces in Datadog.
|
|
229
229
|
|
|
230
|
-
#### APM and LLM
|
|
230
|
+
#### APM and LLM observability
|
|
231
231
|
|
|
232
232
|
Import and initialize `dd-trace` before creating the Mastra instance. The `DatadogExporter` detects the existing tracer and skips re-initialization, adding LLM Observability on top of your APM setup:
|
|
233
233
|
|
|
@@ -280,7 +280,7 @@ DD_LLMOBS_ML_APP=my-llm-app
|
|
|
280
280
|
|
|
281
281
|
Server routes appear as APM traces and LLM calls appear as LLM Observability spans, all under the same service in Datadog.
|
|
282
282
|
|
|
283
|
-
> **Note:** Import and initialize `dd-trace` before all other modules
|
|
283
|
+
> **Note:** Import and initialize `dd-trace` before all other modules so its auto-instrumentation can patch HTTP, database, and framework libraries at load time.
|
|
284
284
|
|
|
285
285
|
### Troubleshooting
|
|
286
286
|
|
|
@@ -419,9 +419,9 @@ import { DatadogBridge } from '@mastra/datadog'
|
|
|
419
419
|
// ...
|
|
420
420
|
```
|
|
421
421
|
|
|
422
|
-
> **Note:** Import and initialize `dd-trace` at the
|
|
422
|
+
> **Note:** Import and initialize `dd-trace` at the top of your application's entry file, before any other imports.
|
|
423
423
|
|
|
424
|
-
#### Step 2: Mastra
|
|
424
|
+
#### Step 2: Mastra configuration
|
|
425
425
|
|
|
426
426
|
Add the `DatadogBridge` to your Mastra observability config:
|
|
427
427
|
|
|
@@ -48,7 +48,7 @@ LMNR_PROJECT_API_KEY=lmnr_...
|
|
|
48
48
|
LMNR_BASE_URL=https://api.lmnr.ai
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
### Zero-
|
|
51
|
+
### Zero-config setup
|
|
52
52
|
|
|
53
53
|
With environment variables set, use the exporter with no configuration:
|
|
54
54
|
|
|
@@ -71,7 +71,7 @@ export const mastra = new Mastra({
|
|
|
71
71
|
})
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
-
### Explicit
|
|
74
|
+
### Explicit configuration
|
|
75
75
|
|
|
76
76
|
You can also pass credentials directly (takes precedence over environment variables):
|
|
77
77
|
|
|
@@ -46,7 +46,7 @@ LANGFUSE_SECRET_KEY=sk-lf-xxxxxxxxxxxx
|
|
|
46
46
|
LANGFUSE_BASE_URL=https://cloud.langfuse.com # Or your self-hosted URL
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
### Zero-
|
|
49
|
+
### Zero-config setup
|
|
50
50
|
|
|
51
51
|
With environment variables set, use the exporter with no configuration:
|
|
52
52
|
|
|
@@ -67,7 +67,7 @@ export const mastra = new Mastra({
|
|
|
67
67
|
})
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
### Explicit
|
|
70
|
+
### Explicit configuration
|
|
71
71
|
|
|
72
72
|
You can also pass credentials directly (takes precedence over environment variables):
|
|
73
73
|
|
|
@@ -98,11 +98,11 @@ export const mastra = new Mastra({
|
|
|
98
98
|
|
|
99
99
|
## Configuration options
|
|
100
100
|
|
|
101
|
-
### Realtime vs
|
|
101
|
+
### Realtime vs batch mode
|
|
102
102
|
|
|
103
103
|
The Langfuse exporter supports two modes for sending traces:
|
|
104
104
|
|
|
105
|
-
#### Realtime
|
|
105
|
+
#### Realtime mode (development)
|
|
106
106
|
|
|
107
107
|
Traces appear immediately in Langfuse dashboard, ideal for debugging:
|
|
108
108
|
|
|
@@ -114,7 +114,7 @@ new LangfuseExporter({
|
|
|
114
114
|
})
|
|
115
115
|
```
|
|
116
116
|
|
|
117
|
-
#### Batch
|
|
117
|
+
#### Batch mode (production)
|
|
118
118
|
|
|
119
119
|
Better performance with automatic batching:
|
|
120
120
|
|
|
@@ -126,7 +126,7 @@ new LangfuseExporter({
|
|
|
126
126
|
})
|
|
127
127
|
```
|
|
128
128
|
|
|
129
|
-
#### Batch
|
|
129
|
+
#### Batch tuning for high-volume traces
|
|
130
130
|
|
|
131
131
|
For self-hosted Langfuse deployments or streamed runs that produce many spans per second, you can tune the OTEL batch size and flush interval to reduce request pressure on the Langfuse ingestion endpoint:
|
|
132
132
|
|
|
@@ -155,7 +155,7 @@ new Observability({
|
|
|
155
155
|
})
|
|
156
156
|
```
|
|
157
157
|
|
|
158
|
-
### Complete
|
|
158
|
+
### Complete configuration
|
|
159
159
|
|
|
160
160
|
```typescript
|
|
161
161
|
new LangfuseExporter({
|
|
@@ -197,7 +197,7 @@ The trace name dropdown in Langfuse evaluator filters lists every distinct value
|
|
|
197
197
|
|
|
198
198
|
If you set a custom `traceName` via `mastra.metadata.traceName`, your value takes precedence over the default agent name.
|
|
199
199
|
|
|
200
|
-
A run started with `tracingOptions.nestUnderParent` doesn't own the trace,
|
|
200
|
+
A run started with `tracingOptions.nestUnderParent` doesn't own the trace, and the exporter doesn't write the trace name, input, output, metadata, user, or session from it. See [Nesting a run under an earlier run](https://mastra.ai/docs/observability/tracing/overview).
|
|
201
201
|
|
|
202
202
|
## Filtering observations by span attributes
|
|
203
203
|
|
|
@@ -226,7 +226,7 @@ const tracingOptions = {
|
|
|
226
226
|
|
|
227
227
|
This example produces `langfuse.trace.metadata.customerId` and `langfuse.trace.metadata.tier`.
|
|
228
228
|
|
|
229
|
-
Metadata on the root span is also forwarded. Mastra sets `runId` and `resourceId` on every agent and workflow root span, and you can add your own keys through `tracingOptions.metadata`. The exporter forwards each of these root span keys to `langfuse.trace.metadata.<key>`. Keys that map to a dedicated Langfuse field (`userId`, `sessionId`, `threadId`, `traceName`, and `version`)
|
|
229
|
+
Metadata on the root span is also forwarded. Mastra sets `runId` and `resourceId` on every agent and workflow root span, and you can add your own keys through `tracingOptions.metadata`. The exporter forwards each of these root span keys to `langfuse.trace.metadata.<key>`. Keys that map to a dedicated Langfuse field (`userId`, `sessionId`, `threadId`, `traceName`, and `version`) aren't duplicated as trace metadata. Other metadata on child spans stays on the observation. Dedicated fields such as session IDs follow their own mapping rules.
|
|
230
230
|
|
|
231
231
|
Notes:
|
|
232
232
|
|
|
@@ -241,7 +241,7 @@ The exporter maps span metadata to Langfuse sessions using `sessionId`, or `thre
|
|
|
241
241
|
|
|
242
242
|
For [Observational Memory](https://mastra.ai/docs/memory/observational-memory), the Langfuse exporter keeps observer and reflector spans in the caller's session, even when child spans arrive before their parents. An explicit `sessionId`, including an empty string, takes precedence. Otherwise, the exporter uses the original caller thread carried by Observational Memory before falling back to the span's own `threadId`. Observational Memory captures that caller identity from the caller span's non-empty `threadId`, or the original request's thread ID. Nested observation preserves the outer caller identity.
|
|
243
243
|
|
|
244
|
-
This thread-to-session fallback is specific to Langfuse
|
|
244
|
+
This thread-to-session fallback is specific to Langfuse, and Observational Memory doesn't synthesize generic `sessionId` metadata from a thread ID for other exporters.
|
|
245
245
|
|
|
246
246
|
Internal observer and reflector execution threads remain separate. Multi-thread observation uses the invoking caller's session, not the first thread in the batch. This session behavior applies regardless of the `bufferOnIdle` setting and doesn't change buffering or span parentage.
|
|
247
247
|
|
|
@@ -262,7 +262,7 @@ See the [`LangfuseExporter` reference](https://mastra.ai/reference/observability
|
|
|
262
262
|
|
|
263
263
|
You can link LLM generations to prompts stored in [Langfuse Prompt Management](https://langfuse.com/docs/prompt-management). It enables version tracking and metrics for your prompts.
|
|
264
264
|
|
|
265
|
-
### Using the
|
|
265
|
+
### Using the helper (recommended)
|
|
266
266
|
|
|
267
267
|
Use `withLangfusePrompt` with `buildTracingOptions` for the cleanest API:
|
|
268
268
|
|
|
@@ -291,7 +291,7 @@ export const supportAgent = new Agent({
|
|
|
291
291
|
|
|
292
292
|
The `withLangfusePrompt` helper accepts `name` and `version` fields for prompt linking. Langfuse v5 requires both fields.
|
|
293
293
|
|
|
294
|
-
### Manual
|
|
294
|
+
### Manual fields
|
|
295
295
|
|
|
296
296
|
You can also pass manual fields if you're not using the Langfuse SDK:
|
|
297
297
|
|
|
@@ -299,7 +299,7 @@ You can also pass manual fields if you're not using the Langfuse SDK:
|
|
|
299
299
|
const tracingOptions = buildTracingOptions(withLangfusePrompt({ name: 'my-prompt', version: 1 }))
|
|
300
300
|
```
|
|
301
301
|
|
|
302
|
-
### Prompt
|
|
302
|
+
### Prompt object fields
|
|
303
303
|
|
|
304
304
|
The prompt object requires both `name` and `version`:
|
|
305
305
|
|
|
@@ -49,7 +49,7 @@ LANGCHAIN_PROJECT=my-project # Default project for traces
|
|
|
49
49
|
LANGSMITH_BASE_URL=https://api.smith.langchain.com # For self-hosted
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
### Zero-
|
|
52
|
+
### Zero-config setup
|
|
53
53
|
|
|
54
54
|
With environment variables set, use the exporter with no configuration:
|
|
55
55
|
|
|
@@ -70,7 +70,7 @@ export const mastra = new Mastra({
|
|
|
70
70
|
})
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
### Explicit
|
|
73
|
+
### Explicit configuration
|
|
74
74
|
|
|
75
75
|
You can also pass credentials directly (takes precedence over environment variables):
|
|
76
76
|
|
|
@@ -97,7 +97,7 @@ export const mastra = new Mastra({
|
|
|
97
97
|
|
|
98
98
|
## Configuration options
|
|
99
99
|
|
|
100
|
-
### Complete
|
|
100
|
+
### Complete configuration
|
|
101
101
|
|
|
102
102
|
```typescript
|
|
103
103
|
new LangSmithExporter({
|
|
@@ -134,7 +134,7 @@ The `projectName` config option takes precedence over the `LANGCHAIN_PROJECT` en
|
|
|
134
134
|
|
|
135
135
|
You can override at runtime LangSmith settings per-span using `withLangsmithMetadata`. This is useful for routing traces to different projects based on runtime conditions (e.g., customer, environment, or feature).
|
|
136
136
|
|
|
137
|
-
### Using the
|
|
137
|
+
### Using the helper
|
|
138
138
|
|
|
139
139
|
Use `withLangsmithMetadata` with `buildTracingOptions` to set LangSmith-specific options:
|
|
140
140
|
|
|
@@ -154,7 +154,7 @@ export const supportAgent = new Agent({
|
|
|
154
154
|
})
|
|
155
155
|
```
|
|
156
156
|
|
|
157
|
-
### Dynamic
|
|
157
|
+
### Dynamic project routing
|
|
158
158
|
|
|
159
159
|
Use `requestContext` to route traces to different projects based on runtime conditions.
|
|
160
160
|
|
|
@@ -184,7 +184,7 @@ export const supportAgent = new Agent({
|
|
|
184
184
|
})
|
|
185
185
|
```
|
|
186
186
|
|
|
187
|
-
### Available
|
|
187
|
+
### Available fields
|
|
188
188
|
|
|
189
189
|
The `withLangsmithMetadata` helper accepts these fields:
|
|
190
190
|
|
|
@@ -198,7 +198,7 @@ All fields are optional. The helper merges with any existing metadata, so you ca
|
|
|
198
198
|
|
|
199
199
|
## Conversation threads
|
|
200
200
|
|
|
201
|
-
LangSmith groups runs into a [Thread](https://docs.langchain.com/langsmith/threads) using the `session_id` metadata key. The exporter sets it on every run of a trace. The root run takes the first value it finds: an explicit `withLangsmithMetadata({ sessionId })`, then `sessionId` in span metadata, then the Mastra memory `threadId`.
|
|
201
|
+
LangSmith groups runs into a [Thread](https://docs.langchain.com/langsmith/threads) using the `session_id` metadata key. The exporter sets it on every run of a trace. The root run takes the first value it finds: an explicit `withLangsmithMetadata({ sessionId })`, then `sessionId` in span metadata, then the Mastra memory `threadId`. Because child runs take the session of their parent run, a delegated sub-agent stays in the conversation's Thread even though it runs on its own derived thread.
|
|
202
202
|
|
|
203
203
|
Agents with memory set `threadId` on each run, so turns on the same memory thread appear as one Thread in LangSmith without extra configuration:
|
|
204
204
|
|
|
@@ -211,7 +211,7 @@ await agent.generate('and again', { memory })
|
|
|
211
211
|
|
|
212
212
|
## Scores and feedback
|
|
213
213
|
|
|
214
|
-
Scores sent through `mastra.observability.addScore()` show up in LangSmith as feedback on the matching run. A score with only a `traceId` is attached to the trace's root run
|
|
214
|
+
Scores sent through `mastra.observability.addScore()` show up in LangSmith as feedback on the matching run. A score with only a `traceId` is attached to the trace's root run. A score with a `spanId` is attached to that span's run.
|
|
215
215
|
|
|
216
216
|
```typescript
|
|
217
217
|
await mastra.observability.addScore({
|
|
@@ -221,7 +221,7 @@ await mastra.observability.addScore({
|
|
|
221
221
|
})
|
|
222
222
|
```
|
|
223
223
|
|
|
224
|
-
Each LangSmith run id is derived from its Mastra span id,
|
|
224
|
+
Each LangSmith run id is derived from its Mastra span id, which means a span-level score works from any process, after a restart, and long after the trace was exported. A trace-level score finds the root run in the exporter's project through the `mastra_trace_id` metadata the exporter stores on every run. Runs exported by earlier versions of `@mastra/langsmith` keep their original ids and can only be scored from the process that exported them. The same derivation is exported as `langsmithRunIdFor()` if you need to link to a run from your own UI:
|
|
225
225
|
|
|
226
226
|
```typescript
|
|
227
227
|
import { langsmithRunIdFor } from '@mastra/langsmith'
|