Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: capture performance of parsing api response #37081

Merged
merged 4 commits into from
Oct 25, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions app/client/src/api/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand All @@ -19,6 +20,30 @@ export const apiRequestConfig = {

const axiosInstance: AxiosInstance = axios.create();

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(
"transformApiResponse",
{ url: this.url },
transfromFn.call(this, ...args),
);

return resp;
} else {
// eslint-disable-next-line no-console
console.error("could not find the api transformerFn");

// return the data as it is.
return args[0];
}
},
];

axiosInstance.interceptors.request.use(apiRequestInterceptor);

axiosInstance.interceptors.response.use(
Expand Down
Loading