Record a completed span
- TypeScript
- Python
Measure a live span
UsestartSpan() / start_span() when you want the SDK to measure duration:
- TypeScript
- Python
- TypeScript
- Python
durationMs / duration_ms on trace.recordSpan(...) / trace.record_span(...), trace.recordGeneration(...) / trace.record_generation(...), trace.recordTool(...) / trace.record_tool(...), or span end(...) when you already measured the operation. If you omit child duration, Lemma splits the parent span’s remaining unclaimed duration equally across siblings that also omitted duration. For handle spans, duration is only finalized when the handle ends.
The same handle pattern exists for typed children: use trace.startTool(...) / trace.start_tool(...) for live tool calls and trace.startGeneration(...) / trace.start_generation(...) for live model calls.
Pass contract fields as native props such as embeddingModelName and rerankerOutputDocuments. The full supported list is in Native contract props. Use attributes only when you need to send raw span attributes that do not yet have a native SDK prop.
Attach by trace ID
If a helper receives only IDs, create the span from the client. This detached helper API is TypeScript-specific:traceId is required for detached spans. When the detached span has a parent, use parentSpanId; missing IDs warn and no-op.
Nesting spans
Spans, generations, and tools recorded duringlemma.trace() become children of that trace. Calls made on a span handle become children of that span.
Next steps
Threads & context
Group conversations and attach users.
Trace contract
The exact shape Lemma reads.