> Discover all available pages from the documentation index: https://mastra.zisheng.pro/ja/llms.txt # LangSmithExporter Observability のために Tracing データを LangSmith へ送信します。 ## コンストラクター ```typescript new LangSmithExporter(config: LangSmithExporterConfig) ``` ## `LangSmithExporterConfig` ```typescript 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` など ## メソッド ### `exportTracingEvent` ```typescript async exportTracingEvent(event: TracingEvent): Promise ``` Tracing イベントを LangSmith へエクスポートします。 ### flush ```typescript async flush(): Promise ``` exporter をシャットダウンせず、保留中のすべての Span を LangSmith へ強制的にフラッシュします。ランタイム終了前に Span が確実にエクスポートされるようにする必要がある、サーバーレス環境で役立ちます。 ### shutdown ```typescript async shutdown(): Promise ``` アクティブなすべての Span を終了し、Trace マップをクリアします。 ## 使用方法 ```typescript 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 タイプ | LangSmith タイプ | | -------------------- | ------------- | | `MODEL_GENERATION` | `llm` | | `MODEL_CHUNK` | `llm` | | `TOOL_CALL` | `tool` | | `MCP_TOOL_CALL` | `tool` | | `PROVIDER_TOOL_CALL` | `tool` | | その他すべて | `chain` | ## `withLangsmithMetadata` Tracing オプションに LangSmith 固有のメタデータを追加する helper 関数です。 ```typescript function withLangsmithMetadata(metadata: LangSmithMetadataInput): TracingOptionsUpdater ``` ### `LangSmithMetadataInput` ### 使用方法 ```typescript 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', }), ) ```