Skip to main content

LangSmithExporter

Sends Tracing data to LangSmith for observability.

Constructor
Direct link to Constructor

new LangSmithExporter(config: LangSmithExporterConfig)

LangSmithExporterConfig
Direct link to LangSmithExporterConfig

interface LangSmithExporterConfig extends ClientConfig, BaseExporterConfig {
client?: Client;
projectName?: string;
}

Extends both ClientConfig (from LangSmith SDK) and BaseExporterConfig:

  • From BaseExporterConfig: logger?: IMastraLogger, logLevel?: LogLevel | 'debug' | 'info' | 'warn' | 'error'
  • From ClientConfig: apiKey, apiUrl, callerOptions, hideInputs, hideOutputs, etc.

Methods
Direct link to Methods

exportTracingEvent
Direct link to exportTracingEvent

async exportTracingEvent(event: TracingEvent): Promise<void>

Exports a tracing event to LangSmith.

shutdown
Direct link to shutdown

async shutdown(): Promise<void>

Ends all active spans and clears the trace map.

Usage
Direct link to Usage

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",
});

Environment Variables
Direct link to Environment Variables

VariableDescription
LANGSMITH_API_KEYYour LangSmith API key
LANGCHAIN_PROJECTDefault project name for traces (used if projectName not specified)
LANGSMITH_BASE_URLAPI URL for self-hosted instances

Span Type Mapping
Direct link to Span Type Mapping

Span TypeLangSmith Type
MODEL_GENERATIONllm
MODEL_CHUNKllm
TOOL_CALLtool
MCP_TOOL_CALLtool
All otherschain