Arthur exporter
Arthur 透過開源的 Arthur Engine,為 AI 應用程式提供可觀測性及評估平台。Arthur exporter 使用 OpenTelemetry 及 OpenInference 語義慣例傳送 Trace。
安裝安裝 的直接連結
- npm
- pnpm
- Yarn
- Bun
npm install @mastra/arthur@latest
pnpm add @mastra/arthur@latest
yarn add @mastra/arthur@latest
bun add @mastra/arthur@latest
配置配置 的直接連結
先決條件先決條件 的直接連結
- Arthur Engine 執行個體:按照 Docker Compose 部署指南啟動 Arthur Engine
- API 金鑰:在位於
http://localhost:3030的 Arthur Engine UI 中產生 API 金鑰 - 任務 ID(可選):建立任務,將 Trace 路由至指定任務
任務路由任務路由 的直接連結
Arthur Engine 透過以下兩種方式將 Trace 與任務關聯:
- 按服務名稱:在可觀測性配置中設定
serviceName。Arthur Engine 會自動將 Trace 路由至名稱相符的任務,並在有需要時建立該任務。 - 按任務 ID:將預先存在的
taskId傳入 exporter,以直接將 Trace 傳送至指定任務。
如果兩者均有提供,會優先使用 taskId。
環境變數環境變數 的直接連結
.env
# 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:
src/mastra/index.ts
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()],
},
},
}),
})
明確配置明確配置 的直接連結
你亦可直接傳入憑證(其優先級高於環境變數):
src/mastra/index.ts
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,
}),
],
},
},
}),
})
配置選項配置選項 的直接連結
完整配置完整配置 的直接連結
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自訂 metadata 的直接連結
非保留的 span 屬性會序列化至 OpenInference metadata payload,並顯示於 Arthur。你可透過 tracingOptions.metadata 加入這些屬性:
await agent.generate(input, {
tracingOptions: {
metadata: {
companyId: 'acme-co',
tier: 'enterprise',
},
},
})
input、output、sessionId、thread/user ID 及 OpenInference ID 等保留欄位會自動排除。
OpenInference 語義慣例OpenInference 語義慣例 的直接連結
此 exporter 為生成式 AI 應用程式實作了 OpenInference 語義慣例,在不同的可觀測性平台之間提供標準化的 Trace 結構。