> Discover all available pages from the documentation index: https://mastra.zisheng.pro/llms.txt # DeepEvalExporter 将 Tracing 数据发送到 [Confident AI](https://www.confident-ai.com/),用于评估和可观测性。由基于 DeepEval SDK 构建的 `@mastra/deepeval` 导出。 有关设置和用法,请参阅 [Confident AI exporter](https://mastra.zisheng.pro/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'` - 日志级别(默认值: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 的 tag。 **metadata** (`Record`): 应用到每条 Trace 的元数据。 **threadId** (`string`): 应用到每条 Trace 的 thread ID。根 Span 元数据中的 threadId 会按请求覆盖此值。 **userId** (`string`): 应用到每条 Trace 的 user ID。根 Span 元数据中的 userId 会按请求覆盖此值。 **testCaseId** (`string`): 应用到每条 Trace 的 test case ID。根 Span 元数据中的 testCaseId 会按请求覆盖此值。 **turnId** (`string`): 应用到每条 Trace 的 turn ID。根 Span 元数据中的 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 配置和导出错误记录到控制台。 **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,并刷新待发送数据。 ## 用法 ### 零配置(使用环境变量) ```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`)会被丢弃。