@mastra/observability 1.0.0 → 1.1.0-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/CHANGELOG.md +27 -0
- package/dist/exporters/index.d.ts +1 -0
- package/dist/exporters/index.d.ts.map +1 -1
- package/dist/exporters/json.d.ts +386 -0
- package/dist/exporters/json.d.ts.map +1 -0
- package/dist/index.cjs +953 -91
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +952 -92
- package/dist/index.js.map +1 -1
- package/dist/model-tracing.d.ts +6 -0
- package/dist/model-tracing.d.ts.map +1 -1
- package/dist/spans/base.d.ts +2 -0
- package/dist/spans/base.d.ts.map +1 -1
- package/dist/spans/serialization.d.ts +20 -0
- package/dist/spans/serialization.d.ts.map +1 -1
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @mastra/observability
|
|
2
2
|
|
|
3
|
+
## 1.1.0-alpha.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Requires @mastra/core 1.0.5 or later. If upgrading, ensure your @mastra/core package is also updated. ([#12370](https://github.com/mastra-ai/mastra/pull/12370))
|
|
8
|
+
|
|
9
|
+
- Add tool approval tracing to spans for debugging ([#12171](https://github.com/mastra-ai/mastra/pull/12171))
|
|
10
|
+
|
|
11
|
+
Added the ability to see tool approval requests in traces for debugging purposes. When a tool requires approval, a `MODEL_CHUNK` span named `chunk: 'tool-call-approval'` is now created containing:
|
|
12
|
+
- The tool call ID and name for identification
|
|
13
|
+
- The arguments that need approval
|
|
14
|
+
- The resume schema defining the approval response format
|
|
15
|
+
|
|
16
|
+
This enables users to debug their system by seeing approval requests in traces, making it easier to understand the flow of tool approvals and their payloads.
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- Fixed tracingOptions.tags not being preserved when merging defaultOptions with call-site options. Tags set in agent's defaultOptions.tracingOptions are now correctly passed to all observability exporters (Langfuse, Langsmith, Braintrust, Datadog, etc.). Fixes #12209. ([#12220](https://github.com/mastra-ai/mastra/pull/12220))
|
|
21
|
+
|
|
22
|
+
- Tracing fixes: ([#12370](https://github.com/mastra-ai/mastra/pull/12370))
|
|
23
|
+
- Spans now inherit entityType/entityId from the closest non-internal parent (#12250)
|
|
24
|
+
- Processor spans correctly track separate input and output data
|
|
25
|
+
- Model chunk spans are now emitted for all streaming chunks
|
|
26
|
+
- Internal framework spans no longer appear in exported traces
|
|
27
|
+
- Updated dependencies [[`90fc0e5`](https://github.com/mastra-ai/mastra/commit/90fc0e5717cb280c2d4acf4f0410b510bb4c0a72), [`1cf5d2e`](https://github.com/mastra-ai/mastra/commit/1cf5d2ea1b085be23e34fb506c80c80a4e6d9c2b), [`833ae96`](https://github.com/mastra-ai/mastra/commit/833ae96c3e34370e58a1e979571c41f39a720592), [`943772b`](https://github.com/mastra-ai/mastra/commit/943772b4378f625f0f4e19ea2b7c392bd8e71786), [`b5c711b`](https://github.com/mastra-ai/mastra/commit/b5c711b281dd1fb81a399a766bc9f86c55efc13e), [`3efbe5a`](https://github.com/mastra-ai/mastra/commit/3efbe5ae20864c4f3143457f4f3ee7dc2fa5ca76), [`1e49e7a`](https://github.com/mastra-ai/mastra/commit/1e49e7ab5f173582154cb26b29d424de67d09aef), [`751eaab`](https://github.com/mastra-ai/mastra/commit/751eaab4e0d3820a94e4c3d39a2ff2663ded3d91), [`69d8156`](https://github.com/mastra-ai/mastra/commit/69d81568bcf062557c24471ce26812446bec465d), [`60d9d89`](https://github.com/mastra-ai/mastra/commit/60d9d899e44b35bc43f1bcd967a74e0ce010b1af), [`5c544c8`](https://github.com/mastra-ai/mastra/commit/5c544c8d12b08ab40d64d8f37b3c4215bee95b87), [`771ad96`](https://github.com/mastra-ai/mastra/commit/771ad962441996b5c43549391a3e6a02c6ddedc2), [`2b0936b`](https://github.com/mastra-ai/mastra/commit/2b0936b0c9a43eeed9bef63e614d7e02ee803f7e), [`3b04f30`](https://github.com/mastra-ai/mastra/commit/3b04f3010604f3cdfc8a0674731700ad66471cee), [`97e26de`](https://github.com/mastra-ai/mastra/commit/97e26deaebd9836647a67b96423281d66421ca07), [`10523f4`](https://github.com/mastra-ai/mastra/commit/10523f4882d9b874b40ce6e3715f66dbcd4947d2), [`cb72d20`](https://github.com/mastra-ai/mastra/commit/cb72d2069d7339bda8a0e76d4f35615debb07b84), [`42856b1`](https://github.com/mastra-ai/mastra/commit/42856b1c8aeea6371c9ee77ae2f5f5fe34400933), [`66f33ff`](https://github.com/mastra-ai/mastra/commit/66f33ff68620018513e499c394411d1d39b3aa5c), [`ab3c190`](https://github.com/mastra-ai/mastra/commit/ab3c1901980a99910ca9b96a7090c22e24060113), [`d4f06c8`](https://github.com/mastra-ai/mastra/commit/d4f06c85ffa5bb0da38fb82ebf3b040cc6b4ec4e), [`0350626`](https://github.com/mastra-ai/mastra/commit/03506267ec41b67add80d994c0c0fcce93bbc75f), [`bc9fa00`](https://github.com/mastra-ai/mastra/commit/bc9fa00859c5c4a796d53a0a5cae46ab4a3072e4), [`f46a478`](https://github.com/mastra-ai/mastra/commit/f46a4782f595949c696569e891f81c8d26338508), [`90fc0e5`](https://github.com/mastra-ai/mastra/commit/90fc0e5717cb280c2d4acf4f0410b510bb4c0a72), [`f05a3a5`](https://github.com/mastra-ai/mastra/commit/f05a3a5cf2b9a9c2d40c09cb8c762a4b6cd5d565), [`a291da9`](https://github.com/mastra-ai/mastra/commit/a291da9363efd92dafd8775dccb4f2d0511ece7a), [`c5d71da`](https://github.com/mastra-ai/mastra/commit/c5d71da1c680ce5640b1a7f8ca0e024a4ab1cfed), [`07042f9`](https://github.com/mastra-ai/mastra/commit/07042f9f89080f38b8f72713ba1c972d5b1905b8), [`0423442`](https://github.com/mastra-ai/mastra/commit/0423442b7be2dfacba95890bea8f4a810db4d603)]:
|
|
28
|
+
- @mastra/core@1.1.0-alpha.0
|
|
29
|
+
|
|
3
30
|
## 1.0.0
|
|
4
31
|
|
|
5
32
|
### Major Changes
|
|
@@ -1 +1 @@
|
|
|
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,mBAAmB,CAAC;AAGlC,cAAc,SAAS,CAAC;AACxB,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,mBAAmB,CAAC;AAGlC,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Exporter for Observability Testing
|
|
3
|
+
*
|
|
4
|
+
* A full-featured exporter primarily designed for testing purposes that provides:
|
|
5
|
+
* - In-memory event collection with JSON serialization
|
|
6
|
+
* - File output support
|
|
7
|
+
* - Span lifecycle tracking and validation
|
|
8
|
+
* - Query methods for filtering spans by type, trace ID, span ID, etc.
|
|
9
|
+
* - Statistics and analytics on collected spans
|
|
10
|
+
*/
|
|
11
|
+
import type { TracingEvent, TracingEventType, AnyExportedSpan, ExportedSpan, SpanType } from '@mastra/core/observability';
|
|
12
|
+
import { BaseExporter } from './base.js';
|
|
13
|
+
import type { BaseExporterConfig } from './base.js';
|
|
14
|
+
/**
|
|
15
|
+
* Span state tracking for lifecycle validation
|
|
16
|
+
*/
|
|
17
|
+
interface SpanState {
|
|
18
|
+
/** Whether SPAN_STARTED was received */
|
|
19
|
+
hasStart: boolean;
|
|
20
|
+
/** Whether SPAN_ENDED was received */
|
|
21
|
+
hasEnd: boolean;
|
|
22
|
+
/** Whether SPAN_UPDATED was received */
|
|
23
|
+
hasUpdate: boolean;
|
|
24
|
+
/** All events for this span in order */
|
|
25
|
+
events: TracingEvent[];
|
|
26
|
+
/** Whether this is an event span (zero duration) */
|
|
27
|
+
isEventSpan?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Statistics about collected spans
|
|
31
|
+
*/
|
|
32
|
+
export interface JsonExporterStats {
|
|
33
|
+
/** Total number of events collected */
|
|
34
|
+
totalEvents: number;
|
|
35
|
+
/** Number of unique spans */
|
|
36
|
+
totalSpans: number;
|
|
37
|
+
/** Number of unique traces */
|
|
38
|
+
totalTraces: number;
|
|
39
|
+
/** Number of completed spans */
|
|
40
|
+
completedSpans: number;
|
|
41
|
+
/** Number of incomplete spans (started but not ended) */
|
|
42
|
+
incompleteSpans: number;
|
|
43
|
+
/** Breakdown by event type */
|
|
44
|
+
byEventType: {
|
|
45
|
+
started: number;
|
|
46
|
+
updated: number;
|
|
47
|
+
ended: number;
|
|
48
|
+
};
|
|
49
|
+
/** Breakdown by span type */
|
|
50
|
+
bySpanType: Record<string, number>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Span node in a tree structure with nested children
|
|
54
|
+
*/
|
|
55
|
+
export interface SpanTreeNode {
|
|
56
|
+
/** The span data */
|
|
57
|
+
span: AnyExportedSpan;
|
|
58
|
+
/** Child spans nested under this span */
|
|
59
|
+
children: SpanTreeNode[];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Normalized span data for snapshot testing.
|
|
63
|
+
* Dynamic fields (IDs, timestamps) are replaced with stable values.
|
|
64
|
+
*/
|
|
65
|
+
export interface NormalizedSpan {
|
|
66
|
+
/** Stable ID like <span-1>, <span-2> */
|
|
67
|
+
id: string;
|
|
68
|
+
/** Normalized trace ID like <trace-1>, <trace-2> */
|
|
69
|
+
traceId: string;
|
|
70
|
+
/** Normalized parent ID, or undefined for root */
|
|
71
|
+
parentId?: string;
|
|
72
|
+
/** Span name */
|
|
73
|
+
name: string;
|
|
74
|
+
/** Span type */
|
|
75
|
+
type: string;
|
|
76
|
+
/** Entity type */
|
|
77
|
+
entityType?: string;
|
|
78
|
+
/** Entity ID */
|
|
79
|
+
entityId?: string;
|
|
80
|
+
/** Whether the span completed (had an endTime) */
|
|
81
|
+
completed: boolean;
|
|
82
|
+
/** Span attributes */
|
|
83
|
+
attributes?: Record<string, unknown>;
|
|
84
|
+
/** Span metadata */
|
|
85
|
+
metadata?: Record<string, unknown>;
|
|
86
|
+
/** Input data */
|
|
87
|
+
input?: unknown;
|
|
88
|
+
/** Output data */
|
|
89
|
+
output?: unknown;
|
|
90
|
+
/** Error info if span failed */
|
|
91
|
+
errorInfo?: unknown;
|
|
92
|
+
/** Is an event span */
|
|
93
|
+
isEvent: boolean;
|
|
94
|
+
/** Is root span */
|
|
95
|
+
isRootSpan: boolean;
|
|
96
|
+
/** Tags */
|
|
97
|
+
tags?: string[];
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Normalized tree node for snapshot testing
|
|
101
|
+
*/
|
|
102
|
+
export interface NormalizedTreeNode {
|
|
103
|
+
/** Normalized span data */
|
|
104
|
+
span: NormalizedSpan;
|
|
105
|
+
/** Child nodes (omitted if empty) */
|
|
106
|
+
children?: NormalizedTreeNode[];
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Incomplete span information for debugging
|
|
110
|
+
*/
|
|
111
|
+
export interface IncompleteSpanInfo {
|
|
112
|
+
spanId: string;
|
|
113
|
+
span: AnyExportedSpan | undefined;
|
|
114
|
+
state: {
|
|
115
|
+
hasStart: boolean;
|
|
116
|
+
hasUpdate: boolean;
|
|
117
|
+
hasEnd: boolean;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Configuration for JsonExporter
|
|
122
|
+
*/
|
|
123
|
+
export interface JsonExporterConfig extends BaseExporterConfig {
|
|
124
|
+
/**
|
|
125
|
+
* Whether to validate span lifecycles in real-time.
|
|
126
|
+
* When true, will log warnings for lifecycle violations.
|
|
127
|
+
* @default true
|
|
128
|
+
*/
|
|
129
|
+
validateLifecycle?: boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Whether to store verbose logs for debugging.
|
|
132
|
+
* @default true
|
|
133
|
+
*/
|
|
134
|
+
storeLogs?: boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Indentation for JSON output (number of spaces, or undefined for compact).
|
|
137
|
+
* @default 2
|
|
138
|
+
*/
|
|
139
|
+
jsonIndent?: number;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* JSON Exporter for testing and debugging observability.
|
|
143
|
+
*
|
|
144
|
+
* Provides comprehensive span collection, querying, and JSON output capabilities
|
|
145
|
+
* designed primarily for testing purposes but useful for debugging as well.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* const exporter = new JsonExporter();
|
|
150
|
+
*
|
|
151
|
+
* // Use with Mastra
|
|
152
|
+
* const mastra = new Mastra({
|
|
153
|
+
* observability: {
|
|
154
|
+
* configs: {
|
|
155
|
+
* test: {
|
|
156
|
+
* serviceName: 'test',
|
|
157
|
+
* exporters: [exporter],
|
|
158
|
+
* },
|
|
159
|
+
* },
|
|
160
|
+
* },
|
|
161
|
+
* });
|
|
162
|
+
*
|
|
163
|
+
* // Run some operations...
|
|
164
|
+
*
|
|
165
|
+
* // Query spans
|
|
166
|
+
* const agentSpans = exporter.getSpansByType('agent_run');
|
|
167
|
+
* const traceSpans = exporter.getByTraceId('abc123');
|
|
168
|
+
*
|
|
169
|
+
* // Get statistics
|
|
170
|
+
* const stats = exporter.getStatistics();
|
|
171
|
+
*
|
|
172
|
+
* // Export to JSON
|
|
173
|
+
* await exporter.writeToFile('./traces.json');
|
|
174
|
+
* const jsonString = exporter.toJSON();
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
export declare class JsonExporter extends BaseExporter {
|
|
178
|
+
#private;
|
|
179
|
+
name: string;
|
|
180
|
+
constructor(config?: JsonExporterConfig);
|
|
181
|
+
/**
|
|
182
|
+
* Process incoming tracing events with lifecycle tracking
|
|
183
|
+
*/
|
|
184
|
+
protected _exportTracingEvent(event: TracingEvent): Promise<void>;
|
|
185
|
+
/**
|
|
186
|
+
* Get all collected events
|
|
187
|
+
*/
|
|
188
|
+
get events(): TracingEvent[];
|
|
189
|
+
/**
|
|
190
|
+
* Get completed spans by SpanType (e.g., 'agent_run', 'tool_call')
|
|
191
|
+
*
|
|
192
|
+
* @param type - The SpanType to filter by
|
|
193
|
+
* @returns Array of completed exported spans of the specified type
|
|
194
|
+
*/
|
|
195
|
+
getSpansByType<T extends SpanType>(type: T): ExportedSpan<T>[];
|
|
196
|
+
/**
|
|
197
|
+
* Get events by TracingEventType (SPAN_STARTED, SPAN_UPDATED, SPAN_ENDED)
|
|
198
|
+
*
|
|
199
|
+
* @param type - The TracingEventType to filter by
|
|
200
|
+
* @returns Array of events of the specified type
|
|
201
|
+
*/
|
|
202
|
+
getByEventType(type: TracingEventType): TracingEvent[];
|
|
203
|
+
/**
|
|
204
|
+
* Get all events and spans for a specific trace
|
|
205
|
+
*
|
|
206
|
+
* @param traceId - The trace ID to filter by
|
|
207
|
+
* @returns Object containing events and final spans for the trace
|
|
208
|
+
*/
|
|
209
|
+
getByTraceId(traceId: string): {
|
|
210
|
+
events: TracingEvent[];
|
|
211
|
+
spans: AnyExportedSpan[];
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* Get all events for a specific span
|
|
215
|
+
*
|
|
216
|
+
* @param spanId - The span ID to filter by
|
|
217
|
+
* @returns Object containing events and final span state
|
|
218
|
+
*/
|
|
219
|
+
getBySpanId(spanId: string): {
|
|
220
|
+
events: TracingEvent[];
|
|
221
|
+
span: AnyExportedSpan | undefined;
|
|
222
|
+
state: SpanState | undefined;
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* Get all unique spans (returns the final state of each span)
|
|
226
|
+
*/
|
|
227
|
+
getAllSpans(): AnyExportedSpan[];
|
|
228
|
+
/**
|
|
229
|
+
* Get only completed spans (those that have received SPAN_ENDED)
|
|
230
|
+
*/
|
|
231
|
+
getCompletedSpans(): AnyExportedSpan[];
|
|
232
|
+
/**
|
|
233
|
+
* Get root spans only (spans with no parent)
|
|
234
|
+
*/
|
|
235
|
+
getRootSpans(): AnyExportedSpan[];
|
|
236
|
+
/**
|
|
237
|
+
* Get incomplete spans (started but not yet ended)
|
|
238
|
+
*/
|
|
239
|
+
getIncompleteSpans(): IncompleteSpanInfo[];
|
|
240
|
+
/**
|
|
241
|
+
* Get unique trace IDs from all collected spans
|
|
242
|
+
*/
|
|
243
|
+
getTraceIds(): string[];
|
|
244
|
+
/**
|
|
245
|
+
* Get comprehensive statistics about collected spans
|
|
246
|
+
*/
|
|
247
|
+
getStatistics(): JsonExporterStats;
|
|
248
|
+
/**
|
|
249
|
+
* Serialize all collected data to JSON string
|
|
250
|
+
*
|
|
251
|
+
* @param options - Serialization options
|
|
252
|
+
* @returns JSON string of all collected data
|
|
253
|
+
*/
|
|
254
|
+
toJSON(options?: {
|
|
255
|
+
indent?: number;
|
|
256
|
+
includeEvents?: boolean;
|
|
257
|
+
includeStats?: boolean;
|
|
258
|
+
}): string;
|
|
259
|
+
/**
|
|
260
|
+
* Build a tree structure from spans, nesting children under their parents
|
|
261
|
+
*
|
|
262
|
+
* @returns Array of root span tree nodes (spans with no parent)
|
|
263
|
+
*/
|
|
264
|
+
buildSpanTree(): SpanTreeNode[];
|
|
265
|
+
/**
|
|
266
|
+
* Serialize spans as a tree structure to JSON string
|
|
267
|
+
*
|
|
268
|
+
* @param options - Serialization options
|
|
269
|
+
* @returns JSON string with spans nested in tree format
|
|
270
|
+
*/
|
|
271
|
+
toTreeJSON(options?: {
|
|
272
|
+
indent?: number;
|
|
273
|
+
includeStats?: boolean;
|
|
274
|
+
}): string;
|
|
275
|
+
/**
|
|
276
|
+
* Build a normalized tree structure suitable for snapshot testing.
|
|
277
|
+
*
|
|
278
|
+
* Normalizations applied:
|
|
279
|
+
* - Span IDs replaced with stable placeholders (<span-1>, <span-2>, etc.)
|
|
280
|
+
* - Trace IDs replaced with stable placeholders (<trace-1>, <trace-2>, etc.)
|
|
281
|
+
* - parentSpanId replaced with normalized parent ID
|
|
282
|
+
* - Timestamps replaced with durationMs (or null if not ended)
|
|
283
|
+
* - Empty children arrays are omitted
|
|
284
|
+
*
|
|
285
|
+
* @returns Array of normalized root tree nodes
|
|
286
|
+
*/
|
|
287
|
+
buildNormalizedTree(): NormalizedTreeNode[];
|
|
288
|
+
/**
|
|
289
|
+
* Generate an ASCII tree structure graph for debugging.
|
|
290
|
+
* Shows span type and name in a hierarchical format.
|
|
291
|
+
*
|
|
292
|
+
* @param nodes - Normalized tree nodes (defaults to current normalized tree)
|
|
293
|
+
* @returns Array of strings representing the tree structure
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```
|
|
297
|
+
* agent_run: "agent run: 'test-agent'"
|
|
298
|
+
* ├── processor_run: "input processor: validator"
|
|
299
|
+
* │ └── agent_run: "agent run: 'validator-agent'"
|
|
300
|
+
* └── model_generation: "llm: 'mock-model-id'"
|
|
301
|
+
* ```
|
|
302
|
+
*/
|
|
303
|
+
generateStructureGraph(nodes?: NormalizedTreeNode[]): string[];
|
|
304
|
+
/**
|
|
305
|
+
* Serialize spans as a normalized tree structure for snapshot testing.
|
|
306
|
+
* Includes a __structure__ field with an ASCII tree graph for readability.
|
|
307
|
+
*
|
|
308
|
+
* @param options - Serialization options
|
|
309
|
+
* @returns JSON string with normalized spans in tree format
|
|
310
|
+
*/
|
|
311
|
+
toNormalizedTreeJSON(options?: {
|
|
312
|
+
indent?: number;
|
|
313
|
+
includeStructure?: boolean;
|
|
314
|
+
}): string;
|
|
315
|
+
/**
|
|
316
|
+
* Write collected data to a JSON file
|
|
317
|
+
*
|
|
318
|
+
* @param filePath - Path to write the JSON file
|
|
319
|
+
* @param options - Serialization options
|
|
320
|
+
*/
|
|
321
|
+
writeToFile(filePath: string, options?: {
|
|
322
|
+
indent?: number;
|
|
323
|
+
includeEvents?: boolean;
|
|
324
|
+
includeStats?: boolean;
|
|
325
|
+
format?: 'flat' | 'tree' | 'normalized';
|
|
326
|
+
}): Promise<void>;
|
|
327
|
+
/**
|
|
328
|
+
* Assert that the current normalized tree matches a snapshot file.
|
|
329
|
+
* Throws an error with a diff if they don't match.
|
|
330
|
+
*
|
|
331
|
+
* The snapshot format includes:
|
|
332
|
+
* - `__structure__`: ASCII tree graph (compared first for quick validation)
|
|
333
|
+
* - `spans`: The normalized span tree (detailed comparison)
|
|
334
|
+
*
|
|
335
|
+
* Supports special markers in the snapshot:
|
|
336
|
+
* - `{"__or__": ["value1", "value2"]}` - matches if actual equals any listed value
|
|
337
|
+
* - `{"__any__": "string"}` - matches any string value
|
|
338
|
+
* - `{"__any__": "number"}` - matches any number value
|
|
339
|
+
* - `{"__any__": "boolean"}` - matches any boolean value
|
|
340
|
+
* - `{"__any__": "object"}` - matches any object value
|
|
341
|
+
* - `{"__any__": "array"}` - matches any array value
|
|
342
|
+
* - `{"__any__": true}` - matches any non-null/undefined value
|
|
343
|
+
*
|
|
344
|
+
* Environment variables:
|
|
345
|
+
* Use `{ updateSnapshot: true }` option to update the snapshot instead of comparing
|
|
346
|
+
*
|
|
347
|
+
* @param snapshotName - Name of the snapshot file (resolved relative to __snapshots__ directory)
|
|
348
|
+
* @param options - Options for snapshot comparison
|
|
349
|
+
* @param options.updateSnapshot - If true, update the snapshot file instead of comparing
|
|
350
|
+
* @throws Error if the snapshot doesn't match (and updateSnapshot is false)
|
|
351
|
+
*/
|
|
352
|
+
assertMatchesSnapshot(snapshotName: string, options?: {
|
|
353
|
+
updateSnapshot?: boolean;
|
|
354
|
+
}): Promise<void>;
|
|
355
|
+
/**
|
|
356
|
+
* Get all stored logs
|
|
357
|
+
*/
|
|
358
|
+
getLogs(): string[];
|
|
359
|
+
/**
|
|
360
|
+
* Dump logs to console for debugging (uses console.error for visibility in test output)
|
|
361
|
+
*/
|
|
362
|
+
dumpLogs(): void;
|
|
363
|
+
/**
|
|
364
|
+
* Validate final state - useful for test assertions
|
|
365
|
+
*
|
|
366
|
+
* @returns Object with validation results
|
|
367
|
+
*/
|
|
368
|
+
validateFinalState(): {
|
|
369
|
+
valid: boolean;
|
|
370
|
+
singleTraceId: boolean;
|
|
371
|
+
allSpansComplete: boolean;
|
|
372
|
+
traceIds: string[];
|
|
373
|
+
incompleteSpans: IncompleteSpanInfo[];
|
|
374
|
+
};
|
|
375
|
+
/**
|
|
376
|
+
* Clear all collected events and state
|
|
377
|
+
*/
|
|
378
|
+
clearEvents(): void;
|
|
379
|
+
/**
|
|
380
|
+
* Alias for clearEvents (compatibility with TestExporter)
|
|
381
|
+
*/
|
|
382
|
+
reset(): void;
|
|
383
|
+
shutdown(): Promise<void>;
|
|
384
|
+
}
|
|
385
|
+
export {};
|
|
386
|
+
//# sourceMappingURL=json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/exporters/json.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAUH,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,QAAQ,EACT,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAEjD;;GAEG;AACH,UAAU,SAAS;IACjB,wCAAwC;IACxC,QAAQ,EAAE,OAAO,CAAC;IAClB,sCAAsC;IACtC,MAAM,EAAE,OAAO,CAAC;IAChB,wCAAwC;IACxC,SAAS,EAAE,OAAO,CAAC;IACnB,wCAAwC;IACxC,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,oDAAoD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