Repository navigation
logfmt: fall back to raw text when orjson rejects dict keys - #292
Merged
Merged
Conversation
added 3 commits
November 14, 2026 01:44
- hiscore_scraper: str() aiohttp istr header keys; orjson rejects str subclasses - JsonFormatter: catch TypeError from orjson, emit record.getMessage() - add regression tests for both paths
- prefix fallback output with logfmt_json_fallback instead of silent raw text - append exception traceback to fallback lines - scraper: sample info wide events at 1/1000 (~600 req/s) - scraper: assert dumped header keys are str for orjson
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.
Summary
--- Logging error ---crash in the scraper:dump_error()built header dicts from aiohttp'sCIMultiDict, whoseistrkeys arestrsubclasses that orjson rejects (TypeError: Dict key must be str), killing the whole log line.errors.py: coerce response-header keys withstr(key)at the boundary so dumped errors are always JSON-safe.logfmt/core.py:JsonFormatter.format()now catchesTypeErrorfrom orjson and emitsrecord.getMessage()as raw text, so a JSON-unsafe payload at a log site still lands instead of being lost.ts/lvlfields); log consumers should tolerate a rare non-JSON line.Testing
uv run pytest test/components/bot_detector/logfmt/test_core.py test/bases/bot_detector/hiscore_scraper/test_errors.py -q— 15 passeddump_error()header keys are exactlystrandorjson.dumps(dumped)succeeds on a simulated 502ClientResponseErroruv run ruff checkanduv run ruff format --checkon the four changed files — cleanuv run mypyon the two changed source files — clean