Skip to main content

LangfuseExporter

Sends AI tracing data to Langfuse for observability.

Constructor

new LangfuseExporter(config: LangfuseExporterConfig)

LangfuseExporterConfig

interface LangfuseExporterConfig {
publicKey?: string;
secretKey?: string;
baseUrl?: string;
realtime?: boolean;
logLevel?: "debug" | "info" | "warn" | "error";
options?: any;
}

Methods

exportEvent

async exportEvent(event: AITracingEvent): Promise<void>

Exports a tracing event to Langfuse.

export

async export(spans: ReadOnlyAISpan[]): Promise<void>

Batch exports spans to Langfuse.

shutdown

async shutdown(): Promise<void>

Flushes pending data and shuts down the client.

Usage

import { LangfuseExporter } from "@mastra/langfuse";

const exporter = new LangfuseExporter({
publicKey: process.env.LANGFUSE_PUBLIC_KEY,
secretKey: process.env.LANGFUSE_SECRET_KEY,
baseUrl: "https://cloud.langfuse.com",
realtime: true,
});

Span Mapping

  • Root spans → Langfuse traces
  • LLM_GENERATION spans → Langfuse generations
  • All other spans → Langfuse spans
  • Event spans → Langfuse events