Musterby Elitery
Integrations

Mastra

Trace Mastra TypeScript agents in Muster via the @mastra/langfuse exporter.

Mastra is a TypeScript agent framework offering memory, tool-calling, deterministic workflows, and RAG primitives. Muster captures Mastra agent runs through the @mastra/langfuse exporter.

Setup

1. Create a Mastra project

npx create-mastra

2. Configure credentials

Add to your .env:

LANGFUSE_PUBLIC_KEY="pk-lf-..."
LANGFUSE_SECRET_KEY="sk-lf-..."
LANGFUSE_BASEURL="https://app.getmuster.io"
OPENAI_API_KEY="sk-..."

3. Install the exporter

npm install @mastra/langfuse

4. Define an agent

// src/mastra/agents/chefAgent.ts
import { openai } from "@ai-sdk/openai";
import { Agent } from "@mastra/core/agent";

export const chefAgent = new Agent({
  name: "chefAgent",
  instructions: "You are a Michelin star chef. Suggest a recipe based on available ingredients.",
  model: openai("gpt-4o-mini"),
});

5. Register the agent and configure the Muster exporter

// src/mastra/index.ts
import { Mastra } from "@mastra/core";
import { LangfuseExporter } from "@mastra/langfuse";
import { chefAgent } from "./agents/chefAgent";

export const mastra = new Mastra({
  agents: { chefAgent },
  telemetry: {
    serviceName: "ai",
    enabled: true,
    export: {
      type: "custom",
      exporter: new LangfuseExporter({
        publicKey: process.env.LANGFUSE_PUBLIC_KEY!,
        secretKey: process.env.LANGFUSE_SECRET_KEY!,
        baseUrl: process.env.LANGFUSE_BASEURL,
      }),
    },
  },
});

6. Run the dev server

npm run dev

Every agent invocation produces a trace in Muster.

Configuration Modes

The exporter supports two modes:

  • Realtime (development): flush after each event with realtime: true.
  • Batch (production, default): buffer and send in batches.

Additional options: baseUrl, logLevel, environment, version, release.

Troubleshooting

See also