IntegrationsEve

Observability for eve with Langfuse

This guide shows you how to integrate Langfuse with eve to trace and debug your agents. eve emits OpenTelemetry spans for every run, so connecting Langfuse is a matter of pointing those spans at your Langfuse project.

What is eve? eve is an open-source TypeScript framework from Vercel for building durable agents as ordinary files in a project. It ships with durable execution, a sandbox, tools, subagents, schedules, and built-in OpenTelemetry tracing.

What is Langfuse? Langfuse is an open-source observability platform for AI agents and LLM applications. It helps you visualize and monitor model calls, tool usage, cost, latency, and more.

Every eve run produces a trace, and the spans are standard OpenTelemetry, built on the Vercel AI SDK telemetry conventions. eve registers its tracer in agent/instrumentation.ts via registerOTel. By adding the LangfuseSpanProcessor, every model call and tool call flows into Langfuse — where Langfuse maps them to traces, generations, and tool observations.

Get Started

Create an eve agent

If you don't have an eve agent yet, scaffold one with the eve CLI:

npx eve@latest init my-agent
cd my-agent

See the full eve quickstart for details.

Install the Langfuse OpenTelemetry packages

Add the Langfuse span processor and the Vercel OpenTelemetry helper that eve's instrumentation uses:

npm install @langfuse/otel @vercel/otel

Add your Langfuse credentials

Get your API keys from your Langfuse project settings and add them to your agent's .env file. You can sign up for Langfuse Cloud or self-host Langfuse.

.env
LANGFUSE_PUBLIC_KEY="pk-lf-..."
LANGFUSE_SECRET_KEY="sk-lf-..."
LANGFUSE_BASE_URL="https://cloud.langfuse.com" # 🇪🇺 EU region
# LANGFUSE_BASE_URL="https://us.cloud.langfuse.com" # 🇺🇸 US region

Register the Langfuse span processor

eve configures telemetry in agent/instrumentation.ts. Register the LangfuseSpanProcessor on the registerOTel call so eve's spans are exported to Langfuse:

agent/instrumentation.ts
import { defineInstrumentation } from "eve/instrumentation";
import { registerOTel } from "@vercel/otel";
import { LangfuseSpanProcessor, isDefaultExportSpan } from "@langfuse/otel";

export default defineInstrumentation({
  setup: ({ agentName }) =>
    registerOTel({
      serviceName: agentName,
      spanProcessors: [
        new LangfuseSpanProcessor({
          // Keep Langfuse's default export filter (Langfuse SDK spans, GenAI
          // spans, and known LLM instrumentors), and additionally keep eve's
          // `gen_ai` spans and its own run span (scope `eve`). Everything else —
          // eve's durable-workflow orchestration and the @vercel/otel HTTP
          // spans — is dropped.
          shouldExportSpan: ({ otelSpan }) =>
            isDefaultExportSpan(otelSpan) ||
            ["gen_ai", "eve"].includes(otelSpan.instrumentationScope.name),
        }),
      ],
    }),
});

The LangfuseSpanProcessor reads LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY, and LANGFUSE_BASE_URL from the environment.

