1- import { Fragment } from 'react' ;
1+ import { Fragment , useEffect , useMemo } from 'react' ;
22
33import Feature from 'sentry/components/acl/feature' ;
44import { FeatureBadge } from 'sentry/components/core/badge/featureBadge' ;
5+ import { limitedMetricsSupportPrefixes } from 'sentry/data/platformCategories' ;
56import { t } from 'sentry/locale' ;
7+ import type { PlatformKey } from 'sentry/types/project' ;
8+ import { trackAnalytics } from 'sentry/utils/analytics' ;
69import { useLocation } from 'sentry/utils/useLocation' ;
710import useOrganization from 'sentry/utils/useOrganization' ;
11+ import useProjects from 'sentry/utils/useProjects' ;
812import { useGetSavedQueries } from 'sentry/views/explore/hooks/useGetSavedQueries' ;
913import { PRIMARY_NAV_GROUP_CONFIG } from 'sentry/views/nav/primary/config' ;
1014import { SecondaryNav } from 'sentry/views/nav/secondary/secondary' ;
@@ -17,6 +21,7 @@ const MAX_STARRED_QUERIES_DISPLAYED = 20;
1721export function ExploreSecondaryNav ( ) {
1822 const organization = useOrganization ( ) ;
1923 const location = useLocation ( ) ;
24+ const { projects} = useProjects ( ) ;
2025
2126 const baseUrl = `/organizations/${ organization . slug } /explore` ;
2227
@@ -25,6 +30,28 @@ export function ExploreSecondaryNav() {
2530 perPage : MAX_STARRED_QUERIES_DISPLAYED ,
2631 } ) ;
2732
33+ const hasMetricsSupportedPlatform = projects . some ( project => {
34+ const platform = project . platform || 'unknown' ;
35+ return Array . from ( limitedMetricsSupportPrefixes ) . some ( prefix =>
36+ platform . startsWith ( prefix )
37+ ) ;
38+ } ) ;
39+
40+ const userPlatforms = useMemo (
41+ ( ) => [
42+ ...new Set ( projects . map ( project => ( project . platform as PlatformKey ) || 'unknown' ) ) ,
43+ ] ,
44+ [ projects ]
45+ ) ;
46+
47+ useEffect ( ( ) => {
48+ trackAnalytics ( 'metrics.nav.rendered' , {
49+ organization,
50+ metrics_tab_visible : hasMetricsSupportedPlatform ,
51+ platforms : userPlatforms ,
52+ } ) ;
53+ } , [ organization , hasMetricsSupportedPlatform , userPlatforms ] ) ;
54+
2855 return (
2956 < Fragment >
3057 < SecondaryNav . Header >
@@ -51,15 +78,17 @@ export function ExploreSecondaryNav() {
5178 { t ( 'Logs' ) }
5279 </ SecondaryNav . Item >
5380 </ Feature >
54- < Feature features = "tracemetrics-enabled" >
55- < SecondaryNav . Item
56- to = { `${ baseUrl } /metrics/` }
57- analyticsItemName = "explore_metrics"
58- trailingItems = { < FeatureBadge type = "alpha" /> }
59- >
60- { t ( 'Metrics' ) }
61- </ SecondaryNav . Item >
62- </ Feature >
81+ { hasMetricsSupportedPlatform && (
82+ < Feature features = "tracemetrics-enabled" >
83+ < SecondaryNav . Item
84+ to = { `${ baseUrl } /metrics/` }
85+ analyticsItemName = "explore_metrics"
86+ trailingItems = { < FeatureBadge type = "alpha" /> }
87+ >
88+ { t ( 'Metrics' ) }
89+ </ SecondaryNav . Item >
90+ </ Feature >
91+ ) }
6392 < Feature
6493 features = "discover-basic"
6594 hookName = "feature-disabled:discover2-sidebar-item"
0 commit comments