Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.uselemma.ai/llms.txt

Use this file to discover all available pages before exploring further.

Langfuse is the recommended greenfield instrumentation path. For new implementations, use Langfuse as the instrumentation layer, then export those spans to Lemma. This keeps framework/provider edge-case handling in Langfuse while Lemma receives normalized trace data for monitoring and analysis. If you already use OpenTelemetry-compatible instrumentation (OpenInference, Arize, Braintrust, provider SDK instrumentation, or another OTel stack), you do not need to adopt Langfuse. Keep your existing instrumentation and configure Lemma as an OpenTelemetry export destination.

Lemma-only export

Configure OpenTelemetry with Lemma’s OpenTelemetry exporter. These examples do not require LANGFUSE_* environment variables.
Install Langfuse’s OpenTelemetry processor and the Lemma OpenTelemetry exporter:
npm install @langfuse/otel @opentelemetry/exporter-trace-otlp-proto @opentelemetry/sdk-trace-node
Enable framework instrumentation. For the Vercel AI SDK, use experimental_telemetry so model calls emit OpenTelemetry spans that Langfuse can process:
import { streamText } from "ai";

await streamText({
  model: "openai/gpt-4o-mini",
  messages: [{ role: "user", content: "Help me understand my invoice" }],
  experimental_telemetry: {
    isEnabled: true,
    functionId: "support-agent",
    metadata: {
      "gen_ai.agent.name": "planwise-support-agent",
      "lemma.thread_id": "thread_123",
    },
  },
});
By semantic convention, gen_ai.agent.name should use snake_case, CamelCase, or kebab-case values, such as support_agent, SupportAgent, or support-agent.Then configure LangfuseSpanProcessor with an OTLPTraceExporter targeting Lemma:
import { LangfuseSpanProcessor } from "@langfuse/otel";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";

const provider = new NodeTracerProvider({
  spanProcessors: [
    new LangfuseSpanProcessor({
      exporter: new OTLPTraceExporter({
        url: process.env.LEMMA_BASE_URL,
        headers: {
          Authorization: `Bearer ${process.env.LEMMA_API_KEY}`,
          "X-Lemma-Project-ID": process.env.LEMMA_PROJECT_ID,
        },
      }),
    }),
  ],
});

provider.register();
In Next.js, put the provider setup in root instrumentation.ts and run it only in the Node runtime:
// instrumentation.ts
export async function register() {
  if (process.env.NEXT_RUNTIME === 'nodejs') {
    const { LangfuseSpanProcessor } = await import("@langfuse/otel");
    const { OTLPTraceExporter } = await import("@opentelemetry/exporter-trace-otlp-proto");
    const { NodeTracerProvider } = await import("@opentelemetry/sdk-trace-node");

    const provider = new NodeTracerProvider({
      spanProcessors: [
        new LangfuseSpanProcessor({
          exporter: new OTLPTraceExporter({
            url: process.env.LEMMA_BASE_URL,
            headers: {
              Authorization: `Bearer ${process.env.LEMMA_API_KEY}`,
              "X-Lemma-Project-ID": process.env.LEMMA_PROJECT_ID,
            },
          }),
        }),
      ],
    });

    provider.register();
  }
}
Required environment variables for Lemma-only export:
  • LEMMA_BASE_URL (https://api.uselemma.ai/otel/v1/traces)
  • LEMMA_API_KEY
  • LEMMA_PROJECT_ID

Export to both Langfuse and Lemma

If you want traces in both systems, add two Langfuse processors:
import { LangfuseSpanProcessor } from "@langfuse/otel";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";

const lemmaExporter = new OTLPTraceExporter({
  url: process.env.LEMMA_BASE_URL,
  headers: {
    Authorization: `Bearer ${process.env.LEMMA_API_KEY}`,
    "X-Lemma-Project-ID": process.env.LEMMA_PROJECT_ID,
  },
});

const provider = new NodeTracerProvider({
  spanProcessors: [
    new LangfuseSpanProcessor(), // default destination: Langfuse
    new LangfuseSpanProcessor({ exporter: lemmaExporter }), // second destination: Lemma
  ],
});

provider.register();
See OpenTelemetry export for details and caveats.
If you export to Langfuse as well as Lemma, also set:
  • LANGFUSE_PUBLIC_KEY
  • LANGFUSE_SECRET_KEY
  • LANGFUSE_BASE_URL (for example https://cloud.langfuse.com)

Framework instrumentation

Use Langfuse-native framework guides, then keep Lemma as an export destination:

Next steps