@mastra/observability 1.0.0-beta.10 → 1.0.0-beta.11

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/CHANGELOG.md CHANGED
@@ -1,5 +1,100 @@
1
1
  # @mastra/observability
2
2
 
3
+ ## 1.0.0-beta.11
4
+
5
+ ### Major Changes
6
+
7
+ - **Breaking Change**: Convert OUTPUT generic from `OutputSchema` constraint to plain generic ([#11741](https://github.com/mastra-ai/mastra/pull/11741))
8
+
9
+ This change removes the direct dependency on Zod typings in the public API by converting all `OUTPUT extends OutputSchema` generic constraints to plain `OUTPUT` generics throughout the codebase. This is preparation for moving to a standard schema approach.
10
+ - All generic type parameters previously constrained to `OutputSchema` (e.g., `<OUTPUT extends OutputSchema = undefined>`) are now plain generics with defaults (e.g., `<OUTPUT = undefined>`)
11
+ - Affects all public APIs including `Agent`, `MastraModelOutput`, `AgentExecutionOptions`, and stream/generate methods
12
+ - `InferSchemaOutput<OUTPUT>` replaced with `OUTPUT` throughout
13
+ - `PartialSchemaOutput<OUTPUT>` replaced with `Partial<OUTPUT>`
14
+ - Schema fields now use `NonNullable<OutputSchema<OUTPUT>>` instead of `OUTPUT` directly
15
+ - Added `FullOutput<OUTPUT>` type representing complete output with all fields
16
+ - Added `AgentExecutionOptionsBase<OUTPUT>` type
17
+ - `getFullOutput()` method now returns `Promise<FullOutput<OUTPUT>>`
18
+ - `Agent` class now generic: `Agent<TAgentId, TTools, TOutput>`
19
+ - `agent.generate()` and `agent.stream()` methods have updated signatures
20
+ - `MastraModelOutput<OUTPUT>` no longer requires `OutputSchema` constraint
21
+ - Network route and streaming APIs updated to use plain OUTPUT generic
22
+
23
+ **Before:**
24
+
25
+ ```typescript
26
+ const output = await agent.generate<z.ZodType>({
27
+ messages: [...],
28
+ structuredOutput: { schema: mySchema }
29
+ });
30
+
31
+ **After:**
32
+ const output = await agent.generate<z.infer<typeof mySchema>>({
33
+ messages: [...],
34
+ structuredOutput: { schema: mySchema }
35
+ });
36
+ // Or rely on type inference:
37
+ const output = await agent.generate({
38
+ messages: [...],
39
+ structuredOutput: { schema: mySchema }
40
+ });
41
+
42
+ ```
43
+
44
+ ### Minor Changes
45
+
46
+ - Add `hideInput` and `hideOutput` options to `TracingOptions` for protecting sensitive data in traces. ([#11969](https://github.com/mastra-ai/mastra/pull/11969))
47
+
48
+ When set to `true`, these options hide input/output data from all spans in a trace, including child spans. This is useful for protecting sensitive information from being logged to observability platforms.
49
+
50
+ ```typescript
51
+ const agent = mastra.getAgent('myAgent');
52
+ await agent.generate('Process this sensitive data', {
53
+ tracingOptions: {
54
+ hideInput: true, // Input will be hidden from all spans
55
+ hideOutput: true, // Output will be hidden from all spans
56
+ },
57
+ });
58
+ ```
59
+
60
+ The options can be used independently (hide only input or only output) or together. The settings are propagated to all child spans via `TraceState`, ensuring consistent behavior across the entire trace.
61
+
62
+ Fixes #10888
63
+
64
+ - Added `TrackingExporter` base class with improved handling for: ([#11870](https://github.com/mastra-ai/mastra/pull/11870))
65
+ - **Out-of-order span processing**: Spans that arrive before their parents are now queued and processed once dependencies are available
66
+ - **Delayed cleanup**: Trace data is retained briefly after spans end to handle late-arriving updates
67
+ - **Memory management**: Configurable limits on pending and total traces to prevent memory leaks
68
+
69
+ New configuration options on `TrackingExporterConfig`:
70
+ - `earlyQueueMaxAttempts` - Max retry attempts for queued events (default: 5)
71
+ - `earlyQueueTTLMs` - TTL for queued events in ms (default: 30000)
72
+ - `traceCleanupDelayMs` - Delay before cleaning up completed traces (default: 30000)
73
+ - `maxPendingCleanupTraces` - Soft cap on traces awaiting cleanup (default: 100)
74
+ - `maxTotalTraces` - Hard cap on total traces (default: 500)
75
+
76
+ Updated @mastra/braintrust, @mastra/langfuse, @mastra/langsmith, @mastra/posthog to use the new TrackingExporter
77
+
78
+ ### Patch Changes
79
+
80
+ - feat(spans): implement entity inheritance for child spans ([#11914](https://github.com/mastra-ai/mastra/pull/11914))
81
+
82
+ Added tests to verify that child spans inherit entityId and entityName from their parent spans when not explicitly provided. Also included functionality to allow child spans to override these inherited values. This ensures proper entity identification across multiple levels of span hierarchy.
83
+
84
+ - Improved tracing by filtering infrastructure chunks from model streams and adding success attribute to tool spans. ([#11943](https://github.com/mastra-ai/mastra/pull/11943))
85
+
86
+ Added generic input/output attribute mapping for additional span types in Arize exporter.
87
+
88
+ - Real-time span export for Inngest workflow engine ([#11973](https://github.com/mastra-ai/mastra/pull/11973))
89
+ - Spans are now exported immediately when created and ended, instead of being batched at workflow completion
90
+ - Added durable span lifecycle hooks (`createStepSpan`, `endStepSpan`, `errorStepSpan`, `createChildSpan`, `endChildSpan`, `errorChildSpan`) that wrap span operations in Inngest's `step.run()` for memoization
91
+ - Added `rebuildSpan()` method to reconstruct span objects from exported data after Inngest replay
92
+ - Fixed nested workflow step spans missing output data
93
+ - Spans correctly maintain parent-child relationships across Inngest's durable execution boundaries using `tracingIds`
94
+
95
+ - Updated dependencies [[`ebae12a`](https://github.com/mastra-ai/mastra/commit/ebae12a2dd0212e75478981053b148a2c246962d), [`c61a0a5`](https://github.com/mastra-ai/mastra/commit/c61a0a5de4904c88fd8b3718bc26d1be1c2ec6e7), [`69136e7`](https://github.com/mastra-ai/mastra/commit/69136e748e32f57297728a4e0f9a75988462f1a7), [`449aed2`](https://github.com/mastra-ai/mastra/commit/449aed2ba9d507b75bf93d427646ea94f734dfd1), [`eb648a2`](https://github.com/mastra-ai/mastra/commit/eb648a2cc1728f7678768dd70cd77619b448dab9), [`0131105`](https://github.com/mastra-ai/mastra/commit/0131105532e83bdcbb73352fc7d0879eebf140dc), [`9d5059e`](https://github.com/mastra-ai/mastra/commit/9d5059eae810829935fb08e81a9bb7ecd5b144a7), [`ef756c6`](https://github.com/mastra-ai/mastra/commit/ef756c65f82d16531c43f49a27290a416611e526), [`b00ccd3`](https://github.com/mastra-ai/mastra/commit/b00ccd325ebd5d9e37e34dd0a105caae67eb568f), [`3bdfa75`](https://github.com/mastra-ai/mastra/commit/3bdfa7507a91db66f176ba8221aa28dd546e464a), [`e770de9`](https://github.com/mastra-ai/mastra/commit/e770de941a287a49b1964d44db5a5763d19890a6), [`52e2716`](https://github.com/mastra-ai/mastra/commit/52e2716b42df6eff443de72360ae83e86ec23993), [`27b4040`](https://github.com/mastra-ai/mastra/commit/27b4040bfa1a95d92546f420a02a626b1419a1d6), [`610a70b`](https://github.com/mastra-ai/mastra/commit/610a70bdad282079f0c630e0d7bb284578f20151), [`8dc7f55`](https://github.com/mastra-ai/mastra/commit/8dc7f55900395771da851dc7d78d53ae84fe34ec), [`8379099`](https://github.com/mastra-ai/mastra/commit/8379099fc467af6bef54dd7f80c9bd75bf8bbddf), [`8c0ec25`](https://github.com/mastra-ai/mastra/commit/8c0ec25646c8a7df253ed1e5ff4863a0d3f1316c), [`ff4d9a6`](https://github.com/mastra-ai/mastra/commit/ff4d9a6704fc87b31a380a76ed22736fdedbba5a), [`69821ef`](https://github.com/mastra-ai/mastra/commit/69821ef806482e2c44e2197ac0b050c3fe3a5285), [`1ed5716`](https://github.com/mastra-ai/mastra/commit/1ed5716830867b3774c4a1b43cc0d82935f32b96), [`4186bdd`](https://github.com/mastra-ai/mastra/commit/4186bdd00731305726fa06adba0b076a1d50b49f), [`7aaf973`](https://github.com/mastra-ai/mastra/commit/7aaf973f83fbbe9521f1f9e7a4fd99b8de464617)]:
96
+ - @mastra/core@1.0.0-beta.22
97
+
3
98
  ## 1.0.0-beta.10
4
99
 
5
100
  ### Minor Changes
package/README.md CHANGED
@@ -1,99 +1,54 @@
1
1
  # Mastra Observability
2
2
 
3
- A comprehensive observability system for AI operations in Mastra, providing type-safe span tracking, event-driven exports, and flexible tracing configuration.
3
+ Tracing and monitoring for AI operations in Mastra.
4
4
 
5
- ## Overview
5
+ ## Installation
6
6
 
7
- The Mastra Observability system enables detailed observability for AI-driven applications by tracking operations through spans that capture metadata, timing, and context. It's designed to work seamlessly with Mastra's architecture while providing flexible configuration and export options.
8
-
9
- ## Key Features
10
-
11
- - **Type-Safe Spans**: Strongly typed metadata based on span type prevents runtime errors
12
- - **Event-Driven Architecture**: Real-time tracing events for immediate observability
13
- - **OpenTelemetry Compatible**: Uses standard trace and span ID formats for integration
14
- - **Flexible Sampling**: Multiple sampling strategies with custom sampler support
15
- - **Pluggable Processors**: Modify or filter span fields before export
16
- - **Pluggable Exporters**: Multiple export formats and destinations
17
- - **Automatic Lifecycle Management**: Spans automatically emit events without manual intervention
18
-
19
- ## Quick Start
20
-
21
- ### Manual Tracing
22
-
23
- ```typescript
24
- import { DefaultObservabilityInstance, SpanType } from '@mastra/observability';
25
-
26
- // Create observability instance
27
- const observability = new DefaultObservabilityInstance({
28
- name: 'my-app',
29
- serviceName: 'my-app',
30
- });
31
-
32
- // Start an agent span
33
- const agentSpan = observability.startSpan({
34
- type: SpanType.AGENT_RUN,
35
- name: 'customer-support-agent',
36
- attributes: {
37
- agentId: 'agent-123',
38
- instructions: 'Help with customer support',
39
- maxSteps: 10,
40
- },
41
- });
42
-
43
- // Create child spans for nested operations
44
- const llmSpan = agentSpan.createChildSpan({
45
- type: SpanType.MODEL_GENERATION,
46
- name: 'gpt-4-response',
47
- attributes: {
48
- model: 'gpt-4',
49
- provider: 'openai',
50
- streaming: false,
51
- },
52
- });
53
-
54
- // End spans with results
55
- llmSpan.end({
56
- output: 'Generated response',
57
- attributes: { usage: { totalTokens: 180 } },
58
- });
59
- agentSpan.end();
7
+ ```bash
8
+ npm install @mastra/observability
60
9
  ```
61
10
 
62
- ### Span Types
63
-
64
- - **`WORKFLOW_RUN`**: Root span for entire workflow execution
65
- - **`WORKFLOW_STEP`**: Individual step execution within a workflow
66
- - **`AGENT_RUN`**: Agent processing (supports tools, memory, multi-step)
67
- - **`MODEL_GENERATION`**: Individual model API calls with token usage
68
- - **`TOOL_CALL`**: Function/tool execution
69
- - **`MCP_TOOL_CALL`**: Model Context Protocol tool execution
70
- - **`PROCESSOR_RUN`**: Input/output processor execution
71
- - **`GENERIC`**: Custom spans for other operations
72
-
73
- ### Basic Configuration
74
-
75
- Enable observability in your Mastra instance:
11
+ ## Quick Start
76
12
 
77
13
  ```typescript
78
14
  import { Mastra } from '@mastra/core';
79
- import { Observability } from '@mastra/observability';
15
+ import { Observability, DefaultExporter, CloudExporter, SensitiveDataFilter } from '@mastra/observability';
80
16
 
81
17
  export const mastra = new Mastra({
82
- // ... other config
83
18
  observability: new Observability({
84
- default: { enabled: true },
19
+ configs: {
20
+ default: {
21
+ serviceName: 'my-app',
22
+ exporters: [
23
+ new DefaultExporter(), // Persists traces for Mastra Studio
24
+ new CloudExporter(), // Sends to Mastra Cloud
25
+ ],
26
+ spanOutputProcessors: [new SensitiveDataFilter()],
27
+ },
28
+ },
85
29
  }),
86
30
  });
87
31
  ```
88
32
 
89
- This enables the `DefaultExporter` and `CloudExporter`, with the `SensitiveDataFilter` span output processor, and `always` sampling.
33
+ ## Features
34
+
35
+ - **Auto-instrumentation** - Traces agent runs, LLM calls, tool executions, and workflows
36
+ - **Pluggable Exporters** - Exporters for Studio and Cloud, plus integrations for Arize, Braintrust, Langfuse, LangSmith, and OpenTelemetry
37
+ - **Sampling Strategies** - Always, ratio-based, or custom sampling
38
+ - **Span Processors** - Transform or filter span data before export
39
+ - **OpenTelemetry Compatible** - Standard trace/span ID formats for integration
90
40
 
91
- ## Performance Considerations
41
+ ## Span Types
92
42
 
93
- ### Current Implementation
43
+ - `WORKFLOW_RUN` - Workflow execution
44
+ - `WORKFLOW_STEP` - Individual workflow step
45
+ - `AGENT_RUN` - Agent processing
46
+ - `MODEL_GENERATION` - LLM API calls
47
+ - `TOOL_CALL` - Tool execution
48
+ - `MCP_TOOL_CALL` - MCP tool execution
49
+ - `PROCESSOR_RUN` - Processor execution
50
+ - `GENERIC` - Custom operations
94
51
 
95
- The current implementation prioritizes correctness and ease of use:
52
+ ## Documentation
96
53
 
97
- - **Automatic Lifecycle Management**: All spans automatically emit events through method wrapping
98
- - **Real-time Export**: Events are exported immediately when they occur
99
- - **Memory Overhead**: Each span maintains references to tracing instance
54
+ For configuration options, exporters, sampling strategies, and more, see the [full documentation](https://mastra.ai/docs/v1/observability/overview).
@@ -49,12 +49,13 @@ export interface BaseExporterConfig {
49
49
  * ```
50
50
  */
51
51
  export declare abstract class BaseExporter implements ObservabilityExporter {
52
+ #private;
52
53
  /** Exporter name - must be implemented by subclasses */
53
54
  abstract name: string;
54
55
  /** Mastra logger instance */
55
56
  protected logger: IMastraLogger;
56
- /** Whether this exporter is disabled */
57
- protected isDisabled: boolean;
57
+ /** Public getter for disabled state */
58
+ get isDisabled(): boolean;
58
59
  /**
59
60
  * Initialize the base exporter with logger
60
61
  */
@@ -1 +1 @@
1
- {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/exporters/base.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAiB,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAE3G;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,sCAAsC;IACtC,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,mFAAmF;IACnF,QAAQ,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;CAC3D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,8BAAsB,YAAa,YAAW,qBAAqB;IACjE,wDAAwD;IACxD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,6BAA6B;IAC7B,SAAS,CAAC,MAAM,EAAE,aAAa,CAAC;IAEhC,wCAAwC;IACxC,SAAS,CAAC,UAAU,EAAE,OAAO,CAAS;IAEtC;;OAEG;gBACS,MAAM,GAAE,kBAAuB;IAO3C;;OAEG;IACH,WAAW,CAAC,MAAM,EAAE,aAAa,GAAG,I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CloudExporterConfig } from './cloud.js';
5
+ export * from './tracking.js';
6
+ export * from './cloud.js';
7
7
  export * from './console.js';
8
8
  export * from './default.js';
9
9
  export * from './test.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/exporters/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,cAAc,QAAQ,CAAC;AAGvB,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,YAAY,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AACnD,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/exporters/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAG3B,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC"}