diff --git a/packages/utils/src/instrument/fetch.ts b/packages/utils/src/instrument/fetch.ts index 9a0a959c4c3a..fb58c0ae16e8 100644 --- a/packages/utils/src/instrument/fetch.ts +++ b/packages/utils/src/instrument/fetch.ts @@ -64,21 +64,10 @@ function instrumentFetch(): void { DEBUG_BUILD && logger.warn('Failed to clone response body.'); } - if (clonedResponseForResolving && clonedResponseForResolving.body) { - const responseReader = clonedResponseForResolving.body.getReader(); - - // eslint-disable-next-line no-inner-declarations - function consumeChunks({ done }: { done: boolean }): Promise { - if (!done) { - return responseReader.read().then(consumeChunks); - } else { - return Promise.resolve(); - } - } - - responseReader - .read() - .then(consumeChunks) + if (clonedResponseForResolving) { + clonedResponseForResolving + // This waits until the full body has been received + .text() .then(() => { triggerHandlers('fetch', { ...handlerData, @@ -97,11 +86,7 @@ function instrumentFetch(): void { }); } - return new Promise(resolve => { - setTimeout(() => { - resolve(response); - }, 0); - }); + return response; }, (error: Error) => { const erroredHandlerData: HandlerDataFetch = {