メインコンテンツへ移動

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';

メソッド
メソッドへの直接リンク

exportTracingEvent
exporttracingeventへの直接リンク

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

Tracing イベントをコンソールへエクスポートします。

shutdown
shutdownへの直接リンク

async shutdown(): Promise<void>

シャットダウンメッセージをログに記録します。

出力形式
出力形式への直接リンク

exporter はイベントタイプに応じて異なる形式で出力します。

SPAN_STARTED
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
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
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]
────────────────────────────────────────

使用方法
使用方法への直接リンク

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 文字の区切り線を使用します

関連項目
関連項目への直接リンク

ドキュメント
ドキュメントへの直接リンク

その他の Exporter
その他の Exporterへの直接リンク

リファレンス
リファレンスへの直接リンク