> Discover all available pages from the documentation index: https://mastra.zisheng.pro/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 key**:在 `http://localhost:3030` 的 Arthur Engine UI 中[生成 API key](https://docs.arthur.ai/docs/api-keys-management) 3. **Task ID**(可选):[创建 task](https://docs.arthur.ai/docs/create-a-task),将 Trace 路由到特定 task ### Task 路由 Arthur Engine 通过两种方式将 Trace 与 task 关联: - **按服务名称**:在可观测性配置中设置 `serviceName`。Arthur Engine 会自动将 Trace 路由到名称匹配的 task,并在需要时创建它。 - **按 task ID**:将已有的 `taskId` 传给 exporter,直接将 Trace 发送到特定 task。 如果两者都提供,`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, }, }) ``` ### 自定义元数据 非保留 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 结构。 ## 相关内容 - [Tracing 概览](https://mastra.zisheng.pro/docs/observability/tracing/overview) - [ArthurExporter 参考](https://mastra.zisheng.pro/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)