Skip to main content

ConsoleExporter

Outputs trace events to the console for debugging and development.

Constructor
Direct link to Constructor

new ConsoleExporter(config?: BaseExporterConfig)

BaseExporterConfig
Direct link to BaseExporterConfig

interface BaseExporterConfig {
logger?: IMastraLogger;
logLevel?: LogLevel | 'debug' | 'info' | 'warn' | 'error';
}

Properties
Direct link to Properties

readonly name = 'tracing-console-exporter';

Methods
Direct link to Methods

exportTracingEvent
Direct link to exportTracingEvent

async exportTracingEvent(event: TracingEvent): Promise<void>

Exports a tracing event to the console.

shutdown
Direct link to shutdown

async shutdown(): Promise<void>

Logs shutdown message.

Output Format
Direct link to Output Format

The exporter outputs different formats based on event type:

SPAN_STARTED
Direct link to SPAN_STARTED

🚀 SPAN_STARTED
Type: [span type]
Name: [span name]
ID: [span id]
Trace ID: [trace id]
Input: [formatted input]
Attributes: [formatted attributes]
────────────────────────────────────────

SPAN_ENDED
Direct link to SPAN_ENDED

✅ 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
Direct link to SPAN_UPDATED

📝 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
Direct link to Usage

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
Direct link to 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
Direct link to See Also

Documentation
Direct link to Documentation

Other Exporters
Direct link to Other Exporters

Reference
Direct link to Reference