Skip to content

Commit

Permalink
feat(api): improve router logs fields (#5299)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardlt authored Jul 6, 2020
1 parent 10e3e4b commit 25787f1
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions engine/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,13 @@ func (r *Router) handle(uri string, scope HandlerScope, handlers ...*service.Han

// Log request start
start := time.Now()
log.Info(ctx, "%s | BEGIN | %s [%s]", req.Method, req.URL, rc.Name)
log.InfoWithFields(ctx, logrus.Fields{
"method": req.Method,
"route": cleanURL,
"request_uri": req.RequestURI,
"deprecated": rc.IsDeprecated,
"handler": rc.Name,
}, "%s | BEGIN | %s [%s]", req.Method, req.URL, rc.Name)

// Defer log request end
deferFunc := func(ctx context.Context) {
Expand All @@ -400,13 +406,15 @@ func (r *Router) handle(uri string, scope HandlerScope, handlers ...*service.Han
latency := end.Sub(start)

log.InfoWithFields(ctx, logrus.Fields{
"method": req.Method,
"latency_int": latency.Nanoseconds,
"latency_human": latency,
"status": responseWriter.statusCode,
"route": cleanURL,
"request_uri": req.RequestURI,
"deprecated": rc.IsDeprecated,
"method": req.Method,
"latency_num": latency.Nanoseconds(),
"latency": latency,
"status_num": responseWriter.statusCode,
"status": responseWriter.statusCode,
"route": cleanURL,
"request_uri": req.RequestURI,
"deprecated": rc.IsDeprecated,
"handler": rc.Name,
}, "%s | END | %s [%s] | [%d]", req.Method, req.URL, rc.Name, responseWriter.statusCode)

observability.RecordFloat64(ctx, ServerLatency, float64(latency)/float64(time.Millisecond))
Expand Down

0 comments on commit 25787f1

Please sign in to comment.