> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-TW/llms.txt # ArthurExporter 使用 OpenTelemetry 與 OpenInference semantic convention,將 Tracing 資料傳送至 [Arthur Engine](https://github.com/arthur-ai/arthur-engine)。 ## 建構函式 ```typescript new ArthurExporter(config: ArthurExporterConfig) ``` ## `ArthurExporterConfig` ```typescript type ArthurExporterConfig = Omit & { apiKey?: string endpoint?: string taskId?: string headers?: Record } ``` 繼承自 `OtelExporterConfig`(排除 `provider` 與 `exporter`),其中包括: - `timeout?: number` - 匯出逾時(毫秒,預設:30000) - `batchSize?: number` - 每批 span 數量(預設:512) - `logLevel?: LogLevel | 'debug' | 'info' | 'warn' | 'error'` - Log 層級(預設:WARN) - `resourceAttributes?: Record` - 自訂 resource 屬性 ### 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 semantic convention 批次匯出 span。 ### flush ```typescript async flush(): Promise ``` 強制將所有緩衝的 span flush 至設定的 endpoint,而不關閉 exporter。這在 serverless 環境中特別實用,可確保 runtime 結束前已匯出 span。 ### shutdown ```typescript async shutdown(): Promise ``` Flush 待處理資料並關閉 client。 ## 使用方式 ### 零設定(使用環境變數) ```typescript import { ArthurExporter } from '@mastra/arthur' // Set ARTHUR_API_KEY and ARTHUR_BASE_URL (optionally ARTHUR_TASK_ID) const exporter = new ArthurExporter() ``` ### 明確設定 ```typescript import { ArthurExporter } from '@mastra/arthur' const exporter = new ArthurExporter({ apiKey: process.env.ARTHUR_API_KEY!, endpoint: 'http://localhost:3030', taskId: process.env.ARTHUR_TASK_ID, // Optional }) ``` ## `OpenInference` semantic convention ArthurExporter 會為生成式 AI 應用程式實作 [OpenInference Semantic Conventions](https://github.com/Arize-ai/openinference/tree/main/spec),在不同可觀測性平台之間提供標準化的 trace 結構。 ## 標籤支援 ArthurExporter 支援以 trace 標籤進行分類與篩選。標籤只會套用至根 span,並對應至原生 OpenInference `tag.tags` semantic convention。 ### 使用方式 ```typescript const result = await agent.generate('Hello', { tracingOptions: { tags: ['production', 'experiment-v2', 'user-request'], }, }) ``` ### 標籤的儲存方式 標籤會使用 OpenInference `tag.tags` 屬性儲存: ```json { "tag.tags": ["production", "experiment-v2", "user-request"] } ``` ## 相關內容 - [ArthurExporter 文件](https://mastra.zisheng.pro/zh-TW/docs/observability/integrations/exporters/arthur) - [Arthur Engine 文件](https://docs.arthur.ai/) - [Arthur Engine 儲存庫](https://github.com/arthur-ai/arthur-engine)