Skip to main content

ArizeExporter

将跟踪数据发送到 Arize Phoenix、Arize AX,或任何支持 OpenInference 语义规范的 OpenTelemetry 兼容可观测性平台。

🌐 Sends Tracing data to Arize Phoenix, Arize AX, or any OpenTelemetry-compatible observability platform that supports OpenInference semantic conventions.

构造函数
Direct link to 构造函数

🌐 Constructor

new ArizeExporter(config: ArizeExporterConfig)

ArizeExporterConfig
Direct link to ArizeExporterConfig

type ArizeExporterConfig = Omit<OtelExporterConfig, 'provider'> & {
// Phoenix / OpenTelemetry configuration
endpoint?: string;
apiKey?: string;

// Arize AX configuration
spaceId?: string;

// Common configuration
projectName?: string;
headers?: Record<string, string>;
}

继承自 OtelExporterConfig(不包括 provider),其包括:

🌐 Inherits from OtelExporterConfig (excluding provider), which includes:

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

元数据直通
Direct link to 元数据直通

🌐 Metadata passthrough

非保留的 span 属性会被序列化到 OpenInference metadata 负载中。通过 tracingOptions.metadata 添加它们(例如,companyIdtier)。保留字段如 inputoutputsessionId、线程/用户 ID 和 OpenInference ID 会被自动排除。

🌐 Non-reserved span attributes are serialized into the OpenInference metadata payload. Add them via tracingOptions.metadata (e.g., companyId, tier). Reserved fields such as input, output, sessionId, thread/user IDs, and OpenInference IDs are excluded automatically.

方法
Direct link to 方法

🌐 Methods

exportTracingEvent
Direct link to exportTracingEvent

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

将跟踪事件导出到配置的端点。

🌐 Exports a tracing event to the configured endpoint.

export
Direct link to export

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

使用 OpenInference 语义约定通过 OpenTelemetry 批量导出跨度。

🌐 Batch exports spans using OpenTelemetry with OpenInference semantic conventions.

flush
Direct link to flush

async flush(): Promise<void>

强制将任何缓冲的跨度刷新到配置的端点,而不会关闭导出器。在无服务器环境中非常有用,因为你需要确保在运行时终止之前导出跨度。

🌐 Force flushes any buffered spans to the configured endpoint without shutting down the exporter. Useful in serverless environments where you need to ensure spans are exported before the runtime terminates.

shutdown
Direct link to shutdown

async shutdown(): Promise<void>

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

🌐 Flushes pending data and shuts down the client.

用法
Direct link to 用法

🌐 Usage

零配置(使用环境变量)
Direct link to 零配置(使用环境变量)

🌐 Zero-Config (using environment variables)

import { ArizeExporter } from "@mastra/arize";

// For Phoenix: Set PHOENIX_ENDPOINT, PHOENIX_API_KEY, PHOENIX_PROJECT_NAME
// For Arize AX: Set ARIZE_SPACE_ID, ARIZE_API_KEY, ARIZE_PROJECT_NAME
const exporter = new ArizeExporter();

凤凰配置
Direct link to 凤凰配置

🌐 Phoenix Configuration

import { ArizeExporter } from "@mastra/arize";

const exporter = new ArizeExporter({
endpoint: "http://localhost:6006/v1/traces",
apiKey: process.env.PHOENIX_API_KEY, // Optional for local Phoenix
projectName: "my-ai-project",
});

Arize AX 配置
Direct link to Arize AX 配置

🌐 Arize AX Configuration

import { ArizeExporter } from "@mastra/arize";

const exporter = new ArizeExporter({
spaceId: process.env.ARIZE_SPACE_ID!,
apiKey: process.env.ARIZE_API_KEY!,
projectName: "my-ai-project",
});

OpenInference 语义约定
Direct link to OpenInference 语义约定

🌐 OpenInference Semantic Conventions

ArizeExporter 实现了面向生成式 AI 应用的 OpenInference 语义规范,在不同的可观测性平台之间提供标准化的跟踪结构。

🌐 The ArizeExporter implements OpenInference Semantic Conventions for generative AI applications, providing standardized trace structure across different observability platforms.

标签支持
Direct link to 标签支持

🌐 Tags Support

ArizeExporter 支持跟踪标签用于分类和过滤。标签仅应用于根跨度,并映射到本地 OpenInference 的 tag.tags 语义约定。

🌐 The ArizeExporter supports trace tagging for categorization and filtering. Tags are only applied to root spans and are mapped to the native OpenInference tag.tags semantic convention.

用法
Direct link to 用法

🌐 Usage

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

标签的存储方式
Direct link to 标签的存储方式

🌐 How Tags Are Stored

标签使用 OpenInference tag.tags 属性存储:

🌐 Tags are stored using the OpenInference tag.tags attribute:

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

🌐 Related