lemma.trace(). Register the processor
once, then run OpenAI Agents normally.
TypeScript
Install both packages:LEMMA_API_KEY and LEMMA_PROJECT_ID:
Python
Install the Python extra:LEMMA_API_KEY and LEMMA_PROJECT_ID:
Root input, output, user, and thread
Both TypeScript and Python processors promote the same root fields on the Lemma trace:
Soft tool failures (
isError / is_error / Mastra error: true) mark the tool
span as ERROR without failing the root when a later generation succeeds.
Flush and shutdown
CallforceFlush() / force_flush() (or shutdown()) to send any still-open
traces exactly once. A later onTraceEnd / on_trace_end for a flushed trace is
a no-op, so spans are never duplicated in the append-only ingest store.
What Lemma records
OpenAI Agents trace
group_id is recorded as the Lemma thread id, so runs in
the same conversation stay grouped.
Privacy
The integration always records prompts, tool inputs, tool outputs, model output, and error messages — a trace cannot show what a run produced or why it failed without them. Redact secrets and sensitive user data before they reach the agent.Debugging
Use debug mode to confirm spans are arriving live and nested under the expected parent:span started and span ended logs. Tool/function spans should include
the generation or agent span ID as parentId in TypeScript or parent_id in
Python.