Observability architecture
Superseded for scope. This file described the scrape pipeline only. The whole-application design is
docs/architecture/OBSERVABILITY-ARCHITECTURE.md. Kept for audit history; its 25-question incident matrix remains useful as a pipeline checklist.
Read-only proposal. Nothing here is implemented yet; current coverage is quantified in
LOGGING-COVERAGE.md (8 log() calls across ~40 modules).
1. Current state, honestly
| Capability | Today |
|---|---|
| Correlation id | requestId exists per HTTP request, returned in x-request-id, not logged and not propagated |
| Queue trace | message carries {ref, hmac} only — no message id, no search id in clear, no enqueue time |
| Attempt identity | none (message.attempts is logged once, in one event) |
| D1 metrics | none (no rows read/written/duration) |
| Scraper-side trace | scraper logs to stderr; no request id echoed, no X-Request-Id accepted |
| Log envelope | log(level, event, fields) → one JSON line, no ts/service/version/stage |
| Frontend | no client error channel; failures render from HTTP status only |
| DLQ | exists, unobserved |
Consequence: of the 25 incident questions in the audit request, 7 can be answered today
(which route, which user via owner_id in D1 rows, which source, how many rows persisted,
whether an execution row exists, HTTP status, retry count from searches.updated_at
inference). The rest require the design below.
2. Identifier model (one id per causal boundary)
| Id | Created by | Lives in | Purpose | Trust |
|---|---|---|---|---|
trace_id (W3C 32-hex) | first entry point (browser fetch or cron) or crypto.randomUUID() | traceparent header, every log line, queue message field | causal chain across services | not authorization |
request_id | router (x-request-id honoured, else UUID) | response header, logs | one HTTP request | client-supplied ⇒ never trusted for auth |
operation_id | producer | searches.id (exists) | one user search | server-generated |
task_id | producer, per source message | searches.id + ":" + source_id (deterministic) | one source fetch | derived, not random |
message_id | Queues (message.id) | log field only | physical delivery | platform |
attempt_id | consumer, per invocation | message.id + ":" + message.attempts | one delivery attempt | server-generated |
dispatch_attempt_id | scraperClient right before fetch | ops_scraper_executions.attempt_id (new column) | one external request | server-generated |
source_id | catalogue | message + rows | which board | server-side catalogue |
user_ref | hash of owner id (existing hash.ts) | every log line | pseudonymous user | never reversible in logs |
Rules:
- Propagate, do not regenerate. Consumer reads
trace_idfrom the message; if absent it starts one and logstrace.repaired. - The message carries ids and a ref, never a token, resume text or email body.
- W3C
traceparentis emitted to scrapers asX-Trace-Id(they do not speaktraceparenttoday; a shared header is the honest minimum until they do). - Client-provided
x-request-idis sanitised (^[A-Za-z0-9-]{8,64}$) and labelledrequest_id.source=clientso an operator can tell.
3. Log envelope (one line, JSON, versioned)
{
"ts": "2026-11-19T00:00:00.000Z",
"sev": "info", // debug|info|warn|error|fatal
"evt": "scrape.dispatched", // EVENT-CATALOG.md
"evt_v": 1,
"svc": "jobwzrd-backend", // or minizrd / jobindie / gateway
"env": "local|staging|prod",
"ver": "git-sha",
"trace_id": "…", "request_id": "…",
"operation_id": "srch_…", "task_id": "srch_…:greenhouse",
"message_id": "…", "attempt_id": "…", "dispatch_attempt_id": "…",
"user_ref": "u_8f3c…", // pseudonymous hash, never the raw id
"source_id": "greenhouse", "scraper_service": "minizrd",
"stage": "dispatch|response|validate|ingest|settle", // exact boundary
"dur_ms": 2314,
"outcome": "ok|empty|failed|held|uncertain",
"err_code": "SCRAPER_UPSTREAM_502", "err_class": "upstream|policy|config|db|auth|internal",
"retryable": false,
"http_status": 502,
"rows_read": 0, "rows_written": 50, "fetched": 250, "stored": 50, "skipped": 3
}Hard rules:
- Never log:
Authorization,Cookie,Proxy-Authorization, OAuth tokens, API keys, resume bytes, email bodies, signed R2 URLs, upstream proxy userinfo. - SQL parameters are logged only as shapes (
{"owner":"u_ref","limit":50}), never values from user profiles. - Success events may be sampled (target: 10 % of
http.request.completed); failures, state transitions and security events are never sampled. - Every event in
EVENT-CATALOG.mdstates which fields are mandatory.
4. Stage instrumentation map (where the boundary actually is)
| Boundary | Event | Answers |
|---|---|---|
| Browser → route | http.request.received / .completed | Q1, Q2 |
| Route → feature | feature.entered (debug) | Q2 |
| Auth | auth.session.resolved / .rejected | Q1, Q2, security |
| Repository | db.batch.started / .committed / .failed (rows, stmts, ms) | Q14, Q15 |
| Producer | search.created, queue.published (message id, enqueued_at) | Q3, Q4 |
| Consumer claim | queue.consumed, task.claimed, task.reclaimed (lease) | Q4, Q5, Q19 |
| Scraper client | scrape.dispatch.started (attempt id, before fetch) | Q7 |
| Scraper client | scrape.dispatch.completed (status, ms, bytes) / .failed (err class) | Q8, Q9, Q10 |
| Validation | canonical.validated (accepted, skipped, wrong_source) | Q11, Q12, Q13 |
| Ingest | ingest.batch.committed (created, updated, rejected, ms) | Q14, Q15 |
| Settle | search.settled (status, sources_ok/failed) | Q21 |
| Retry | message.retried (attempt, delay, reason) | Q16, Q17 |
| DLQ | message.dead_lettered (queue, attempts, last error) | Q18 |
| Duplicate | task.duplicate_ignored (original attempt id) | Q19, Q20 |
| Frontend | client.request.failed (route, status, trace id) | Q1 |
| Scrapers | scraper.request.received / .completed / .rejected (their logs, JSON) | Q7, Q9 |
scrape.dispatch.started must be written before the fetch call. That single ordering
is what separates "never left" from "may have reached the board" (Q7/Q20/Q21) and is the
foundation of the uncertain-outcome model in FAILURE-MODE-REGISTER.md.
5. Where the data goes (deployment design)
| Signal | Destination | Retention | Notes |
|---|---|---|---|
| Structured logs | Workers Logs (real-time, dashboard) | platform default | dev + short incident window |
| Structured logs (archive) | Logpush → R2 bucket jobwzrd-logs-prod, partitioned env/dt=YYYY-MM-DD/svc/ | 90 days hot, 1 year cold (proposed) | requires a Logpush job per Worker; delivery is best-effort — missing-interval detection is mandatory |
| Queue metrics | Cloudflare Queues analytics (backlog, retries, DLQ) | platform | alerts on backlog age, not on count alone |
| Custom counters | Analytics Engine dataset jobwzrd_ops | 90 days | per-source latency/success, cap refusals, cache hit ratio |
| D1 operational state | ops_scraper_executions (exists), new ops_dispatch_attempts, ops_cap_ledger | 30 days via ops_table_policy | not high-volume diagnostics; one row per source attempt only |
| Audit | ops_audit_events | 1 year | auth, erasure, config changes |
| Frontend errors | same Worker log pipeline via POST /api/v1/client-errors (new, sampled) | 30 days | no PII, trace id only |
Explicitly rejected: high-volume diagnostic rows in D1 (write contention with ingestion); a self-hosted log stack in this phase.
Unproven: Logpush delivery gap detection. Implement a daily partition-completeness check
(list dt= prefixes for yesterday, compare to expected services) before claiming archival
completeness.
6. Incident question matrix (the audit's 25 questions)
| # | Question | After this design | Today |
|---|---|---|---|
| 1 | Which user operation? | operation_id + user_ref on every line | partial (D1 rows) |
| 2 | Which route? | http.request.completed.route | yes |
| 3 | Which Worker? | ver + svc (consumer vs producer invocation id) | no |
| 4 | Which queue/message? | message_id, queue | no |
| 5 | Which invocation? | attempt_id | no |
| 6 | Which scraper/source? | scraper_service, source_id | partial |
| 7 | Did the request leave? | scrape.dispatch.started before fetch | no |
| 8 | Did the board receive it? | scraper-side log + gateway log both keyed by trace | no |
| 9 | Did the scraper answer? | scrape.dispatch.completed.http_status | no |
| 10 | Was it valid? | canonical.validated outcome | no |
| 11 | Validation success? | accepted/skipped/wrong_source | no |
| 12 | Fetched count | fetched | yes (execution row) |
| 13 | Accepted/rejected | stored, skipped | yes |
| 14 | Rows persisted | ingest.batch.committed.rows_written | yes |
| 15 | Batch commit/rollback | db.batch.failed + ingest.batch.* | no |
| 16 | Retried? | message.retried | no |
| 17 | How many times? | attempt_id sequence | partial |
| 18 | Ack or DLQ? | message.acked / message.dead_lettered | no |
| 19 | Another worker, same task? | task.duplicate_ignored | no |
| 20 | Duplicated external effect? | dispatch_attempt_id uniqueness + uncertain state | no |
| 21 | Complete/partial/uncertain? | search.settled.status + per-source states | no (no partial) |
| 22 | Exact failure boundary? | stage | no |
| 23 | Cause? | err_code + err_class | no |
| 24 | Safe recovery? | RECOVERY-RUNBOOKS.md keyed by err_code | no |
| 25 | How to verify recovery? | runbook verification step + search.settled counter | no |
7. Cost note
At 1,000 heavy-user days (200 messages/day each = 200k messages), a log line per stage (~8 per source attempt = 1.6M lines/day) is the dominant Logpush volume. Sampling success events at 10 % cuts it to ~200k/day while keeping every failure. That is engineering judgement, not a measured bill [UNPROVEN].