Enabling Debug Mode
- TypeScript
- Python
Code APIEnvironment variable
What Gets Logged
All output is prefixed with[LEMMA:trace-wrapper] or [LEMMA:processor] so you can filter it easily.
wrapAgent / wrap_agent
| Event | When it fires |
|---|---|
span started | A new root span is opened for a run, with agent name, run ID, and autoEndRoot value |
span ended via onComplete | onComplete / on_complete was called and ended the span (only when autoEndRoot: false) |
onComplete called but span not ended | onComplete was called but autoEndRoot is active or the span was already ended |
span auto-ended after fn returned | The wrapped function returned and the span was ended automatically |
span ended on error | An uncaught exception ended the span, with the error message |
RunBatchSpanProcessor
| Event | When it fires |
|---|---|
onStart: top-level run span | A new ai.agent.run root span was started, with span ID, run ID, and whether auto-end is on |
onStart: child span | A child span was started and attributed to a run |
onEnd: span ended | Any span ended, with span name, run ID, whether it’s the top-level span, and whether it was skipped for export |
onEnd: direct child ended | A direct child of a root span ended, with remaining child count |
onEnd: triggering auto-end of top-level span | All direct children finished and the root span is being auto-ended |
exporting batch | A batch of spans is being sent to the exporter, with run ID and span count |
force_flush called | forceFlush was called |
shutdown called | shutdown was called |
Example Output
Running a simple agent with debug mode enabled produces output like this:Common Issues
Run never appears in the dashboard
Symptom: Your agent runs successfully but no trace shows up. What to look for: Check whetherexporting batch appears in the logs. If it does, the spans were sent and the issue is likely downstream (network, API key, or ingestion). If it doesn’t, work backwards through these checks:
-
No
onStart: top-level run span—registerOTelwas never called, or was called after the agent ran. Make sureregisterOTelis called once at startup before any agent invocations. -
onStart: top-level run spanappears butexporting batchnever does — The root span was opened but the run batch never completed. This usually means the top-level span never ended:- With
autoEndRoot: true(the default): check thatspan auto-ended after fn returnedappears. If it doesn’t, the function may have thrown and the error path should showspan ended on error. - With
autoEndRoot: false: check thatspan ended via onCompleteappears. If it doesn’t,onCompletewas never called.
- With
-
exporting batchappears withspanCount: 1— Only the root span was exported and no child spans. Child spans from frameworks like the Vercel AI SDK or OpenAI Agents SDK won’t appear unless their instrumentation is registered. See the integrations.
Spans appear but the run doesn’t close
Symptom: You seeonStart lines for child spans, but exporting batch never fires and the run hangs open in the dashboard.
What to look for: Check the remainingChildren value on onEnd: direct child ended lines. If it never reaches 0, a child span that was opened never ended — commonly a streaming span left open if an error is swallowed mid-stream.
onEnd: triggering auto-end of top-level span line only fires once remainingChildren hits 0. If that line is missing, find the span that was started but never ended and ensure its lifecycle is closed (e.g. by awaiting the stream to completion or using a finally block).
Spans are started but not attributed to a run
Symptom: You seeonStart: child span but no matching onStart: top-level run span before it.
What to look for: The processor only attributes child spans to a run if it saw the parent run start first. This can happen if:
- The child span is created outside the
wrapAgentcontext (before or after the wrapped function executes) - The span’s parent context doesn’t trace back to an
ai.agent.runspan
skipped: true on a span
Symptom: A span appears in onEnd logs with skipped: true and is not included in the export batch.
What to look for: The processor skips spans from the next.js instrumentation scope to avoid noise from framework internals. If you’re seeing unexpected spans skipped, check the spanName in the log — the span may be emitted by Next.js middleware or routing and is intentionally excluded.
Checking Debug Mode State
- TypeScript
- Python
Debug mode is off by default and intended for local troubleshooting. It writes directly to stdout — avoid leaving it enabled in production.

