feat: add OpenTelemetry SDK, collector and telemetry stores

Collector (contrib), Prometheus, Loki, Tempo and Grafana with provisioning
from git; SDK in API and worker with level 3 metrics, traces and logs
carrying trace_id/span_id; telemetry off by default outside the stand;
broker healthcheck runs as the broker user so a fresh stand starts once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-11 10:19:50 +03:00
co-authored by Claude Opus 5.5
parent 9b35c256b7
commit a4497e3f32
62 changed files with 6175 additions and 214 deletions
+36
View File
@@ -0,0 +1,36 @@
"""Запуск телеметрии точкой входа процесса (API, worker)."""
from src.config import settings
from src.infra.logger import AbstractLogger, get_logger
from src.infra.telemetry import core
from src.infra.telemetry.core import Exporters
from src.infra.telemetry.logs import install_log_hooks
logger: AbstractLogger = get_logger().bind(module="telemetry")
def start_process_telemetry(
service_name: str,
*,
exporters: Exporters | None = None,
) -> bool:
"""По `[telemetry]`: выключено — ничего. Включено — `OTEL_*` удаляются
из окружения с `warning` (имена без значений), затем провайдеры и хуки
журнала. `True` — телеметрия работает."""
config = settings.telemetry
if not config.enabled and exporters is None:
return False
ignored = core.remove_otel_environment()
started = core.start(
service_name=service_name,
instance_id=settings.app.instance_id,
config=config,
exporters=exporters,
)
install_log_hooks()
if ignored:
logger.warning(
"Ignored OpenTelemetry environment variables",
names=ignored,
)
return started