ArthurExporter
使用 OpenTelemetry 和 OpenInference 语义约定将 Tracing 数据发送到 Arthur Engine。
构造函数构造函数的直接链接
new ArthurExporter(config: ArthurExporterConfig)
ArthurExporterConfigarthurexporterconfig的直接链接
type ArthurExporterConfig = Omit<OtelExporterConfig, 'provider' | 'exporter'> & {
apiKey?: string
endpoint?: string
taskId?: string
headers?: Record<string, string>
}
继承自 OtelExporterConfig(不包括 provider 和 exporter),其中包含:
timeout?: number- 导出超时时间(毫秒,默认值:30000)batchSize?: number- 每批 Span 的数量(默认值:512)logLevel?: LogLevel | 'debug' | 'info' | 'warn' | 'error'- 日志级别(默认值:WARN)resourceAttributes?: Record<string, any>- 自定义资源属性
元数据透传元数据透传的直接链接
非保留的 Span 属性会序列化到 OpenInference metadata payload 中。可通过 tracingOptions.metadata 添加这些属性(例如 companyId、tier)。input、output、sessionId、thread/user ID 和 OpenInference ID 等保留字段会自动排除。
方法方法的直接链接
exportTracingEventexporttracingevent的直接链接
async exportTracingEvent(event: TracingEvent): Promise<void>
将 Tracing 事件导出到配置的 endpoint。
exportexport的直接链接
async export(spans: ReadOnlySpan[]): Promise<void>
使用 OpenTelemetry 和 OpenInference 语义约定批量导出 Span。
flushflush的直接链接
async flush(): Promise<void>
强制将缓冲区中的所有 Span 刷新到配置的 endpoint,而不关闭 Exporter。适用于需要确保运行时终止前已导出 Span 的 serverless 环境。
shutdownshutdown的直接链接
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"]
}