UNPKG

@mastra/core

Version:

Mastra is a framework for building AI-powered applications and agents with a modern TypeScript stack.

135 lines (98 loc) • 3.66 kB
# ConsoleExporter Outputs trace events to the console for debugging and development. ## Constructor ```typescript new ConsoleExporter(config?: BaseExporterConfig) ``` **config** (`BaseExporterConfig`): Configuration options **config.logger** (`IMastraLogger`): Logger instance (falls back to ConsoleLogger with INFO level) **config.logLevel** (`LogLevel | 'debug' | 'info' | 'warn' | 'error'`): Log level for the exporter (default: INFO) ## Properties ```typescript readonly name = 'tracing-console-exporter'; ``` ## Methods ### `exportTracingEvent` ```typescript async exportTracingEvent(event: TracingEvent): Promise<void> ``` Exports a tracing event to the console. ### shutdown ```typescript async shutdown(): Promise<void> ``` Logs shutdown message. ## Output format The exporter outputs different formats based on event type: ### SPAN\_STARTED ```text šŸš€ SPAN_STARTED Type: [span type] Name: [span name] ID: [span id] Trace ID: [trace id] Input: [formatted input] Attributes: [formatted attributes] ──────────────────────────────────────── ``` ### SPAN\_ENDED ```text āœ… SPAN_ENDED Type: [span type] Name: [span name] ID: [span id] Duration: [duration]ms Trace ID: [trace id] Input: [formatted input] Output: [formatted output] Error: [formatted error if present] Attributes: [formatted attributes] ──────────────────────────────────────── ``` ### SPAN\_UPDATED ```text šŸ“ SPAN_UPDATED Type: [span type] Name: [span name] ID: [span id] Trace ID: [trace id] Input: [formatted input] Output: [formatted output] Error: [formatted error if present] Updated Attributes: [formatted attributes] ──────────────────────────────────────── ``` ## Usage ```typescript import { ConsoleExporter } from '@mastra/observability' import { ConsoleLogger, LogLevel } from '@mastra/core/logger' // Use default logger (INFO level) const exporter = new ConsoleExporter() // Use custom log level const exporter = new ConsoleExporter({ logLevel: 'debug', }) // Use custom logger instance const customLogger = new ConsoleLogger({ level: LogLevel.DEBUG }) const exporterWithLogger = new ConsoleExporter({ logger: customLogger, }) ``` ## Implementation details - Formats attributes as JSON with 2-space indentation - Calculates and displays span duration in milliseconds - Handles serialization errors gracefully - Logs unimplemented event types as warnings - Uses 80-character separator lines between events ## See also ### Documentation - [Tracing Overview](https://mastra.ai/docs/observability/tracing/overview): Complete guide - [Exporters](https://mastra.ai/docs/observability/tracing/overview): Exporter concepts ### Other Exporters - [MastraStorageExporter](https://mastra.ai/reference/observability/tracing/exporters/mastra-storage-exporter): Storage persistence - [MastraPlatformExporter](https://mastra.ai/reference/observability/tracing/exporters/mastra-platform-exporter): Mastra platform - [Langfuse](https://mastra.ai/reference/observability/tracing/exporters/langfuse): Langfuse integration - [Braintrust](https://mastra.ai/reference/observability/tracing/exporters/braintrust): Braintrust integration ### Reference - [Configuration](https://mastra.ai/reference/observability/tracing/configuration): Configuration options - [Interfaces](https://mastra.ai/reference/observability/tracing/interfaces): Type definitions