One agent execution = one trace. Wrap the run in a single root span so every model and tool call nests under it. See the trace contract.
Mastra traces render fully in Lemma today. Automated issue detection is being expanded to this shape — see Good trace vs bad trace for current status.
Recipe
Register the Langfuse → Lemma exporter
Register the exporter once, before any agent runs. This matches Setup.Set the environment variables. Lemma-only export needs no
LANGFUSE_* credentials.Enable Mastra telemetry
Turn on Mastra’s OpenTelemetry telemetry so model and tool activity is emitted as spans into the provider you registered. See the Langfuse Mastra guide for configuration details.
Wrap the whole run in one root span
Wrap The spans Mastra emits inside the callback become children of the root, producing one nested trace:
agent.generate in a single root span so every model and tool call nests under one trace. Record the input and final output on the root, and set a stable agent name.Verify in Lemma
Open the Lemma dashboard → Traces and confirm:- One trace per run — a full agent run is one trace, not one per model call.
- Root has input and output — the root span shows the user message and the final response.
- Generations are nested — each model call appears as a child generation with model and token usage.
- Tools are nested — each tool invocation appears as a child tool span with arguments and result.
Next steps
Trace contract
The exact shape Lemma reads.
Setup
Wire the Langfuse → Lemma exporter.
Threads and sessions
Group multi-turn conversations with a thread id.
Good vs bad traces
What issue detection looks for, per shape.