Skip to Content
JobWzrd Docs

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

CapabilityToday
Correlation idrequestId exists per HTTP request, returned in x-request-id, not logged and not propagated
Queue tracemessage carries {ref, hmac} only — no message id, no search id in clear, no enqueue time
Attempt identitynone (message.attempts is logged once, in one event)
D1 metricsnone (no rows read/written/duration)
Scraper-side tracescraper logs to stderr; no request id echoed, no X-Request-Id accepted
Log envelopelog(level, event, fields) → one JSON line, no ts/service/version/stage
Frontendno client error channel; failures render from HTTP status only
DLQexists, 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)

IdCreated byLives inPurposeTrust
trace_id (W3C 32-hex)first entry point (browser fetch or cron) or crypto.randomUUID()traceparent header, every log line, queue message fieldcausal chain across servicesnot authorization
request_idrouter (x-request-id honoured, else UUID)response header, logsone HTTP requestclient-supplied ⇒ never trusted for auth
operation_idproducersearches.id (exists)one user searchserver-generated
task_idproducer, per source messagesearches.id + ":" + source_id (deterministic)one source fetchderived, not random
message_idQueues (message.id)log field onlyphysical deliveryplatform
attempt_idconsumer, per invocationmessage.id + ":" + message.attemptsone delivery attemptserver-generated
dispatch_attempt_idscraperClient right before fetchops_scraper_executions.attempt_id (new column)one external requestserver-generated
source_idcataloguemessage + rowswhich boardserver-side catalogue
user_refhash of owner id (existing hash.ts)every log linepseudonymous usernever reversible in logs

Rules:

  • Propagate, do not regenerate. Consumer reads trace_id from the message; if absent it starts one and logs trace.repaired.
  • The message carries ids and a ref, never a token, resume text or email body.
  • W3C traceparent is emitted to scrapers as X-Trace-Id (they do not speak traceparent today; a shared header is the honest minimum until they do).
  • Client-provided x-request-id is sanitised (^[A-Za-z0-9-]{8,64}$) and labelled request_id.source=client so 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.md states which fields are mandatory.

4. Stage instrumentation map (where the boundary actually is)

BoundaryEventAnswers
Browser → routehttp.request.received / .completedQ1, Q2
Route → featurefeature.entered (debug)Q2
Authauth.session.resolved / .rejectedQ1, Q2, security
Repositorydb.batch.started / .committed / .failed (rows, stmts, ms)Q14, Q15
Producersearch.created, queue.published (message id, enqueued_at)Q3, Q4
Consumer claimqueue.consumed, task.claimed, task.reclaimed (lease)Q4, Q5, Q19
Scraper clientscrape.dispatch.started (attempt id, before fetch)Q7
Scraper clientscrape.dispatch.completed (status, ms, bytes) / .failed (err class)Q8, Q9, Q10
Validationcanonical.validated (accepted, skipped, wrong_source)Q11, Q12, Q13
Ingestingest.batch.committed (created, updated, rejected, ms)Q14, Q15
Settlesearch.settled (status, sources_ok/failed)Q21
Retrymessage.retried (attempt, delay, reason)Q16, Q17
DLQmessage.dead_lettered (queue, attempts, last error)Q18
Duplicatetask.duplicate_ignored (original attempt id)Q19, Q20
Frontendclient.request.failed (route, status, trace id)Q1
Scrapersscraper.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)

SignalDestinationRetentionNotes
Structured logsWorkers Logs (real-time, dashboard)platform defaultdev + 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 metricsCloudflare Queues analytics (backlog, retries, DLQ)platformalerts on backlog age, not on count alone
Custom countersAnalytics Engine dataset jobwzrd_ops90 daysper-source latency/success, cap refusals, cache hit ratio
D1 operational stateops_scraper_executions (exists), new ops_dispatch_attempts, ops_cap_ledger30 days via ops_table_policynot high-volume diagnostics; one row per source attempt only
Auditops_audit_events1 yearauth, erasure, config changes
Frontend errorssame Worker log pipeline via POST /api/v1/client-errors (new, sampled)30 daysno 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)

#QuestionAfter this designToday
1Which user operation?operation_id + user_ref on every linepartial (D1 rows)
2Which route?http.request.completed.routeyes
3Which Worker?ver + svc (consumer vs producer invocation id)no
4Which queue/message?message_id, queueno
5Which invocation?attempt_idno
6Which scraper/source?scraper_service, source_idpartial
7Did the request leave?scrape.dispatch.started before fetchno
8Did the board receive it?scraper-side log + gateway log both keyed by traceno
9Did the scraper answer?scrape.dispatch.completed.http_statusno
10Was it valid?canonical.validated outcomeno
11Validation success?accepted/skipped/wrong_sourceno
12Fetched countfetchedyes (execution row)
13Accepted/rejectedstored, skippedyes
14Rows persistedingest.batch.committed.rows_writtenyes
15Batch commit/rollbackdb.batch.failed + ingest.batch.*no
16Retried?message.retriedno
17How many times?attempt_id sequencepartial
18Ack or DLQ?message.acked / message.dead_letteredno
19Another worker, same task?task.duplicate_ignoredno
20Duplicated external effect?dispatch_attempt_id uniqueness + uncertain stateno
21Complete/partial/uncertain?search.settled.status + per-source statesno (no partial)
22Exact failure boundary?stageno
23Cause?err_code + err_classno
24Safe recovery?RECOVERY-RUNBOOKS.md keyed by err_codeno
25How to verify recovery?runbook verification step + search.settled counterno

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].

On this page