Prometheus#

Prometheus metrics extension for SQLSpec. Provides a statement observer and configuration helpers that record SQL execution counts, duration histograms, and row count histograms.

Configuration#

Use sqlspec.config.PrometheusConfig in extension_config["prometheus"]. These settings apply across adapters; no adapter-specific subtype is needed.

class sqlspec.config.PrometheusConfig[source]

Bases: TypedDict

Configuration options for Prometheus metrics.

Use in extension_config["prometheus"].

enabled: NotRequired[bool]

True.

Type:

Enable the extension. Default

namespace: NotRequired[str]

"sqlspec".

Type:

Prometheus metric namespace. Default

subsystem: NotRequired[str]

"driver".

Type:

Prometheus metric subsystem. Default

registry: NotRequired[Any]

Custom Prometheus registry (defaults to the global registry).

label_names: NotRequired[tuple[str, ...]]

("driver", "operation").

Type:

Labels applied to metrics. Default

duration_buckets: NotRequired[tuple[float, ...]]

Histogram buckets for query duration (seconds).

Observer#

class sqlspec.extensions.prometheus.PrometheusStatementObserver[source]#

Bases: object

Statement observer that records Prometheus metrics.

__init__(*, namespace='sqlspec', subsystem='driver', registry=None, label_names=('db_system', 'operation'), duration_buckets=None)[source]#

Helpers#

sqlspec.extensions.prometheus.enable_metrics(*, base_config=None, namespace='sqlspec', subsystem='driver', registry=None, label_names=('db_system', 'operation'), duration_buckets=None)[source]#

Attach a Prometheus-backed statement observer to the provided config.

Return type:

ObservabilityConfig