Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ui): add analytic event to metrics chart views #3570

Merged
merged 4 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {GridFilterModel, GridSortModel} from '@mui/x-data-grid-pro';
import React, {useMemo} from 'react';
import React, {useEffect, useMemo, useRef, useState} from 'react';

import {MOON_400} from '../../../../../../common/css/color.styles';
import * as userEvents from '../../../../../../integrations/analytics/userEvents';
import {IconInfo} from '../../../../../Icon';
import {WaveLoader} from '../../../../../Loaders/WaveLoader';
import {Tailwind} from '../../../../../Tailwind';
Expand Down Expand Up @@ -114,6 +115,8 @@ export const CallsCharts = ({
columns
);

useFireAnalyticsForMetricsPlotsViewed(entity, project, calls.loading);

const chartData = useMemo(() => {
if (calls.loading || !calls.result || calls.result.length === 0) {
return {latency: [], errors: [], requests: []};
Expand Down Expand Up @@ -188,3 +191,37 @@ export const CallsCharts = ({
</Tailwind>
);
};

/**
* Fires an analytics event when the metrics plots are viewed.
* This is used to track the usage and latency of the metrics plots.
* Only fires once when opened.
*/
const useFireAnalyticsForMetricsPlotsViewed = (
entity: string,
project: string,
loading: boolean
) => {
const [callsQueryStartTime, setCallsQueryStartTime] = useState<number | null>(
null
);
const sentEvent = useRef(false);
useEffect(() => {
if (sentEvent.current) {
return;
}
if (loading) {
const startTime = Date.now();
setCallsQueryStartTime(startTime);
} else if (!loading && callsQueryStartTime !== null) {
const endTime = Date.now();
const latency = endTime - callsQueryStartTime;
userEvents.metricsPlotsViewed({
entity,
project,
latency,
});
sentEvent.current = true;
}
}, [loading, callsQueryStartTime, entity, project]);
};
25 changes: 25 additions & 0 deletions weave-js/src/integrations/analytics/userEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,28 @@ export const callTreeCellClicked = makeTrackEvent<
};
}
>('Weave call tree cell clicked');

export const metricsPlotsViewed = makeTrackEvent<
{
entity: string;
project: string;
latency: number;
},
{
_description: `User viewed metrics plots`;
_location: '';
_motivation: 'Used for tracking metrics plots';
entity: {
description: 'Entity of call';
exampleValues: ['my-entity'];
};
project: {
description: 'Project of call';
exampleValues: ['my-project'];
};
latency: {
description: 'Latency of calls stream query (ms)';
exampleValues: [1000, 500];
};
}
>('Weave metrics plots viewed');