> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-TW/llms.txt # DeepEvalExporter 將 Tracing 資料傳送至 [Confident AI](https://www.confident-ai.com/),以進行評估與可觀測性分析。由建構於 DeepEval SDK 之上的 `@mastra/deepeval` 匯出。 如需設定與使用方式,請參閱 [Confident AI exporter](https://mastra.zisheng.pro/zh-TW/docs/observability/integrations/exporters/confident-ai)。 ## 建構函式 ```typescript new DeepEvalExporter(config?: DeepEvalExporterConfig) ``` ## `DeepEvalExporterConfig` ```typescript interface DeepEvalExporterConfig extends BaseExporterConfig { apiKey?: string environment?: string name?: string tags?: string[] metadata?: Record threadId?: string userId?: string testCaseId?: string turnId?: string metricCollection?: string traceMetricCollection?: string llmMetricCollection?: string agentMetricCollection?: string toolMetricCollectionMap?: Record prompt?: Prompt debug?: boolean traceCaptureSink?: (trace: Trace) => void } ``` 擴充 `BaseExporterConfig`,其中包括: - `logger?: IMastraLogger` - Logger 執行個體 - `logLevel?: LogLevel | 'debug' | 'info' | 'warn' | 'error'` - Log 層級(預設:INFO) **apiKey** (`string`): Confident AI API key。若未設定,則使用 CONFIDENT\_API\_KEY 環境變數。找不到 key 時,exporter 會自行停用。 **environment** (`string`): Trace 環境。依序使用 CONFIDENT\_TRACE\_ENVIRONMENT 與 'development' 作為備援。 **name** (`string`): 套用至每個 trace 的名稱。預設為 Mastra serviceName。 **tags** (`string[]`): 套用至每個 trace 的標籤。 **metadata** (`Record`): 套用至每個 trace 的 metadata。 **threadId** (`string`): 套用至每個 trace 的 Thread ID。根 span metadata 中的 threadId 會針對該請求覆寫此值。 **userId** (`string`): 套用至每個 trace 的 User ID。根 span metadata 中的 userId 會針對該請求覆寫此值。 **testCaseId** (`string`): 套用至每個 trace 的 test case ID。根 span metadata 中的 testCaseId 會針對該請求覆寫此值。 **turnId** (`string`): 套用至每個 trace 的 turn ID。根 span metadata 中的 turnId 會針對該請求覆寫此值。 **metricCollection** (`string`): Trace 層級的指標集合。 **traceMetricCollection** (`string`): Trace 層級的指標集合。優先於 metricCollection。 **llmMetricCollection** (`string`): 套用至 LLM span 的指標集合。 **agentMetricCollection** (`string`): 套用至 Agent span 的指標集合。 **toolMetricCollectionMap** (`Record`): 依 Tool 名稱套用的指標集合。 **prompt** (`Prompt`): 附加至 LLM span 的 Confident AI 代管 prompt 連結。 **debug** (`boolean`): 將 exporter 設定與匯出錯誤記錄至 console。 **traceCaptureSink** (`(trace: Trace) => void`): 在本機接收已完成的 trace,而不將其傳送至 Confident AI。用於離線評估。 **logLevel** (`'debug' | 'info' | 'warn' | 'error'`): Logger 層級(預設:'info') ## 方法 ### `exportTracingEvent` ```typescript async exportTracingEvent(event: TracingEvent): Promise ``` 將 tracing 事件匯出至 Confident AI。從 Mastra span 串流建立 trace 樹狀結構,並在根 span 結束時傳送 trace。 ### `flush` ```typescript async flush(): Promise ``` 等待所有進行中的 trace 傳送作業完成,而不關閉 exporter。 ### `shutdown` ```typescript async shutdown(): Promise ``` 完成所有開啟中的 trace,並 flush 待處理的傳送作業。 ## 使用方式 ### 零設定(使用環境變數) ```typescript import { DeepEvalExporter } from '@mastra/deepeval' // Reads from CONFIDENT_API_KEY, CONFIDENT_TRACE_ENVIRONMENT const exporter = new DeepEvalExporter() ``` ### 明確設定 ```typescript import { DeepEvalExporter } from '@mastra/deepeval' const exporter = new DeepEvalExporter({ apiKey: process.env.CONFIDENT_API_KEY, environment: 'production', }) ``` ## Span 類型對應 | Mastra span 類型 | Confident AI span 類型 | | ---------------------------------------------------------------------- | -------------------- | | `AGENT_RUN`, `WORKFLOW_RUN` | `AGENT` | | `MODEL_GENERATION` | `LLM` | | `TOOL_CALL`, `MCP_TOOL_CALL`, `PROVIDER_TOOL_CALL`, `CLIENT_TOOL_CALL` | `TOOL` | | `RAG_EMBEDDING`, `RAG_VECTOR_OPERATION` | `RETRIEVER` | | 所有其他匯出的 span 類型 | `CUSTOM` | 事件 span(例如 `MODEL_CHUNK`)會被捨棄。