> ## Documentation Index
> Fetch the complete documentation index at: https://puzzlet-9ba7bb98.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Mastra

> Trace Mastra agents in AgentMark using Mastra's OpenTelemetry exporter.

[Mastra](https://github.com/mastra-ai/mastra) emits OpenTelemetry traces following the GenAI semantic conventions through its observability layer. The `@mastra/otel-exporter` package forwards those spans to any OTLP endpoint. Point it at AgentMark and agent runs, model calls, and tool calls arrive normalized. Mastra is a TypeScript framework.

## Setup

<Steps>
  <Step title="Install the exporter">
    ```bash theme={null}
    npm install @mastra/observability @mastra/otel-exporter \
      @opentelemetry/exporter-trace-otlp-http
    ```
  </Step>

  <Step title="Point the exporter at AgentMark">
    Add an `Observability` instance with the OTLP exporter to your Mastra app. Use your AgentMark API key and app id from project settings.

    ```typescript theme={null}
    import { Mastra } from "@mastra/core/mastra";
    import { Observability } from "@mastra/observability";
    import { OtelExporter } from "@mastra/otel-exporter";

    const observability = new Observability({
      configs: {
        otel: {
          serviceName: "my-app",
          exporters: [
            new OtelExporter({
              provider: {
                custom: {
                  endpoint: "https://api.agentmark.co/v1/traces",
                  protocol: "http/json",
                  headers: {
                    Authorization: process.env.AGENTMARK_API_KEY!, // raw key, no "Bearer" prefix
                    "X-Agentmark-App-Id": process.env.AGENTMARK_APP_ID!,
                  },
                },
              },
            }),
          ],
        },
      },
    });

    export const mastra = new Mastra({
      agents: { myAgent },
      observability,
    });
    ```
  </Step>

  <Step title="Run your agent">
    Run your Mastra agent as usual. Each agent run, model call, and tool call arrives in AgentMark as a span, grouped into a trace. See [Traces and logs](/observe/traces-and-logs).
  </Step>
</Steps>

## What AgentMark captures

Mastra's model spans use the OpenTelemetry GenAI conventions (model, token usage, input and output messages, and finish reason), which AgentMark maps onto its normalized trace fields, and token counts feed [cost tracking](/observe/cost-and-token-tracking) automatically.

## Next steps

<CardGroup cols={2}>
  <Card title="OpenTelemetry" icon="plug" href="/integrations/tracing/opentelemetry">
    The endpoint, authentication, and GenAI conventions AgentMark reads
  </Card>

  <Card title="Traces and logs" icon="list-tree" href="/observe/traces-and-logs">
    Explore traces once they arrive
  </Card>
</CardGroup>

<div className="mt-8 rounded-lg bg-blue-50 p-6 dark:bg-blue-900/30">
  <h3 className="font-semibold mb-3">Have questions?</h3>
  <p className="mb-4">Reach out any time:</p>

  <ul>
    <li>
      Email the team at <a href="mailto:hello@agentmark.co" className="text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-200">[hello@agentmark.co](mailto:hello@agentmark.co)</a> for support
    </li>

    <li>
      Schedule an <a href="https://cal.com/ryan-randall/enterprise" className="text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-200">Enterprise Demo</a> to learn about AgentMark's business solutions
    </li>
  </ul>
</div>
