Skip to main content
  1. Sign up — Create an account at platform.respan.ai
  2. Create an API key — Generate one on the API keys page
  3. Add credits or a provider key — Add credits on the Credits page or connect your own provider key on the Integrations page

What is Mastra?

Mastra is a TypeScript framework for building AI agents and workflows. This guide shows how to set up Respan tracing with Mastra to monitor your AI-powered applications.

Setup

1

Install dependencies

pnpm install
2

Set environment variables

.env.local
OPENAI_API_KEY=your-openai-api-key
RESPAN_API_KEY=your-respan-api-key
RESPAN_BASE_URL=https://api.respan.ai
3

Configure Mastra with Respan telemetry

In your Mastra config (e.g. src/mastra/index.ts), set the telemetry export to use the Respan exporter:
src/mastra/index.ts
import { RespanExporter } from "@respan/exporter-vercel";

// Inside your Mastra config
telemetry: {
  serviceName: "respan-mastra-example",
  enabled: true,
  export: {
    type: "custom",
    exporter: new RespanExporter({
      apiKey: process.env.RESPAN_API_KEY,
      baseUrl: process.env.RESPAN_BASE_URL,
      debug: true,
    })
  }
}
4

Run the project

mastra dev
This opens the Mastra playground where you can interact with the agent.
5

View your trace

Open the Traces page in the Respan dashboard.

Observability

With this integration, Respan auto-captures:
  • Agent runs — each agent execution as a span
  • LLM calls — model, input/output messages, token usage
  • Performance metrics — latency per step
  • Errors — failed runs and error details
View traces on the Traces page.