console: send telemetry event on feature flag enable/disable

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/7948
GitOrigin-RevId: 0dbb12e0bd291249f447ac58968b63c960630c49
This commit is contained in:
Rikin Kachhia 2023-02-16 16:14:11 +05:30 committed by hasura-bot
parent fc40739f62
commit 2e57bfe0ea
2 changed files with 26 additions and 1 deletions

View File

@ -1,6 +1,8 @@
import { useMutation, useQueryClient } from 'react-query'; import { useMutation, useQueryClient } from 'react-query';
import { FeatureFlagId, useFeatureFlags } from '@/features/FeatureFlags'; import { FeatureFlagId, useFeatureFlags } from '@/features/FeatureFlags';
import { saveFeatureFlagsStateToLocalStorage } from '../utils'; import { saveFeatureFlagsStateToLocalStorage } from '../utils';
import { sendTelemetryEvent, SetFeatureFlagEvent } from '@/telemetry';
import { availableFeatureFlags } from '@/features/FeatureFlags/availableFeatureFlags';
export function useSetFeatureFlagEnabled() { export function useSetFeatureFlagEnabled() {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
@ -17,6 +19,18 @@ export function useSetFeatureFlagEnabled() {
if (isError || isLoading || !data) { if (isError || isLoading || !data) {
throw new Error('Feature flags not loaded'); 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 => { const newFlags = data.map(item => {
if (item.id !== flagId) { if (item.id !== flagId) {
return item; return item;

View File

@ -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 = { export type TelemetryPayload = {
server_version: string; server_version: string;