Gated by DECNET_DEVELOPER_TRACING env var (default off, zero overhead). When enabled, traces flow through FastAPI routes, background workers (collector, ingester, profiler, sniffer, prober), engine/mutator operations, and all DB calls via TracedRepository proxy. Includes Jaeger docker-compose for local dev and 18 unit tests.
34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
"""
|
|
Repository factory — selects a :class:`BaseRepository` implementation based on
|
|
``DECNET_DB_TYPE`` (``sqlite`` or ``mysql``).
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from typing import Any
|
|
|
|
from decnet.web.db.repository import BaseRepository
|
|
|
|
|
|
def get_repository(**kwargs: Any) -> BaseRepository:
|
|
"""Instantiate the repository implementation selected by ``DECNET_DB_TYPE``.
|
|
|
|
Keyword arguments are forwarded to the concrete implementation:
|
|
|
|
* SQLite accepts ``db_path``.
|
|
* MySQL accepts ``url`` and engine tuning knobs (``pool_size``, …).
|
|
"""
|
|
db_type = os.environ.get("DECNET_DB_TYPE", "sqlite").lower()
|
|
|
|
if db_type == "sqlite":
|
|
from decnet.web.db.sqlite.repository import SQLiteRepository
|
|
repo = SQLiteRepository(**kwargs)
|
|
elif db_type == "mysql":
|
|
from decnet.web.db.mysql.repository import MySQLRepository
|
|
repo = MySQLRepository(**kwargs)
|
|
else:
|
|
raise ValueError(f"Unsupported database type: {db_type}")
|
|
|
|
from decnet.telemetry import wrap_repository
|
|
return wrap_repository(repo)
|