Send Mastra Traces to KloudMate
Mastra traces its own agent runs, model calls, tool calls, and workflows. Add its OpenTelemetry exporter and point it at KloudMate to see every run in AI Observability with its model, tokens, estimated cost, and errors.
Prerequisites
Section titled “Prerequisites”- A KloudMate API key, from Settings → Ingest Keys.
- Mastra 1.x (
@mastra/core) on Node.js 22.13 or later.
Install the packages
Section titled “Install the packages”Add the exporter
Section titled “Add the exporter”Add an Observability config with an OtelExporter to your Mastra instance:
The Mastra exporter doesn’t read the OTEL_EXPORTER_OTLP_* variables, so the endpoint and header go in the config. Use the full traces URL, ending in /v1/traces. KloudMate expects the raw API key in the Authorization header, with no Bearer prefix.
If the KloudMate agent runs on the same machine, set the endpoint to http://localhost:4318/v1/traces and leave out headers.
In a short-lived script or a serverless function, call await mastra.observability.flush() before the process exits, so the last spans are sent.
Group a conversation
Section titled “Group a conversation”Pass a memory thread when you call the agent. KloudMate uses the thread ID as the conversation ID, so the turns of one conversation are grouped together:
stream() takes the same memory option. Configure a Memory on the agent if you also want Mastra to keep the conversation history.
Control what’s captured
Section titled “Control what’s captured”Mastra records prompts and responses by default, and its sensitive-data filter redacts fields such as passwords, tokens, and API keys before export. To leave the input or output out of a single call, pass tracingOptions:
Check the data
Section titled “Check the data”Run the agent once, then open AI Observability → Traces. The run appears as a turn named after the agent, with its model, steps, tokens, and estimated cost.