Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix(sessions): do not use axios base instance (#9556)

Vikrant Guptac44efeab330d
diff --git a/frontend/src/api/common/logEvent.ts b/frontend/src/api/common/logEvent.ts
index fd09002582..e4460ddf1f 100644
--- a/frontend/src/api/common/logEvent.ts
+++ b/frontend/src/api/common/logEvent.ts
@@ -1,4 +1,4 @@
-import { ApiBaseInstance as axios } from 'api';
+import { LogEventAxiosInstance as axios } from 'api';
import { ErrorResponseHandler } from 'api/ErrorResponseHandler';
import { AxiosError } from 'axios';
import { ErrorResponse, SuccessResponse } from 'types/api';
diff --git a/frontend/src/api/dynamicVariables/__tests__/getFieldKeys.test.ts b/frontend/src/api/dynamicVariables/__tests__/getFieldKeys.test.ts
index c94c915b62..54c7250d12 100644
--- a/frontend/src/api/dynamicVariables/__tests__/getFieldKeys.test.ts
+++ b/frontend/src/api/dynamicVariables/__tests__/getFieldKeys.test.ts
@@ -1,13 +1,11 @@
/* eslint-disable sonarjs/no-duplicate-string */
-import { ApiBaseInstance } from 'api';
+import axios from 'api';
import { getFieldKeys } from '../getFieldKeys';
// Mock the API instance
jest.mock('api', () => ({
- ApiBaseInstance: {
- get: jest.fn(),
- },
+ get: jest.fn(),
}));
describe('getFieldKeys API', () => {
@@ -31,33 +29,33 @@ describe('getFieldKeys API', () => {
it('should call API with correct parameters when no args provided', async () => {
// Mock successful API response
- (ApiBaseInstance.get as jest.Mock).mockResolvedValueOnce(mockSuccessResponse);
+ (axios.get as jest.Mock).mockResolvedValueOnce(mockSuccessResponse);
// Call function with no parameters
await getFieldKeys();
// Verify API was called correctly with empty params object
- expect(ApiBaseInstance.get).toHaveBeenCalledWith('/fields/keys', {
+ expect(axios.get).toHaveBeenCalledWith('/fields/keys', {
params: {},
});
});
it('should call API with signal parameter when provided', async () => {
// Mock successful API response
- (ApiBaseInstance.get as jest.Mock).mockResolvedValueOnce(mockSuccessResponse);
+ (axios.get as jest.Mock).mockResolvedValueOnce(mockSuccessResponse);
// Call function with signal parameter
await getFieldKeys('traces');
// Verify API was called with signal parameter
- expect(ApiBaseInstance.get).toHaveBeenCalledWith('/fields/keys', {
+ expect(axios.get).toHaveBeenCalledWith('/fields/keys', {
params: { signal: 'traces' },
});
});
it('should call API with name parameter when provided', async () => {
// Mock successful API response
- (ApiBaseInstance.get as jest.Mock).mockResolvedValueOnce({
+ (axios.get as jest.Mock).mockResolvedValueOnce({
status: 200,
data: {
status: 'success',
@@ -72,14 +70,14 @@ describe('getFieldKeys API', () => {
await getFieldKeys(undefined, 'service');
// Verify API was called with name parameter
- expect(ApiBaseInstance.get).toHaveBeenCalledWith('/fields/keys', {
+ expect(axios.get).toHaveBeenCalledWith('/fields/keys', {
params: { name: 'service' },
});
});
it('should call API with both signal and name when provided', async () => {
// Mock successful API response
- (ApiBaseInstance.get as jest.Mock).mockResolvedValueOnce({
+ (axios.get as jest.Mock).mockResolvedValueOnce({
status: 200,
data: {
status: 'success',
@@ -94,14 +92,14 @@ describe('getFieldKeys API', () => {
await getFieldKeys('logs', 'service');
// Verify API was called with both parameters
- expect(ApiBaseInstance.get).toHaveBeenCalledWith('/fields/keys', {
+ expect(axios.get).toHaveBeenCalledWith('/fields/keys', {
params: { signal: 'logs', name: 'service' },
});
});
it('should return properly formatted response', async () => {
// Mock API to return our response
- (ApiBaseInstance.get as jest.Mock).mockResolvedValueOnce(mockSuccessResponse);
+ (axios.get as jest.Mock).mockResolvedValueOnce(mockSuccessResponse);
// Call the function
const result = await getFieldKeys('traces');
diff --git a/frontend/src/api/dynamicVariables/__tests__/getFieldValues.test.ts b/frontend/src/api/dynamicVariables/__tests__/getFieldValues.test.ts
index 896e939e9a..1622bc8a06 100644
--- a/frontend/src/api/dynamicVariables/__tests__/getFieldValues.test.ts
+++ b/frontend/src/api/dynamicVariables/__tests__/getFieldValues.test.ts
@@ -1,13 +1,11 @@
/* eslint-disable sonarjs/no-duplicate-string */
-import { ApiBaseInstance } from 'api';
+import axios from 'api';
import { getFieldValues } from '../getFieldValues';
// Mock the API instance
jest.mock('api', () => ({
- ApiBaseInstance: {
- get: jest.fn(),
- },
+ get: jest.fn(),
}));
describe('getFieldValues API', () => {
@@ -17,7 +15,7 @@ describe('getFieldValues API', () => {
it('should call the API with correct parameters (no options)', async () => {
// Mock API response
- (ApiBaseInstance.get as jest.Mock).mockResolvedValueOnce({
+ (axios.get as jest.Mock).mockResolvedValueOnce({
status: 200,
data: {
status: 'success',
@@ -34,14 +32,14 @@ describe('getFieldValues API', () => {
await getFieldValues();
// Verify API was called correctly with empty params
- expect(ApiBaseInstance.get).toHaveBeenCalledWith('/fields/values', {
+ expect(axios.get).toHaveBeenCalledWith('/fields/values', {
params: {},
});
});
it('should call the API with signal parameter', async () => {
// Mock API response
- (ApiBaseInstance.get as jest.Mock).mockResolvedValueOnce({
+ (axios.get as jest.Mock).mockResolvedValueOnce({
status: 200,
data: {
status: 'success',
@@ -58,14 +56,14 @@ describe('getFieldValues API', () => {
await getFieldValues('traces');
// Verify API was called with signal parameter
- expect(ApiBaseInstance.get).toHaveBeenCalledWith('/fields/values', {
+ expect(axios.get).toHaveBeenCalledWith('/fields/values', {
params: { signal: 'traces' },
});
});
it('should call the API with name parameter', async () => {
// Mock API response
- (ApiBaseInstance.get as jest.Mock).mockResolvedValueOnce({
+ (axios.get as jest.Mock).mockResolvedValueOnce({
status: 200,
data: {
status: 'success',
@@ -82,14 +80,14 @@ describe('getFieldValues API', () => {
await getFieldValues(undefined, 'service.name');
// Verify API was called with name parameter
- expect(ApiBaseInstance.get).toHaveBeenCalledWith('/fields/values', {
+ expect(axios.get).toHaveBeenCalledWith('/fields/values', {
params: { name: 'service.name' },
});
});
it('should call the API with value parameter', async () => {
// Mock API response
- (ApiBaseInstance.get as jest.Mock).mockResolvedValueOnce({
+ (axios.get as jest.Mock).mockResolvedValueOnce({
status: 200,
data: {
status: 'success',
@@ -106,14 +104,14 @@ describe('getFieldValues API', () => {
await getFieldValues(undefined, 'service.name', 'front');
// Verify API was called with value parameter
- expect(ApiBaseInstance.get).toHaveBeenCalledWith('/fields/values', {
+ expect(axios.get).toHaveBeenCalledWith('/fields/values', {
params: { name: 'service.name', searchText: 'front' },
});
});
it('should call the API with time range parameters', async () => {
// Mock API response
- (ApiBaseInstance.get as jest.Mock).mockResolvedValueOnce({
+ (axios.get as jest.Mock).mockResolvedValueOnce({
status: 200,
data: {
status: 'success',
@@ -138,7 +136,7 @@ describe('getFieldValues API', () => {
);
// Verify API was called with time range parameters (converted to milliseconds)
- expect(ApiBaseInstance.get).toHaveBeenCalledWith('/fields/values', {
+ expect(axios.get).toHaveBeenCalledWith('/fields/values', {
params: {
signal: 'logs',
name: 'service.name',
@@ -165,7 +163,7 @@ describe('getFieldValues API', () => {
},
};
- (ApiBaseInstance.get as jest.Mock).mockResolvedValueOnce(mockResponse);
+ (axios.get as jest.Mock).mockResolvedValueOnce(mockResponse);
// Call the function
const result = await getFieldValues('traces', 'mixed.values');
@@ -196,7 +194,7 @@ describe('getFieldValues API', () => {
};
// Mock API to return our response
- (ApiBaseInstance.get as jest.Mock).mockResolvedValueOnce(mockApiResponse);
+ (axios.get as jest.Mock).mockResolvedValueOnce(mockApiResponse);
// Call the function
const result = await getFieldValues('traces', 'service.name');
diff --git a/frontend/src/api/dynamicVariables/getFieldKeys.ts b/frontend/src/api/dynamicVariables/getFieldKeys.ts
index 12bfdf1d1e..3a9dd00011 100644
--- a/frontend/src/api/dynamicVariables/getFieldKeys.ts
+++ b/frontend/src/api/dynamicVariables/getFieldKeys.ts
@@ -1,4 +1,4 @@
-import { ApiBaseInstance } from 'api';
+import axios from 'api';
import { ErrorResponseHandlerV2 } from 'api/ErrorResponseHandlerV2';
import { AxiosError } from 'axios';
import { ErrorV2Resp, SuccessResponseV2 } from 'types/api';
@@ -24,7 +24,7 @@ export const getFieldKeys = async (
}
try {
- const response = await ApiBaseInstance.get('/fields/keys', { params });
+ const response = await axios.get('/fields/keys', { params });
return {
httpStatusCode: response.status,
diff --git a/frontend/src/api/dynamicVariables/getFieldValues.ts b/frontend/src/api/dynamicVariables/getFieldValues.ts
index 6e0c60ec2b..2ae6101882 100644
--- a/frontend/src/api/dynamicVariables/getFieldValues.ts
+++ b/frontend/src/api/dynamicVariables/getFieldValues.ts
@@ -1,5 +1,5 @@
/* eslint-disable sonarjs/cognitive-complexity */
-import { ApiBaseInstance } from 'api';
+import axios from 'api';
import { ErrorResponseHandlerV2 } from 'api/ErrorResponseHandlerV2';
import { AxiosError } from 'axios';
import { ErrorV2Resp, SuccessResponseV2 } from 'types/api';
@@ -47,7 +47,7 @@ export const getFieldValues = async (
}
try {
- const response = await ApiBaseInstance.get('/fields/values', { params });
+ const response = await axios.get('/fields/values', { params });
// Normalize values from different types (stringValues, boolValues, etc.)
if (response.data?.data?.values) {
diff --git a/frontend/src/api/index.ts b/frontend/src/api/index.ts
index 430982b14e..a24cf6be90 100644
--- a/frontend/src/api/index.ts
+++ b/frontend/src/api/index.ts
@@ -200,15 +200,15 @@ ApiV5Instance.interceptors.request.use(interceptorsRequestResponse);
//
// axios Base
-export const ApiBaseInstance = axios.create({
+export const LogEventAxiosInstance = axios.create({
baseURL: `${ENVIRONMENT.baseURL}${apiV1}`,
});
-ApiBaseInstance.interceptors.response.use(
+LogEventAxiosInstance.interceptors.response.use(
interceptorsResponse,
interceptorRejectedBase,
);
-ApiBaseInstance.interceptors.request.use(interceptorsRequestResponse);
+LogEventAxiosInstance.interceptors.request.use(interceptorsRequestResponse);
//
// gateway Api V1
diff --git a/frontend/src/api/infra/getHostAttributeKeys.ts b/frontend/src/api/infra/getHostAttributeKeys.ts
index 1a34cd4479..ce39b79788 100644
--- a/frontend/src/api/infra/getHostAttributeKeys.ts
+++ b/frontend/src/api/infra/getHostAttributeKeys.ts
@@ -1,4 +1,4 @@
-import { ApiBaseInstance } from 'api';
+import axios from 'api';
import { ErrorResponseHandler } from 'api/ErrorResponseHandler';
import { AxiosError, AxiosResponse } from 'axios';
import { baseAutoCompleteIdKeysOrder } from 'constants/queryBuilder';
@@ -17,7 +17,7 @@ export const getHostAttributeKeys = async (
try {
const response: AxiosResponse<{
data: IQueryAutocompleteResponse;
- }> = await ApiBaseInstance.get(
+ }> = await axios.get(
`/${entity}/attribute_keys?dataSource=metrics&searchText=${searchText}`,
{
params: {
diff --git a/frontend/src/api/messagingQueues/onboarding/getOnboardingStatus.ts b/frontend/src/api/messagingQueues/onboarding/getOnboardingStatus.ts
index da82e70134..79bb859b04 100644
--- a/frontend/src/api/messagingQueues/onboarding/getOnboardingStatus.ts
+++ b/frontend/src/api/messagingQueues/onboarding/getOnboardingStatus.ts
@@ -1,4 +1,4 @@
-import { ApiBaseInstance } from 'api';
+import axios from 'api';
import { ErrorResponseHandler } from 'api/ErrorResponseHandler';
import { AxiosError } from 'axios';
import { SOMETHING_WENT_WRONG } from 'constants/api';
@@ -20,7 +20,7 @@ const getOnboardingStatus = async (props: {
}): Promise<SuccessResponse<OnboardingStatusResponse> | ErrorResponse> => {
const { endpointService, ...rest } = props;
try {
- const response = await ApiBaseInstance.post(
+ const response = await axios.post(
`/messaging-queues/kafka/onboarding/${endpointService || 'consumers'}`,
rest,
);
diff --git a/frontend/src/api/quickFilters/getCustomFilters.ts b/frontend/src/api/quickFilters/getCustomFilters.ts
index b5bd6308e8..6bea61347e 100644
--- a/frontend/src/api/quickFilters/getCustomFilters.ts
+++ b/frontend/src/api/quickFilters/getCustomFilters.ts
@@ -1,4 +1,4 @@
-import { ApiBaseInstance } from 'api';
+import axios from 'api';
import { ErrorResponseHandler } from 'api/ErrorResponseHandler';
import { AxiosError } from 'axios';
import { ErrorResponse, SuccessResponse } from 'types/api';
@@ -9,7 +9,7 @@ const getCustomFilters = async (
): Promise<SuccessResponse<PayloadProps> | ErrorResponse> => {
const { signal } = props;
try {
- const response = await ApiBaseInstance.get(`orgs/me/filters/${signal}`);
+ const response = await axios.get(`/orgs/me/filters/${signal}`);
return {
statusCode: 200,
diff --git a/frontend/src/api/quickFilters/updateCustomFilters.ts b/frontend/src/api/quickFilters/updateCustomFilters.ts
index 46285a35a9..497dd60607 100644
--- a/frontend/src/api/quickFilters/updateCustomFilters.ts
+++ b/frontend/src/api/quickFilters/updateCustomFilters.ts
@@ -1,4 +1,4 @@
-import { ApiBaseInstance } from 'api';
+import axios from 'api';
import { AxiosError } from 'axios';
import { SuccessResponse } from 'types/api';
import { UpdateCustomFiltersProps } from 'types/api/quickFilters/updateCustomFilters';
@@ -6,7 +6,7 @@ import { UpdateCustomFiltersProps } from 'types/api/quickFilters/updateCustomFil
const updateCustomFiltersAPI = async (
props: UpdateCustomFiltersProps,
): Promise<SuccessResponse<void> | AxiosError> =>
- ApiBaseInstance.put(`orgs/me/filters`, {
+ axios.put(`/orgs/me/filters`, {
...props.data,
});
diff --git a/frontend/src/api/thirdPartyApis/listOverview.ts b/frontend/src/api/thirdPartyApis/listOverview.ts
index 303ee03ae0..7477cce591 100644
--- a/frontend/src/api/thirdPartyApis/listOverview.ts
+++ b/frontend/src/api/thirdPartyApis/listOverview.ts
@@ -1,4 +1,4 @@
-import { ApiBaseInstance } from 'api';
+import axios from 'api';
import { ErrorResponseHandlerV2 } from 'api/ErrorResponseHandlerV2';
import { AxiosError } from 'axios';
import { ErrorV2Resp, SuccessResponseV2 } from 'types/api';
@@ -9,15 +9,12 @@ const listOverview = async (
): Promise<SuccessResponseV2<PayloadProps>> => {
const { start, end, show_ip: showIp, filter } = props;
try {
- const response = await ApiBaseInstance.post(
- `/third-party-apis/overview/list`,
- {
- start,
- end,
- show_ip: showIp,
- filter,
- },
- );
+ const response = await axios.post(`/third-party-apis/overview/list`, {
+ start,
+ end,
+ show_ip: showIp,
+ filter,
+ });
return {
httpStatusCode: response.status,
diff --git a/frontend/src/api/trace/getSpanPercentiles.ts b/frontend/src/api/trace/getSpanPercentiles.ts
index 7d275401ba..5704484c80 100644
--- a/frontend/src/api/trace/getSpanPercentiles.ts
+++ b/frontend/src/api/trace/getSpanPercentiles.ts
@@ -1,4 +1,4 @@
-import { ApiBaseInstance } from 'api';
+import axios from 'api';
import { ErrorResponseHandlerV2 } from 'api/ErrorResponseHandlerV2';
import { AxiosError } from 'axios';
import { ErrorV2Resp, SuccessResponseV2 } from 'types/api';
@@ -11,7 +11,7 @@ const getSpanPercentiles = async (
props: GetSpanPercentilesProps,
): Promise<SuccessResponseV2<GetSpanPercentilesResponseDataProps>> => {
try {
- const response = await ApiBaseInstance.post('/span_percentile', {
+ const response = await axios.post('/span_percentile', {
...props,
});