symfonic.infra.trace¶
trace ¶
TraceStoreProtocol -- abstract interface for execution trace persistence.
The library depends only on this protocol. Concrete adapters (PostgreSQL, Redis, etc.) live in the application layer. InMemoryTraceStore is the default implementation using a bounded deque.
ExecutionTrace
dataclass
¶
ExecutionTrace(
run_id: str,
source: str = "chat",
start_time: float = time.monotonic(),
events: list[TraceEvent] = list(),
)
InMemoryTraceStore ¶
Default trace store using an in-memory bounded deque.
Suitable for development and single-process deployments. Data is lost on restart. For production, inject a PostgresTraceStore or similar adapter that satisfies TraceStoreProtocol.
Source code in src/symfonic/infra/trace.py
finish_trace ¶
Append a done event and move the trace to completed storage.
Source code in src/symfonic/infra/trace.py
get_trace ¶
latest ¶
start_trace ¶
Create a new active trace and return it.
Source code in src/symfonic/infra/trace.py
TraceEvent
dataclass
¶
Single event in an execution trace.
TraceStoreProtocol ¶
Bases: Protocol
Abstract interface for execution trace storage.
All concrete adapters (in-memory, PostgreSQL, Redis, …) must satisfy this structural protocol. The library never imports a concrete class.
finish_trace ¶
Mark a trace as complete and move it from active to storage.
A "done" event is appended before archiving. Calling with an unknown run_id is a no-op.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_id
|
str
|
Identifier of the trace to finish. |
required |
Source code in src/symfonic/infra/trace.py
get_trace ¶
Return an active (in-progress) trace, or None if not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_id
|
str
|
Identifier to look up. |
required |
latest ¶
Return the most recent completed traces as plain dicts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int
|
Maximum number of traces to return. |
10
|
start_trace ¶
Begin tracking a new execution trace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_id
|
str
|
Unique identifier for this execution run. |
required |
source
|
str
|
Label for the caller type (e.g. "chat", "stream", "worker"). |
'chat'
|
Returns:
| Type | Description |
|---|---|
ExecutionTrace
|
The newly created ExecutionTrace with an initial "start" event. |