Repository navigation
Initialize debug logging at startup and isolate request settings - #721
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #721 +/- ##
==========================================
+ Coverage 86.95% 87.33% +0.38%
==========================================
Files 39 39
Lines 2008 2022 +14
==========================================
+ Hits 1746 1766 +20
+ Misses 238 232 -6
Partials 24 24
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Clue can now start request debug logging enabled, without first making an HTTP request to its debug endpoint:
Previously the debug middleware always began with its separate process-wide switch disabled, even when the service's startup logger enabled debug. This option initializes that same switch before the servers start. Existing HTTP requests can still turn logging on or off. Mounting a handler without the option leaves the state unchanged; if several handlers explicitly initialize it, the last mounted value wins.
Request settings must not leak between calls
The existing switch was an unsynchronized Boolean. In addition,
log.Withcreated a logger with a separate lock but shared its mutable options. Applying a request's debug setting could therefore race with another request or change an already-running stream, contradicting the documented rule that toggles affect only subsequent streams.The process-wide switch now uses atomic reads and writes. The HTTP and gRPC logging middleware own one logger per request or stream, including when request IDs are disabled.
log.Withcopies the logging options and their slice storage; output writers and formatting functions remain shared. The debug middleware applies the selected state to that existing request logger, so the outer logging middleware can still flush buffered messages when a request fails.This deliberately preserves
log.Context's existing in-place configuration behavior. If callers supply a logger to debug middleware, it must belong to the request—normally by placing the corresponding Clue logging middleware first. Debug middleware without a supplied logger continues to create a default logger.No endpoint paths, query values, response formats, payload limits, dependencies, or persisted data change. Existing callers need no migration; callers that want startup debug opt into the new option after updating Clue. Consumers release their usual binaries, with no coordinated service cutover required.
Verification
go test -race ./...passes.golangci-lint run --timeout 3mreports zero issues.