-
Notifications
You must be signed in to change notification settings - Fork 9
Conversation
340a646
to
0525973
Compare
2142349
to
1db7b76
Compare
users/api/logging.go
Outdated
if err != nil { | ||
lm.logger.Warn(fmt.Sprintf("%s with error: %s.", message, err)) | ||
args = append(args, slog.String("error", err.Error())) | ||
lm.logger.Error("Register client failed to complete successfully", args...) |
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.
Let's use Warn
. The correct log level, however, can only be set properly by inspecting the error; we'll not do that in this PR.
auth/api/logging.go
Outdated
if err != nil { | ||
lm.logger.Warn(fmt.Sprintf("%s with error: %s.", message, err)) | ||
args = append(args, slog.String("error", err.Error())) |
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.
args = append(args, slog.String("error", err.Error())) | |
args = append(args, slog.Any("error", err)) |
Do this for the rest. It returns a better error format
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 have reviewed logging in ws
, users
, things
, twins
, readers
, provision
and messaging use that information to change the other services
Also have a look at this case
func (lm *loggingMiddleware) Cert(token, thingID, duration string) (cert, key string, err error) {
defer func(begin time.Time) {
args := []interface{}{
slog.String("duration", time.Since(begin).String()),
slog.String("thing_id", thingID),
slog.String("duration", duration),
}
if err != nil {
args = append(args, slog.String("error", err.Error()))
lm.logger.Warn("Cert failed to complete successfully", args...)
return
}
lm.logger.Info("Cert completed successfully", args...)
}(time.Now())
return lm.svc.Cert(token, thingID, duration)
}
This is found in provision. This logs is not informative or clear on what it does Cert completed successfully
because the underlying function creates a certificate. Use go docs to infer what a function does and make the log statemes clear and concise as to what is happening
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.
Some packages have not been updated for example consumers/writers/api/logging.go
auth/api/logging.go
Outdated
@@ -28,314 +27,533 @@ func LoggingMiddleware(svc auth.Service, logger *slog.Logger) auth.Service { | |||
|
|||
func (lm *loggingMiddleware) ListObjects(ctx context.Context, pr auth.PolicyReq, nextPageToken string, limit int32) (p auth.PolicyPage, err error) { | |||
defer func(begin time.Time) { | |||
message := fmt.Sprintf("Method list_objects took %s to complete", time.Since(begin)) | |||
args := []interface{}{ |
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.
Use any
instead of interface{}
.
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 the same for all the other cases.
auth/api/logging.go
Outdated
slog.Group( | ||
"object", | ||
slog.String("type", pr.ObjectType), | ||
), | ||
slog.Group( | ||
"subject", | ||
slog.String("id", pr.Subject), | ||
slog.String("type", pr.SubjectType), |
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.
Let's flatten Policy by using a single Group here, like:
slog.Group( | |
"object", | |
slog.String("type", pr.ObjectType), | |
), | |
slog.Group( | |
"subject", | |
slog.String("id", pr.Subject), | |
slog.String("type", pr.SubjectType), | |
slog.Group( | |
"policy_request", | |
slog.String("object_type", pr.ObjectType), | |
slog.String("subject_id", pr.Subject), | |
slog.String("subject_type", pr.SubjectType)) |
Signed-off-by: Musilah <[email protected]>
Signed-off-by: Musilah <[email protected]>
Signed-off-by: Musilah <[email protected]>
Signed-off-by: Musilah <[email protected]>
Signed-off-by: Musilah <[email protected]>
Signed-off-by: Musilah <[email protected]>
Signed-off-by: Musilah <[email protected]>
Signed-off-by: Musilah <[email protected]>
Signed-off-by: Musilah <[email protected]>
Signed-off-by: Musilah <[email protected]>
Signed-off-by: Musilah <[email protected]>
Signed-off-by: Musilah <[email protected]>
Signed-off-by: Musilah <[email protected]>
Signed-off-by: Musilah <[email protected]>
Signed-off-by: Musilah <[email protected]>
Signed-off-by: Musilah <[email protected]>
Signed-off-by: Musilah <[email protected]>
Signed-off-by: Musilah <[email protected]>
Signed-off-by: Musilah <[email protected]>
Signed-off-by: Musilah <[email protected]>
Signed-off-by: Musilah <[email protected]>
Signed-off-by: Musilah <[email protected]>
4c3e4d5
to
5381de8
Compare
Signed-off-by: Musilah <[email protected]>
slog.String("type", pr.ObjectType), | ||
), | ||
slog.Group("subject", | ||
slog.String("id", pr.Subject), |
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.
We need to make this user ID, rather than the token. Let's open a ticket for this, it's out of the scope for this PR.
Signed-off-by: Musilah <[email protected]>
What type of PR is this?
This is an optimisation for Logging.
What does this do?
This improves Logging by updating the filtering and searchability through structured logs.
Which issue(s) does this PR fix/relate to?
Have you included tests for your changes?
No.
Did you document any new/modified feature?
No.
Notes
N/A.