Registering the LangfuseSpanProcessor via registerOTel requires @vercel/otel v2 or later, which is built on the same OpenTelemetry JS SDK v2 as @langfuse/otel (vercel/otel#154). The install command above already pulls in a compatible version. If you wire Langfuse into a custom OpenTelemetry setup instead, you can register the processor on a NodeSDK as well.

eve runs every turn as a durable workflow, so it emits many low-level orchestration spans (instrumentation scope workflow) alongside the model and tool calls (scope gen_ai) and the run span (scope eve). shouldExportSpan replaces Langfuse's default filter, so the snippet above composes with isDefaultExportSpan to keep that default behavior — Langfuse SDK spans (langfuse-sdk), GenAI spans, and known LLM instrumentors — and then also keeps eve's gen_ai and eve scopes. The result is one clean trace: agent invocations, generations, and tool calls nested under eve's run span, plus any observations you add with the Langfuse SDK (see the "Interoperability with the JS/TS SDK" section below), without the workflow plumbing. Keeping the eve scope matters — it is the parent that holds the GenAI spans together, so dropping it would leave them as orphaned spans. To keep eve's full run tree including the workflow spans, drop only the HTTP noise with ({ otelSpan }) => otelSpan.instrumentationScope.name !== "@vercel/otel/fetch", or use () => true to export everything. See filtering by instrumentation scope for more.

Define a simple agent

A minimal eve agent is a tool plus a system prompt. The weather agent below — a single getWeather tool and a short instruction — produces the kind of run shown in the example trace below:

agent/tools/getWeather.ts
import { defineTool } from "eve/tools";
import { z } from "zod";

export default defineTool({
  description: "Return mock weather data for a city.",
  inputSchema: z.object({ city: z.string().min(1) }),
  async execute({ city }) {
    return { city, condition: "cloudy", temperatureC: 18 };
  },
});
agent/agent.ts
import { defineAgent } from "eve";

export default defineAgent({
  model: "openai/gpt-4o-mini",
});
agent/instructions.md
You are a concise weather assistant. When asked about the weather, call the
getWeather tool, then answer in one sentence. Mention that the data is mocked.

eve discovers these files automatically. Model provider authentication (the Vercel AI Gateway or an OPENAI_API_KEY) follows the eve quickstart.

Run your agent

Start your agent and send it a message, for example "What's the weather in Berlin? Use the getWeather tool, then answer in one sentence.":

npm run dev

Each run is now exported to Langfuse.

View traces in Langfuse

Open your Langfuse dashboard to see the trace for each run. With the scope filter above, eve's spans map to the Langfuse data model as follows:

  • The eve run becomes the root span that the rest nest under.
  • Agent invocations become agent observations.
  • Model calls become generations with the model name, token usage, and cost.
  • Tool calls become tool observations with their inputs and outputs.

eve agent run trace in Langfuse, showing the eve run span with nested agent invocations, model generations, and a getWeather tool call

View this example trace in Langfuse →

Interoperability with the JS/TS SDK

You can use this integration together with the Langfuse SDKs to add additional attributes or group observations into a single trace.

The Context Manager allows you to wrap your instrumented code using context managers (with with statements), which allows you to add additional attributes to the trace. Any observation created inside the callback will automatically be nested under the active observation, and the observation will be ended when the callback finishes.

import { startActiveObservation, propagateAttributes } from "npm:@langfuse/tracing";

await startActiveObservation("context-manager", async (span) => {
  span.update({
    input: { query: "What is the capital of France?" },
  });

  // Propagate userId to all child observations
  await propagateAttributes(
    {
      userId: "user-123",
      sessionId: "session-123",
      metadata: {
        source: "api",
        region: "us-east-1",
      },
      tags: ["api", "user"],
      version: "1.0.0",
    },
    async () => {

      // YOUR CODE HERE
      const { text } = await generateText({
        model: openai("gpt-5"),
        prompt: "What is the capital of France?",
        experimental_telemetry: { isEnabled: true },
      });
    }
  );
  span.update({ output: "Paris" });
});

Learn more about using the Context Manager in the Langfuse SDK instrumentation docs.

The observe wrapper is a powerful tool for tracing existing functions without modifying their internal logic. It acts as a decorator that automatically creates a span or generation around the function call. You can use the propagateAttributes function to add attributes to the observation from within the wrapped function.

import { observe, propagateAttributes } from "@langfuse/tracing";
import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";

// An existing function
const processUserRequest = observe(
  async (userQuery: string) => {

    // Propagate attributes to all child observations
    return await propagateAttributes(
      {
        userId: "user-123",
        sessionId: "session-123",
        metadata: {
          source: "api",
          region: "us-east-1",
        },
        tags: ["api", "user"],
        version: "1.0.0",
      },
      async () => {

        // YOUR CODE HERE
        const { text } = await generateText({
          model: openai("gpt-5"),
          prompt: userQuery,
          experimental_telemetry: { isEnabled: true },
        });

        return text;
      }
    );
  },
  { name: "process-user-request" }
);

const result = await processUserRequest("some query");

Learn more about using the Decorator in the Langfuse SDK instrumentation docs.

Troubleshooting

No traces appearing

First, enable debug mode in the JS/TS SDK:

export LANGFUSE_LOG_LEVEL="DEBUG"

Then run your application and check the debug logs:

  • OTel spans appear in the logs: Your application is instrumented correctly but traces are not reaching Langfuse. To resolve this:
    1. Call forceFlush() at the end of your application to ensure all traces are exported. This is especially important in short-lived environments like serverless functions.
    2. Verify that you are using the correct API keys and base URL.
  • No OTel spans in the logs: Your application is not instrumented correctly. Make sure the instrumentation runs before your application code.
Unwanted observations in Langfuse

The Langfuse SDK is based on OpenTelemetry. Other libraries in your application may emit OTel spans that are not relevant to you. These still count toward your billable units, so you should filter them out. See Unwanted spans in Langfuse for details.

Missing attributes

Some attributes may be stored in the metadata object of the observation rather than being mapped to the Langfuse data model. If a mapping or integration does not work as expected, please raise an issue on GitHub.

Next Steps

Once you have instrumented your code, you can manage, evaluate and debug your application:

References


Was this page helpful?

Last edited