ConsoleExporter
Outputs trace events to the console for debugging and development.
ConstructorConstructor的直接链接
new ConsoleExporter(config?: BaseExporterConfig)
config?:
BaseExporterConfig
Configuration options
BaseExporterConfig
logger?:
IMastraLogger
Logger instance (falls back to ConsoleLogger with INFO level)
logLevel?:
LogLevel | 'debug' | 'info' | 'warn' | 'error'
Log level for the exporter (default: INFO)
PropertiesProperties的直接链接
readonly name = 'tracing-console-exporter';
MethodsMethods的直接链接
exportTracingEventexporttracingevent的直接链接
async exportTracingEvent(event: TracingEvent): Promise<void>
Exports a tracing event to the console.
shutdownshutdown的直接链接
async shutdown(): Promise<void>
Logs shutdown message.
Output formatOutput format的直接链接
The exporter outputs different formats based on event type:
SPAN_STARTEDSPAN_STARTED的直接链接
🚀 SPAN_STARTED
Type: [span type]
Name: [span name]
ID: [span id]
Trace ID: [trace id]
Input: [formatted input]
Attributes: [formatted attributes]
────────────────────────────────────────
SPAN_ENDEDSPAN_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_UPDATEDSPAN_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]
────────────────────────────────────────
UsageUsage的直接链接
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 detailsImplementation 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 alsoSee also的直接链接
DocumentationDocumentation的直接链接
- Tracing Overview: Complete guide
Other ExportersOther Exporters的直接链接
- MastraStorageExporter: Storage persistence
- MastraPlatformExporter: Mastra platform
- Langfuse: Langfuse integration
- Braintrust: Braintrust integration
ReferenceReference的直接链接
- Configuration: Configuration options
- Interfaces: Type definitions