> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-HK/llms.txt # ConsoleExporter 將 tracing 事件輸出至控制台,以供除錯及開發使用。 ## 建構函式 ```typescript new ConsoleExporter(config?: BaseExporterConfig) ``` **config** (`BaseExporterConfig`): 設定選項 **config.logger** (`IMastraLogger`): Logger 執行個體(如未設定,會改用 INFO 層級的 ConsoleLogger) **config.logLevel** (`LogLevel | 'debug' | 'info' | 'warn' | 'error'`): 匯出器的日誌層級(預設:INFO) ## 屬性 ```typescript readonly name = 'tracing-console-exporter'; ``` ## 方法 ### `exportTracingEvent` ```typescript async exportTracingEvent(event: TracingEvent): Promise ``` 將 tracing 事件匯出至控制台。 ### shutdown ```typescript async shutdown(): Promise ``` 記錄關閉訊息。 ## 輸出格式 匯出器會按事件類型輸出不同格式: ### 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] ──────────────────────────────────────── ``` ## 用法 ```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, }) ``` ## 實作詳情 - 將屬性格式化為縮排 2 個空格的 JSON - 計算並以毫秒顯示 span 持續時間 - 妥善處理序列化錯誤 - 將尚未實作的事件類型記錄為警告 - 在事件之間使用 80 個字元長的分隔線 ## 另請參閱 ### 文件 - [Tracing 概覽](https://mastra.zisheng.pro/zh-HK/docs/observability/tracing/overview):完整指南 - [Exporter](https://mastra.zisheng.pro/zh-HK/docs/observability/integrations/overview):exporter 概念 ### 其他匯出器 - [MastraStorageExporter](https://mastra.zisheng.pro/zh-HK/reference/observability/tracing/exporters/mastra-storage-exporter):儲存持久化 - [MastraPlatformExporter](https://mastra.zisheng.pro/zh-HK/reference/observability/tracing/exporters/mastra-platform-exporter):Mastra 平台 - [Langfuse](https://mastra.zisheng.pro/zh-HK/reference/observability/tracing/exporters/langfuse):Langfuse 整合 - [Braintrust](https://mastra.zisheng.pro/zh-HK/reference/observability/tracing/exporters/braintrust):Braintrust 整合 ### 參考 - [設定](https://mastra.zisheng.pro/zh-HK/reference/observability/tracing/configuration):設定選項 - [介面](https://mastra.zisheng.pro/zh-HK/reference/observability/tracing/interfaces):類型定義