-
-
Notifications
You must be signed in to change notification settings - Fork 2k
🔥 feat: log.WithContext automatically includes context fields #4106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
24
commits into
main
Choose a base branch
from
copilot/fix-request-id-logging
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+608
−9
Open
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
71579fd
Initial plan
Copilot 73ddbe9
feat: add context field extraction to log.WithContext via RegisterCon…
Copilot e862b94
fix: apply betteralign struct field ordering for defaultLogger
Copilot 2c4216c
docs: improve documentation for context extractors and requestid init
Copilot 4549449
refactor: replace init() with sync.Once in New(), add basicauth extra…
Copilot ae206fb
feat: add log context extractors for csrf, keyauth, and session middl…
Copilot a0d4054
Update log/log.go
gaby 041145b
Update log/log.go
gaby 40bd5d0
security: redact sensitive values (api-key, csrf-token) in log contex…
Copilot add61a5
fix: skip context extractors that return empty key to prevent malform…
Copilot 8234a50
Merge branch 'main' into copilot/fix-request-id-logging
gaby 1b78967
fix: make RegisterContextExtractor concurrent-safe with RWMutex, reda…
Copilot e5f0b43
docs: fix redactSessionID comment to accurately describe >8 vs <=8 be…
Copilot 57fd7aa
fix: CSRF extractor respects DisableValueRedaction; clarify WithConte…
Copilot be7f6ff
docs: clarify WithContext accepted context types in log.md
Copilot 13b97d7
Potential fix for pull request finding
gaby c419d2a
fix: always redact CSRF tokens in log extractor, remove sync.Once con…
Copilot 34d3cb8
test: add missing Test_BasicAuth_LogWithContext for complete coverage
Claude 060dd32
Merge branch 'main' into copilot/fix-request-id-logging
gaby 7695b26
Potential fix for pull request finding
gaby 3f98165
fix: remove blank line after function signature in basicauth_test.go …
Copilot cdcd49b
feat: make log.WithContext accept any instead of context.Context for …
Claude 3da399c
Merge branch 'main' into copilot/fix-request-id-logging
gaby b3fc68a
docs: add output examples and format compatibility notes to log.WithC…
Claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since these are values that are written internally, I have two questions:
to ensure that it is possible to format this output.
Since everything is output in JSON format in the microservices world, it would be good if these values could also directly conform to this schema.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now it registers in the middleware, but that doesn't do anything unless the user is using fiberlog.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added compatibility note in b3fc68a addressing both points:
Always written: Yes, context fields are automatically included with every
log.WithContext(c)call in a handler. This is intentional for request correlation. If you need to log without context fields, use the regularlog.Info()methods instead oflog.WithContext(c).Info().Formatting: The default format is
key=valuepairs prepended to messages. For JSON/structured logging, the note now recommends using theLogwmethods (e.g.,log.WithContext(c).Infow("message", "key", "value")) which preserve field structure and work better with JSON formatters.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I use three middleware components from the core, for example, requestId, csrf, and session
and then call the log method multiple times in my business logic handler, as a consumer I might not want to see the IDs of these three core middleware components in the output every time