Repository navigation
feat: log requests, and what an extraction actually saw - #7
Merged
Merged
Conversation
The service had no logger. `buildServer` constructed a bare `Fastify()`,
whose default is `logger: false`, which makes `app.log` a no-op -- so
index.ts's startup line, its shutdown lines and every in-request error
went nowhere. `docker logs bots-sleevenote-1` on the deployed instance
returned nothing at all. A failed lookup left no trace, and diagnosing
one meant reproducing it.
Two lines now come out of a request.
`request completed`, from an onResponse hook: method, url, status,
durationMs and the X-Cache disposition. Fastify's own incoming/completed
pair is suppressed via `LogController({ disableRequestLogging: true })`
so a request is exactly one line, with `cache` beside `durationMs` so a
hit is distinguishable from a resolve at a glance.
`extraction failed`, when an extraction throws: kind, id, error class,
and evidence.
The evidence is the point, and the reason this ships before the fix it
serves. `normalizeByKind` returning null becomes a NotFoundError, which
the HTTP layer answers 404 and negative-caches for TTL_NEGATIVE. But
null covers two unrelated situations -- Spotify said the entity is gone,
and we captured nothing at all. A live playlist was served as "not
found" because the second was reported as the first, and being
negative-cached it stayed that way.
ExtractionEvidence records what the capture saw: how many JSON
responses, which distinct statuses, which distinct paths. `recorded: 0`
is the signature of a capture that saw nothing -- our failure, not
evidence of absence. Every throw inside runExtraction carries it, so a
line without evidence means exactly one of two things: a failure relayed
to a waiter (reviveFailure rebuilds from a wire form that does not carry
the capture -- read the holder's own line), or a timeout, rejected from
outside the extraction and never having had one.
Splitting those two cases onto different status codes is the next
change. This one exists so that split is written against observed
evidence rather than a guess about what Spotify's page emits for a
deleted id.
ExtractionTimeoutError joins the same base class so every extraction
failure produces one diagnostic line; the instanceof chain that maps 504
is unchanged, since it tests leaf classes.
LOG_LEVEL (default `info`) is the one new knob. Tests pass `silent`, or
inject a recording logger through the new optional `logger` dep.
Co-Authored-By: Claude & Lothrop (cycle.five@proton.me)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Step 1 of two. This is the instrument; the classification fix it serves is the next PR, and ships against data this produces rather than a guess.
The service had no logger at all
buildServerconstructed a bareFastify(). Its default islogger: false, which makesapp.loga no-op — soindex.ts's startup line, its shutdown lines, and every in-request error went nowhere:Empty. Not "quiet" — the deployed instance has never emitted a single line, including its own "listening on :3000". Chasing a failed lookup today meant asking the user which URL they'd pasted, because nothing on the server side knew.
Two lines per request
request completed— anonResponsehook carrying method, url, status,durationMsand theX-Cachedisposition:{"level":30,"reqId":"req-1","method":"GET","url":"/v1/track/abc","status":200,"durationMs":8433,"cache":"miss","msg":"request completed"}Fastify's own incoming/completed pair is suppressed with
LogController({ disableRequestLogging: true }), so a request is exactly one line.cachesitting next todurationMsis what makes a cache hit distinguishable from a real resolve at a glance — the exact question that took four tool calls to answer this morning.extraction failed— when an extraction throws:{"level":40,"reqId":"req-1","kind":"playlist","id":"6FPDT...","error":"NotFoundError", "evidence":{"recorded":0,"statuses":[],"paths":[]},"msg":"extraction failed"}Why
evidenceis the whole pointnormalizeByKindreturningnullbecomes aNotFoundError, which the HTTP layer answers 404 and negative-caches forTTL_NEGATIVE(600s). Butnullcovers two unrelated situations:A live playlist was served as "not found" this morning because (2) was reported as (1) — and being negative-cached, it stayed that way.
ExtractionEvidencerecords what the capture actually saw: how many JSON responses, which distinct statuses, which distinct paths.recorded: 0is the signature of (2) — our failure, not evidence of absence.Every throw inside
runExtractioncarries evidence, so a line without it means exactly one of two things, both documented at the log site: a failure relayed to a waiter (reviveFailurerebuilds from a wire form that does not carry the capture — read the holder's own line), or a timeout, which is rejected from outside the extraction and never had one.ExtractionTimeoutErrorjoins the same base class so every extraction failure produces one diagnostic line. Theinstanceofchain that maps 504 is unchanged — it tests leaf classes.What is deliberately NOT here
No status codes change. A deleted playlist and a silent capture both still return 404. Splitting them is the next PR, and the open question it has to settle first is whether a genuinely deleted entity emits a capturable 4xx JSON response — if it doesn't, real 404s stop being negative-cached and every request for a dead id re-scrapes. That is a question for the logs, not for my model of Spotify's page.
These logs should also explain an anomaly from this morning: a second attempt re-scraped six minutes after a failure that should have written a live 600s negative marker.
Verification
npm test— 100 passed, 9 skipped (live suite). Suite output is silent again; the three server-building configs passLOG_LEVEL: 'silent'.npx tsc --noEmit— clean, and thelogControllerroute avoids thedisableRequestLoggingdeprecation warning that the shorthand emits.tests/logging.test.ts. Mutation-checked: droppingevidencefrom the log line fails 2 of them.LOG_LEVEL(defaultinfo) documented in README and.env.example; the narrative is indocs/design-notes.md.Version 0.2.0 — new observable behaviour and a new knob, no API change.
🤖 Generated with Claude Code