> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-HK/llms.txt # Arthur exporter [Arthur](https://arthur.ai/) 透過開源的 [Arthur Engine](https://github.com/arthur-ai/arthur-engine),為 AI 應用程式提供可觀測性及評估平台。Arthur exporter 使用 OpenTelemetry 及 [OpenInference](https://github.com/Arize-ai/openinference/tree/main/spec) 語義慣例傳送 Trace。 ## 安裝 **npm**: ```bash npm install @mastra/arthur@latest ``` **pnpm**: ```bash pnpm add @mastra/arthur@latest ``` **Yarn**: ```bash yarn add @mastra/arthur@latest ``` **Bun**: ```bash bun add @mastra/arthur@latest ``` ## 配置 ### 先決條件 1. **Arthur Engine 執行個體**:按照 [Docker Compose 部署指南](https://docs.arthur.ai/docs/arthur-genai-engine-docker-compose-deployment-guide)啟動 Arthur Engine 2. **API 金鑰**:在位於 `http://localhost:3030` 的 Arthur Engine UI 中[產生 API 金鑰](https://docs.arthur.ai/docs/api-keys-management) 3. **任務 ID**(可選):[建立任務](https://docs.arthur.ai/docs/create-a-task),將 Trace 路由至指定任務 ### 任務路由 Arthur Engine 透過以下兩種方式將 Trace 與任務關聯: - **按服務名稱**:在可觀測性配置中設定 `serviceName`。Arthur Engine 會自動將 Trace 路由至名稱相符的任務,並在有需要時建立該任務。 - **按任務 ID**:將預先存在的 `taskId` 傳入 exporter,以直接將 Trace 傳送至指定任務。 如果兩者均有提供,會優先使用 `taskId`。 ### 環境變數 ```bash # Required ARTHUR_API_KEY=your-api-key ARTHUR_BASE_URL=http://localhost:3030 # Optional - route traces to a pre-existing task by ID ARTHUR_TASK_ID=your-task-id ``` ### 零配置設定 設定環境變數後,無需任何配置即可使用 exporter: ```typescript import { Mastra } from '@mastra/core' import { Observability } from '@mastra/observability' import { ArthurExporter } from '@mastra/arthur' export const mastra = new Mastra({ observability: new Observability({ configs: { arthur: { serviceName: 'my-service', exporters: [new ArthurExporter()], }, }, }), }) ``` ### 明確配置 你亦可直接傳入憑證(其優先級高於環境變數): ```typescript import { Mastra } from '@mastra/core' import { Observability } from '@mastra/observability' import { ArthurExporter } from '@mastra/arthur' export const mastra = new Mastra({ observability: new Observability({ configs: { arthur: { serviceName: 'my-service', exporters: [ new ArthurExporter({ apiKey: process.env.ARTHUR_API_KEY!, endpoint: process.env.ARTHUR_BASE_URL!, taskId: process.env.ARTHUR_TASK_ID, }), ], }, }, }), }) ``` ## 配置選項 ### 完整配置 ```typescript new ArthurExporter({ // Arthur Configuration apiKey: 'your-api-key', // Required endpoint: 'http://localhost:3030', // Required taskId: 'your-task-id', // Optional // Optional OTLP settings headers: { 'x-custom-header': 'value', // Additional headers for OTLP requests }, // Debug and performance tuning logLevel: 'debug', // Logging: debug | info | warn | error batchSize: 512, // Batch size before exporting spans timeout: 30000, // Timeout in ms before exporting spans // Custom resource attributes resourceAttributes: { 'deployment.environment': process.env.NODE_ENV, 'service.version': process.env.APP_VERSION, }, }) ``` ### 自訂 metadata 非保留的 span 屬性會序列化至 OpenInference `metadata` payload,並顯示於 Arthur。你可透過 `tracingOptions.metadata` 加入這些屬性: ```ts await agent.generate(input, { tracingOptions: { metadata: { companyId: 'acme-co', tier: 'enterprise', }, }, }) ``` `input`、`output`、`sessionId`、thread/user ID 及 OpenInference ID 等保留欄位會自動排除。 ## OpenInference 語義慣例 此 exporter 為生成式 AI 應用程式實作了 [OpenInference 語義慣例](https://github.com/Arize-ai/openinference/tree/main/spec),在不同的可觀測性平台之間提供標準化的 Trace 結構。 ## 相關內容 - [Trace 概覽](https://mastra.zisheng.pro/zh-HK/docs/observability/tracing/overview) - [ArthurExporter 參考資料](https://mastra.zisheng.pro/zh-HK/reference/observability/tracing/exporters/arthur) - [Arthur Engine 文件](https://docs.arthur.ai/) - [Arthur Engine 程式碼庫](https://github.com/arthur-ai/arthur-engine) - [OpenInference 規格](https://github.com/Arize-ai/openinference/tree/main/spec)