Skip to content

feat: ship API and worker logs to ClickHouse over OTLP [#241] - #44

Merged
hariharanweb merged 8 commits into
mainfrom
feat/241-logs-to-clickhouse
Nov 11, 2026
Merged

hariharanweb merged 8 commits into
mainfrom
feat/241-logs-to-clickhouse

Conversation

@hariharanweb

@hariharanweb hariharanweb commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Part of OpenAgriNet/engineering-tracker#241.

What

  • pipeline/observability.py: when OTEL_EXPORTER_OTLP_ENDPOINT is set, root-logger INFO+ lines from the API and worker go over OTLP/HTTP. No-op when unset.
  • Wired into the API lifespan and worker main() (flushed on shutdown).
  • Local otel-collector + clickhouse under compose profile observability; a plain docker compose up is unchanged.
  • Request log line per API call (method, URI + query, status, duration; no bodies). 4xx WARNING / 5xx ERROR with error detail; caught causes and unhandled exceptions carry tracebacks; streamed responses timed to the last byte; /health at DEBUG.
  • Temporal interceptor logs every workflow and activity start / completion / failure / cancellation.
  • Startup messages are log lines; API startup failures and worker crashes are logged and flushed.
  • Three vector-delete handlers that swallowed exceptions now log them.
  • OTEL_SERVICE_NAME set per service (knowledge-provider-api / -worker).
  • Docs: .env.example, ENV.md, README.md, AGENTS.md, ADR 0007.

Decisions

  • /search query text and payload are kept (no allowlist, unlike DSS).
  • Operator username/email ships with the lines (accepted: operators are staff).
  • service.name defaults to knowledge-provider; exports give up after 5s so shutdown fits Docker's stop grace.
  • Shared env sends to the existing ClickStack collector via OTEL_* env vars; helm wiring is not in this PR.
  • Deferred: transaction_id / message_id on /search logs go in the next story, once callers send them.

Verification

  • uv run ruff check . clean; uv run pytest -m "not slow" 747 passed (new: tests/test_observability.py, tests/test_observability_wiring.py).
  • Local stack: /search lines (with query text) and worker lines land in otel.otel_logs; DEBUG not shipped.
  • With the collector stopped, /search still returns 200.

🤖 Generated with Claude Code

hariharanweb and others added 4 commits November 5, 2026 15:18
Root-logger INFO+ lines go to an OTLP collector when
OTEL_EXPORTER_OTLP_ENDPOINT is set; a local collector and ClickHouse
run under the compose `observability` profile. See ADR 0007.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Default service.name to knowledge-provider when OTEL_SERVICE_NAME is unset
- Cap export at 5s so shutdown with the collector down fits Docker's stop grace
- Keep operator emails out of shipped logs: /search logs user id, email-OTP
  lines move to a logger that is not exported
- Let env_file carry OTEL_EXPORTER_OTLP_ENDPOINT instead of a compose override
- Test provider ownership and the API/worker wiring

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Operator identity is fine to ship; restore user.username/email on /search
lines and export email-OTP lines again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hariharanweb
hariharanweb force-pushed the feat/241-logs-to-clickhouse branch from 3b316e9 to c295e34 Compare November 5, 2026 10:25
hariharanweb and others added 4 commits November 5, 2026 17:09
- Request middleware: method, URI with query, status, duration; error
  detail on non-2xx, traceback on unhandled exceptions; no bodies
- Worker interceptor logs every activity's start, completion or failure
- API and worker startup messages are log lines instead of prints

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Request logging is pure ASGI: streamed responses timed to the last
  byte, mid-stream failures logged; 5xx at ERROR with the caught cause;
  429 and reason-phrase fallback for missing detail; /health at DEBUG
- Temporal interceptor also logs workflows, and cancellations of both;
  activity failures at WARNING (Temporal logs the traceback)
- Log API startup failures and worker crashes, then flush
- Log the three vector-delete handlers that swallowed exceptions

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hariharanweb
hariharanweb merged commit 3e0468a into main Nov 11, 2026
3 checks passed
@hariharanweb
hariharanweb deleted the feat/241-logs-to-clickhouse branch November 11, 2026 05:41
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.

2 participants