Skip to main content

Tracing

For usage examples, see Usage - Tracing.

TracingClient

Client for sending traces to the Mentiora platform.

Methods

sendTrace(event: TraceEvent): Promise<SendTraceResult>

Send a trace event to the platform (async only).

Parameters:

  • event: TraceEvent - The trace event to send

Returns: Promise<SendTraceResult>

Example:

const result = await client.tracing.sendTrace({
traceId: '019505a0-b7c2-7000-8000-000000000001', // UUID v7
spanId: '019505a0-b7c2-7000-8000-000000000002', // UUID v7
name: 'llm.call',
type: 'llm',
startTime: new Date(),
endTime: new Date(),
});

flush(): Promise<void>

Currently a no-op reserved for future batching support. Safe to include in shutdown handlers for forward compatibility.

Returns: Promise<void>

Example:

await client.tracing.flush();

Types

TraceEvent

interface UsageInfo {
prompt_tokens?: number;
completion_tokens?: number;
total_tokens?: number;
}

interface TraceEvent {
traceId: string; // Unique trace ID (UUID v7 format)
spanId: string; // Unique span ID (UUID v7 format)
parentSpanId?: string; // Parent span for nesting (UUID v7 format)
threadId?: string; // Optional. If omitted, the SDK sets it to a new UUID v7 before sending.
name: string; // Span name, e.g., 'llm.call', 'tool.execute'
type: 'llm' | 'tool' | 'chat' | 'error' | 'custom';
input?: unknown; // Prompt, tool input, etc.
output?: unknown; // Response, tool result
startTime: Date | string; // ISO 8601 timestamp
endTime?: Date | string;
durationMs?: number;
metadata?: Record<string, unknown>;
tags?: string[];
error?: TraceError; // Error details (when type === 'error')
usage?: UsageInfo; // Token usage (LLM-specific)
model?: string; // Model name (e.g., 'gpt-4', 'claude-3')
provider?: string; // Provider name (e.g., 'openai', 'anthropic')
}

Note: traceId/trace_id and spanId/span_id must be in UUID v7 format. The plugins automatically generate UUID v7 IDs.

Serialization

model_dump_for_api() (Python only)

Serialize the trace event for the Mentiora API. Handles datetime conversion to ISO 8601 strings and uses camelCase field names as expected by the backend.

event = TraceEvent(...)
payload = event.model_dump_for_api()
# Returns dict with camelCase keys: {'traceId': '...', 'spanId': '...', ...}

TraceError

interface TraceError {
message: string;
type?: string;
stack?: string;
}

SendTraceResult

interface SendTraceResult {
success: boolean;
traceId: string;
spanId: string;
error?: string;
}

TraceType

type TraceType = 'llm' | 'tool' | 'chat' | 'error' | 'custom';

See also: Client | Errors | Plugins