Instrumentation¶
psycache has pluggable instrumentation for observability.
Pass one or more providers to the instrumentations parameter of PostgresCache (or AsyncPostgresCache) and every cache operation is reported to them:
from sqlalchemy import create_engine
from psycache import PostgresCache
from psycache.instrumentation.prometheus import PrometheusInstrumentation
from psycache.instrumentation.sentry import SentryInstrumentation
from psycache.sqlalchemy import SQLAlchemyCachePool
engine = create_engine("postgresql+psycopg://psycache@127.0.0.1/psycache")
cache = PostgresCache(
SQLAlchemyCachePool(engine),
instrumentations=(
SentryInstrumentation(),
PrometheusInstrumentation(),
),
)
engine.dispose()
Two providers ship with psycache:
- Prometheus: counters, histograms, and gauges for metrics scraping.
- Sentry: cache spans for distributed tracing.
You can also write your own; see Custom Instrumentation.