> Discover all available pages from the documentation index: https://mastra.zisheng.pro/fr/llms.txt # LangSmithExporter Envoie les données de Tracing à LangSmith à des fins d’observabilité. ## Constructeur ```typescript new LangSmithExporter(config: LangSmithExporterConfig) ``` ## `LangSmithExporterConfig` ```typescript interface LangSmithExporterConfig extends ClientConfig, BaseExporterConfig { client?: Client projectName?: string } ``` Étend à la fois `ClientConfig` (du SDK LangSmith) et `BaseExporterConfig` : - Depuis `BaseExporterConfig` : `logger?: IMastraLogger`, `logLevel?: LogLevel | 'debug' | 'info' | 'warn' | 'error'` - Depuis `ClientConfig` : `apiKey`, `apiUrl`, `callerOptions`, `hideInputs`, `hideOutputs`, etc. ## Méthodes ### `exportTracingEvent` ```typescript async exportTracingEvent(event: TracingEvent): Promise ``` Exporte un événement de tracing vers LangSmith. ### flush ```typescript async flush(): Promise ``` Force l’envoi vers LangSmith de tous les spans en attente sans arrêter l’exportateur. Cette méthode est utile dans les environnements serverless où vous devez vous assurer que les spans sont exportés avant l’arrêt du runtime. ### shutdown ```typescript async shutdown(): Promise ``` Met fin à tous les spans actifs et efface la table des traces. ## Utilisation ```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', }) ``` ## Variables d’environnement | Variable | Description | | -------------------- | ------------------------------------------------------------------------------------- | | `LANGSMITH_API_KEY` | Votre clé d’API LangSmith | | `LANGCHAIN_PROJECT` | Nom du projet par défaut pour les traces (utilisé si `projectName` n’est pas indiqué) | | `LANGSMITH_BASE_URL` | URL de l’API pour les instances auto-hébergées | ## Correspondance des types de spans | Type de span | Type LangSmith | | -------------------- | -------------- | | `MODEL_GENERATION` | `llm` | | `MODEL_CHUNK` | `llm` | | `TOOL_CALL` | `tool` | | `MCP_TOOL_CALL` | `tool` | | `PROVIDER_TOOL_CALL` | `tool` | | Tous les autres | `chain` | ## `withLangsmithMetadata` Fonction utilitaire permettant d’ajouter des métadonnées propres à LangSmith aux options de tracing. ```typescript function withLangsmithMetadata(metadata: LangSmithMetadataInput): TracingOptionsUpdater ``` ### `LangSmithMetadataInput` ### Utilisation ```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', }), ) ```