> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-TW/llms.txt # BraintrustExporter 將 Tracing 資料傳送至 Braintrust,以進行 eval 與可觀測性分析。 ## 建構函式 ```typescript new BraintrustExporter(config: BraintrustExporterConfig) ``` ## `BraintrustExporterConfig` ```typescript interface BraintrustExporterConfig extends BaseExporterConfig { apiKey?: string endpoint?: string projectName?: string braintrustLogger?: Logger currentSpan?: () => Span | undefined tuningParameters?: Record } ``` 擴充 `BaseExporterConfig`,其中包括: - `logger?: IMastraLogger` - Logger 執行個體 - `logLevel?: LogLevel | 'debug' | 'info' | 'warn' | 'error'` - Log 層級(預設:INFO) ## 方法 ### `exportTracingEvent` ```typescript async exportTracingEvent(event: TracingEvent): Promise ``` 將 tracing 事件匯出至 Braintrust。 ### export ```typescript async export(spans: ReadOnlySpan[]): Promise ``` 將 span 批次匯出至 Braintrust。 ### flush ```typescript async flush(): Promise ``` 強制將所有緩衝的 span flush 至 Braintrust,而不關閉 exporter。這在 serverless 環境中特別實用,可確保 runtime 結束前已匯出 span。 ### shutdown ```typescript async shutdown(): Promise ``` Flush 待處理資料並關閉 client。 ## 使用方式 ### 零設定(使用環境變數) ```typescript import { BraintrustExporter } from '@mastra/braintrust' // Reads from BRAINTRUST_API_KEY, BRAINTRUST_ENDPOINT const exporter = new BraintrustExporter() ``` ### 明確設定 ```typescript import { BraintrustExporter } from '@mastra/braintrust' const exporter = new BraintrustExporter({ apiKey: process.env.BRAINTRUST_API_KEY, projectName: 'my-ai-project', }) ``` ## Span 類型對應 | Span 類型 | Braintrust 類型 | | --------------------------- | ------------- | | `MODEL_GENERATION` | `llm` | | `MODEL_CHUNK` | `llm` | | `TOOL_CALL` | `tool` | | `MCP_TOOL_CALL` | `tool` | | `PROVIDER_TOOL_CALL` | `tool` | | `WORKFLOW_CONDITIONAL_EVAL` | `function` | | `WORKFLOW_WAIT_EVENT` | `function` | | 所有其他類型 | `task` |