From 2e57bfe0ea13416485e301651dfc768f29b47eab Mon Sep 17 00:00:00 2001 From: Rikin Kachhia <54616969+rikinsk@users.noreply.github.com> Date: Thu, 16 Feb 2023 16:14:11 +0530 Subject: [PATCH] console: send telemetry event on feature flag enable/disable PR-URL: https://github.com/hasura/graphql-engine-mono/pull/7948 GitOrigin-RevId: 0dbb12e0bd291249f447ac58968b63c960630c49 --- .../FeatureFlags/hooks/useSetFeatureFlagEnabled.ts | 14 ++++++++++++++ .../console/legacy-ce/src/lib/telemetry/index.ts | 13 ++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/frontend/libs/console/legacy-ce/src/lib/features/FeatureFlags/hooks/useSetFeatureFlagEnabled.ts b/frontend/libs/console/legacy-ce/src/lib/features/FeatureFlags/hooks/useSetFeatureFlagEnabled.ts index 091cd627f6e..5721c57fb78 100644 --- a/frontend/libs/console/legacy-ce/src/lib/features/FeatureFlags/hooks/useSetFeatureFlagEnabled.ts +++ b/frontend/libs/console/legacy-ce/src/lib/features/FeatureFlags/hooks/useSetFeatureFlagEnabled.ts @@ -1,6 +1,8 @@ import { useMutation, useQueryClient } from 'react-query'; import { FeatureFlagId, useFeatureFlags } from '@/features/FeatureFlags'; import { saveFeatureFlagsStateToLocalStorage } from '../utils'; +import { sendTelemetryEvent, SetFeatureFlagEvent } from '@/telemetry'; +import { availableFeatureFlags } from '@/features/FeatureFlags/availableFeatureFlags'; export function useSetFeatureFlagEnabled() { const queryClient = useQueryClient(); @@ -17,6 +19,18 @@ export function useSetFeatureFlagEnabled() { if (isError || isLoading || !data) { throw new Error('Feature flags not loaded'); } + + const setFeatureFlagEvent: SetFeatureFlagEvent = { + type: 'SET_FEATURE_FLAG', + data: { + feature_flag: + availableFeatureFlags.find(x => x.id === flagId)?.title || + 'Unknown', + value: newState, + }, + }; + sendTelemetryEvent(setFeatureFlagEvent); + const newFlags = data.map(item => { if (item.id !== flagId) { return item; diff --git a/frontend/libs/console/legacy-ce/src/lib/telemetry/index.ts b/frontend/libs/console/legacy-ce/src/lib/telemetry/index.ts index 834ffb41f39..d90528f49a6 100644 --- a/frontend/libs/console/legacy-ce/src/lib/telemetry/index.ts +++ b/frontend/libs/console/legacy-ce/src/lib/telemetry/index.ts @@ -20,7 +20,18 @@ export type ConnectDBEvent = { }; }; -export type TelemetryEvent = RunTimeErrorEvent | ConnectDBEvent; +export type SetFeatureFlagEvent = { + type: 'SET_FEATURE_FLAG'; + data: { + feature_flag: string; + value: boolean; + }; +}; + +export type TelemetryEvent = + | RunTimeErrorEvent + | ConnectDBEvent + | SetFeatureFlagEvent; export type TelemetryPayload = { server_version: string;