Skip to content

Commit b002ecc

Browse files
epinzurclaude
andauthored
Fix deprecated observability config in create-mastra (#11768)
## Description Updating remaining template with changes from #11674 ## Related Issue(s) ## Type of Change - [X] Bug fix (non-breaking change that fixes an issue) - [ ] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [ ] Code refactoring - [ ] Performance improvement - [ ] Test update ## Checklist - [ ] I have made corresponding changes to the documentation (if applicable) - [ ] I have added tests that prove my fix is effective or that my feature works <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Enhanced observability: support for multiple trace exporters and automatic sensitive-data redaction for improved monitoring and privacy. * **Behavior Changes** * Query serialization now encodes arrays and objects as JSON strings in query parameters, changing how complex values are transmitted. * **Documentation** * Updated examples and guidance to reflect the new observability configuration patterns. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent ef756c6 commit b002ecc

4 files changed

Lines changed: 52 additions & 13 deletions

File tree

e2e-tests/no-bundling/template/src/mastra/index.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Mastra } from '@mastra/core/mastra';
22
import { PinoLogger } from '@mastra/loggers';
33
import { LibSQLStore } from '@mastra/libsql';
4-
import { Observability } from '@mastra/observability';
4+
import { Observability, DefaultExporter, CloudExporter, SensitiveDataFilter } from '@mastra/observability';
55
import { weatherWorkflow } from './workflows/weather-workflow';
66
import { weatherAgent } from './agents/weather-agent';
77
import { toolCallAppropriatenessScorer, completenessScorer, translationScorer } from './scorers/weather-scorer';
@@ -20,8 +20,18 @@ export const mastra = new Mastra({
2020
level: 'info',
2121
}),
2222
observability: new Observability({
23-
// Enables DefaultExporter and CloudExporter for tracing
24-
default: { enabled: true },
23+
configs: {
24+
default: {
25+
serviceName: 'mastra',
26+
exporters: [
27+
new DefaultExporter(), // Persists traces to storage for Mastra Studio
28+
new CloudExporter(), // Sends traces to Mastra Cloud (if MASTRA_CLOUD_ACCESS_TOKEN is set)
29+
],
30+
spanOutputProcessors: [
31+
new SensitiveDataFilter(), // Redacts sensitive data like passwords, tokens, keys
32+
],
33+
},
34+
},
2535
}),
2636
bundler: {
2737
externals: true,

examples/agent-v6/src/mastra/index.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Mastra } from '@mastra/core/mastra';
22
import { LibSQLStore } from '@mastra/libsql';
33
import { weatherAgent, weatherToolLoopAgent } from './agents';
4-
import { Observability } from '@mastra/observability';
4+
import { Observability, DefaultExporter, CloudExporter, SensitiveDataFilter } from '@mastra/observability';
55

66
const storage = new LibSQLStore({
77
id: 'mastra-storage',
@@ -23,6 +23,17 @@ export const mastra = new Mastra({
2323
},
2424
},
2525
observability: new Observability({
26-
default: { enabled: true },
26+
configs: {
27+
default: {
28+
serviceName: 'mastra',
29+
exporters: [
30+
new DefaultExporter(), // Persists traces to storage for Mastra Studio
31+
new CloudExporter(), // Sends traces to Mastra Cloud (if MASTRA_CLOUD_ACCESS_TOKEN is set)
32+
],
33+
spanOutputProcessors: [
34+
new SensitiveDataFilter(), // Redacts sensitive data like passwords, tokens, keys
35+
],
36+
},
37+
},
2738
}),
2839
});

packages/cli/src/commands/init/utils.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ export const mastra = new Mastra()
495495
import { Mastra } from '@mastra/core/mastra';
496496
import { PinoLogger } from '@mastra/loggers';
497497
import { LibSQLStore } from '@mastra/libsql';
498-
import { Observability } from '@mastra/observability';
498+
import { Observability, DefaultExporter, CloudExporter, SensitiveDataFilter } from '@mastra/observability';
499499
${addWorkflow ? `import { weatherWorkflow } from './workflows/weather-workflow';` : ''}
500500
${addAgent ? `import { weatherAgent } from './agents/weather-agent';` : ''}
501501
${addScorers ? `import { toolCallAppropriatenessScorer, completenessScorer, translationScorer } from './scorers/weather-scorer';` : ''}
@@ -512,8 +512,18 @@ export const mastra = new Mastra({
512512
level: 'info',
513513
}),
514514
observability: new Observability({
515-
// Enables DefaultExporter and CloudExporter for tracing
516-
default: { enabled: true },
515+
configs: {
516+
default: {
517+
serviceName: 'mastra',
518+
exporters: [
519+
new DefaultExporter(), // Persists traces to storage for Mastra Studio
520+
new CloudExporter(), // Sends traces to Mastra Cloud (if MASTRA_CLOUD_ACCESS_TOKEN is set)
521+
],
522+
spanOutputProcessors: [
523+
new SensitiveDataFilter(), // Redacts sensitive data like passwords, tokens, keys
524+
],
525+
},
526+
},
517527
}),
518528
});
519529
`,

packages/core/src/mastra/index.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,17 @@ export interface Config<
144144
*
145145
* @example
146146
* ```typescript
147-
* import { Observability } from '@mastra/observability';
147+
* import { Observability, DefaultExporter, CloudExporter, SensitiveDataFilter } from '@mastra/observability';
148148
*
149149
* new Mastra({
150150
* observability: new Observability({
151-
* default: { enabled: true }
151+
* configs: {
152+
* default: {
153+
* serviceName: 'mastra',
154+
* exporters: [new DefaultExporter(), new CloudExporter()],
155+
* spanOutputProcessors: [new SensitiveDataFilter()],
156+
* },
157+
* },
152158
* })
153159
* })
154160
* ```
@@ -401,7 +407,9 @@ export class Mastra<
401407
* connectionString: process.env.DATABASE_URL
402408
* }),
403409
* logger: new PinoLogger({ name: 'MyApp' }),
404-
* observability: { default: { enabled: true }},
410+
* observability: new Observability({
411+
* configs: { default: { serviceName: 'mastra', exporters: [new DefaultExporter()] } },
412+
* }),
405413
* });
406414
* ```
407415
*/
@@ -471,8 +479,8 @@ export class Mastra<
471479
} else {
472480
this.#logger?.warn(
473481
'Observability configuration error: Expected an Observability instance, but received a config object. ' +
474-
'Import and instantiate: import { Observability } from "@mastra/observability"; ' +
475-
'then pass: observability: new Observability({ default: { enabled: true } }). ' +
482+
'Import and instantiate: import { Observability, DefaultExporter } from "@mastra/observability"; ' +
483+
'then pass: observability: new Observability({ configs: { default: { serviceName: "mastra", exporters: [new DefaultExporter()] } } }). ' +
476484
'Observability has been disabled.',
477485
);
478486
this.#observability = new NoOpObservability();

0 commit comments

Comments
 (0)