-
Notifications
You must be signed in to change notification settings - Fork 25
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
feat(logging): Swap loggers from zap to log/slog #319
Conversation
Hi @zalgonoise, I see that you wrote all test cases manually for the logger. Go provides It checks that all keys and values are printed, that the groups work, and stuff like that. |
I also edited the title to fit the conventional commits convention, as we usually use it: We can discuss getting rid of it, and use GitHub labels instead. This would also make the releases prettier with GitHubs changelog generator. PS: The issue number / reference is automatically added when we squash the PR. |
Hi @MarvinJWendt :D I also looked into So, when using the interface as middleware, it felt a bit like I was just testing the standard library's JSON slog.Handler just to look for an attribute! But give me some time to read through the package a bit more, if I can find a good way to use it without checking the other attributes :) |
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.
I just found this one minor simplification. Nice job!
@johannes-riecken awesome input! Thanks for noticing, I don't know how I let that slide! :D |
Looking into this (and other) PR's CI jobs, it seems that the semgrep one is failing:
Looking into semgrep's action on Github, it seems that they've marked it as deprecated. They point to the following guide for Github The problem that I am having is their requirement to login in order to have the Sarif output that is used for
The command above runs fine (and we can include it in the Makefile as well). However if I add the
Does anyone have a better idea on how we should approach this change, for semgrep? :) |
@MarvinJWendt another update regarding Unfortunately, we are unable to use it for this particular wrapper / decorator. The problem with While that makes it a great suggestion for the experimental repo, we need that context for those tests. A regular |
Waiting for #328, to run CI workflows again |
I noticed that I left an unresolved comment, it's already as an accepted change :D @johannes-riecken would you like to take another look? :) |
9a56234
to
3957031
Compare
resolved conflicts on go.mod / go.sum :) while we're at it, updated all dependencies (within Go 1.21). We're still able to do the jump to 1.22 at any time :D probably in a dedicated issue / PR |
a4f5b17
to
bff1dd7
Compare
… added trace context handler; added gRPC interceptor logger
… the text template parser
…g/slog; added trace context handler; added gRPC interceptor logger
Co-authored-by: Johannes Riecken <johannes.riecken@gmail.com>
Co-authored-by: Johannes Riecken <johannes.riecken@gmail.com>
…g/slog; added trace context handler; added gRPC interceptor logger
…g/slog; added trace context handler; added gRPC interceptor logger
…g/slog; added trace context handler; added gRPC interceptor logger
…g/slog; added trace context handler; added gRPC interceptor logger
…g/slog; added trace context handler; added gRPC interceptor logger
…g/slog; added trace context handler; added gRPC interceptor logger
bff1dd7
to
3872c0b
Compare
…g/slog; added trace context handler; added gRPC interceptor logger
…g/slog; added trace context handler; added gRPC interceptor logger
…g/slog; added trace context handler; added gRPC interceptor logger
This PR replaces
go-uber/zap
with Go standard library'slog/slog
. Theinternal/log
package within the template folder now includes:New(level string) *slog.Logger
function to replace the formerNewAtLevel
function. It still works pretty much the same way but does not return an error through safe defaults.NewSpanContextHandler(handler slog.Handler, withSpanID bool) slog.Handler
function, that decorates aslog.Handler
to add context-provided trace and span IDs as attributes (optional)InterceptorLogger(l *slog.Logger) logging.Logger
function which could be used for gRPC services as a logging interceptor.When adding the span context handler and interceptor logger logic, the tests started failing with an error:
After some debugging this error was coming from the text template parser, as it read through the test files, found two open braces and thought it should be handling a template. To address this issue, I've changed
pkg/gotemplate
not to parse the content with the text template if it is a*_test.go
file. This approach can be discussed better in case we'd prefer to have an exclusion list for specific paths, instead.Closes #311