events property
Broadcast stream of connection-lifecycle events emitted by the runtime (connection lost, worker recovered, pool resized, etc.).
Events are best-effort observability signals — listeners do not
block emission, and the stream keeps working even if no listener
is attached. Pattern-match on the sealed OdbcEvent variants to
stay forward-compatible.
Example — wire events to a logger and Prometheus-style metrics:
service.events.listen((e) {
switch (e) {
case ConnectionLost(:final connectionId, :final reason):
log.warning('connection lost: $connectionId — ${reason.message}');
case AutoReconnectAttempted(:final attempt, :final maxAttempts):
metrics.counter('odbc.reconnect.attempts').inc();
log.info('reconnect $attempt/$maxAttempts');
case WorkerRecovered():
metrics.counter('odbc.worker.recovered').inc();
case PoolResize(:final poolId, :final newSize):
metrics.gauge(
'odbc.pool.size',
newSize,
labels: {'poolId': '$poolId'},
);
case SlowQueryDetected(:final durationMs, :final sql):
log.warning(
'slow query (${durationMs}ms): ${sql.substring(0, 60)}',
);
}
});
Implementation
@override
Stream<OdbcEvent> get events => _eventsController.stream;