ConsoleExporter
将 Trace 事件输出到控制台,用于调试和开发。
构造函数构造函数的直接链接
new ConsoleExporter(config?: BaseExporterConfig)
config?:
BaseExporterConfig
配置选项
BaseExporterConfig
logger?:
IMastraLogger
Logger 实例(未设置时使用 INFO 级别的 ConsoleLogger)
logLevel?:
LogLevel | 'debug' | 'info' | 'warn' | 'error'
Exporter 的日志级别(默认值:INFO)
属性属性的直接链接
readonly name = 'tracing-console-exporter';
方法方法的直接链接
exportTracingEventexporttracingevent的直接链接
async exportTracingEvent(event: TracingEvent): Promise<void>
将 Tracing 事件导出到控制台。
shutdownshutdown的直接链接
async shutdown(): Promise<void>
记录关闭消息。
输出格式输出格式的直接链接
Exporter 会根据事件类型输出不同格式:
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]
────────────────────────────────────────
用法用法的直接链接
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,
})
实现细节实现细节的直接链接
- 以 2 个空格缩进的 JSON 格式输出属性
- 计算并显示 Span 持续时间(毫秒)
- 妥善处理序列化错误
- 将未实现的事件类型记录为警告
- 在事件之间使用 80 个字符宽的分隔线
另请参阅另请参阅的直接链接
文档文档的直接链接
- Tracing 概览:完整指南
- Exporter:Exporter 概念
其他 Exporter其他 Exporter的直接链接
- MastraStorageExporter:存储持久化
- MastraPlatformExporter:Mastra 平台
- Langfuse:Langfuse 集成
- Braintrust:Braintrust 集成