-
Notifications
You must be signed in to change notification settings - Fork 43
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
echo_logrus: use std context for fields #1174
Conversation
cmd/image-builder/logging.go
Outdated
}) | ||
|
||
if !SkipPath(c.Path()) { | ||
c.Logger().Debugf("Started request") | ||
ctxLogger.WithContext(ctx).WithFields(rd).Debugf("Started request") |
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.
This hunk is probably unnecessary, I was experimenting around to find the best solution. Can put it back, should work just fine. It really does not matter if you use echo interface or logrus interface, the result is the same. In fact, the counterpart for this line "Processed request ..." does use logrus interface, so why not to keep this change.
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.
ctxLogger.WithContext(ctx).WithFields(rd).Debugf("Started request") | |
ctxLogger.WithContext(ctx).Debugf("Started request") |
my WithFields
is also not needed here, right?
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.
It is either this, or I can make use of the echo logger created above. Let me use the echo logger instead, looks better.
@@ -154,7 +154,8 @@ func main() { | |||
if values.Error != nil { | |||
fields["error"] = values.Error | |||
} | |||
logrus.WithFields(fields).Infof("Processed request %s %s", values.Method, values.URI) | |||
logrus.WithContext(c.Request().Context()). | |||
WithFields(fields).Infof("Processed request %s %s", values.Method, values.URI) |
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.
Here WithContext
was missing, somewhat unrelated to the change but I think it is worth fixing.
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.
do you think also adding
"path": c.Path(),
to the fields here would be beneficial as this is better for log entry searches/grouping (in contrast to values.URI
) I guess
but no stopper for this PR I guess
(hmm or is this added by the c.Request().Context()
anyway? - I'll check)
} | ||
|
||
func (l *EchoLogrusLogger) Panicj(j log.JSON) { | ||
b, err := json.Marshal(j) | ||
if err != nil { | ||
panic(err) | ||
} | ||
l.Logger.WithContext(l.Ctx).WithFields(l.Fields).Panicln(string(b)) | ||
l.Logger.WithContext(l.Ctx).Panicln(string(b)) | ||
} |
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.
This file is a full revert. No other changes.
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.
Awesome thanks, looks nicer and even covers more use cases!
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.
Very nice, thanks
cmd/image-builder/logging.go
Outdated
}) | ||
|
||
if !SkipPath(c.Path()) { | ||
c.Logger().Debugf("Started request") | ||
ctxLogger.WithContext(ctx).WithFields(rd).Debugf("Started request") |
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.
ctxLogger.WithContext(ctx).WithFields(rd).Debugf("Started request") | |
ctxLogger.WithContext(ctx).Debugf("Started request") |
my WithFields
is also not needed here, right?
} | ||
|
||
func (l *EchoLogrusLogger) Panicj(j log.JSON) { | ||
b, err := json.Marshal(j) | ||
if err != nil { | ||
panic(err) | ||
} | ||
l.Logger.WithContext(l.Ctx).WithFields(l.Fields).Panicln(string(b)) | ||
l.Logger.WithContext(l.Ctx).Panicln(string(b)) | ||
} |
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.
Awesome thanks, looks nicer and even covers more use cases!
Rebased. |
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.
LGTM
@@ -154,7 +154,8 @@ func main() { | |||
if values.Error != nil { | |||
fields["error"] = values.Error | |||
} | |||
logrus.WithFields(fields).Infof("Processed request %s %s", values.Method, values.URI) | |||
logrus.WithContext(c.Request().Context()). | |||
WithFields(fields).Infof("Processed request %s %s", values.Method, values.URI) |
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.
do you think also adding
"path": c.Path(),
to the fields here would be beneficial as this is better for log entry searches/grouping (in contrast to values.URI
) I guess
but no stopper for this PR I guess
(hmm or is this added by the c.Request().Context()
anyway? - I'll check)
The way I search paths is simply doing normal search across all fields and once I get request-id I search for that to get the full history of a request. This will work because the path is logged at least once on every request. I can add this if you want. |
This PR is stale because it has been open 30 days with no activity. Remove "Stale" label or comment or this will be closed in 7 days. |
Signed-off-by: Lukas Zapletal <lzap+git@redhat.com>
/retest |
This is a followup of https://github.com/osbuild/image-builder/pull/1171/files
I have couple of concerns with the recent changes.
logrus.Fields
is a map and context is a lightweight object by design. Paths typically contain one or two fields maximum, with path and method this is up to 4 map elements.I have to add I do not believe it is a good thing to add path, method and all path params to every single log line, I think it would be better to only log this once at the beginning of the request and devs can use correlation ids to find the line from any logged line. This proposal adds those fields everywhere tho.