Observers API Reference
ProcessorObserver
async_batch_llm.observers.ProcessorObserver
Bases: ABC
Abstract base class for processor event observers.
on_event
abstractmethod
async
Handle processor event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
ProcessingEvent
|
The event type |
required |
data
|
dict[str, Any]
|
Event-specific data |
required |
BaseObserver
async_batch_llm.observers.BaseObserver
Bases: ProcessorObserver
Base observer with no-op implementation.
MetricsObserver
async_batch_llm.observers.MetricsObserver
Bases: BaseObserver
Collect metrics for monitoring (thread-safe).
Initialize metrics collector.
Source code in src/async_batch_llm/observers/metrics.py
export_dict
async
Export metrics as a dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing all metrics and computed statistics |
Example
observer = MetricsObserver()
... process items ...
data = await observer.export_dict() print(data["success_rate"])
Source code in src/async_batch_llm/observers/metrics.py
export_json
async
Export metrics as JSON string.
Returns:
| Type | Description |
|---|---|
str
|
JSON string containing all metrics and computed statistics |
Example
observer = MetricsObserver()
... process items ...
json_str = await observer.export_json() print(json_str)
Source code in src/async_batch_llm/observers/metrics.py
export_prometheus
async
Export metrics in Prometheus text format.
Returns:
| Type | Description |
|---|---|
str
|
Prometheus-formatted metrics string |
Example
observer = MetricsObserver()
... process items ...
prom_text = await observer.export_prometheus() print(prom_text)
HELP async_batch_llm_items_processed Total items processed
TYPE async_batch_llm_items_processed counter
async_batch_llm_items_processed 100 ...
Source code in src/async_batch_llm/observers/metrics.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | |
get_metrics
async
Get collected metrics with computed statistics (thread-safe).
Source code in src/async_batch_llm/observers/metrics.py
on_event
async
Collect metrics from events (thread-safe).
Source code in src/async_batch_llm/observers/metrics.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
reset
async
Reset all metrics (thread-safe).
Async since v0.16: the reset acquires the same lock as
on_event, so counts from an in-flight event can no longer land
in the discarded pre-reset dict.