compass.utilities.event_log#

Replayable event logs for one jurisdiction’s run

An EventLog appends one JSON object per line to a file as each step happens, so a run can be followed live and replayed afterwards. The log for the jurisdiction being processed is tracked with a context variable, so code anywhere in the pipeline can record events with emit_event() without passing the log around.

Events link to the workflow map (compass/data/workflow.json5): each names the step it happened in with event_step(), and each decision records which way it went with emit_branch(), so a replay can draw the path a run took against every path that was possible.

Functions

body_preview(raw[, content_type, limit])

Start of a response body as text, if it is text at all

current_event_log()

EventLog or None: The event log for the work in progress

document_summary(doc)

Describe a document compactly for an event

emit_branch(step, outcome, **fields)

Record which way a workflow decision went

emit_event(kind, **fields)

Record an event if an event log is active, else do nothing

error_details(error)

Event fields describing an exception and what caused it

event_step(step)

Link events inside to a node of the workflow map

event_tags(**tags)

Attach tags (e.g. the document being checked) to events inside.

http_exchange(response, body)

Describe an HTTP exchange for the event log

loggable_headers(headers)

HTTP headers as a dict for an event, with secrets redacted

record_document_fetch(source, doc, error, ...)

ELM fetch hook: record what one document fetch produced

record_http_error(url, error)

ELM error hook: record why a URL gave no response at all

record_http_response(url, response, body)

ELM response hook: record each HTTP response as it arrives

response_metadata(model, response)

Summarize an API response to diagnose empty or cut answers

use_event_log(log)

Make log the current event log within this context

Classes

EventLog(path)

Append-only JSONL event stream for one jurisdiction

ResponseRecorder([tracker])

Usage tracker stand-in that remembers the API response metadata