Skip to content
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
4 changes: 3 additions & 1 deletion static/app/utils/analytics/metricsAnalyticsEvent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ export type MetricsAnalyticsEventParameters = {
organization: Organization;
};
'metrics.nav.rendered': {
has_feature_flag: boolean;
has_metrics_supported_platform: boolean;
metrics_supported_platform_name: string | undefined;
metrics_tab_visible: boolean;
organization: Organization;
platforms: Array<PlatformKey | 'unknown'>;
};
'metrics.onboarding': {
organization: Organization;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Fragment, useEffect, useMemo} from 'react';
import {Fragment, useEffect, useMemo, useRef} from 'react';

import Feature from 'sentry/components/acl/feature';
import {FeatureBadge} from 'sentry/components/core/badge/featureBadge';
Expand All @@ -10,6 +10,7 @@ import {useLocation} from 'sentry/utils/useLocation';
import useOrganization from 'sentry/utils/useOrganization';
import useProjects from 'sentry/utils/useProjects';
import {useGetSavedQueries} from 'sentry/views/explore/hooks/useGetSavedQueries';
import {canUseMetricsUI} from 'sentry/views/explore/metrics/metricsFlags';
import {PRIMARY_NAV_GROUP_CONFIG} from 'sentry/views/nav/primary/config';
import {SecondaryNav} from 'sentry/views/nav/secondary/secondary';
import {ExploreSavedQueryNavItems} from 'sentry/views/nav/secondary/sections/explore/exploreSavedQueryNavItems';
Expand Down Expand Up @@ -38,23 +39,32 @@ export function ExploreSecondaryNav() {
[projects]
);

const hasMetricsSupportedPlatform = projects.some(project => {
const platform = project.platform || 'unknown';
return Array.from(limitedMetricsSupportPrefixes).some(prefix =>
platform.startsWith(prefix)
);
});
const metricsSupportedPlatformNameRef = useRef<string | undefined>(undefined);

if (!metricsSupportedPlatformNameRef.current) {
const metricsSupportedPlatform = projects.find(project => {
const platform = project.platform || 'unknown';
return Array.from(limitedMetricsSupportPrefixes).find(prefix =>
platform.startsWith(prefix)
);
});
metricsSupportedPlatformNameRef.current = metricsSupportedPlatform?.slug;
}

const hasMetricsSupportedPlatform = !!metricsSupportedPlatformNameRef.current;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Metrics UI Out of Sync with Project Data

The metricsSupportedPlatformNameRef is set conditionally during render and never updates when projects changes. If projects load asynchronously or change later, hasMetricsSupportedPlatform will remain stale, preventing the Metrics nav item from appearing even when supported platforms exist, and causing analytics to report incorrect data.

Fix in Cursor Fix in Web


useEffect(() => {
if (userPlatforms.length === 0) {
return;
}
trackAnalytics('metrics.nav.rendered', {
organization,
metrics_tab_visible: hasMetricsSupportedPlatform,
platforms: userPlatforms,
has_feature_flag: canUseMetricsUI(organization),
has_metrics_supported_platform: hasMetricsSupportedPlatform,
metrics_supported_platform_name: metricsSupportedPlatformNameRef.current,
metrics_tab_visible: hasMetricsSupportedPlatform && canUseMetricsUI(organization),
});
}, [organization, hasMetricsSupportedPlatform, userPlatforms]);
}, [organization, hasMetricsSupportedPlatform, userPlatforms.length]);

return (
<Fragment>
Expand Down
Loading