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 key:在
http://localhost:3030的 Arthur Engine UI 中生成 API key - Task ID(可选):创建 task,将 Trace 路由到特定 task
Task 路由Task 路由的直接链接
Arthur Engine 通过两种方式将 Trace 与 task 关联:
- 按服务名称:在可观测性配置中设置
serviceName。Arthur Engine 会自动将 Trace 路由到名称匹配的 task,并在需要时创建它。 - 按 task ID:将已有的
taskId传给 exporter,直接将 Trace 发送到特定 task。
如果两者都提供,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,
},
})
自定义元数据自定义元数据的直接链接
非保留 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 结构。