symfonic.core.observability.mongo_metrics_store¶
mongo_metrics_store ¶
MongoMetricsStore — durable :class:MetricsStore on the llm_calls
collection (v8.8.0).
The MongoDB counterpart to :class:PostgresMetricsStore. Uses motor
(async, matching the async fan-out + reads) behind the existing
symfonic-core[mongodb] extra. The scaffold owns collection bootstrap by
calling :meth:ensure_indexes on startup (idempotent — Mongo is schemaless,
no migration). Retention is native: a TTL index on created_at expires
old documents automatically, so :meth:prune is an on-demand fallback.
Every read returns the same snapshot dict shape the collector emits, so the
scaffold's build_conversation_detail() + response models are reused
unchanged across backends.
MongoMetricsStore ¶
Durable :class:MetricsStore backed by a Mongo llm_calls collection.
Parameters¶
database_factory
Zero-arg callable returning a motor async database
(AsyncIOMotorDatabase). Kept as a factory (not a bound db) to
match PostgresMetricsStore's framework-agnostic wiring.
retention_days
TTL for the created_at index created by :meth:ensure_indexes.
Source code in src/symfonic/core/observability/mongo_metrics_store.py
ensure_indexes ¶
Create the read + TTL indexes (idempotent). Called on startup.
motor index creation is async, but startup wiring is sync
(mirrors the Postgres migration step), so this schedules the coro
on the running loop when there is one, else runs it to completion.
Source code in src/symfonic/core/observability/mongo_metrics_store.py
prune
async
¶
On-demand purge (the TTL index handles routine expiry).