Skip to main content

ConsoleExporter

将跟踪事件输出到控制台以进行调试和开发。

🌐 Outputs trace events to the console for debugging and development.

构造函数
Direct link to 构造函数

🌐 Constructor

new ConsoleExporter(config?: BaseExporterConfig)

BaseExporterConfig
Direct link to BaseExporterConfig

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

属性
Direct link to 属性

🌐 Properties

readonly name = 'tracing-console-exporter';

方法
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.

输出格式
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]
────────────────────────────────────────

用法
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
});

实现细节
Direct link to 实现细节

🌐 Implementation Details

  • 将属性格式化为带有2个空格缩进的JSON
  • 计算并显示跨度持续时间(毫秒)
  • 优雅地处理序列化错误
  • 将未实现的事件类型记录为警告
  • 在事件之间使用80字符的分隔线

另请参阅
Direct link to 另请参阅

🌐 See Also

文档
Direct link to 文档

🌐 Documentation

其他导出器
Direct link to 其他导出器

🌐 Other Exporters

参考
Direct link to 参考

🌐 Reference