Repository navigation
requestlog: one structured line per HTTP request - #9
Merged
Merged
Conversation
Built-in apps wrote no access log and only untyped handler errors, so a collected container log could not show traffic or failures. Add appserver/requestlog: Wrap emits one JSON line per request (method, path, route, status, bytes, duration, request id) and never the query, headers or body. Successful probes are skipped; a handler panic is observed, not recovered. httpx.WriteError records its error on the wrapped request instead of printing a second line; without the wrapper it is unchanged.
An app with its own X-Request-Id contract (AI Gateway's invocation ID) replaces the header; log that value so header and line still match. Some apps forward an error code taken from an upstream body; emit error_code only when it is a safe token, otherwise "other".
http.MaxBytesReader signals the server through an unexported ResponseWriter method that a wrapper cannot forward, so an oversized body no longer closed the connection. Set the header when a handler answers 413.
This was referenced Nov 18, 2026
Merged
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.
Why
Built-in apps emit no access log. After container log collection was enabled on Craftsman (2026-11-18), opening the production Builder Console produced zero lines; typed 4xx/5xx, proxy 502s and provider failures leave no trace. There is no setting to turn logging on.
What
appserver/requestlog(new, stdlib only):Wrap(next, Options{Service})writes one JSON line per request to stderr:ts, level, msg, service, method, path, route, status, bytes, duration_ms, request_id, pluserror_code/error/outcome/reason/panicwhen present.errortext only for 5xx/panic, cut at 512 bytes.GET /healthzandGET /readyzare skipped; failed probes are logged.Flush,http.ResponseController, andHijackwhen the underlying writer supports it.httpx.WriteErrorkeeps its signature. On a wrapped request it records the error on the line and no longer prints a second line; without the wrapper its behaviour is unchanged.SetError,SetOutcome,IDlet handlers annotate the current line; no-ops when unwrapped.Additive; intended as v0.7.0. No platform minimum change.
Verification
go vetandgo test ./... -count=1: pass.go test -raceonrequestlogandhttpx: pass.httptest: 200 with?token=…logs the path without the query; untyped error logsinternal_error+ text; typed 403 logserror_codeonly;/healthzlogs nothing; 404 logs withoutroute; panic logspanic:trueand net/http prints the stack at the original handler line.Adoption
Apps bump to v0.7.0 and wrap the handler once in
cmd/server/main.go.