Skip to main content
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

1

Install the exporter

npm install @mastra/observability @mastra/otel-exporter \
  @opentelemetry/exporter-trace-otlp-http
2

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.
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,
});
3

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.

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 automatically.

Next steps

OpenTelemetry

The endpoint, authentication, and GenAI conventions AgentMark reads

Traces and logs

Explore traces once they arrive

Have questions?

Reach out any time: