LangSmithExporter
将 Tracing 数据发送到 LangSmith,用于可观测性。
构造函数构造函数的直接链接
new LangSmithExporter(config: LangSmithExporterConfig)
LangSmithExporterConfiglangsmithexporterconfig的直接链接
interface LangSmithExporterConfig extends ClientConfig, BaseExporterConfig {
client?: Client
projectName?: string
}
同时扩展 ClientConfig(来自 LangSmith SDK)和 BaseExporterConfig:
- 来自
BaseExporterConfig:logger?: IMastraLogger、logLevel?: LogLevel | 'debug' | 'info' | 'warn' | 'error' - 来自
ClientConfig:apiKey、apiUrl、callerOptions、hideInputs、hideOutputs等
方法方法的直接链接
exportTracingEventexporttracingevent的直接链接
async exportTracingEvent(event: TracingEvent): Promise<void>
将 Tracing 事件导出到 LangSmith。
flushflush的直接链接
async flush(): Promise<void>
强制将所有待处理的 Span 刷新到 LangSmith,而不关闭 Exporter。适用于需要确保运行时终止前已导出 Span 的 serverless 环境。
shutdownshutdown的直接链接
async shutdown(): Promise<void>
结束所有活跃 Span 并清除 Trace map。
用法用法的直接链接
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',
})
环境变量环境变量的直接链接
| 变量 | 说明 |
|---|---|
LANGSMITH_API_KEY | 你的 LangSmith API key |
LANGCHAIN_PROJECT | Trace 的默认项目名称(未指定 projectName 时使用) |
LANGSMITH_BASE_URL | 自托管实例的 API URL |
Span 类型映射Span 类型映射的直接链接
| Span 类型 | LangSmith 类型 |
|---|---|
MODEL_GENERATION | llm |
MODEL_CHUNK | llm |
TOOL_CALL | tool |
MCP_TOOL_CALL | tool |
PROVIDER_TOOL_CALL | tool |
| 所有其他类型 | chain |
withLangsmithMetadatawithlangsmithmetadata的直接链接
用于向 Tracing 选项添加 LangSmith 专用元数据的 helper 函数。
function withLangsmithMetadata(metadata: LangSmithMetadataInput): TracingOptionsUpdater
LangSmithMetadataInputlangsmithmetadatainput的直接链接
用法用法的直接链接
import { buildTracingOptions } from '@mastra/observability'
import { withLangsmithMetadata } from '@mastra/langsmith'
// Route to a specific project
const tracingOptions = buildTracingOptions(withLangsmithMetadata({ projectName: 'my-project' }))
// Set multiple fields
const tracingOptions = buildTracingOptions(
withLangsmithMetadata({
projectName: 'my-project',
sessionId: 'user-123',
}),
)