quick logging middleware cleanup (#3446)
#### Does this PR need a docs update or release note? - [x] ⛔ No #### Type of change - [x] 🧹 Tech Debt/Cleanup
This commit is contained in:
parent
7f3c38a626
commit
53f734db2e
@ -122,28 +122,20 @@ func (mw *LoggingMiddleware) Intercept(
|
|||||||
middlewareIndex int,
|
middlewareIndex int,
|
||||||
req *http.Request,
|
req *http.Request,
|
||||||
) (*http.Response, error) {
|
) (*http.Response, error) {
|
||||||
ctx := clues.Add(
|
|
||||||
req.Context(),
|
|
||||||
"method", req.Method,
|
|
||||||
"url", LoggableURL(req.URL.String()),
|
|
||||||
"request_len", req.ContentLength)
|
|
||||||
|
|
||||||
// call the next middleware
|
// call the next middleware
|
||||||
resp, err := pipeline.Next(req, middlewareIndex)
|
resp, err := pipeline.Next(req, middlewareIndex)
|
||||||
|
|
||||||
if strings.Contains(req.URL.String(), "users//") {
|
|
||||||
logger.Ctx(ctx).Error("malformed request url: missing resource")
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp == nil {
|
if resp == nil {
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx = clues.Add(
|
ctx := clues.Add(
|
||||||
ctx,
|
req.Context(),
|
||||||
"status", resp.Status,
|
"method", req.Method,
|
||||||
"statusCode", resp.StatusCode,
|
"url", LoggableURL(req.URL.String()),
|
||||||
"content_len", resp.ContentLength)
|
"request_content_len", req.ContentLength,
|
||||||
|
"resp_status", resp.Status,
|
||||||
|
"resp_status_code", resp.StatusCode,
|
||||||
|
"resp_content_len", resp.ContentLength)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
log = logger.Ctx(ctx)
|
log = logger.Ctx(ctx)
|
||||||
@ -153,6 +145,10 @@ func (mw *LoggingMiddleware) Intercept(
|
|||||||
|
|
||||||
// special case: always info log 429 responses
|
// special case: always info log 429 responses
|
||||||
if resp.StatusCode == http.StatusTooManyRequests {
|
if resp.StatusCode == http.StatusTooManyRequests {
|
||||||
|
if logExtra {
|
||||||
|
log = log.With("response", getRespDump(ctx, resp, true))
|
||||||
|
}
|
||||||
|
|
||||||
log.Infow(
|
log.Infow(
|
||||||
"graph api throttling",
|
"graph api throttling",
|
||||||
"limit", resp.Header.Get(rateLimitHeader),
|
"limit", resp.Header.Get(rateLimitHeader),
|
||||||
@ -180,16 +176,16 @@ func (mw *LoggingMiddleware) Intercept(
|
|||||||
log.Infow("2xx graph api resp", "response", dump)
|
log.Infow("2xx graph api resp", "response", dump)
|
||||||
}
|
}
|
||||||
case 3:
|
case 3:
|
||||||
log.With("redirect_location", LoggableURL(resp.Header.Get(locationHeader)))
|
log = log.With("redirect_location", LoggableURL(resp.Header.Get(locationHeader)))
|
||||||
|
|
||||||
if logExtra {
|
if logExtra {
|
||||||
log.With("response", getRespDump(ctx, resp, false))
|
log = log.With("response", getRespDump(ctx, resp, false))
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("graph api redirect: " + resp.Status)
|
log.Info("graph api redirect: " + resp.Status)
|
||||||
default:
|
default:
|
||||||
if logExtra {
|
if logExtra {
|
||||||
log.With("response", getRespDump(ctx, resp, true))
|
log = log.With("response", getRespDump(ctx, resp, true))
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Error("graph api error: " + resp.Status)
|
log.Error("graph api error: " + resp.Status)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user