LangSmithExporter
Sends Tracing data to LangSmith for observability.
ConstructorConstructor的直接链接
new LangSmithExporter(config: LangSmithExporterConfig)
LangSmithExporterConfiglangsmithexporterconfig的直接链接
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.
MethodsMethods的直接链接
exportTracingEventexporttracingevent的直接链接
async exportTracingEvent(event: TracingEvent): Promise<void>
Exports a tracing event to LangSmith.
flushflush的直接链接
async flush(): Promise<void>
Force flushes any pending spans to LangSmith without shutting down the exporter. Useful in serverless environments where you need to ensure spans are exported before the runtime terminates.
Waits for the LangSmith client's queued and in-flight batches. When the client uses manualFlushMode: true, this calls client.flush() for you, so you don't need to flush the client yourself. Overlapping calls wait for the earlier upload to finish.
shutdownshutdown的直接链接
async shutdown(): Promise<void>
Ends all active spans and clears the trace map. Spans that are still open are ended with a shutdown error, and their updates are sent to LangSmith before the promise resolves.
UsageUsage的直接链接
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 variablesEnvironment variables的直接链接
| Variable | Description |
|---|---|
LANGSMITH_API_KEY | Your LangSmith API key |
LANGCHAIN_PROJECT | Default project name for traces (used if projectName not specified) |
LANGSMITH_BASE_URL | API URL for self-hosted instances |
Span type mappingSpan type mapping的直接链接
| Span Type | LangSmith Type |
|---|---|
MODEL_GENERATION | llm |
MODEL_CHUNK | llm |
TOOL_CALL | tool |
MCP_TOOL_CALL | tool |
PROVIDER_TOOL_CALL | tool |
| All others | chain |
withLangsmithMetadatawithlangsmithmetadata的直接链接
Helper function to add LangSmith-specific metadata to tracing options.
function withLangsmithMetadata(metadata: LangSmithMetadataInput): TracingOptionsUpdater
LangSmithMetadataInputlangsmithmetadatainput的直接链接
UsageUsage的直接链接
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',
}),
)