refactor: promote MarshalAndSanitize to sanitize package#4742
Merged
Conversation
6 tasks
…exWithFallback in middleware Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/750f30d1-5ed7-4441-80e3-c41c31f716a9 Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor semantic function clustering analysis
refactor: promote Apr 28, 2026
MarshalAndSanitize to sanitize package
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors best-effort “marshal to JSON then redact secrets” logging logic by promoting the helper from internal/server into the shared internal/logger/sanitize package, and updates call sites/tests to use the shared implementation.
Changes:
- Add
sanitize.MarshalAndSanitize(value any) stringas a public helper for best-effort JSON marshal + secret redaction. - Replace
marshalAndSanitizeForLogusage intool_registry.gowith the promoted helper and remove the local wrapper. - Update the existing redaction test to call the promoted helper.
Show a summary per file
| File | Description |
|---|---|
| internal/logger/sanitize/sanitize.go | Adds shared MarshalAndSanitize helper for safe-to-log JSON serialization. |
| internal/server/tool_registry.go | Switches response logging to use sanitize.MarshalAndSanitize and removes the duplicated local helper. |
| internal/server/tool_registry_test.go | Updates redaction coverage test to use the promoted helper. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 3/3 changed files
- Comments generated: 1
Comment on lines
+500
to
+504
| @@ -500,7 +501,7 @@ func TestMarshalAndSanitizeForLog_RedactsSecrets(t *testing.T) { | |||
| assert := assert.New(t) | |||
|
|
|||
| const secret = "ghp_1234567890123456789012345678901234567890" | |||
| sanitized := marshalAndSanitizeForLog(map[string]interface{}{ | |||
| sanitized := sanitize.MarshalAndSanitize(map[string]interface{}{ | |||
Collaborator
|
@copilot addresss the review feedback |
…unction Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/fb4225cc-c58f-495c-9e62-90540a57b48c Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Contributor
Author
This was referenced Apr 28, 2026
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.
The
marshalAndSanitizeForLoghelper inserver/tool_registry.goduplicated a marshal+sanitize pattern that belongs ininternal/logger/sanitize. Two other items from the same analysis (strutil.RandomHexWithFallbackand its use inmiddleware.generateRandomID) were already implemented.Changes
internal/logger/sanitize/sanitize.go— addsMarshalAndSanitize(value any) string, a public best-effort helper that marshals to JSON and redacts secrets viaSanitizeStringinternal/server/tool_registry.go— removes the localmarshalAndSanitizeForLogwrapper; both call sites now usesanitize.MarshalAndSanitizeinternal/server/tool_registry_test.go— updates the coverage test to call the promoted public functionWarning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
example.com/tmp/go-build2454462384/b513/launcher.test /tmp/go-build2454462384/b513/launcher.test -test.testlogfile=/tmp/go-build2454462384/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build2454462384/b492/_pkg_.a g_.a -I x_amd64/vet --gdwarf-5 serviceconfig lcache/go/1.25.9-bool x_amd64/vet -W .cfg 509129435/b314//-ifaceassert x_amd64/vet . --gdwarf2 9129435/b314/ x_amd64/vet(dns block)invalid-host-that-does-not-exist-12345.com/tmp/go-build2454462384/b495/config.test /tmp/go-build2454462384/b495/config.test -test.testlogfile=/tmp/go-build2454462384/b495/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build2454462384/b396/vet.cfg o/otlp@v1.10.0/trace/v1/trace.pb.go om/tetratelabs/wazero@v1.11.0/api/wasm.go x_amd64/vet --gdwarf-5 --64 -o x_amd64/vet -I g_.a -I x_amd64/vet --gdwarf-5 /grpc_binarylog_-atomic -o x_amd64/vet(dns block)nonexistent.local/tmp/go-build2454462384/b513/launcher.test /tmp/go-build2454462384/b513/launcher.test -test.testlogfile=/tmp/go-build2454462384/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build2454462384/b492/_pkg_.a g_.a -I x_amd64/vet --gdwarf-5 serviceconfig lcache/go/1.25.9-bool x_amd64/vet -W .cfg 509129435/b314//-ifaceassert x_amd64/vet . --gdwarf2 9129435/b314/ x_amd64/vet(dns block)slow.example.com/tmp/go-build2454462384/b513/launcher.test /tmp/go-build2454462384/b513/launcher.test -test.testlogfile=/tmp/go-build2454462384/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build2454462384/b492/_pkg_.a g_.a -I x_amd64/vet --gdwarf-5 serviceconfig lcache/go/1.25.9-bool x_amd64/vet -W .cfg 509129435/b314//-ifaceassert x_amd64/vet . --gdwarf2 9129435/b314/ x_amd64/vet(dns block)this-host-does-not-exist-12345.com/tmp/go-build2454462384/b522/mcp.test /tmp/go-build2454462384/b522/mcp.test -test.testlogfile=/tmp/go-build2454462384/b522/testlog.txt -test.paniconexit0 -test.timeout=10m0s .cfg�� olang.org/grpc@v-errorsas ZnYX/DVOjGTTnGVe-ifaceassert x_amd64/vet . telabs/wazero --64 x_amd64/vet .cfg�� 9129435/b392/_pkg_.a ache/go/1.25.9/x64/src/net/http/-c=4 x_amd64/vet --gdwarf-5 g/protobuf/interrun -o x_amd64/vet(dns block)If you need me to access, download, or install something from one of these locations, you can either: