From ab2e1da6a2164042d57b34ad9619c3dbc4fb8e9b Mon Sep 17 00:00:00 2001 From: Vemparala Surya Vamsi Date: Fri, 25 Oct 2024 09:36:05 +0530 Subject: [PATCH 1/4] capture performance of parsing api response --- app/client/src/api/Api.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/app/client/src/api/Api.ts b/app/client/src/api/Api.ts index 1eff364c4d04..625c617bb64b 100644 --- a/app/client/src/api/Api.ts +++ b/app/client/src/api/Api.ts @@ -19,6 +19,29 @@ export const apiRequestConfig = { const axiosInstance: AxiosInstance = axios.create(); +axiosInstance.defaults.transformResponse = [ + function (...args) { + const transformResponseAr = axios.defaults.transformResponse; + + if (Array.isArray(transformResponseAr) && transformResponseAr?.[0]) { + const transfromFn = transformResponseAr?.[0]; + const resp = startAndEndSpanForFn( + "transformApiResponse", + { url: this.url }, + transfromFn.call(this, ...args), + ); + + return resp; + } else { + // eslint-disable-next-line no-console + console.error("could not find the api transformFn transformerFn"); + + // return the data as it is. + return args[0]; + } + }, +]; + axiosInstance.interceptors.request.use(apiRequestInterceptor); axiosInstance.interceptors.response.use( From c80224e19352efb9a22817e7c12bf2818c5703e8 Mon Sep 17 00:00:00 2001 From: Vemparala Surya Vamsi Date: Fri, 25 Oct 2024 09:39:49 +0530 Subject: [PATCH 2/4] small fix --- app/client/src/api/Api.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/client/src/api/Api.ts b/app/client/src/api/Api.ts index 625c617bb64b..a75a9d49b37d 100644 --- a/app/client/src/api/Api.ts +++ b/app/client/src/api/Api.ts @@ -7,6 +7,7 @@ import { } from "./interceptors"; import { REQUEST_TIMEOUT_MS } from "ee/constants/ApiConstants"; import { convertObjectToQueryParams } from "utils/URLUtils"; +import { startAndEndSpanForFn } from "UITelemetry/generateTraces"; export const apiRequestConfig = { baseURL: "/api/", @@ -23,6 +24,7 @@ axiosInstance.defaults.transformResponse = [ function (...args) { const transformResponseAr = axios.defaults.transformResponse; + // Pick up the transformFn from the defaults and wrap it in with telemetry code if (Array.isArray(transformResponseAr) && transformResponseAr?.[0]) { const transfromFn = transformResponseAr?.[0]; const resp = startAndEndSpanForFn( @@ -34,7 +36,7 @@ axiosInstance.defaults.transformResponse = [ return resp; } else { // eslint-disable-next-line no-console - console.error("could not find the api transformFn transformerFn"); + console.error("could not find the api transformerFn"); // return the data as it is. return args[0]; From 46887acd07a825d7773e1d29a719b868bb4ff6b5 Mon Sep 17 00:00:00 2001 From: Vemparala Surya Vamsi Date: Fri, 25 Oct 2024 10:15:16 +0530 Subject: [PATCH 3/4] samll fix --- app/client/src/api/Api.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/client/src/api/Api.ts b/app/client/src/api/Api.ts index a75a9d49b37d..1fd1f28d216d 100644 --- a/app/client/src/api/Api.ts +++ b/app/client/src/api/Api.ts @@ -30,7 +30,7 @@ axiosInstance.defaults.transformResponse = [ const resp = startAndEndSpanForFn( "transformApiResponse", { url: this.url }, - transfromFn.call(this, ...args), + () => transfromFn.call(this, ...args), ); return resp; From 92f9d882b4f0dd40b1b3e38cb817b371b8288a68 Mon Sep 17 00:00:00 2001 From: Vemparala Surya Vamsi Date: Fri, 25 Oct 2024 10:38:26 +0530 Subject: [PATCH 4/4] axios fix --- app/client/src/api/Api.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/client/src/api/Api.ts b/app/client/src/api/Api.ts index 1fd1f28d216d..e724fdac1830 100644 --- a/app/client/src/api/Api.ts +++ b/app/client/src/api/Api.ts @@ -24,11 +24,11 @@ axiosInstance.defaults.transformResponse = [ function (...args) { const transformResponseAr = axios.defaults.transformResponse; - // Pick up the transformFn from the defaults and wrap it in with telemetry code + // Pick up the transformFn from axios defaults and wrap it in with telemetry code so that we can capture how long it takes parse an api response if (Array.isArray(transformResponseAr) && transformResponseAr?.[0]) { const transfromFn = transformResponseAr?.[0]; const resp = startAndEndSpanForFn( - "transformApiResponse", + "axios.transformApiResponse", { url: this.url }, () => transfromFn.call(this, ...args), );