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

# Mastra traces

> Send Mastra observability traces to EvalGate with an exporter.

# Mastra traces

`@evalgate/sdk/integrations/mastra` provides an exporter for
[Mastra observability](https://mastra.ai/docs/observability/tracing/overview).
Add it to your observability configuration next to any exporter you already
use.

```ts theme={null} theme={null}
import { Mastra } from "@mastra/core";
import { Observability } from "@mastra/observability";
import { EvalGateMastraExporter } from "@evalgate/sdk/integrations/mastra";

export const mastra = new Mastra({
  observability: new Observability({
    configs: {
      evalgate: {
        serviceName: "my-app",
        exporters: [new EvalGateMastraExporter()],
      },
    },
  }),
});
```

The exporter reads `EVALGATE_API_KEY` (a key with `traces:write`) unless you
pass `apiKey`.

## What is sent

The exporter keeps ended spans and sends a trace to `/api/otel/v1/traces`
when its root span ends. It sends the span name, type, timing and parent link,
and:

| Span type | Attributes |
| - | - |
| `agent_run` | `gen_ai.operation.name` `invoke_agent`, `gen_ai.agent.name` |
| `model_generation` | `gen_ai.operation.name` `chat`, `gen_ai.request.model`, `gen_ai.provider.name`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens` |
| `model_step`, `model_inference` | Model and provider; token counts under `mastra.usage.*`, because the generation already holds the total |
| `tool_call`, `mcp_tool_call` | `gen_ai.operation.name` `execute_tool`, `gen_ai.tool.name`, `gen_ai.tool.call.success` |
| `workflow_run` | `gen_ai.operation.name` `invoke_workflow` |

Prompts, instructions, inputs, outputs, tool payloads and error messages are
never sent. A token count Mastra did not report is left out, not sent as zero.

Mastra's own OpenTelemetry exporter also works: send its spans to
`/api/otel/v1/traces`, or use a [collector](/docs/integrations/traces/fan-out.md).

## Status

Tested against the `ObservabilityExporter` interface of `@mastra/core` 1.83.0
with fixture spans. No live run has been recorded yet, so the adapter is
`fixture_qualified` in [Integration adapters](/docs/guides/integration-adapters.md).


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