feat: OpenTelemetry LGTM observability, dev tooling, and memoir UX fixes (#31)

* add staging ios app build script

* feat(api): add OpenTelemetry LGTM stack for local observability

Wire OTel traces, metrics, and logs through a collector to Tempo,
Prometheus, and Loki, with custom LLM instrumentation, dev compose overlay,
Grafana provisioning, env templates, and development.sh auto-start.

Co-authored-by: Cursor <cursoragent@cursor.com>

* feat: expand observability, harden dev tooling, and fix expo staging UX

Add business and LLM Prometheus metrics with Grafana dashboards, alerting,
and a metrics verification script. Wire telemetry through adapters and core
LLM paths, and document the local LGTM workflow.

Fix development.sh for macOS bash 3.2, open Grafana and eval-web in Chrome,
and repair eval-web auto-open (unbound EVAL_WEB_BROWSER_SCHEDULED). Merge
internal-eval into the main dev script with improved compose handling.

Require EXPO_PUBLIC_* at build time, improve iOS HTTP ATS for staging IPs,
show memoir empty state instead of load errors when no chapters exist, and
add jest env setup plus chapter list response normalization.

Co-authored-by: Cursor <cursoragent@cursor.com>

* chore: enable Grafana Assistant Cursor plugin

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix: memoir empty state and repair withdrawn 0020_chapters_book_id stamp

Show empty memoir UI when the chapter list succeeds with no items; treat auth/404 as non-fatal. Extend alembic revision repair so local dev DBs stamped with the removed 0020_chapters_book_id migration can roll back and upgrade to 0019.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Kevin <kevin@brighteng.org>
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Sully
2026-05-20 15:12:21 +08:00
committed by GitHub
parent 0d417331fd
commit fa42757916
85 changed files with 3894 additions and 405 deletions

View File

@@ -16,6 +16,37 @@
# LIFE_ECHO_API_HOST_PORT=8000
# 若 Caddy 跑在独立容器且非 host 网络,不要用 127.0.0.1,应把 Caddy 加入与本 compose 相同的 Docker 网络,并对 http://life-echo-api-prod:8000 做 reverse_proxy。
# =============================================================================
# OpenTelemetry见 docs/observability.mdSettings 只读 .env勿 shell export
# =============================================================================
# docker-compose.observability.yml 宿主机端口(高位口,避免 3000/9090/4317 冲突)
# GRAFANA_HOST_PORT=48300
# PROMETHEUS_HOST_PORT=49090
# OTEL_GRPC_HOST_PORT=48317
# OTEL_HTTP_HOST_PORT=48318
# OTEL_COLLECTOR_HEALTH_HOST_PORT=48333
# TEMPO_HTTP_HOST_PORT=43200
# LOKI_HTTP_HOST_PORT=43100
#
# --- development.env.development本机 uvicorn/celery ---
# OTEL_ENABLED=true
# OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:48317
# OTEL_TRACES_SAMPLER=always_on
#
# --- staging / production.env.staging / .env.production容器内 compose ---
# OTEL_ENABLED=false
# OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317
# OTEL_TRACES_SAMPLER=parentbased_traceidratio
# OTEL_TRACES_SAMPLER_ARG=0.1
#
OTEL_ENABLED=true
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:48317
OTEL_EXPORTER_OTLP_INSECURE=true
OTEL_SERVICE_NAME=life-echo-api
OTEL_TRACES_SAMPLER=always_on
# OTEL_TRACES_SAMPLER_ARG=0.1
# OTEL_METRIC_EXPORT_INTERVAL_MS=10000
# =============================================================================
# Loggingloguru sink 最低级别TRACE / DEBUG / INFO / WARNING / ERROR / CRITICAL
# =============================================================================
@@ -140,7 +171,7 @@ REDIS_SESSION_TTL=86400
# CELERY_MEMORY_ENRICHMENT_QUEUE=memory_idle
# =============================================================================
# Internal evaluation APIinternal_main / internal-eval.sh;与主 API 进程隔离)
# Internal evaluation APIinternal_maindevelopment.sh 默认一并启动;与主 API 进程隔离)
# =============================================================================
# 本地:`openssl rand -hex 32`;不用 internal eval 时可留空
INTERNAL_EVAL_API_KEY=