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.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
chore: add analytics for metrics explorer (#8108)
Amlan Kumar Nandyf77bb888a82f
diff --git a/frontend/src/container/ExplorerOptions/ExplorerOptions.tsx b/frontend/src/container/ExplorerOptions/ExplorerOptions.tsxindex fa4a723f17..98b94df993 100644--- a/frontend/src/container/ExplorerOptions/ExplorerOptions.tsx+++ b/frontend/src/container/ExplorerOptions/ExplorerOptions.tsx@@ -24,6 +24,10 @@ import { QueryParams } from 'constants/query';import { PANEL_TYPES } from 'constants/queryBuilder';import ROUTES from 'constants/routes';import ExportPanelContainer from 'container/ExportPanel/ExportPanelContainer';+import {+ MetricsExplorerEventKeys,+ MetricsExplorerEvents,+} from 'container/MetricsExplorer/events';import { useOptionsMenu } from 'container/OptionsMenu';import {defaultLogsSelectedColumns,@@ -140,7 +144,9 @@ function ExplorerOptions({panelType,});} else if (isMetricsExplorer) {- logEvent('Metrics Explorer: Save view clicked', {+ logEvent(MetricsExplorerEvents.SaveViewClicked, {+ [MetricsExplorerEventKeys.Tab]: 'explorer',+ [MetricsExplorerEventKeys.OneChartPerQueryEnabled]: isOneChartPerQuery,panelType,});}@@ -184,8 +190,10 @@ function ExplorerOptions({panelType,});} else if (isMetricsExplorer) {- logEvent('Metrics Explorer: Create alert', {+ logEvent(MetricsExplorerEvents.AddToAlertClicked, {panelType,+ [MetricsExplorerEventKeys.Tab]: 'explorer',+ [MetricsExplorerEventKeys.OneChartPerQueryEnabled]: isOneChartPerQuery,});}@@ -218,11 +226,14 @@ function ExplorerOptions({panelType,});} else if (isMetricsExplorer) {- logEvent('Metrics Explorer: Add to dashboard clicked', {+ logEvent(MetricsExplorerEvents.AddToDashboardClicked, {panelType,+ [MetricsExplorerEventKeys.Tab]: 'explorer',+ [MetricsExplorerEventKeys.OneChartPerQueryEnabled]: isOneChartPerQuery,});}setIsExport(true);+ // eslint-disable-next-line react-hooks/exhaustive-deps}, [isLogsExplorer, isMetricsExplorer, panelType, setIsExport, sourcepage]);const {diff --git a/frontend/src/container/MetricsExplorer/Explorer/Explorer.tsx b/frontend/src/container/MetricsExplorer/Explorer/Explorer.tsxindex 1f04fcd9c6..d20b18dc0e 100644--- a/frontend/src/container/MetricsExplorer/Explorer/Explorer.tsx+++ b/frontend/src/container/MetricsExplorer/Explorer/Explorer.tsx@@ -2,6 +2,7 @@ import './Explorer.styles.scss';import * as Sentry from '@sentry/react';import { Switch } from 'antd';+import logEvent from 'api/common/logEvent';import { initialQueriesMap, PANEL_TYPES } from 'constants/queryBuilder';import ExplorerOptionWrapper from 'container/ExplorerOptions/ExplorerOptionWrapper';import RightToolbarActions from 'container/QueryBuilder/components/ToolbarActions/RightToolbarActions';@@ -10,7 +11,7 @@ import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';import { useShareBuilderUrl } from 'hooks/queryBuilder/useShareBuilderUrl';import { useSafeNavigate } from 'hooks/useSafeNavigate';import ErrorBoundaryFallback from 'pages/ErrorBoundaryFallback/ErrorBoundaryFallback';-import { useCallback, useMemo, useState } from 'react';+import { useCallback, useEffect, useMemo, useState } from 'react';import { useSearchParams } from 'react-router-dom-v5-compat';import { Dashboard } from 'types/api/dashboard/getAll';import { Query } from 'types/api/queryBuilder/queryBuilderData';@@ -18,6 +19,7 @@ import { DataSource } from 'types/common/queryBuilder';import { generateExportToDashboardLink } from 'utils/dashboard/generateExportToDashboardLink';import { v4 as uuid } from 'uuid';+import { MetricsExplorerEventKeys, MetricsExplorerEvents } from '../events';import QuerySection from './QuerySection';import TimeSeries from './TimeSeries';import { ExplorerTabs } from './types';@@ -93,6 +95,12 @@ function Explorer(): JSX.Element {[stagedQuery],);+ useEffect(() => {+ logEvent(MetricsExplorerEvents.TabChanged, {+ [MetricsExplorerEventKeys.Tab]: 'explorer',+ });+ }, []);+return (<Sentry.ErrorBoundary fallback={<ErrorBoundaryFallback />}><div className="metrics-explorer-explore-container">diff --git a/frontend/src/container/MetricsExplorer/Explorer/QuerySection.tsx b/frontend/src/container/MetricsExplorer/Explorer/QuerySection.tsxindex 399bfcf091..d1d85ce039 100644--- a/frontend/src/container/MetricsExplorer/Explorer/QuerySection.tsx+++ b/frontend/src/container/MetricsExplorer/Explorer/QuerySection.tsx@@ -1,4 +1,5 @@import { Button } from 'antd';+import logEvent from 'api/common/logEvent';import { PANEL_TYPES } from 'constants/queryBuilder';import { QueryBuilder } from 'container/QueryBuilder';import { ButtonWrapper } from 'container/TracesExplorer/QuerySection/styles';@@ -6,6 +7,8 @@ import { useGetPanelTypesQueryParam } from 'hooks/queryBuilder/useGetPanelTypesQimport { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';import { DataSource } from 'types/common/queryBuilder';+import { MetricsExplorerEventKeys, MetricsExplorerEvents } from '../events';+function QuerySection(): JSX.Element {const { handleRunQuery } = useQueryBuilder();@@ -19,7 +22,15 @@ function QuerySection(): JSX.Element {version="v4"actions={<ButtonWrapper>- <Button onClick={(): void => handleRunQuery()} type="primary">+ <Button+ onClick={(): void => {+ handleRunQuery();+ logEvent(MetricsExplorerEvents.QueryBuilderQueryChanged, {+ [MetricsExplorerEventKeys.Tab]: 'explorer',+ });+ }}+ type="primary"+ >Run Query</Button></ButtonWrapper>diff --git a/frontend/src/container/MetricsExplorer/Inspect/ExpandedView.tsx b/frontend/src/container/MetricsExplorer/Inspect/ExpandedView.tsxindex 29d58f4dc8..9a01fcc7b1 100644--- a/frontend/src/container/MetricsExplorer/Inspect/ExpandedView.tsx+++ b/frontend/src/container/MetricsExplorer/Inspect/ExpandedView.tsx@@ -4,6 +4,7 @@import { Color } from '@signozhq/design-tokens';import { Card, Tooltip, Typography } from 'antd';import { ColumnsType } from 'antd/es/table';+import logEvent from 'api/common/logEvent';import { InspectMetricsSeries } from 'api/metricsExplorer/getInspectMetricsDetails';import classNames from 'classnames';import ResizeTable from 'components/ResizeTable/ResizeTable';@@ -11,6 +12,7 @@ import { DataType } from 'container/LogDetailedView/TableView';import { ArrowDownCircle, ArrowRightCircle, Focus } from 'lucide-react';import { useEffect, useMemo, useState } from 'react';+import { MetricsExplorerEventKeys, MetricsExplorerEvents } from '../events';import {SPACE_AGGREGATION_OPTIONS_FOR_EXPANDED_VIEW,TIME_AGGREGATION_OPTIONS,@@ -39,6 +41,21 @@ function ExpandedView({setSelectedTimeSeries,] = useState<InspectMetricsSeries | null>(null);+ useEffect(() => {+ logEvent(MetricsExplorerEvents.InspectPointClicked, {+ [MetricsExplorerEventKeys.Modal]: 'inspect',+ [MetricsExplorerEventKeys.Filters]: metricInspectionOptions.filters,+ [MetricsExplorerEventKeys.TimeAggregationInterval]:+ metricInspectionOptions.timeAggregationInterval,+ [MetricsExplorerEventKeys.TimeAggregationOption]:+ metricInspectionOptions.timeAggregationOption,+ [MetricsExplorerEventKeys.SpaceAggregationOption]:+ metricInspectionOptions.spaceAggregationOption,+ [MetricsExplorerEventKeys.SpaceAggregationLabels]:+ metricInspectionOptions.spaceAggregationLabels,+ });+ }, [metricInspectionOptions]);+useEffect(() => {if (step !== InspectionStep.COMPLETED) {setSelectedTimeSeries(options?.timeSeries ?? null);diff --git a/frontend/src/container/MetricsExplorer/Inspect/GraphView.tsx b/frontend/src/container/MetricsExplorer/Inspect/GraphView.tsxindex 72a9abd5bd..947672ac64 100644--- a/frontend/src/container/MetricsExplorer/Inspect/GraphView.tsx+++ b/frontend/src/container/MetricsExplorer/Inspect/GraphView.tsx@@ -1,5 +1,6 @@import { Color } from '@signozhq/design-tokens';import { Button, Skeleton, Switch, Typography } from 'antd';+import logEvent from 'api/common/logEvent';import Uplot from 'components/Uplot';import { useIsDarkMode } from 'hooks/useDarkMode';import { useResizeObserver } from 'hooks/useDimensions';@@ -8,6 +9,7 @@ import { useSelector } from 'react-redux';import { AppState } from 'store/reducers';import { GlobalReducer } from 'types/reducer/globalTime';+import { MetricsExplorerEventKeys, MetricsExplorerEvents } from '../events';import { formatNumberIntoHumanReadableFormat } from '../Summary/utils';import { METRIC_TYPE_TO_COLOR_MAP, METRIC_TYPE_TO_ICON_MAP } from './constants';import GraphPopover from './GraphPopover';@@ -203,7 +205,14 @@ function GraphView({<div className="view-toggle-button"><Switchchecked={viewType === 'graph'}- onChange={(checked): void => setViewType(checked ? 'graph' : 'table')}+ onChange={(checked): void => {+ const newViewType = checked ? 'graph' : 'table';+ setViewType(newViewType);+ logEvent(MetricsExplorerEvents.InspectViewChanged, {+ [MetricsExplorerEventKeys.Tab]: 'inspect',+ [MetricsExplorerEventKeys.InspectView]: newViewType,+ });+ }}/><Typography.Text>{viewType === 'graph' ? 'Graph View' : 'Table View'}diff --git a/frontend/src/container/MetricsExplorer/Inspect/Inspect.tsx b/frontend/src/container/MetricsExplorer/Inspect/Inspect.tsxindex fe3ebf4861..4fc06873d2 100644--- a/frontend/src/container/MetricsExplorer/Inspect/Inspect.tsx+++ b/frontend/src/container/MetricsExplorer/Inspect/Inspect.tsx@@ -3,6 +3,7 @@ import './Inspect.styles.scss';import * as Sentry from '@sentry/react';import { Color } from '@signozhq/design-tokens';import { Button, Drawer, Empty, Skeleton, Typography } from 'antd';+import logEvent from 'api/common/logEvent';import { useGetMetricDetails } from 'hooks/metricsExplorer/useGetMetricDetails';import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';import { useQueryOperations } from 'hooks/queryBuilder/useQueryBuilderOperations';@@ -11,11 +12,16 @@ import { Compass } from 'lucide-react';import ErrorBoundaryFallback from 'pages/ErrorBoundaryFallback/ErrorBoundaryFallback';import { useCallback, useEffect, useMemo, useState } from 'react';+import { MetricsExplorerEventKeys, MetricsExplorerEvents } from '../events';import ExpandedView from './ExpandedView';import GraphView from './GraphView';import QueryBuilder from './QueryBuilder';import Stepper from './Stepper';-import { GraphPopoverOptions, InspectProps } from './types';+import {+ GraphPopoverOptions,+ InspectProps,+ MetricInspectionAction,+} from './types';import { useInspectMetrics } from './useInspectMetrics';function Inspect({@@ -92,6 +98,25 @@ function Inspect({reset,} = useInspectMetrics(metricName);+ const handleDispatchMetricInspectionOptions = useCallback(+ (action: MetricInspectionAction): void => {+ dispatchMetricInspectionOptions(action);+ logEvent(MetricsExplorerEvents.InspectQueryChanged, {+ [MetricsExplorerEventKeys.Modal]: 'inspect',+ [MetricsExplorerEventKeys.Filters]: metricInspectionOptions.filters,+ [MetricsExplorerEventKeys.TimeAggregationInterval]:+ metricInspectionOptions.timeAggregationInterval,+ [MetricsExplorerEventKeys.TimeAggregationOption]:+ metricInspectionOptions.timeAggregationOption,+ [MetricsExplorerEventKeys.SpaceAggregationOption]:+ metricInspectionOptions.spaceAggregationOption,+ [MetricsExplorerEventKeys.SpaceAggregationLabels]:+ metricInspectionOptions.spaceAggregationLabels,+ });+ },+ [dispatchMetricInspectionOptions, metricInspectionOptions],+ );+const selectedMetricType = useMemo(() => metricDetailsData?.payload?.data?.metadata?.metric_type,[metricDetailsData],@@ -186,7 +211,7 @@ function Inspect({setMetricName={setMetricName}spaceAggregationLabels={spaceAggregationLabels}metricInspectionOptions={metricInspectionOptions}- dispatchMetricInspectionOptions={dispatchMetricInspectionOptions}+ dispatchMetricInspectionOptions={handleDispatchMetricInspectionOptions}inspectionStep={inspectionStep}inspectMetricsTimeSeries={inspectMetricsTimeSeries}searchQuery={searchQuery}@@ -227,12 +252,18 @@ function Inspect({popoverOptions,metricInspectionOptions,spaceAggregationLabels,- dispatchMetricInspectionOptions,+ handleDispatchMetricInspectionOptions,searchQuery,expandedViewOptions,timeAggregatedSeriesMap,]);+ useEffect(() => {+ logEvent(MetricsExplorerEvents.ModalOpened, {+ [MetricsExplorerEventKeys.Modal]: 'inspect',+ });+ }, []);+return (<Sentry.ErrorBoundary fallback={<ErrorBoundaryFallback />}><Drawerdiff --git a/frontend/src/container/MetricsExplorer/Inspect/utils.tsx b/frontend/src/container/MetricsExplorer/Inspect/utils.tsxindex 3405997d7a..bb6b5dc965 100644--- a/frontend/src/container/MetricsExplorer/Inspect/utils.tsx+++ b/frontend/src/container/MetricsExplorer/Inspect/utils.tsx@@ -1,5 +1,6 @@/* eslint-disable no-nested-ternary */import { Card, Input, Select, Typography } from 'antd';+import logEvent from 'api/common/logEvent';import { InspectMetricsSeries } from 'api/metricsExplorer/getInspectMetricsDetails';import { MetricType } from 'api/metricsExplorer/getMetricsList';import classNames from 'classnames';@@ -16,6 +17,7 @@ import {import { TagFilter } from 'types/api/queryBuilder/queryBuilderData';import { DataSource } from 'types/common/queryBuilder';+import { MetricsExplorerEventKeys, MetricsExplorerEvents } from '../events';import {SPACE_AGGREGATION_OPTIONS,TIME_AGGREGATION_OPTIONS,@@ -135,6 +137,9 @@ export function MetricFilters({}}onChange={(value): void => {handleChangeQueryData('filters', value);+ logEvent(MetricsExplorerEvents.FilterApplied, {+ [MetricsExplorerEventKeys.Modal]: 'inspect',+ });dispatchMetricInspectionOptions({type: 'SET_FILTERS',payload: value,diff --git a/frontend/src/container/MetricsExplorer/MetricDetails/AllAttributes.tsx b/frontend/src/container/MetricsExplorer/MetricDetails/AllAttributes.tsxindex 471151545d..6a920e3c64 100644--- a/frontend/src/container/MetricsExplorer/MetricDetails/AllAttributes.tsx+++ b/frontend/src/container/MetricsExplorer/MetricDetails/AllAttributes.tsx@@ -1,5 +1,6 @@import { Button, Collapse, Input, Menu, Popover, Typography } from 'antd';import { ColumnsType } from 'antd/es/table';+import logEvent from 'api/common/logEvent';import { ResizeTable } from 'components/ResizeTable';import { DataType } from 'container/LogDetailedView/TableView';import { useNotifications } from 'hooks/useNotifications';@@ -10,6 +11,7 @@ import { useCopyToClipboard } from 'react-use';import { PANEL_TYPES } from '../../../constants/queryBuilder';import ROUTES from '../../../constants/routes';import { useHandleExplorerTabChange } from '../../../hooks/useHandleExplorerTabChange';+import { MetricsExplorerEventKeys, MetricsExplorerEvents } from '../events';import { AllAttributesProps, AllAttributesValueProps } from './types';import { getMetricDetailsQuery } from './utils';@@ -135,9 +137,16 @@ function AllAttributes({},ROUTES.METRICS_EXPLORER_EXPLORER,);+ logEvent(MetricsExplorerEvents.OpenInExplorerClicked, {+ [MetricsExplorerEventKeys.MetricName]: metricName,+ [MetricsExplorerEventKeys.Tab]: 'summary',+ [MetricsExplorerEventKeys.Modal]: 'metric-details',+ [MetricsExplorerEventKeys.AttributeKey]: groupBy,+ });},[metricName, metricType, handleExplorerTabChange],);+const goToMetricsExploreWithAppliedAttribute = useCallback((key: string, value: string) => {const compositeQuery = getMetricDetailsQuery(metricName, metricType, {@@ -153,6 +162,13 @@ function AllAttributes({},ROUTES.METRICS_EXPLORER_EXPLORER,);+ logEvent(MetricsExplorerEvents.OpenInExplorerClicked, {+ [MetricsExplorerEventKeys.MetricName]: metricName,+ [MetricsExplorerEventKeys.Tab]: 'summary',+ [MetricsExplorerEventKeys.Modal]: 'metric-details',+ [MetricsExplorerEventKeys.AttributeKey]: key,+ [MetricsExplorerEventKeys.AttributeValue]: value,+ });},[metricName, metricType, handleExplorerTabChange],);diff --git a/frontend/src/container/MetricsExplorer/MetricDetails/Metadata.tsx b/frontend/src/container/MetricsExplorer/MetricDetails/Metadata.tsxindex 0a877ffe3a..b735e689f2 100644--- a/frontend/src/container/MetricsExplorer/MetricDetails/Metadata.tsx+++ b/frontend/src/container/MetricsExplorer/MetricDetails/Metadata.tsx@@ -1,5 +1,6 @@import { Button, Collapse, Input, Select, Typography } from 'antd';import { ColumnsType } from 'antd/es/table';+import logEvent from 'api/common/logEvent';import { Temporality } from 'api/metricsExplorer/getMetricDetails';import { MetricType } from 'api/metricsExplorer/getMetricsList';import { UpdateMetricMetadataProps } from 'api/metricsExplorer/updateMetricMetadata';@@ -11,6 +12,7 @@ import { useNotifications } from 'hooks/useNotifications';import { Edit2, Save, X } from 'lucide-react';import { useCallback, useMemo, useState } from 'react';+import { MetricsExplorerEventKeys, MetricsExplorerEvents } from '../events';import {METRIC_TYPE_LABEL_MAP,METRIC_TYPE_VALUES_MAP,@@ -170,6 +172,11 @@ function Metadata({{onSuccess: (response): void => {if (response?.statusCode === 200) {+ logEvent(MetricsExplorerEvents.MetricMetadataUpdated, {+ [MetricsExplorerEventKeys.MetricName]: metricName,+ [MetricsExplorerEventKeys.Tab]: 'summary',+ [MetricsExplorerEventKeys.Modal]: 'metric-details',+ });notifications.success({message: 'Metadata updated successfully',});diff --git a/frontend/src/container/MetricsExplorer/MetricDetails/MetricDetails.tsx b/frontend/src/container/MetricsExplorer/MetricDetails/MetricDetails.tsxindex b0c18ab64b..cb52a2de70 100644--- a/frontend/src/container/MetricsExplorer/MetricDetails/MetricDetails.tsx+++ b/frontend/src/container/MetricsExplorer/MetricDetails/MetricDetails.tsx@@ -11,14 +11,16 @@ import {Tooltip,Typography,} from 'antd';+import logEvent from 'api/common/logEvent';import { useGetMetricDetails } from 'hooks/metricsExplorer/useGetMetricDetails';import { useIsDarkMode } from 'hooks/useDarkMode';import { Compass, Crosshair, X } from 'lucide-react';-import { useCallback, useMemo } from 'react';+import { useCallback, useEffect, useMemo } from 'react';import { PANEL_TYPES } from '../../../constants/queryBuilder';import ROUTES from '../../../constants/routes';import { useHandleExplorerTabChange } from '../../../hooks/useHandleExplorerTabChange';+import { MetricsExplorerEventKeys, MetricsExplorerEvents } from '../events';import { isInspectEnabled } from '../Inspect/utils';import { formatNumberIntoHumanReadableFormat } from '../Summary/utils';import AllAttributes from './AllAttributes';@@ -95,11 +97,22 @@ function MetricDetails({},ROUTES.METRICS_EXPLORER_EXPLORER,);+ logEvent(MetricsExplorerEvents.OpenInExplorerClicked, {+ [MetricsExplorerEventKeys.MetricName]: metricName,+ [MetricsExplorerEventKeys.Tab]: 'summary',+ [MetricsExplorerEventKeys.Modal]: 'metric-details',+ });}}, [metricName, handleExplorerTabChange, metric?.metadata?.metric_type]);const isMetricDetailsError = metricDetailsError || !metric;+ useEffect(() => {+ logEvent(MetricsExplorerEvents.ModalOpened, {+ [MetricsExplorerEventKeys.Modal]: 'metric-details',+ });+ }, []);+return (<Drawerwidth="60%"diff --git a/frontend/src/container/MetricsExplorer/Summary/MetricsTable.tsx b/frontend/src/container/MetricsExplorer/Summary/MetricsTable.tsxindex 27ca8556d7..d08d9954f5 100644--- a/frontend/src/container/MetricsExplorer/Summary/MetricsTable.tsx+++ b/frontend/src/container/MetricsExplorer/Summary/MetricsTable.tsx@@ -108,7 +108,7 @@ function MetricsTable({total: totalCount,}}onRow={(record): { onClick: () => void; className: string } => ({- onClick: (): void => openMetricDetails(record.key),+ onClick: (): void => openMetricDetails(record.key, 'list'),className: 'clickable-row',})}/>diff --git a/frontend/src/container/MetricsExplorer/Summary/MetricsTreemap.tsx b/frontend/src/container/MetricsExplorer/Summary/MetricsTreemap.tsxindex ef9649be1d..ac6381a838 100644--- a/frontend/src/container/MetricsExplorer/Summary/MetricsTreemap.tsx+++ b/frontend/src/container/MetricsExplorer/Summary/MetricsTreemap.tsx@@ -154,7 +154,7 @@ function MetricsTreemap({<foreignObjectwidth={nodeWidth}height={nodeHeight}- onClick={(): void => openMetricDetails(node.data.id)}+ onClick={(): void => openMetricDetails(node.data.id, 'treemap')}><divstyle={{diff --git a/frontend/src/container/MetricsExplorer/Summary/Summary.tsx b/frontend/src/container/MetricsExplorer/Summary/Summary.tsxindex 4aac6f0899..f265efa70c 100644--- a/frontend/src/container/MetricsExplorer/Summary/Summary.tsx+++ b/frontend/src/container/MetricsExplorer/Summary/Summary.tsx@@ -1,18 +1,20 @@import './Summary.styles.scss';import * as Sentry from '@sentry/react';+import logEvent from 'api/common/logEvent';import { initialQueriesMap } from 'constants/queryBuilder';import { usePageSize } from 'container/InfraMonitoringK8s/utils';import { useGetMetricsList } from 'hooks/metricsExplorer/useGetMetricsList';import { useGetMetricsTreeMap } from 'hooks/metricsExplorer/useGetMetricsTreeMap';import ErrorBoundaryFallback from 'pages/ErrorBoundaryFallback/ErrorBoundaryFallback';-import { useCallback, useMemo, useState } from 'react';+import { useCallback, useEffect, useMemo, useState } from 'react';import { useSelector } from 'react-redux';import { useSearchParams } from 'react-router-dom-v5-compat';import { AppState } from 'store/reducers';import { TagFilter } from 'types/api/queryBuilder/queryBuilderData';import { GlobalReducer } from 'types/reducer/globalTime';+import { MetricsExplorerEventKeys, MetricsExplorerEvents } from '../events';import InspectModal from '../Inspect';import MetricDetails from '../MetricDetails';import {@@ -70,6 +72,18 @@ function Summary(): JSX.Element {};}, [searchParams]);+ useEffect(() => {+ logEvent(MetricsExplorerEvents.TabChanged, {+ [MetricsExplorerEventKeys.Tab]: 'summary',+ });+ }, []);++ useEffect(() => {+ logEvent(MetricsExplorerEvents.TimeUpdated, {+ [MetricsExplorerEventKeys.Tab]: 'summary',+ });+ }, [maxTime, minTime]);+// This is used to avoid the filters from being serialized with the idconst queryFiltersWithoutId = useMemo(() => {const filtersWithoutId = {@@ -154,6 +168,9 @@ function Summary(): JSX.Element {[SUMMARY_FILTERS_KEY]: JSON.stringify(value),});setCurrentPage(1);+ logEvent(MetricsExplorerEvents.FilterApplied, {+ [MetricsExplorerEventKeys.Tab]: 'summary',+ });},[setSearchParams, searchParams],);@@ -169,6 +186,14 @@ function Summary(): JSX.Element {const onPaginationChange = (page: number, pageSize: number): void => {setCurrentPage(page);setPageSize(pageSize);+ logEvent(MetricsExplorerEvents.PageNumberChanged, {+ [MetricsExplorerEventKeys.Tab]: 'summary',+ [MetricsExplorerEventKeys.PageNumber]: page,+ });+ logEvent(MetricsExplorerEvents.PageSizeChanged, {+ [MetricsExplorerEventKeys.Tab]: 'summary',+ [MetricsExplorerEventKeys.PageSize]: pageSize,+ });};const formattedMetricsData = useMemo(@@ -176,7 +201,10 @@ function Summary(): JSX.Element {[metricsData],);- const openMetricDetails = (metricName: string): void => {+ const openMetricDetails = (+ metricName: string,+ view: 'list' | 'treemap',+ ): void => {setSelectedMetricName(metricName);setIsMetricDetailsOpen(true);setSearchParams({@@ -184,6 +212,10 @@ function Summary(): JSX.Element {[IS_METRIC_DETAILS_OPEN_KEY]: 'true',[SELECTED_METRIC_NAME_KEY]: metricName,});+ logEvent(MetricsExplorerEvents.MetricClicked, {+ [MetricsExplorerEventKeys.MetricName]: metricName,+ [MetricsExplorerEventKeys.View]: view,+ });};const closeMetricDetails = (): void => {@@ -217,6 +249,23 @@ function Summary(): JSX.Element {});};+ const handleSetHeatmapView = (view: TreemapViewType): void => {+ setHeatmapView(view);+ logEvent(MetricsExplorerEvents.TreemapViewChanged, {+ [MetricsExplorerEventKeys.Tab]: 'summary',+ [MetricsExplorerEventKeys.ViewType]: view,+ });+ };++ const handleSetOrderBy = (orderBy: OrderByPayload): void => {+ setOrderBy(orderBy);+ logEvent(MetricsExplorerEvents.OrderByApplied, {+ [MetricsExplorerEventKeys.Tab]: 'summary',+ [MetricsExplorerEventKeys.ColumnName]: orderBy.columnName,+ [MetricsExplorerEventKeys.Order]: orderBy.order,+ });+ };+return (<Sentry.ErrorBoundary fallback={<ErrorBoundaryFallback />}><div className="metrics-explorer-summary-tab">@@ -227,7 +276,7 @@ function Summary(): JSX.Element {isError={isProportionViewError}viewType={heatmapView}openMetricDetails={openMetricDetails}- setHeatmapView={setHeatmapView}+ setHeatmapView={handleSetHeatmapView}/><MetricsTableisLoading={isMetricsLoading || isMetricsFetching}@@ -236,7 +285,7 @@ function Summary(): JSX.Element {pageSize={pageSize}currentPage={currentPage}onPaginationChange={onPaginationChange}- setOrderBy={setOrderBy}+ setOrderBy={handleSetOrderBy}totalCount={metricsData?.payload?.data?.total || 0}openMetricDetails={openMetricDetails}queryFilters={queryFilters}diff --git a/frontend/src/container/MetricsExplorer/Summary/__tests__/MetricsTable.test.tsx b/frontend/src/container/MetricsExplorer/Summary/__tests__/MetricsTable.test.tsxindex 776c236532..0f9450fe88 100644--- a/frontend/src/container/MetricsExplorer/Summary/__tests__/MetricsTable.test.tsx+++ b/frontend/src/container/MetricsExplorer/Summary/__tests__/MetricsTable.test.tsx@@ -194,7 +194,7 @@ describe('MetricsTable', () => {);fireEvent.click(screen.getByText('Metric 1'));- expect(mockOpenMetricDetails).toHaveBeenCalledWith('metric1');+ expect(mockOpenMetricDetails).toHaveBeenCalledWith('metric1', 'list');});it('calls setOrderBy when column header is clicked', () => {diff --git a/frontend/src/container/MetricsExplorer/Summary/types.ts b/frontend/src/container/MetricsExplorer/Summary/types.tsindex 4996a79424..b836c9d79a 100644--- a/frontend/src/container/MetricsExplorer/Summary/types.ts+++ b/frontend/src/container/MetricsExplorer/Summary/types.ts@@ -1,5 +1,5 @@import { MetricsTreeMapResponse } from 'api/metricsExplorer/getMetricsTreeMap';-import React, { Dispatch, SetStateAction } from 'react';+import React from 'react';import {IBuilderQuery,TagFilter,@@ -12,9 +12,9 @@ export interface MetricsTableProps {pageSize: number;currentPage: number;onPaginationChange: (page: number, pageSize: number) => void;- setOrderBy: Dispatch<SetStateAction<OrderByPayload>>;+ setOrderBy: (orderBy: OrderByPayload) => void;totalCount: number;- openMetricDetails: (metricName: string) => void;+ openMetricDetails: (metricName: string, view: 'list' | 'treemap') => void;queryFilters: TagFilter;}@@ -28,7 +28,7 @@ export interface MetricsTreemapProps {isLoading: boolean;isError: boolean;viewType: TreemapViewType;- openMetricDetails: (metricName: string) => void;+ openMetricDetails: (metricName: string, view: 'list' | 'treemap') => void;setHeatmapView: (value: TreemapViewType) => void;}diff --git a/frontend/src/container/MetricsExplorer/events.ts b/frontend/src/container/MetricsExplorer/events.tsnew file mode 100644index 0000000000..014f533cfd--- /dev/null+++ b/frontend/src/container/MetricsExplorer/events.ts@@ -0,0 +1,51 @@+/**+ * This file contains all analytics events for the Metrics Explorer.+ */+export enum MetricsExplorerEvents {+ TabChanged = 'Metrics Explorer: Tab visited',+ ModalOpened = 'Metrics Explorer: Modal opened',+ MetricClicked = 'Metrics Explorer: Metric clicked',+ FilterApplied = 'Metrics Explorer: Filter applied',+ TimeUpdated = 'Metrics Explorer: Time updated',+ TreemapViewChanged = 'Metrics Explorer: Treemap view changed',+ PageNumberChanged = 'Metrics Explorer: Page number changed',+ PageSizeChanged = 'Metrics Explorer: Page size changed',+ OrderByApplied = 'Metrics Explorer: Order by applied',+ MetricMetadataUpdated = 'Metrics Explorer: Metric metadata updated',+ OpenInExplorerClicked = 'Metrics Explorer: Open in explorer clicked',+ InspectViewChanged = 'Metrics Explorer: Inspect view changed',+ InspectQueryChanged = 'Metrics Explorer: Inspect query changed',+ InspectPointClicked = 'Metrics Explorer: Inspect point clicked',+ QueryBuilderQueryChanged = 'Metrics Explorer: QueryBuilder query changed',+ YAxisUnitApplied = 'Metrics Explorer: Y axis unit applied',+ AddToAlertClicked = 'Metrics Explorer: Add to alert clicked',+ AddToDashboardClicked = 'Metrics Explorer: Add to dashboard clicked',+ SaveViewClicked = 'Metrics Explorer: Save view clicked',+ SearchApplied = 'Metrics Explorer: Search applied',+ ViewEdited = 'Metrics Explorer: View edited',+ ViewDeleted = 'Metrics Explorer: View deleted',+}++export enum MetricsExplorerEventKeys {+ Tab = 'tab',+ Modal = 'modal',+ View = 'view',+ Interval = 'interval',+ ViewType = 'viewType',+ PageNumber = 'pageNumber',+ PageSize = 'pageSize',+ ColumnName = 'columnName',+ Order = 'order',+ AttributeKey = 'attributeKey',+ AttributeValue = 'attributeValue',+ MetricName = 'metricName',+ InspectView = 'inspectView',+ TimeAggregationOption = 'timeAggregationOption',+ TimeAggregationInterval = 'timeAggregationInterval',+ SpaceAggregationOption = 'spaceAggregationOption',+ SpaceAggregationLabels = 'spaceAggregationLabels',+ OneChartPerQueryEnabled = 'oneChartPerQueryEnabled',+ YAxisUnit = 'yAxisUnit',+ ViewName = 'viewName',+ Filters = 'filters',+}diff --git a/frontend/src/pages/SaveView/index.tsx b/frontend/src/pages/SaveView/index.tsxindex e470cf3013..c8c8fd810c 100644--- a/frontend/src/pages/SaveView/index.tsx+++ b/frontend/src/pages/SaveView/index.tsx@@ -17,6 +17,10 @@ import {} from 'components/ExplorerCard/utils';import { DATE_TIME_FORMATS } from 'constants/dateTimeFormats';import { getRandomColor } from 'container/ExplorerOptions/utils';+import {+ MetricsExplorerEventKeys,+ MetricsExplorerEvents,+} from 'container/MetricsExplorer/events';import { useDeleteView } from 'hooks/saveViews/useDeleteView';import { useGetAllViews } from 'hooks/saveViews/useGetAllViews';import { useUpdateView } from 'hooks/saveViews/useUpdateView';@@ -155,6 +159,10 @@ function SaveView(): JSX.Element {logEvent('Logs Views: Views visited', {number: viewsData?.data?.data?.length,});+ } else if (sourcepage === DataSource.METRICS) {+ logEvent(MetricsExplorerEvents.TabChanged, {+ [MetricsExplorerEventKeys.Tab]: 'views',+ });}logEventCalledRef.current = true;}@@ -176,6 +184,9 @@ function SaveView(): JSX.Element {});hideEditViewModal();refetchAllView();+ logEvent(MetricsExplorerEvents.ViewEdited, {+ [MetricsExplorerEventKeys.Tab]: 'views',+ });},onError: (err) => {showErrorNotification(notifications, err);@@ -204,6 +215,10 @@ function SaveView(): JSX.Element {},SOURCEPAGE_VS_ROUTES[sourcepage],);+ logEvent(MetricsExplorerEvents.OpenInExplorerClicked, {+ [MetricsExplorerEventKeys.Tab]: 'views',+ [MetricsExplorerEventKeys.ViewName]: name,+ });}};diff --git a/frontend/src/pages/SaveView/utils.ts b/frontend/src/pages/SaveView/utils.tsindex fff54a6ceb..637ac5542e 100644--- a/frontend/src/pages/SaveView/utils.ts+++ b/frontend/src/pages/SaveView/utils.ts@@ -1,6 +1,11 @@import { NotificationInstance } from 'antd/es/notification/interface';+import logEvent from 'api/common/logEvent';import { MenuItemLabelGeneratorProps } from 'components/ExplorerCard/types';import { showErrorNotification } from 'components/ExplorerCard/utils';+import {+ MetricsExplorerEventKeys,+ MetricsExplorerEvents,+} from 'container/MetricsExplorer/events';import { UseMutateAsyncFunction } from 'react-query';import { DeleteViewPayloadProps } from 'types/api/saveViews/types';@@ -29,6 +34,9 @@ export const deleteViewHandler = ({message: 'View Deleted Successfully',});refetchAllView();+ logEvent(MetricsExplorerEvents.ViewDeleted, {+ [MetricsExplorerEventKeys.Tab]: 'views',+ });},onError: (err) => {showErrorNotification(notifications, err);