> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sazabi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Mastra

> Add Sazabi as a custom OTLP exporter in your Mastra observability config to stream agent traces directly to Sazabi.

[All Mastra integration capabilities](https://docs.sazabi.com/catalogs/integrations/mastra)

## About

Stream Mastra agent traces into Sazabi. Add Mastra's `OtelExporter` to your app's observability config and point it at a Sazabi endpoint. Mastra creates and batches spans for your agent runs, so traces flow to Sazabi without you setting up the OpenTelemetry SDK yourself.

## Prerequisites

* A Mastra application using `@mastra/core`. You also need `@mastra/otel-exporter` and `@mastra/observability`.
* Your Sazabi intake URL (shown above).

## Set up in the dashboard

**Step 1**

### Set the intake URL

Set `SAZABI_INTAKE_URL` to your intake URL (shown above) in the application that initializes Mastra. Mastra's custom OTLP exporter reads this environment variable.

```bash theme={"system"}
SAZABI_INTAKE_URL=<your intake URL>
```

**Step 2**

### Configure Mastra

Add Sazabi as a custom OTLP exporter in your Mastra observability config:

```typescript theme={"system"}
// src/mastra/index.ts
import { Mastra } from "@mastra/core";
import { OtelExporter } from "@mastra/otel-exporter";
import { Observability } from "@mastra/observability";

export const mastra = new Mastra({
  observability: new Observability({
    configs: {
      default: {
        serviceName: "my-mastra-app",
        exporters: [
          new OtelExporter({
            provider: {
              custom: {
                endpoint: process.env.SAZABI_INTAKE_URL,
                protocol: "http/json",
              },
            },
          }),
        ],
      },
    },
  }),
  // Add your agents, tools, and workflows here
});

// Use your Mastra instance
const agent = mastra.getAgent("my-agent");
const response = await agent.generate("Hello, world!");
```

**Step 3**

### Redeploy the service

Redeploy or restart the service so Mastra picks up the new observability configuration and the `SAZABI_INTAKE_URL` environment variable.

**Step 4**

### Hand off the change

Commit these changes on a new branch, push it, and open a pull request. Keep the intake URL and any keys in environment variables or a secret store, and commit only configuration that references them.

## Set up with the CLI

You can also register the Mastra log source with the [Sazabi CLI](https://docs.sazabi.com/reference/cli.md) (installed and authenticated — see [CLI reference](https://docs.sazabi.com/reference/cli/log-sources.md)).

Registering the source mints the same intake URL the dashboard shows above (the public key is embedded in its hostname):

```bash theme={"system"}
sazabi log-sources create mastra --mode manual
```

The command prints the intake URL for the new source — copy the whole URL and point your sender at it using the configuration shown above. Run `sazabi log-sources get <log-source-id>` at any time to reprint the endpoint, or `sazabi log-sources list` to see every log source in the project.

## Verify

Run a Mastra agent, tool, or workflow to generate a trace. Open the [Intake page](https://docs.sazabi.com/guides/instrument/intake.md) in the Sazabi dashboard and confirm traces from the **Mastra** source appear. Records typically arrive within a minute or two of the run.

## Troubleshooting

**No traces appear after running an agent** — Confirm `SAZABI_INTAKE_URL` is set in the process environment and that `new Observability({ configs: { default: { exporters: [...] } } })` is wired into the `Mastra` constructor. Check the application logs for exporter initialization errors.

**Spans have no agent or tool attributes** — The `OtelExporter` sends spans produced by Mastra's built-in instrumentation. If the agent definition is not registered with the Mastra instance, its runs produce no spans.

## Further reading

> [card] [Intake](https://docs.sazabi.com/guides/instrument/intake.md)
>
> See per-source ingestion volume and health in the Intake page.

> [card] [Instrument](https://docs.sazabi.com/guides/instrument.md)
>
> Learn how to send data to Sazabi.

> [card] [Log sources](https://docs.sazabi.com/catalogs/log-sources.md)
>
> Browse the full log source catalog.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.