LangSmithExporter
将追踪数据发送到 LangSmith 以实现可观测性。
🌐 Sends Tracing data to LangSmith for observability.
构造函数Direct link to 构造函数
🌐 Constructor
new LangSmithExporter(config: LangSmithExporterConfig)
LangSmithExporterConfigDirect link to LangSmithExporterConfig
interface LangSmithExporterConfig extends ClientConfig, BaseExporterConfig {
client?: Client;
projectName?: string;
}
同时扩展 ClientConfig(来自 LangSmith SDK)和 BaseExporterConfig:
🌐 Extends both ClientConfig (from LangSmith SDK) and BaseExporterConfig:
- 来自
BaseExporterConfig:logger?: IMastraLogger,logLevel?: LogLevel | 'debug' | 'info' | 'warn' | 'error' - 来自
ClientConfig:apiKey、apiUrl、callerOptions、hideInputs、hideOutputs等。
方法Direct link to 方法
🌐 Methods
exportTracingEventDirect link to exportTracingEvent
async exportTracingEvent(event: TracingEvent): Promise<void>
将跟踪事件导出到 LangSmith。
🌐 Exports a tracing event to LangSmith.
flushDirect 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.
shutdownDirect 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_GENERATION | llm |
MODEL_CHUNK | llm |
TOOL_CALL | tool |
MCP_TOOL_CALL | tool |
| 其他所有 | chain |