Skip to content

Commit

Permalink
chore: capture performance of parsing api response (appsmithorg#37081)
Browse files Browse the repository at this point in the history
## Description
Capture performance of parsing api responses.

Fixes #`Issue Number`  
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

/ok-to-test tags="@tag.All"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/11512264036>
> Commit: 92f9d88
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11512264036&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Fri, 25 Oct 2024 06:47:52 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit


- **New Features**
- Introduced a telemetry feature for enhanced monitoring of API requests
and responses.

- **Bug Fixes**
- Improved error handling by logging issues when default transformation
functions are not found.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
vsvamsi1 authored Oct 25, 2024
1 parent 4cf8d37 commit 415085e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions 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 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(
"axios.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

0 comments on commit 415085e

Please sign in to comment.