feat: json log format and W3C trace context propagation#446
Open
joaopaulosr95 wants to merge 1 commit into
Open
feat: json log format and W3C trace context propagation#446joaopaulosr95 wants to merge 1 commit into
joaopaulosr95 wants to merge 1 commit into
Conversation
Author
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.
Adds per-request correlation to hsds logs and an optional JSON output format as a way to make it easier to debug it in production.
Motivation
On a busy node, log lines from all in-flight requests interleave with nothing tying a line to the request that produced it, and there's no way to match SN and DN logs for the same client call. OTel-instrumented clients (h5pyd via requests instrumentation included) already send a W3C
traceparentheader; hsds just needs to read and forward it.What changed
log.request()adopts the incomingtraceparent(or generates a fresh trace id) into aContextVar, so every line logged while handling that request carries its trace idhttpUtil.http_get/post/put/deleteforward the header to DNs — one grep finds a client request across all nodeslog_formatconfig key:text(default, sameREQ>/RSP>/LEVEL>layout as today) orjson(one object per line, with method/path/domain on REQ and status/reason/path on RSP lines). Settable via config.yml,LOG_FORMATenv var, or--log_formatlog_timestamps: true)hsds_app._enqueue_output(was overridden byput_line = Truesince introduction)Sample output, same request seen on SN and DN:
Logger API is unchanged (
log.info(...)etc.), so no call sites were touched;log_stats/req_countin/infobehave as before.Malformed traceparent headers are ignored, and a fresh trace id is generated.
Testing
New unit tests in
tests/unit/logger_test.pycover both formats, level filtering, traceparent parse/generate/reject, and header forwarding on all fourhttp_*helpers against a real aiohttp test server. Also verified on a local SN + 2 DN posix deployment: a single client PUT logs the same trace id on sn/dn1/dn2 in both formats.