Skip to content

Commit 4cb096d

Browse files
authored
add docs for serializationOptions (#11500)
## Description Adds documentation for the `serializationOptions` configuration option introduced in PR #11484. This feature allows users to configure how span data (input, output, and attributes) is serialized/truncated before export in Mastra Observability. **Changes:** - Added `serializationOptions` to the `ObservabilityInstanceConfig` interface in the reference docs - Added a new `SerializationOptions` interface section with a PropertiesTable listing all options (`maxStringLength`, `maxDepth`, `maxArrayLength`, `maxObjectKeys`) - Added a "Serialization Options" section to the tracing overview guide with: - Configuration examples - Options table with defaults - Use case examples for debugging (increasing limits) and production (reducing limits) ## Related Issue(s) #11484 ## Type of Change - [ ] 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) - [x] Documentation update - [ ] Code refactoring - [ ] Performance improvement - [ ] Test update ## Checklist - [x] 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 ## Release Notes * **Documentation** * Added comprehensive Serialization Options documentation section detailing span data truncation during export, including configuration parameters and usage examples * Introduced new serializationOptions configuration with four optional parameters (maxStringLength, maxDepth, maxArrayLength, maxObjectKeys) for controlling span data serialization behavior <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 05b8bee commit 4cb096d

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

docs/src/content/en/docs/observability/tracing/overview.mdx

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,67 @@ Processors are executed in the order they're defined, allowing you to chain mult
633633
- Sampling high-volume traces
634634
- Enriching spans with business context
635635

636+
## Serialization Options
637+
638+
Serialization options control how span data (input, output, and attributes) is truncated before export. This is useful when working with large payloads, deeply nested objects, or when you need to optimize trace storage.
639+
640+
### Configuration
641+
642+
Add `serializationOptions` to your observability configuration:
643+
644+
```ts title="src/mastra/index.ts"
645+
export const mastra = new Mastra({
646+
observability: new Observability({
647+
configs: {
648+
default: {
649+
serviceName: "my-service",
650+
serializationOptions: {
651+
maxStringLength: 2048, // Maximum length for string values (default: 1024)
652+
maxDepth: 10, // Maximum depth for nested objects (default: 6)
653+
maxArrayLength: 100, // Maximum number of items in arrays (default: 50)
654+
maxObjectKeys: 75, // Maximum number of keys in objects (default: 50)
655+
},
656+
exporters: [new DefaultExporter()],
657+
},
658+
},
659+
}),
660+
});
661+
```
662+
663+
### Available Options
664+
665+
| Option | Default | Description |
666+
| --- | --- | --- |
667+
| `maxStringLength` | 1024 | Maximum length for string values. Longer strings are truncated. |
668+
| `maxDepth` | 6 | Maximum depth for nested objects. Deeper levels are omitted. |
669+
| `maxArrayLength` | 50 | Maximum number of items in arrays. Additional items are omitted. |
670+
| `maxObjectKeys` | 50 | Maximum number of keys in objects. Additional keys are omitted. |
671+
672+
### Use Cases
673+
674+
**Increasing limits for debugging**: If your agents or tools work with large documents, API responses, or data structures, increase these limits to capture more context in your traces:
675+
676+
```ts
677+
serializationOptions: {
678+
maxStringLength: 8192, // Capture longer text content
679+
maxDepth: 12, // Handle deeply nested JSON responses
680+
maxArrayLength: 200, // Keep more items from large lists
681+
}
682+
```
683+
684+
**Reducing trace size for production**: Lower these values to reduce storage costs and improve performance when you don't need full payload visibility:
685+
686+
```ts
687+
serializationOptions: {
688+
maxStringLength: 256, // Truncate strings aggressively
689+
maxDepth: 3, // Shallow object representation
690+
maxArrayLength: 10, // Keep only first few items
691+
maxObjectKeys: 20, // Limit object keys
692+
}
693+
```
694+
695+
All options are optional — if not specified, they fall back to the defaults shown above.
696+
636697
## Retrieving Trace IDs
637698

638699
When you execute agents or workflows with tracing enabled, the response includes a `traceId` that you can use to look up the full trace in your observability platform. This is useful for debugging, customer support, or correlating traces with other events in your system.

docs/src/content/en/reference/observability/tracing/configuration.mdx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ interface ObservabilityInstanceConfig {
5151
spanOutputProcessors?: SpanOutputProcessor[];
5252
includeInternalSpans?: boolean;
5353
requestContextKeys?: string[];
54+
serializationOptions?: SerializationOptions;
5455
}
5556
```
5657

@@ -98,6 +99,54 @@ interface ObservabilityInstanceConfig {
9899
description: "RequestContext keys to extract as metadata (supports dot notation)",
99100
required: false,
100101
},
102+
{
103+
name: "serializationOptions",
104+
type: "SerializationOptions",
105+
description: "Options for controlling serialization of span data (input/output/attributes)",
106+
required: false,
107+
},
108+
]}
109+
/>
110+
111+
## SerializationOptions
112+
113+
Options for controlling how span data is serialized before export. Use these to customize truncation limits for large payloads.
114+
115+
```typescript
116+
interface SerializationOptions {
117+
maxStringLength?: number;
118+
maxDepth?: number;
119+
maxArrayLength?: number;
120+
maxObjectKeys?: number;
121+
}
122+
```
123+
124+
<PropertiesTable
125+
props={[
126+
{
127+
name: "maxStringLength",
128+
type: "number",
129+
description: "Maximum length for string values (default: 1024)",
130+
required: false,
131+
},
132+
{
133+
name: "maxDepth",
134+
type: "number",
135+
description: "Maximum depth for nested objects (default: 6)",
136+
required: false,
137+
},
138+
{
139+
name: "maxArrayLength",
140+
type: "number",
141+
description: "Maximum number of items in arrays (default: 50)",
142+
required: false,
143+
},
144+
{
145+
name: "maxObjectKeys",
146+
type: "number",
147+
description: "Maximum number of keys in objects (default: 50)",
148+
required: false,
149+
},
101150
]}
102151
/>
103152

0 commit comments

Comments
 (0)