> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-HK/llms.txt # ArizeExporter 將 Tracing 數據傳送至 Arize Phoenix、Arize AX,或任何支援 OpenInference 語義慣例且與 OpenTelemetry 兼容的可觀測性平台。 ## 建構函式 ```typescript new ArizeExporter(config: ArizeExporterConfig) ``` ## `ArizeExporterConfig` ```typescript type ArizeExporterConfig = Omit & { // Phoenix / OpenTelemetry configuration endpoint?: string apiKey?: string // Arize AX configuration spaceId?: string // Common configuration projectName?: string headers?: Record } ``` 繼承自 `OtelExporterConfig`(不包括 `provider`),當中包括: - `timeout?: number` - 匯出逾時時間(毫秒)(預設:30000) - `batchSize?: number` - 每批的 span 數量(預設:512) - `logLevel?: LogLevel | 'debug' | 'info' | 'warn' | 'error'` - 記錄層級(預設:WARN) - `resourceAttributes?: Record` - 自訂資源屬性 ### Metadata 傳遞 非保留的 span 屬性會序列化至 OpenInference `metadata` payload。請透過 `tracingOptions.metadata` 加入這些屬性(例如 `companyId`、`tier`)。`input`、`output`、`sessionId`、thread/user ID 及 OpenInference ID 等保留欄位會自動排除。 ## 方法 ### `exportTracingEvent` ```typescript async exportTracingEvent(event: TracingEvent): Promise ``` 將 tracing 事件匯出至已設定的 endpoint。 ### export ```typescript async export(spans: ReadOnlySpan[]): Promise ``` 使用 OpenTelemetry 及 OpenInference 語義慣例批次匯出 span。 ### flush ```typescript async flush(): Promise ``` 在不關閉 exporter 的情況下,強制將所有已緩衝的 span 清空並匯出至已設定的 endpoint。這對 serverless 環境尤其有用,可確保 span 在 runtime 終止前完成匯出。 ### shutdown ```typescript async shutdown(): Promise ``` 清空待處理數據並關閉 client。 ## 用法 ### 零設定(使用環境變數) ```typescript import { ArizeExporter } from '@mastra/arize' // For Phoenix: Set PHOENIX_COLLECTOR_ENDPOINT, PHOENIX_API_KEY, PHOENIX_PROJECT_NAME // For Arize AX: Set ARIZE_SPACE_ID, ARIZE_API_KEY, ARIZE_PROJECT_NAME const exporter = new ArizeExporter() ``` ### Phoenix 設定 ```typescript import { ArizeExporter } from '@mastra/arize' const exporter = new ArizeExporter({ endpoint: 'http://localhost:6006/v1/traces', apiKey: process.env.PHOENIX_API_KEY, // Optional for local Phoenix projectName: 'my-ai-project', }) ``` ### Arize AX 設定 ```typescript import { ArizeExporter } from '@mastra/arize' const exporter = new ArizeExporter({ spaceId: process.env.ARIZE_SPACE_ID!, apiKey: process.env.ARIZE_API_KEY!, projectName: 'my-ai-project', }) ``` ## `OpenInference` 語義慣例 ArizeExporter 為生成式 AI 應用程式實作了 [OpenInference 語義慣例](https://github.com/Arize-ai/openinference/tree/main/spec),讓不同可觀測性平台採用標準化的 trace 結構。 ## Tag 支援 ArizeExporter 支援為 trace 加上 tag,以便分類和篩選。Tag 只會套用至 root span,並對應至 OpenInference 原生的 `tag.tags` 語義慣例。 ### 用法 ```typescript const result = await agent.generate('Hello', { tracingOptions: { tags: ['production', 'experiment-v2', 'user-request'], }, }) ``` ### Tag 的儲存方式 Tag 使用 OpenInference `tag.tags` 屬性儲存: ```json { "tag.tags": ["production", "experiment-v2", "user-request"] } ``` ## 相關內容 - [ArizeExporter 文件](https://mastra.zisheng.pro/zh-HK/docs/observability/integrations/exporters/arize) - [Phoenix 文件](https://docs.arize.com/phoenix) - [Arize AX 文件](https://docs.arize.com/)