Skip to main content

LangSmithExporter

将追踪数据发送到 LangSmith 以实现可观测性。

🌐 Sends Tracing data to LangSmith for observability.

构造函数
Direct link to 构造函数

🌐 Constructor

new LangSmithExporter(config: LangSmithExporterConfig)

LangSmithExporterConfig
Direct link to LangSmithExporterConfig

interface LangSmithExporterConfig extends ClientConfig, BaseExporterConfig {
client?: Client;
projectName?: string;
}

同时扩展 ClientConfig(来自 LangSmith SDK)和 BaseExporterConfig

🌐 Extends both ClientConfig (from LangSmith SDK) and BaseExporterConfig:

  • 来自 BaseExporterConfiglogger?: IMastraLoggerlogLevel?: LogLevel | 'debug' | 'info' | 'warn' | 'error'
  • 来自 ClientConfigapiKeyapiUrlcallerOptionshideInputshideOutputs 等。

方法
Direct link to 方法

🌐 Methods

exportTracingEvent
Direct link to exportTracingEvent

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

将跟踪事件导出到 LangSmith。

🌐 Exports a tracing event to LangSmith.

flush
Direct link to flush

async flush(): Promise<void>

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

🌐 Force flushes any pending spans to LangSmith 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>

结束所有活动的跨度并清除追踪映射。

🌐 Ends all active spans and clears the trace map.

用法
Direct link to 用法

🌐 Usage

import { LangSmithExporter } from "@mastra/langsmith";

const exporter = new LangSmithExporter({
apiKey: process.env.LANGSMITH_API_KEY,
projectName: "my-project", // Optional: specify which project to send traces to
apiUrl: "https://api.smith.langchain.com",
logLevel: "info",
});

环境变量
Direct link to 环境变量

🌐 Environment Variables

变量描述
LANGSMITH_API_KEY你的 LangSmith API 密钥
LANGCHAIN_PROJECT跟踪的默认项目名称(如果未指定 projectName 时使用)
LANGSMITH_BASE_URL自托管实例的 API URL

跨度类型映射
Direct link to 跨度类型映射

🌐 Span Type Mapping

跨度类型LangSmith 类型
MODEL_GENERATIONllm
MODEL_CHUNKllm
TOOL_CALLtool
MCP_TOOL_CALLtool
其他所有chain