Skip to content

feat: Opt-in log of every DuckDB HTTP request (#252) - #258

Merged
jrosskopf merged 7 commits into
mainfrom
feat/gh-252-http-debug-log
Nov 24, 2026
Merged

jrosskopf merged 7 commits into
mainfrom
feat/gh-252-http-debug-log

Conversation

@jrosskopf

@jrosskopf jrosskopf commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • New switch log-http-requests: true (top level) or FLAPI_LOG_HTTP_REQUESTS=1 (the env var wins). It writes one line into flAPI's log for each HTTP request DuckDB makes (S3, GCS, HTTP(S); Azure unverified): duckdb http GET <url> -> 200 12ms request_id=req-…. Reads made outside a request carry request_id=-.
  • A custom DuckDB LogSink (src/duckdb_http_log_sink.*) is registered on the main DB and on the bootstrap DB, so the remote --config read is logged too.
  • Attribution: the request thread uses the ambient request id. DuckDB worker threads use an RAII map from (DatabaseInstance*, connection_id) to request_id, set in QueryExecutor.
  • Off by default, at zero cost: DuckDB logging is never touched, and each attribution guard costs one relaxed atomic load.
  • Hardening from the reviews:
    • The URL keeps only scheme, host and path. Userinfo and the whole query are dropped, whatever redact_http_logs is set to.
    • Bytes that could forge log lines are percent-encoded.
    • The text formatter escapes CR/LF in every message.
    • No exception can escape the sink into DuckDB's HTTP path.
  • Docs: OBSERVABILITY §8, the observability component spec, CONFIG_REFERENCE, the flapi-operate skill and CHANGELOG. They spell out the limits: path secrets are not redacted, it is a debugging switch rather than one for production, and it takes over DuckDB's logging config.

Red / green

  • RED, 3ae2f3f / f93ddbc / fff1202, against the main binary: 12 of 15 failed for the stated reasons (no lines; leaks of SECRETJWT/SECRETSIG; forged lines and fields). The full failure lines are in the session notes.
  • GREEN: test_http_debug_log.py 19/19, three runs in a row. Also green:
    • test_remote_templates_s3 (12) and test_remote_templates (37)
    • test_log_correlation, test_audit_*, test_tracing_error_trace_id, test_mcp_request_id, test_env_secrets_hygiene, test_health_stall_detection
    • flapi_tests 1027/1028 (1 skipped) and check_skills --static-only
  • Reviews: two independent crew reviews (correctness/concurrency and security) found no blockers. Every should-fix is fixed and covered by a test.

Not in this PR

  • Pre-existing: the generic Error handling request: line quotes DuckDB's error text, URL included, so a space-separated request_id=FAKE in a URL can look like a field there. Tracked separately.

Test plan

  • Red first, then green, locally on the real binary with FakeS3
  • Crew reviews addressed
  • CI on all platforms

Closes #252

🤖 Generated with Claude Code

https://claude.ai/code/session_018txuxF9jXyiKakpUoXrKBi


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

- New test/integration/test_http_debug_log.py against a fake S3 holding the
  endpoint YAML, its SQL and eight CSV objects read via s3://
- Pins the line format `duckdb http <METHOD> <url> -> <status> <N>ms request_id=<id>`,
  one line per request the store served during the call, no credentials
- Startup reads carry request_id=-; FLAPI_LOG_HTTP_REQUESTS=1 works like the key;
  JSON log format carries the same message
- Switch off: no lines and the same I/O; 8 concurrent calls are not cross-attributed
- RED today except the switch-off test
- Worker-thread scan (duckdb.threads: 4, nine objects incl. a multi-MB one):
  every line carries the request id
- Presigned and user:password URLs, also with redact_http_logs=false in the
  connection init: no signature or password in any line
- A 404 logs -> 404, a refused connection logs -> ERR
- Remote --config fetch logged with request_id=- (bootstrap DuckDB)
- FLAPI_LOG_HTTP_REQUESTS wins over log-http-requests, both directions
- JSON: the record's request_id field is the request's id; text: exactly one
  request_id= per line; re-read after the expected count to catch duplicates
- New top-level key log-http-requests (default false), overridden in both
  directions by FLAPI_LOG_HTTP_REQUESTS; resolved before the endpoint files
  load, since a remote template.path is fetched while they do
- DuckDBHttpLogSink (a duckdb::LogSink, synchronous, unbuffered) writes one
  info line per request: duckdb http <METHOD> <url> -> <status|ERR> <N>ms
- The message is cast back to HTTPLogType's STRUCT with DuckDB's own cast,
  as duckdb_logs_parsed() does, instead of parsing its text
- Attribution: QueryExecutor registers (database, connection id) ->
  request_id for each execution, so worker-thread scans carry the id; then
  the ambient request; then -
- FlapiLogHandler::RequestIdOverride stamps that id once, as request_id= in
  text and the request_id field in JSON, held startup lines included
- Enabled on the main database before any connection (and again after the
  connection init, forcing redact_http_logs=true) and on the bootstrap
  instance that reads a remote --config; off, DuckDB logging is untouched
- URLs also go through PathSchemeUtils::RedactUrl, as a template can turn
  DuckDB's redaction off
- Unit tests pinned to DuckDB 2.0.1's ConstructLogMessage output, the
  attribution guard under concurrency, and the log handler override
- Integration test: the template fetches on /presigned and /dead are
  request lines too; filter to the data object
- OBSERVABILITY.md section 8 and env table, the component spec,
  CONFIG_REFERENCE key and env var, CHANGELOG Unreleased
- flapi-operate skill and the flapi.yaml reference teach log-http-requests
- A template that sets redact_http_logs=false must still leak nothing:
  jwt, one-letter and percent-encoded query keys, ';' separators,
  colon-less userinfo with an '@' in the path, fragments
- RedactUrl: userinfo is what precedes the last '@' of the authority;
  keys are matched percent-decoded; ';' separates
- URL bytes that could end a line or start a field are encoded, and the
  text log format escapes CR/LF in every message
- A log entry that does not parse ('}' in the URL) still leaves an
  attributed line
- The logged URL takes DuckDB's own redaction cut whatever redact_http_logs
  says: userinfo up to the last '@' of the authority and the fragment
  dropped, the whole query replaced by ?redacted; bytes < 0x21, >= 0x7f
  and '"' percent-encoded so the URL is one ASCII token
- The text log format escapes CR/LF in every message
- RedactUrl: RFC 3986 userinfo, percent-decoded keys, ';' separators, and
  jwt/hmac/session/ticket/bearer/assertion plus whole-key sid/code/pw
- An entry that does not parse still logs 'duckdb http ? <unparsed> -> ?'
  with its request id (DuckDBHttpLogLineFor)
- No exception leaves the sink (rate-limited warning); the sink returns
  before parsing when info is filtered out
- Attribution: the thread's own request first, the connection map only on
  threads with none (ResolveHttpRequestId)
- DatabaseManager reads ConfigManager::getLogHttpRequests();
  ResetHttpRequestLogForTest(); the startup notice is a warning; comments
  on DuckDB's logger refresh corrected
- Test corrections: the line has six spaces, not five; a '}' does not break
  DuckDB 2.0.1's STRUCT round trip (pinned), so the integration case checks
  the request is logged without its query; flAPI's generic error line, which
  quotes DuckDB's error text, is outside the field-forgery check
- Debugging only: path secrets are not redacted, parameters reach the log,
  synchronous writes under DuckDB's logging lock, volume grows with globs
- What the URL keeps; worker-thread lines have no trace ids; on-demand
  vs scheduled cache refresh ids; includes need the env var; it takes over
  DuckDB's logging config and duckdb_logs; disable_logging turns it off
- Azure unverified: its extension logs through the Azure SDK pipeline
@jrosskopf
jrosskopf force-pushed the feat/gh-252-http-debug-log branch from 975b773 to efb0f36 Compare November 24, 2026 16:22
@jrosskopf
jrosskopf merged commit db7bf4d into main Nov 24, 2026
29 checks passed
@jrosskopf
jrosskopf deleted the feat/gh-252-http-debug-log branch November 24, 2026 19:43
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.

Debug-only HTTP request logging for remote reads (DuckDB 2.0 logging)

1 participant