> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-HK/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` - 記錄器實例 - `logLevel?: LogLevel | 'debug' | 'info' | 'warn' | 'error'` - 記錄層級(預設:INFO) ## 方法 ### `exportTracingEvent` ```typescript async exportTracingEvent(event: TracingEvent): Promise ``` 將 tracing 事件匯出至 Braintrust。 ### export ```typescript async export(spans: ReadOnlySpan[]): Promise ``` 將 span 批次匯出至 Braintrust。 ### flush ```typescript async flush(): Promise ``` 在不關閉 exporter 的情況下,強制將所有已緩衝的 span 清空並匯出至 Braintrust。這對 serverless 環境尤其有用,可確保 span 在 runtime 終止前完成匯出。 ### shutdown ```typescript async shutdown(): Promise ``` 清空待處理數據並關閉 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` |