-
Notifications
You must be signed in to change notification settings - Fork 63
Description
User story
We need every proxied request to be logged with full metadata — this is the core value proposition of Channels. Build the observer that persists request/response data as each request flows through the proxy.
Details
Weir observer API not finalised. The current Weir observer behaviour and callback signatures are a working design but may change once we're deep in the integration. The acceptance criteria below reflect the current design — expect refinement during implementation.
Build Lightning.Channels.Observer implementing Weir.Observer behaviour to persist every proxied request. This story also includes the Weir modifications needed for observer state threading (deferred from the proxy story to keep scopes clean).
The observer hooks into the proxy pipeline at three points:
- Request started — create a
ChannelRequestrecord synchronously (if insert fails, abort the proxy) - Response started — capture response metadata as it arrives
- Response finished — finalise the
ChannelRequeststate and create aChannelEventwith full details
Implementation notes
Dependencies: #4401 (proxy pipeline), #4399 (schema)
Blocks: #4406 (snapshots), #4408 (history page)
Key technical considerations:
handle_request_startedcreates theChannelRequestsynchronously — if insert fails, proxy is aborted (return error to client)- Request headers must be captured from
connbefore the Weir call, not fromhandle_response_finishedwhich doesn't include them started_atusesDateTime.utc_now(), not Weir's monotonic time- Incremental body hashing (SHA256 via
:crypto.hash_update/2) for both request and response — constant memory - Body preview captured (first 64KB) for both request and response
- Completion persistence is async (via
Task.Supervisor, not bareTask.start) - If async persistence fails,
ChannelRequestmarked aserrorstate and error logged - Sensitive headers (
Authorization,X-API-Key) redacted before storage - TTFB (time to first byte) calculated and stored on event
Weir modifications (deferred from proxy story):
- Observer callbacks need to accept and thread user-defined state — the exact API (tuple option, behaviour callbacks, arity) will be finalised during implementation
- Existing Weir tests must still pass
State derivation for ChannelRequest:
| State | Condition |
|---|---|
pending |
Created, no sink response yet |
success |
Sink returned 2xx |
failed |
Sink returned 4xx or 5xx |
timeout |
Sink connection timed out |
error |
Internal error (e.g., observation failed) |
Release notes
N/A — internal observability infrastructure, not directly user-facing.
User acceptance criteria
-
Lightning.Channels.ObserverimplementsWeir.Observerwith all three callbacks -
handle_request_startedcreates aChannelRequestrecord synchronously; proxy aborted on failure - Request headers captured from
connbefore Weir call -
started_atusesDateTime.utc_now() - Incremental body hashing (SHA256) for request and response — constant memory
- Body preview captured (first 64KB) for request and response
-
ChannelEventcreated with: type, request method/path/headers/body preview+hash, response status/headers/body preview+hash, latency_ms -
ChannelRequest.stateupdated on completion (success/failed/timeout/error) - TTFB calculated and stored on event
- Completion persistence is async via
Task.Supervisor - Async persistence failure marks
ChannelRequestaserrorand logs - Sensitive headers (
Authorization,X-API-Key) redacted before storage - Weir observer callbacks accept and thread user-defined state (API to be finalised during implementation)
- Existing Weir tests still pass