# LangSmith Exporter [LangSmith](https://smith.langchain.com/) is LangChain's platform for monitoring and evaluating LLM applications. The LangSmith exporter sends your traces to LangSmith, providing insights into model performance, debugging capabilities, and evaluation workflows. ## Installation ```bash npm install @mastra/langsmith@latest ``` ```bash pnpm add @mastra/langsmith@latest ``` ```bash yarn add @mastra/langsmith@latest ``` ```bash bun add @mastra/langsmith@latest ``` ## Configuration ### Prerequisites 1. **LangSmith Account**: Sign up at [smith.langchain.com](https://smith.langchain.com) 2. **API Key**: Generate an API key in LangSmith Settings → API Keys 3. **Environment Variables**: Set your credentials ```bash # Required LANGSMITH_API_KEY=ls-xxxxxxxxxxxx # Optional LANGCHAIN_PROJECT=my-project # Default project for traces LANGSMITH_BASE_URL=https://api.smith.langchain.com # For self-hosted ``` ### Zero-Config Setup With environment variables set, use the exporter with no configuration: ```typescript import { Mastra } from "@mastra/core"; import { Observability } from "@mastra/observability"; import { LangSmithExporter } from "@mastra/langsmith"; export const mastra = new Mastra({ observability: new Observability({ configs: { langsmith: { serviceName: "my-service", exporters: [new LangSmithExporter()], }, }, }), }); ``` ### Explicit Configuration You can also pass credentials directly (takes precedence over environment variables): ```typescript import { Mastra } from "@mastra/core"; import { Observability } from "@mastra/observability"; import { LangSmithExporter } from "@mastra/langsmith"; export const mastra = new Mastra({ observability: new Observability({ configs: { langsmith: { serviceName: "my-service", exporters: [ new LangSmithExporter({ apiKey: process.env.LANGSMITH_API_KEY, }), ], }, }, }), }); ``` ## Configuration Options ### Complete Configuration ```typescript new LangSmithExporter({ // Required credentials apiKey: process.env.LANGSMITH_API_KEY!, // Optional settings apiUrl: process.env.LANGSMITH_BASE_URL, // Default: https://api.smith.langchain.com projectName: "my-project", // Project to send traces to (overrides LANGCHAIN_PROJECT env var) callerOptions: { // HTTP client options timeout: 30000, // Request timeout in ms maxRetries: 3, // Retry attempts }, logLevel: "info", // Diagnostic logging: debug | info | warn | error // LangSmith-specific options hideInputs: false, // Hide input data in UI hideOutputs: false, // Hide output data in UI }); ``` ### Environment Variables | Variable | Description | | -------------------- | ----------------------------------------------------------------- | | `LANGSMITH_API_KEY` | Your LangSmith API key (required) | | `LANGCHAIN_PROJECT` | Default project name for traces (optional, defaults to "default") | | `LANGSMITH_BASE_URL` | API URL for self-hosted instances (optional) | The `projectName` config option takes precedence over the `LANGCHAIN_PROJECT` environment variable, allowing you to programmatically route traces to different projects. ## Related - [Tracing Overview](https://mastra.ai/docs/observability/tracing/overview/llms.txt) - [LangSmith Documentation](https://docs.smith.langchain.com/)