Skip to content

Log kernel-images-api as JSON - #495

Draft
tnsardesai wants to merge 3 commits into
mainfrom
hypeship/json-api-logs
Draft

tnsardesai wants to merge 3 commits into
mainfrom
hypeship/json-api-logs

Conversation

@tnsardesai

@tnsardesai tnsardesai commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

kernel-images-api's console output is free-form text: slog's text handler, chi's request logger, and chi's recoverer, which prints a panic's stack as many lines. Anything that wants to search or aggregate these logs has to parse each format with regexes, and breaks silently whenever a message changes.

This makes the API log JSON, one object per line, with the fields meant for indexing under a single attrs key. A log pipeline can then promote attrs as-is, so adding or changing log fields never needs a pipeline change. Values under attrs should stay bounded: no URLs, paths or error text.

Changes

  • slog uses a JSON handler, and slog.SetDefault routes slog.Default() and the standard log package through it, so code that logs without the injected logger (e.g. cdpmonitor) is JSON too. The OTel diagnostics handler is JSON as well.
  • logger.RequestLogger replaces chiMiddleware.Logger on the API, DevTools proxy and ChromeDriver proxy routers. One line per request, as before, with path, bytes and request_id. The level follows the status: INFO, WARN for 4xx, ERROR for 5xx. Indexed: http.request.method, http.route (the chi route pattern), http.response.status_code, duration_ms.
    • The host and query string are no longer logged. The query can carry credentials (e.g. a destination URL passed as a query parameter) and customer file paths; the host is always the VM's own address. path is logged but not indexed.
    • A request whose handler panics past the logger (http.ErrAbortHandler) is logged at ERROR with error.type=aborted and no status, instead of as a 200.
  • logger.Recoverer replaces chiMiddleware.Recoverer with the same behaviour (500 unless the connection was being upgraded; http.ErrAbortHandler re-panics), but logs the panic value and stack as one ERROR line. Indexed: only exception.type, the panic value's Go type (e.g. runtime.boundsError), since the value itself is free-form text.
  • Config's LogValue redaction applies the same with the JSON handler; checked that s2_access_token and otlp_instance_jwt still log as [redacted].
  • The e2e test that greps the API log for an extension load now matches the JSON form.
  • The enterprise extension e2e test no longer looks for Chrome's update.xml / .crx downloads in the API's request log. It already verifies the download through Chrome's state (waitForExtensionInstalled), which is what it now relies on.

Lines the API relays from child processes (e.g. [playwright-daemon] …) and Go runtime crashes are still plain text.

Testing

  • New lib/logger tests: level per status class, fields and attrs contents, request ID and route pattern, the path logged, no host or query (including credentials in a query parameter) anywhere in the line, aborted requests, recovered panic line with only its type indexed plus the 500 request line, upgrades left alone, ErrAbortHandler re-panic. The URL, abort and panic tests fail against the previous version of the logger.
  • go build ./..., go vet, and unit tests (go test -race, excluding e2e) pass, except TestUpstreamManagerDetectsChromiumAndRestart in lib/devtoolsproxy, which also fails intermittently on main in the same environment (temp dir cleanup racing Chromium).
  • e2e tests not run locally.

Considerations

  • Anyone reading /var/log/supervisord/kernel-images-api or the console directly sees JSON instead of key=value; jq helps.

@tnsardesai
tnsardesai force-pushed the hypeship/json-api-logs branch from 7361715 to dc808aa Compare November 7, 2026 05:53
@tnsardesai
tnsardesai force-pushed the hypeship/json-api-logs branch from a0613b5 to 1da9f6b Compare November 9, 2026 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant