From 56980948c20662338e699adbb522312f07570054 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Thu, 16 Nov 2023 13:44:34 +0100 Subject: [PATCH] ref(replay): Add further logging to network body parsing (#9566) We got somewhat closer to figuring out the problem there. Based on this comment: https://github.com/getsentry/sentry-javascript/issues/9339#issuecomment-1811681894 > The requests are now showing with the request body, but the response body is "undefined" It seems that the problem is with parsing the response body for a XHR request. I added some more logging there, to be able to debug this further. --- .../replay/src/coreHandlers/util/networkUtils.ts | 2 ++ packages/replay/src/coreHandlers/util/xhrUtils.ts | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/replay/src/coreHandlers/util/networkUtils.ts b/packages/replay/src/coreHandlers/util/networkUtils.ts index f75ecf0f9bc9..be7b0d193d3d 100644 --- a/packages/replay/src/coreHandlers/util/networkUtils.ts +++ b/packages/replay/src/coreHandlers/util/networkUtils.ts @@ -78,6 +78,8 @@ export function getBodyString(body: unknown): string | undefined { __DEBUG_BUILD__ && logger.warn('[Replay] Failed to serialize body', body); } + __DEBUG_BUILD__ && logger.info('[Replay] Skipping network body because of body type', body); + return undefined; } diff --git a/packages/replay/src/coreHandlers/util/xhrUtils.ts b/packages/replay/src/coreHandlers/util/xhrUtils.ts index b11f8575e2ad..264090084cd9 100644 --- a/packages/replay/src/coreHandlers/util/xhrUtils.ts +++ b/packages/replay/src/coreHandlers/util/xhrUtils.ts @@ -135,15 +135,24 @@ function getResponseHeaders(xhr: XMLHttpRequest): Record { } function _getXhrResponseBody(xhr: XMLHttpRequest): string | undefined { + // We collect errors that happen, but only log them if we can't get any response body + const errors: unknown[] = []; + try { return xhr.responseText; - } catch {} // eslint-disable-line no-empty + } catch (e) { + errors.push(e); + } // Try to manually parse the response body, if responseText fails try { const response = xhr.response; return getBodyString(response); - } catch {} // eslint-disable-line no-empty + } catch (e) { + errors.push(e); + } + + __DEBUG_BUILD__ && logger.warn('[Replay] Failed to get xhr response body', ...errors); return undefined; }