LangSmithExporter
Observability のために 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>
exporter をシャットダウンせず、保留中のすべての Span を LangSmith へ強制的にフラッシュします。ランタイム終了前に Span が確実にエクスポートされるようにする必要がある、サーバーレス環境で役立ちます。
shutdownshutdownへの直接リンク
async shutdown(): Promise<void>
アクティブなすべての Span を終了し、Trace マップをクリアします。
使用方法使用方法への直接リンク
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 キー |
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',
}),
)