From 8096025c5515bbd86864306a5aab520e62734186 Mon Sep 17 00:00:00 2001 From: Abin Simon Date: Mon, 20 Feb 2023 14:44:23 +0530 Subject: [PATCH] Print api response in logs for 4xx errors (#2544) ## Description Print api response in logs for 4xx errors from GC. More info for things like 400 Bad Request could be useful. ## Does this PR need a docs update or release note? - [ ] :white_check_mark: Yes, it's included - [ ] :clock1: Yes, but in a later PR - [x] :no_entry: No ## Type of change - [ ] :sunflower: Feature - [ ] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Test - [ ] :computer: CI/Deployment - [x] :broom: Tech Debt/Cleanup ## Issue(s) * # ## Test Plan - [x] :muscle: Manual - [ ] :zap: Unit test - [ ] :green_heart: E2E --- src/internal/connector/graph/service.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/internal/connector/graph/service.go b/src/internal/connector/graph/service.go index 275e76378..e0539eb9c 100644 --- a/src/internal/connector/graph/service.go +++ b/src/internal/connector/graph/service.go @@ -296,7 +296,7 @@ func (handler *LoggingMiddleware) Intercept( } // Log errors according to api debugging configurations. - // When debugging is toggled, every non-2xx is recorded with a respose dump. + // When debugging is toggled, every non-2xx is recorded with a response dump. // Otherwise, throttling cases and other non-2xx responses are logged // with a slimmer reference for telemetry/supportability purposes. if logger.DebugAPI || os.Getenv(logGraphRequestsEnvKey) != "" { @@ -316,9 +316,16 @@ func (handler *LoggingMiddleware) Intercept( // special case for supportability: log all throttling cases. if resp.StatusCode == http.StatusTooManyRequests { logger.Ctx(ctx).Infow("graph api throttling", "method", req.Method, "url", req.URL) - } - - if resp.StatusCode != http.StatusTooManyRequests && (resp.StatusCode/100) != 2 { + } else if resp.StatusCode == http.StatusBadRequest { + respDump, _ := httputil.DumpResponse(resp, true) + logger.Ctx(ctx).Infow( + "graph api error", + "status", resp.Status, + "method", req.Method, + "url", req.URL, + "response", string(respDump), + ) + } else if resp.StatusCode/100 != 2 { logger.Ctx(ctx).Infow("graph api error", "status", resp.Status, "method", req.Method, "url", req.URL) } }