fix(tracelog): avoid growing truncated query arguments - #2657
Open
sb123sb123 wants to merge 1 commit into
Open
sb123sb123 wants to merge 1 commit into
sb123sb123 wants to merge 1 commit into
Conversation
Owner
|
This addresses both points from my feedback on #2588: configurable truncation and retaining the omitted-byte count. Before merging, please fix Please also clarify the intended behavior for small limits: with Review performed by Codex and checked by me. |
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.
Fixes #2095
Why
tracelogused a fixed 64-byte prefix and then appended the truncation notice. A 65-byte string was therefore logged as 84 bytes, making the logged value longer than the original. The same issue was more pronounced for[]byte, which is logged as hexadecimal. This also makes the truncation length configurable as requested in #998.What changed
TraceLogConfig.MaxLogArgsLen, defaulting to 64 bytes while preserving the existing behavior for zero-value or non-positive settings.[]bytearguments with regression tests.Tests
go test ./tracelog -run '^TestLogQueryArgs(MaxLength|DefaultDoesNotGrow)$' -count=1go vet ./traceloggofmt -l tracelog/tracelog.go tracelog/tracelog_test.go(no output)git diff --checkgo test ./... -run '^$' -count=1(compile-only pass)The database-backed
TestLogQueryArgsHandlesUTF8was also attempted, but the remote Windows host has no PostgreSQL listening onlocalhost:5432, so all query-execution modes failed at connection setup with connection refused. Dependency downloads on that host usedgoproxy.cnbecauseproxy.golang.orgtimed out.AI assistance
This PR was prepared with AI assistance from GPT-5.6 Luna for issue and PR research, implementation drafting, and test review. I read the repository guidance, understand the change, reviewed the complete final diff, and verified the behavior with a baseline reproduction and focused tests.