Setup guides · TypeScript
Mastra
Mastra traces its agent runs itself. The SDK hands Mastra's exporter nomi's own span exporter, joins each Mastra run to the scope around it and is told when Mastra aborts a run. The range is one minor version, and each run's options go through runOptions().
Your coding agent can do the attaching. Ask it:
It finds the places to hook in and asks you the few things only you know. The steps below are what it does.
Start nomi
nomi is one program, nomi.
Download it from the releases page, then:
nomi init
nomi configure -mode sdk -source my-agent -receiver-listen 127.0.0.1:4320
nomi start # leave this running
nomi browser -home "$HOME/.nomi" # opens the run view Everything it records lives in ~/.nomi; -home on any command chooses another folder. nomi doctor says whether it's healthy.
Install the TypeScript SDK (runnomi-sdk 1.0.0) into your agent from the release's packed file. It isn't on npm, so keep the whole address. Then tell it where nomi is:
cd /path/to/your/agent
npm install https://github.com/joshbodunrin/nomi/releases/download/v1.0.0/runnomi-sdk-1.0.0.tgz
export MYAGENT_NOMI_ENABLED=1
export MYAGENT_NOMI_ENDPOINT=http://127.0.0.1:4320
export MYAGENT_NOMI_TOKEN_FILE="$HOME/.nomi/write-token" npm records that address in package.json and the lockfile, so another machine or CI installs the same file. This was checked with npm 10.9.2 from a packed file on disk, from ES module and CommonJS applications; pnpm, yarn and bun weren't.
The SDK has no runtime dependencies and works from ES modules and CommonJS. The settings are read by Observer.fromEnv with prefix: "MYAGENT_NOMI"; the SDK reads the token file itself, so the token is never on a command line. Events are held in memory and sent in the background: what can't be delivered is counted and reported as lost. To keep events on disk through an outage or a restart, set MYAGENT_NOMI_SPOOL_DIR and MYAGENT_NOMI_SOURCE.
These are the same-machine settings. Your agent can also run in a container or on another machine of yours and send to the same nomi: where nomi runs has what changes, and the attach skill can set it up.
nomi never changes how your agent runs: if it’s off, down or hanging, your agent carries on with the same output.
Check your versions
import { mastraSupport } from "runnomi-sdk/integrations/mastra";
console.log(mastraSupport());
The range is @mastra/core 1.85 up to (not including) 1.86, with @mastra/otel-exporter 1.6 up to 1.7, on Node 22.13 or later; pre-releases aren’t accepted. It is one minor version on purpose: Mastra releases about twice a week and what its spans say has changed between releases, so each release is tested before the range moves.
Outside the range, exporterConfig returns null and logs one nomi: Mastra adapter off line; your agent runs as usual, and scopes and declarations are still recorded. exporterConfig(observer, { strict: true }) throws instead. Don’t downgrade your app’s packages to fit.
Attach
Nothing in Mastra or the provider client is wrapped or patched. Beside @mastra/core, install @mastra/observability and @mastra/otel-exporter (in the range above). No OTLP exporter package is needed: nomi’s client sends the spans.
npm install @mastra/observability @mastra/otel-exporter
An app that only has @mastra/core gains both (and what npm installs with them). Beside @mastra/core 1.85.0, that command chose the tested 1.24.2 and 1.6.1 on 2026-11-24. Add --save-exact when your app pins exact versions. Until @mastra/otel-exporter is installed, mastraSupport() shows it as null and unsupported; check again afterwards. If @mastra/core itself is outside the range, don’t add these packages for nomi.
-
Create the observer once, where your app starts, and give Mastra’s own exporter its settings:
import { Mastra } from "@mastra/core/mastra"; import { Observability } from "@mastra/observability"; import { OtelExporter } from "@mastra/otel-exporter"; import { Observer } from "runnomi-sdk"; import { exporterConfig, runOptions, within } from "runnomi-sdk/integrations/mastra"; const observer = Observer.fromEnv("my-agent", { project: "my-repo", agent: "my-agent", prefix: "MYAGENT_NOMI" }); const nomi = exporterConfig(observer); export const mastra = new Mastra({ agents: { support }, ...(nomi && { observability: new Observability({ configs: { nomi: { serviceName: "my-agent", exporters: [new OtelExporter(nomi)] } }, }), }), });exporterConfigreturns nomi’s own span exporter forOtelExporterto hand its spans to: they are queued on the observer’s client and sent by it, so Mastra’s flush never waits on nomi. It holds no token (the token stays in the observer’s client; nothing goes in the repository or inOTEL_*variables). Pass it toOtelExporteras it is, with noheadersortimeoutadded. It isnullwhen nomi is off or Mastra is outside the range;Observabilityrejects a config with no exporter, so build one for nomi only when it isn’tnull. An app that already has anObservabilityconfig addsnew OtelExporter(nomi)to itsexporters. -
Wrap each unit of work, and pass each run’s options through
runOptions(...):const reply = await observer.observe("support_turn", { workflow: "support", group: conversation.id, step: "reply" }, () => mastra.getAgent("support").generate(message, runOptions({ abortSignal: signal, memory })), );Use
runOptions()when the run has no options. It returns your options with two added.tracingOptionsjoins the run to the scope (your owntracingOptionsstay and are kept); without it, the Mastra run is recorded as a separate run from the scope, with no group.onAbortis Mastra’s documented callback: Mastra returns normally from an aborted or timed-out run, and with it the run is recorded as cancelled, or as failed withTimeoutErrorwhen theabortSignalwasAbortSignal.timeout, also when no scope is open around the run. It also sets Mastra’s documentedrunIdwhen you gave none. Put your ownabortSignalandonAbortinsiderunOptions(...), never after it; youronAbortis still called, and whatgeneratereturns doesn’t change. Foragent.stream, read the stream inside the scope. In TypeScript an option that is one of a few fixed strings needsas constinsiderunOptions, or sits beside it with nomi’s spread last:{ toolChoice: "auto", ...runOptions({ abortSignal: signal }) }. Mastra documents the same options for workflow runs; those weren’t tested. With themetadataprofile it also sets Mastra’shideInputandhideOutput, so prompts, replies and tool arguments and results don’t leave the process.An app attached the earlier way changes
tracingOptions: tracingOptions()torunOptions({...})around the whole options object, and can drop thesignal.throwIfAborted()it added for nomi and@opentelemetry/exporter-trace-otlp-proto. -
Inside a Mastra tool, wrap the body in
within(context, fn), so a declaration made in it sits under Mastra’s span for that tool call:execute: (input, context) => within(context, () => observer.tool("refund", { arguments: input, actionId: `refund:${input.order_id}` }, async (call) => { const refund = await backoffice.refund(input); call.effect("committed", refund.id); return refund; })),Without
within, the declaration is still in the run, under the scope aroundgenerate. -
Before the process ends, and in a serverless handler before returning, flush Mastra’s spans and then close, in that order. Without the flush, Mastra’s spans aren’t delivered:
if (nomi) await mastra.observability.flush(); await observer.close();Mastra hands its spans to nomi’s client in batches, every 5 seconds or when flushed, and the close sends them. Spans handed over after the close aren’t sent, and one
nomi:line says so.mastra.shutdown()also hands them over, and prints one extra line of Mastra’s own on stdout.
Don’t wrap what the spans already record (no observer.anthropic around the model call, no observer.tool around the Mastra tool itself), and don’t also set OTEL_EXPORTER_OTLP_ENDPOINT to nomi for a second exporter of the same spans.
Recorded automatically
- Model calls: provider, requested and returned model, input, output and cache-read tokens, the finish reason as Mastra reports it, and prompts and replies unless hidden. The same for streamed runs.
- Mastra’s own retries of a failed model call (twice, seconds apart): each attempt is a failed model call of its own, with the message.
- Tool calls: name, the provider’s tool-call ID, arguments and result unless hidden, duration, and an error with its message when the tool throws.
- The agent run and its structure: the scope, the agent run, Mastra’s loop and its steps, and in each step the model call and the tool calls it asked for.
- Success: Mastra ends a span OK or with an error, so steps are reported as succeeded or failed, not unspecified.
- Mastra’s memory thread as the conversation ID on every span of the run.
- From the scope: the run’s outcome, the class and HTTP status of an error the run threw, its code location, and the commit that ran.
Declared by your code
The scope around each unit of work with its workflow, group and step (the group is what joins a conversation’s turns), decisions (results and issues), effects and logical actions, expected exceptions and waits. No span provides them.
What it can’t see
- An aborted or timed-out run whose options didn’t go through
runOptions(): Mastra ends every span OK, so the run is stored as a success. - A tool call cut short by an abort, unless its body is inside
within(context, fn): it reads as succeeded, which is what Mastra reports. - A killed process’s spans: they were still in the process. With a scope around the run it shows as not finished; without one, nothing is recorded.
- Spans Mastra hadn’t handed over when the process ended (it batches them for up to 5 seconds): they aren’t counted anywhere.
- The code location of a model or tool step. The scope has its own.
- The error class and HTTP status of a failed model call, and the class of a tool’s error: Mastra’s spans carry the message only. The scope has what your code caught.
- The requested output cap and the provider’s response ID: they aren’t on Mastra’s spans.
- Retries inside the provider client: shown as unknown on every model call.
Limits and edge cases
- With the
metadataprofile, Mastra still exports the agent’s system instructions and tool descriptions. A home set to omit content drops them before anything is stored. - A tool error is handed back to the model and the run goes on: the tool step is failed, the run is not.
- Only the Anthropic provider was run. Workflows, networks, scorers, voice, MCP tools and long-running servers weren’t tested.
When nomi is down
Your agent’s output, exit code and requests to the provider are the same with nomi up, down, never answering, answering 500 or refusing the token. What isn’t delivered is counted and said once on stderr. With durable delivery on (NOMI_SPOOL_DIR), the SDK keeps its events on disk and sends them when nomi is back.
Mastra’s spans are counted in that line with the scope events, and Mastra’s flush doesn’t wait on nomi.
Connect your coding agent
nomi includes a server with read-only tools for your coding agent, and a debug skill that teaches it to keep what was observed, what your code declared and what is unknown apart. Pick yours:
Claude Code
claude mcp add nomi -s user -- nomi mcp
mkdir -p ~/.claude/skills && cp -R skills/debug-agent-with-nomi ~/.claude/skills/ Codex
codex mcp add nomi -- nomi mcp
mkdir -p ~/.codex/skills && cp -R skills/debug-agent-with-nomi ~/.codex/skills/ Cursor, in ~/.cursor/mcp.json (or .cursor/mcp.json for one project)
{"mcpServers": {"nomi": {"type": "stdio", "command": "nomi", "args": ["mcp"]}}} Cursor's debug skill (the skill needs Cursor 2.4 or later)
mkdir -p ~/.cursor/skills && cp -R skills/debug-agent-with-nomi ~/.cursor/skills/ Cursor also reads skills from ~/.claude/skills/, so if the skills are already installed for Claude Code, nothing needs copying.
Then open a session in your agent's repository and ask, for example:
- “What went wrong in my agent's last few runs?”
- “Why did this run fail?”
- “What changed between these two runs?”