This tutorial shows how to set up Keywords AI tracing with Mastro to monitor and trace your AI-powered applications.

We have built a pre-built example for you to get started quickly. You can find the code here.

Here’s the tutorial about the Mastra Weather Agent example.

Setup

1. Install Dependencies

pnpm install

2. Environment Variables

Copy the example environment file and add your API keys:

cp .env.local.example .env.local

Update .env.local with your credentials:

.env.local
OPENAI_API_KEY=your-openai-api-key
KEYWORDSAI_API_KEY=your-keywordsai-api-key
KEYWORDSAI_BASE_URL=https://api.keywordsai.co

3. Run the Project

mastra dev

This opens the Mastra playground where you can interact with the weather agent.

Observability

The project is configured with KeywordsAI telemetry in src/mastra/index.ts:

telemetry: {
  serviceName: "keywordai-mastra-example",
  enabled: true,
  export: {
    type: "custom",
    exporter: new KeywordsAIExporter({
      apiKey: process.env.KEYWORDSAI_API_KEY,
      baseUrl: process.env.KEYWORDSAI_BASE_URL,
      debug: true,
    })
  }
}