Observability & Resilience API
Observability
maticlib.observability.trace.StepTrace
Bases: BaseModel
Captures observability data for a single pipeline step.
Attributes:
| Name | Type | Description |
|---|---|---|
step_id |
str
|
Unique identifier for the step. |
step_name |
str
|
Human-readable name of the step. |
start_time |
float
|
Unix timestamp when the step started. |
end_time |
Optional[float]
|
Unix timestamp when the step ended (or None if still running). |
inputs |
Dict[str, Any]
|
Arbitrary input data associated with the step. |
outputs |
Dict[str, Any]
|
Arbitrary output data associated with the step. |
error |
Optional[str]
|
Error message if the step failed. |
prompt_tokens |
int
|
Number of input/prompt tokens consumed. |
completion_tokens |
int
|
Number of completion tokens generated. |
total_tokens |
int
|
Total tokens used (prompt + completion). |
model_name |
Optional[str]
|
LLM or embedding model name used in this step. |
maticlib.observability.trace.PipelineTrace
Bases: BaseModel
Container that aggregates StepTrace records for a full pipeline execution.
Attributes:
| Name | Type | Description |
|---|---|---|
trace_id |
str
|
Unique identifier for this pipeline trace. |
pipeline_name |
str
|
Human-readable name for the pipeline. |
start_time |
float
|
Unix timestamp when the pipeline started. |
end_time |
Optional[float]
|
Unix timestamp when the pipeline ended (or None if still running). |
steps |
List[StepTrace]
|
Ordered list of StepTrace records. |
metadata |
Dict[str, Any]
|
Arbitrary metadata associated with this pipeline run. |
add_step
Appends a completed StepTrace to the pipeline trace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
StepTrace
|
A finished StepTrace to record. |
required |
maticlib.observability.callbacks.BaseCallbackHandler
Bases: ABC
Abstract base class for pipeline event callbacks.
on_pipeline_end
abstractmethod
Called when a pipeline completes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trace
|
PipelineTrace
|
The finished PipelineTrace. |
required |
on_pipeline_start
abstractmethod
Called when a pipeline starts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trace
|
PipelineTrace
|
The PipelineTrace for the starting pipeline. |
required |
on_step_end
abstractmethod
Called when a pipeline step ends.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
StepTrace
|
The completed StepTrace. |
required |
on_step_start
abstractmethod
Called when a pipeline step begins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
StepTrace
|
The StepTrace for the starting step. |
required |
maticlib.observability.callbacks.LoggingCallbackHandler
Bases: BaseCallbackHandler
A callback handler that logs pipeline and step events via Python's logging module.
Initializes the LoggingCallbackHandler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
Logger
|
An optional Python Logger. Defaults to the module logger. |
None
|
Source code in maticlib/observability/callbacks.py
Resilience
maticlib.resilience.retry.RetryPolicy
RetryPolicy(
max_retries=3,
backoff_factor=2.0,
initial_delay=1.0,
exceptions=(Exception,),
logger=None,
)
Configurable retry policy with exponential backoff.
Initializes the RetryPolicy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_retries
|
int
|
Maximum number of retry attempts before raising. |
3
|
backoff_factor
|
float
|
Multiplier applied to the delay after each failed attempt. |
2.0
|
initial_delay
|
float
|
Initial delay in seconds before the first retry. |
1.0
|
exceptions
|
Tuple[Type[Exception], ...]
|
Tuple of exception types to catch and retry on. |
(Exception,)
|
logger
|
Logger
|
Optional Python Logger. Defaults to the module logger. |
None
|
Source code in maticlib/resilience/retry.py
execute
Executes a callable with the retry policy applied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[..., Any]
|
The callable function to execute with retries. |
required |
*args
|
Any
|
Positional arguments forwarded to |
()
|
**kwargs
|
Any
|
Keyword arguments forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The return value of |
Raises:
| Type | Description |
|---|---|
RetryExhaustedError
|
When all retry attempts have failed. |
Source code in maticlib/resilience/retry.py
maticlib.resilience.retry.with_retry
Decorator to apply a retry policy to any function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_retries
|
int
|
Maximum number of retry attempts. |
3
|
backoff_factor
|
float
|
Multiplier applied to the delay after each failure. |
2.0
|
initial_delay
|
float
|
Initial delay in seconds before the first retry. |
1.0
|
exceptions
|
Tuple[Type[Exception], ...]
|
Tuple of exception types to catch and retry on. |
(Exception,)
|
Returns:
| Type | Description |
|---|---|
Callable[[Callable[..., Any]], Callable[..., Any]]
|
A decorator that wraps the target function with the retry policy. |