Skip to content

feat: log aggregation — Loki/Elasticsearch shipping with documented label schema - #10

Merged
btcneves merged 1 commit into
mainfrom
feat/log-aggregation
May 21, 2026
Merged

btcneves merged 1 commit into
mainfrom
feat/log-aggregation

Conversation

@btcneves

@btcneves btcneves commented May 21, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Promtail agent (recommended): make obs-up now starts Prometheus, Grafana, Loki, and Promtail together. Promtail scrapes Docker container stdout/stderr using Docker service discovery, filtered to the autoflowops compose project, and ships streams to Loki. The pipeline extracts level and logger as stream labels; request_id, workspace_id, and user_id as structured metadata.
  • Direct push (optional): Set LOKI_URL or ELASTICSEARCH_URL to activate background-thread handlers (_LokiHandler, _ElasticsearchHandler) that batch and push log entries directly from the backend and Celery worker processes — no sidecar required.
  • Label schema documented in docs/log-aggregation.md with stream labels, structured metadata fields, example LogQL queries, and env var reference.

Files changed

File Change
docker-compose.observability.yml Added Loki + Promtail services + loki_data volume
observability/loki-config.yml New — Loki single-node filesystem config (v13 schema)
observability/promtail-config.yml New — Docker SD, label pipeline, structured metadata
observability/grafana/provisioning/datasources/loki.yml New — Grafana Loki datasource auto-provisioned
backend/app/observability.py Added _LokiHandler, _ElasticsearchHandler, configure_log_shippers()
backend/app/config.py Added loki_url, elasticsearch_url, log_service_name
backend/app/main.py Call configure_log_shippers() on startup
backend/app/worker/celery_app.py Wire shippers via worker_process_init signal
docs/log-aggregation.md New — full label schema reference and setup guide

Test plan

  • make obs-up starts cleanly; Grafana at http://localhost:3001 shows both Prometheus and Loki datasources
  • Promtail at startup discovers autoflowops containers; logs visible in Grafana Explore with {app="autoflowops"}
  • With LOKI_URL=http://loki:3100, backend logs are shipped directly (check Loki API: curl http://localhost:3100/loki/api/v1/labels)
  • With LOKI_URL and ELASTICSEARCH_URL both unset, no handlers are added (default behaviour unchanged)
  • All 251 backend tests pass; lint clean

…ed label schema

- Add Loki + Promtail services to docker-compose.observability.yml
  so `make obs-up` starts the full observability stack (Prometheus,
  Grafana, Loki, Promtail) in one command
- observability/loki-config.yml: single-node filesystem storage (v13 schema)
- observability/promtail-config.yml: Docker SD, compose-project filter,
  JSON pipeline stage; promotes level + logger to stream labels;
  maps request_id / workspace_id / user_id to structured metadata
- observability/grafana/provisioning/datasources/loki.yml: Loki datasource
  auto-provisioned alongside Prometheus
- backend/app/observability.py: optional _LokiHandler and
  _ElasticsearchHandler — batched background-thread push for environments
  without a sidecar agent; activated by LOKI_URL / ELASTICSEARCH_URL env vars
- backend/app/config.py: loki_url, elasticsearch_url, log_service_name settings
- backend/app/main.py: wire configure_log_shippers() on startup
- backend/app/worker/celery_app.py: wire configure_log_shippers() via
  worker_process_init signal so the Celery worker ships logs independently
- docs/log-aggregation.md: label schema reference, LogQL query examples,
  env var table, Promtail project filter instructions
@btcneves
btcneves merged commit 2bbe765 into main May 21, 2026
3 checks passed
@btcneves
btcneves deleted the feat/log-aggregation branch May 21, 2026 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant