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.

1.5 KB
Raw Blame
import { ApiV2Instance as axios } from 'api';
import { ErrorResponseHandler } from 'api/ErrorResponseHandler';
import { AxiosError } from 'axios';
import getStartEndRangeTime from 'lib/getStartEndRangeTime';
import store from 'store';
import { ErrorResponse, SuccessResponse } from 'types/api';
import {
	Props,
	VariableResponseProps,
} from 'types/api/dashboard/variables/query';

const dashboardVariablesQuery = async (
	props: Props,
	signal?: AbortSignal,
): Promise<SuccessResponse<VariableResponseProps> | ErrorResponse> => {
	try {
		const { globalTime } = store.getState();
		const { start, end } = getStartEndRangeTime({
			type: 'GLOBAL_TIME',
			interval: globalTime.selectedTime,
		});

		const timeVariables: Record<string, number> = {
			start_timestamp_ms: parseInt(start, 10) * 1e3,
			end_timestamp_ms: parseInt(end, 10) * 1e3,
			start_timestamp_nano: parseInt(start, 10) * 1e9,
			end_timestamp_nano: parseInt(end, 10) * 1e9,
			start_timestamp: parseInt(start, 10),
			end_timestamp: parseInt(end, 10),
		};

		const payload = { ...props };

		payload.variables = { ...payload.variables, ...timeVariables };

		const response = await axios.post(`/variables/query`, payload, { signal });

		return {
			statusCode: 200,
			error: null,
			message: response.data.status,
			payload: response.data.data,
		};
	} catch (error) {
		const formattedError = ErrorResponseHandler(error as AxiosError);

		throw { message: 'Error fetching data', details: formattedError };
	}
};

export default dashboardVariablesQuery;