跳到主要内容

ArthurExporter

使用 OpenTelemetry 和 OpenInference 语义约定将 Tracing 数据发送到 Arthur Engine

构造函数
构造函数的直接链接

new ArthurExporter(config: ArthurExporterConfig)

ArthurExporterConfig
arthurexporterconfig的直接链接

type ArthurExporterConfig = Omit<OtelExporterConfig, 'provider' | 'exporter'> & {
apiKey?: string
endpoint?: string
taskId?: string
headers?: Record<string, string>
}

继承自 OtelExporterConfig(不包括 providerexporter),其中包含:

  • timeout?: number - 导出超时时间(毫秒,默认值:30000)
  • batchSize?: number - 每批 Span 的数量(默认值:512)
  • logLevel?: LogLevel | 'debug' | 'info' | 'warn' | 'error' - 日志级别(默认值:WARN)
  • resourceAttributes?: Record<string, any> - 自定义资源属性

元数据透传
元数据透传的直接链接

非保留的 Span 属性会序列化到 OpenInference metadata payload 中。可通过 tracingOptions.metadata 添加这些属性(例如 companyIdtier)。inputoutputsessionId、thread/user ID 和 OpenInference ID 等保留字段会自动排除。

方法
方法的直接链接

exportTracingEvent
exporttracingevent的直接链接

async exportTracingEvent(event: TracingEvent): Promise<void>

将 Tracing 事件导出到配置的 endpoint。

export
export的直接链接

async export(spans: ReadOnlySpan[]): Promise<void>

使用 OpenTelemetry 和 OpenInference 语义约定批量导出 Span。

flush
flush的直接链接

async flush(): Promise<void>

强制将缓冲区中的所有 Span 刷新到配置的 endpoint,而不关闭 Exporter。适用于需要确保运行时终止前已导出 Span 的 serverless 环境。

shutdown
shutdown的直接链接

async shutdown(): Promise<void>

刷新待处理数据并关闭客户端。

用法
用法的直接链接

零配置(使用环境变量)
零配置(使用环境变量)的直接链接

import { ArthurExporter } from '@mastra/arthur'

// Set ARTHUR_API_KEY and ARTHUR_BASE_URL (optionally ARTHUR_TASK_ID)
const exporter = new ArthurExporter()

显式配置
显式配置的直接链接

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 语义约定
openinference-semantic-conventions的直接链接

ArthurExporter 为生成式 AI 应用实现了 OpenInference 语义约定,可在不同可观测性平台之间提供标准化的 Trace 结构。

Tag 支持
Tag 支持的直接链接

ArthurExporter 支持为 Trace 添加 tag,以便分类和筛选。Tag 仅应用于根 Span,并映射到原生 OpenInference tag.tags 语义约定。

用法
用法的直接链接

const result = await agent.generate('Hello', {
tracingOptions: {
tags: ['production', 'experiment-v2', 'user-request'],
},
})

Tag 的存储方式
Tag 的存储方式的直接链接

Tag 使用 OpenInference tag.tags 属性存储:

{
"tag.tags": ["production", "experiment-v2", "user-request"]
}