From f77bb888a82fb67a9af8dbe6dc8ad7f0136331fb Mon Sep 17 00:00:00 2001
From: Amlan Kumar Nandy <45410599+amlannandy@users.noreply.github.com>
Date: Tue, 10 Jun 2025 11:42:49 +0700
Subject: [PATCH] chore: add analytics for metrics explorer (#8108)
---
.../ExplorerOptions/ExplorerOptions.tsx | 17 +++++-
.../MetricsExplorer/Explorer/Explorer.tsx | 10 +++-
.../MetricsExplorer/Explorer/QuerySection.tsx | 13 ++++-
.../MetricsExplorer/Inspect/ExpandedView.tsx | 17 ++++++
.../MetricsExplorer/Inspect/GraphView.tsx | 11 +++-
.../MetricsExplorer/Inspect/Inspect.tsx | 37 +++++++++++-
.../MetricsExplorer/Inspect/utils.tsx | 5 ++
.../MetricDetails/AllAttributes.tsx | 16 ++++++
.../MetricDetails/Metadata.tsx | 7 +++
.../MetricDetails/MetricDetails.tsx | 15 ++++-
.../MetricsExplorer/Summary/MetricsTable.tsx | 2 +-
.../Summary/MetricsTreemap.tsx | 2 +-
.../MetricsExplorer/Summary/Summary.tsx | 57 +++++++++++++++++--
.../Summary/__tests__/MetricsTable.test.tsx | 2 +-
.../MetricsExplorer/Summary/types.ts | 8 +--
.../src/container/MetricsExplorer/events.ts | 51 +++++++++++++++++
frontend/src/pages/SaveView/index.tsx | 15 +++++
frontend/src/pages/SaveView/utils.ts | 8 +++
18 files changed, 272 insertions(+), 21 deletions(-)
create mode 100644 frontend/src/container/MetricsExplorer/events.ts
diff --git a/frontend/src/container/ExplorerOptions/ExplorerOptions.tsx b/frontend/src/container/ExplorerOptions/ExplorerOptions.tsx
index fa4a723f1747..98b94df9937f 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.tsx
index 1f04fcd9c6d8..d20b18dc0ee5 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 (