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.

revamps api layer

dhrubesh-makeen88e488bdc73c
diff --git a/frontend/src/api/apiV1.ts b/frontend/src/api/apiV1.ts
new file mode 100644
index 0000000000..2cd9b83295
--- /dev/null
+++ b/frontend/src/api/apiV1.ts
@@ -0,0 +1,3 @@
+const apiV1 = "/api/v1/";
+
+export default apiV1;
diff --git a/frontend/src/api/graphQuery.js b/frontend/src/api/graphQuery.js
deleted file mode 100644
index e679ca505d..0000000000
--- a/frontend/src/api/graphQuery.js
+++ /dev/null
@@ -1,8 +0,0 @@
-import axios from "axios";
-import { ENVIRONMENT } from "Src/constants/env";
-import { Token } from "../utils/token";
-
-// No auth for the API
-export default axios.create({
- baseURL: `${ENVIRONMENT.baseURL}/api/prom/api/v1`,
-});
diff --git a/frontend/src/api/index.ts b/frontend/src/api/index.ts
new file mode 100644
index 0000000000..c580024bcb
--- /dev/null
+++ b/frontend/src/api/index.ts
@@ -0,0 +1,9 @@
+import axios, { AxiosRequestConfig } from "axios";
+import { ENVIRONMENT } from "Src/constants/env";
+import apiV1 from "./apiV1";
+
+export default axios.create({
+ baseURL: `${ENVIRONMENT.baseURL}`,
+});
+
+export { apiV1 };
diff --git a/frontend/src/api/metricsAPI.js b/frontend/src/api/metricsAPI.js
deleted file mode 100644
index f82bf8f357..0000000000
--- a/frontend/src/api/metricsAPI.js
+++ /dev/null
@@ -1,6 +0,0 @@
-import axios from "axios";
-import { ENVIRONMENT } from "Src/constants/env";
-
-export default axios.create({
- baseURL: `${ENVIRONMENT.baseURL}/api/v1/`,
-});
diff --git a/frontend/src/api/submitForm.js b/frontend/src/api/submitForm.js
deleted file mode 100644
index 216569dad5..0000000000
--- a/frontend/src/api/submitForm.js
+++ /dev/null
@@ -1,15 +0,0 @@
-import axios from "axios";
-import { ENVIRONMENT } from "Src/constants/env";
-import { Token } from "../utils/token";
-
-export default axios.create({
- // baseURL: 'https://api.telegram.org/bot1518273960:AAHcgVvym9a0Qkl-PKiCI84X1VZaVbkTud0/',
- // baseURL: 'http://104.211.113.204:8080/api/v1/',
- // baseURL: "/api/v1/",
- baseURL: `${ENVIRONMENT.baseURL}/api/v1/`,
-});
-
-//https://api.telegram.org/bot1518273960:AAHcgVvym9a0Qkl-PKiCI84X1VZaVbkTud0/sendMessage?chat_id=351813222&text=Hello%20there
-
-// Chat ID can be obtained from here
-//https://api.telegram.org/bot1518273960:AAHcgVvym9a0Qkl-PKiCI84X1VZaVbkTud0/getUpdates
diff --git a/frontend/src/api/tracesAPI.js b/frontend/src/api/tracesAPI.js
deleted file mode 100644
index 9c11771e6b..0000000000
--- a/frontend/src/api/tracesAPI.js
+++ /dev/null
@@ -1,12 +0,0 @@
-import axios from "axios";
-import { ENVIRONMENT } from "Src/constants/env";
-import { Token } from "../utils/token";
-//import { format } from 'path';
-
-export default axios.create({
- // baseURL: 'http://104.211.113.204:8080/api/v1/' //comment this line and remove this comment before pushing
- // baseURL: process.env.QUERY_SERVICE_URL,
- // console.log('in traces API', process.env.QUERY_SERVICE_URL)
- // baseURL: "/api/v1/",
- baseURL: `${ENVIRONMENT.baseURL}/api/v1/`,
-});
diff --git a/frontend/src/components/Signup.tsx b/frontend/src/components/Signup.tsx
index c8e7d6593e..6e90ceb6fe 100644
--- a/frontend/src/components/Signup.tsx
+++ b/frontend/src/components/Signup.tsx
@@ -1,6 +1,7 @@
-import React, { useState, useRef, Suspense } from "react";
-import { Row, Space, Button, Input, Checkbox } from "antd";
-import submitForm from "../api/submitForm";
+import React, { useState } from "react";
+import { Row, Space, Button, Input } from "antd";
+import api, { apiV1 } from "../api";
+
import { withRouter } from "react-router";
import { RouteComponentProps } from "react-router-dom";
@@ -15,14 +16,10 @@ const Signup = (props: SignUpProps) => {
password: { value: "", valid: true },
emailOptIn: { value: true },
});
- const passwordInput = useRef(null);
- // const { createAccount } = useActions(signupLogic)
- // const { accountLoading } = useValues(signupLogic)
- // const { plan } = fromParams()
const updateForm = (name: any, target: any, valueAttr = "value") => {
/* Validate password (if applicable) */
- if (name === "firstName") {
+ if (name === "firstName") {
setFormState({
...formState,
firstName: { ...formState.firstName, value: target[valueAttr] },
@@ -49,9 +46,7 @@ const Signup = (props: SignUpProps) => {
let texttolog = JSON.stringify(payload);
-
-
- submitForm.post("user?email=" + texttolog).then((res) => {
+ api.post(apiV1 + "/user?email=" + texttolog).then((res) => {
console.log(res);
console.log(res.data);
});
@@ -118,8 +113,6 @@ const Signup = (props: SignUpProps) => {
/>
</div>
-
-
<div className="input-set">
<label htmlFor="signupFirstName">First Name</label>
<Input
@@ -133,7 +126,7 @@ const Signup = (props: SignUpProps) => {
/>
</div>
- <div className="text-center space-top" style={{marginTop: 12}}>
+ <div className="text-center space-top" style={{ marginTop: 12 }}>
<Button
type="primary"
htmlType="submit"
diff --git a/frontend/src/components/traces/TraceFilter.tsx b/frontend/src/components/traces/TraceFilter.tsx
index 84f12fb993..a1c40fdbb8 100644
--- a/frontend/src/components/traces/TraceFilter.tsx
+++ b/frontend/src/components/traces/TraceFilter.tsx
@@ -15,7 +15,7 @@ import LatencyModalForm from "./LatencyModalForm";
import { FilterStateDisplay } from "./FilterStateDisplay";
import FormItem from "antd/lib/form/FormItem";
-import metricsAPI from "../../api/metricsAPI";
+import api, { apiV1 } from "../../api";
import { useLocation } from "react-router-dom";
import { METRICS_PAGE_QUERY_PARAM } from "Src/constants/query";
@@ -46,18 +46,18 @@ const _TraceFilter = (props: TraceFilterProps) => {
const location = useLocation();
const urlParams = new URLSearchParams(location.search.split("?")[1]);
- useEffect(()=>{
+ useEffect(() => {
handleApplyFilterForm({
service: "",
tags: [],
operation: "",
latency: { min: "", max: "" },
- })
- },[])
+ });
+ }, []);
useEffect(() => {
- metricsAPI
- .get<string[]>("services/list")
+ api
+ .get<string[]>(`${apiV1}/services/list`)
.then((response) => {
setServiceList(response.data);
})
@@ -154,15 +154,17 @@ const _TraceFilter = (props: TraceFilterProps) => {
function handleChangeService(value: string) {
let service_request = "/service/" + value + "/operations";
- metricsAPI.get<string[]>(service_request).then((response) => {
+ api.get<string[]>(apiV1 + service_request).then((response) => {
// form_basefilter.resetFields(['operation',])
setOperationsList(response.data);
});
- let tagkeyoptions_request = "tags?service=" + value;
- metricsAPI.get<TagKeyOptionItem[]>(tagkeyoptions_request).then((response) => {
- setTagKeyOptions(response.data);
- });
+ let tagkeyoptions_request = "/tags?service=" + value;
+ api
+ .get<TagKeyOptionItem[]>(apiV1 + tagkeyoptions_request)
+ .then((response) => {
+ setTagKeyOptions(response.data);
+ });
props.updateTraceFilters({ ...props.traceFilters, service: value });
}
@@ -287,21 +289,21 @@ const _TraceFilter = (props: TraceFilterProps) => {
operation: values.operation,
latency: {
max: "",
- min: ""
+ min: "",
},
});
};
- useEffect(()=>{
- return ()=>{
+ useEffect(() => {
+ return () => {
props.updateTraceFilters({
service: "",
operation: "",
tags: [],
latency: { min: "", max: "" },
});
- }
- },[])
+ };
+ }, []);
return (
<div>
diff --git a/frontend/src/store/actions/metrics.ts b/frontend/src/store/actions/metrics.ts
index c1592a512a..68bc0edc72 100644
--- a/frontend/src/store/actions/metrics.ts
+++ b/frontend/src/store/actions/metrics.ts
@@ -1,5 +1,6 @@
import { Dispatch } from "redux";
-import metricsAPI from "../../api/metricsAPI";
+import api, { apiV1 } from "../../api";
+
import { GlobalTime } from "./global";
import { ActionTypes } from "./types";
import { Token } from "../../utils/token";
@@ -62,9 +63,9 @@ export interface getFilteredTraceMetricsAction {
export const getServicesList = (globalTime: GlobalTime) => {
return async (dispatch: Dispatch) => {
let request_string =
- "services?start=" + globalTime.minTime + "&end=" + globalTime.maxTime;
+ "/services?start=" + globalTime.minTime + "&end=" + globalTime.maxTime;
- const response = await metricsAPI.get<servicesListItem[]>(request_string);
+ const response = await api.get<servicesListItem[]>(apiV1 + request_string);
dispatch<getServicesListAction>({
type: ActionTypes.getServicesList,
@@ -80,14 +81,14 @@ export const getServicesMetrics = (
) => {
return async (dispatch: Dispatch) => {
let request_string =
- "service/overview?service=" +
+ "/service/overview?service=" +
serviceName +
"&start=" +
globalTime.minTime +
"&end=" +
globalTime.maxTime +
"&step=60";
- const response = await metricsAPI.get<metricItem[]>(request_string);
+ const response = await api.get<metricItem[]>(apiV1 + request_string);
dispatch<getServiceMetricsAction>({
type: ActionTypes.getServiceMetrics,
@@ -103,13 +104,13 @@ export const getTopEndpoints = (
) => {
return async (dispatch: Dispatch) => {
let request_string =
- "service/top_endpoints?service=" +
+ "/service/top_endpoints?service=" +
serviceName +
"&start=" +
globalTime.minTime +
"&end=" +
globalTime.maxTime;
- const response = await metricsAPI.get<topEndpointListItem[]>(request_string);
+ const response = await api.get<topEndpointListItem[]>(apiV1 + request_string);
dispatch<getTopEndpointsAction>({
type: ActionTypes.getTopEndpoints,
@@ -125,13 +126,13 @@ export const getFilteredTraceMetrics = (
) => {
return async (dispatch: Dispatch) => {
let request_string =
- "spans/aggregates?start=" +
+ "/spans/aggregates?start=" +
toUTCEpoch(globalTime.minTime) +
"&end=" +
toUTCEpoch(globalTime.maxTime) +
"&" +
filter_params;
- const response = await metricsAPI.get<customMetricsItem[]>(request_string);
+ const response = await api.get<customMetricsItem[]>(apiV1 + request_string);
dispatch<getFilteredTraceMetricsAction>({
type: ActionTypes.getFilteredTraceMetrics,
diff --git a/frontend/src/store/actions/traces.ts b/frontend/src/store/actions/traces.ts
index b694312212..2f8f5ae2d1 100644
--- a/frontend/src/store/actions/traces.ts
+++ b/frontend/src/store/actions/traces.ts
@@ -1,5 +1,6 @@
import { ActionTypes } from "./types";
-import tracesAPI from "../../api/tracesAPI";
+import api, { apiV1 } from "../../api";
+
import { Dispatch } from "redux";
import { GlobalTime } from "./global";
import { toUTCEpoch } from "../../utils/timeUtils";
@@ -121,13 +122,13 @@ export const fetchTraces = (globalTime: GlobalTime, filter_params: string) => {
return async (dispatch: Dispatch) => {
if (globalTime) {
let request_string =
- "spans?limit=100&lookback=2d&start=" +
+ "/spans?limit=100&lookback=2d&start=" +
toUTCEpoch(globalTime.minTime) +
"&end=" +
toUTCEpoch(globalTime.maxTime) +
"&" +
filter_params;
- const response = await tracesAPI.get<traceResponseNew>(request_string);
+ const response = await api.get<traceResponseNew>(apiV1 + request_string);
dispatch<FetchTracesAction>({
type: ActionTypes.fetchTraces,
@@ -140,9 +141,9 @@ export const fetchTraces = (globalTime: GlobalTime, filter_params: string) => {
export const fetchTraceItem = (traceID: string) => {
return async (dispatch: Dispatch) => {
- let request_string = "traces/" + traceID;
- const response = await tracesAPI.get<spansWSameTraceIDResponse>(
- request_string,
+ let request_string = "/traces/" + traceID;
+ const response = await api.get<spansWSameTraceIDResponse>(
+ apiV1 + request_string,
);
dispatch<FetchTraceItemAction>({
diff --git a/frontend/src/store/actions/usage.ts b/frontend/src/store/actions/usage.ts
index b212bc9533..a46b684f4d 100644
--- a/frontend/src/store/actions/usage.ts
+++ b/frontend/src/store/actions/usage.ts
@@ -1,5 +1,6 @@
import { Dispatch } from "redux";
-import metricsAPI from "../../api/metricsAPI";
+import api, { apiV1 } from "../../api";
+
import { ActionTypes } from "./types";
import { GlobalTime } from "./global";
import { toUTCEpoch } from "../../utils/timeUtils";
@@ -21,11 +22,11 @@ export const getUsageData = (
service: string,
) => {
return async (dispatch: Dispatch) => {
- let request_string = `usage?start=${toUTCEpoch(minTime)}&end=${toUTCEpoch(
+ let request_string = `/usage?start=${toUTCEpoch(minTime)}&end=${toUTCEpoch(
maxTime,
)}&step=${step}&service=${service ? service : ""}`;
//Step can only be multiple of 3600
- const response = await metricsAPI.get<usageDataItem[]>(request_string);
+ const response = await api.get<usageDataItem[]>(apiV1 + request_string);
dispatch<getUsageDataAction>({
type: ActionTypes.getUsageData,