Skip to content

Commit 1775021

Browse files
nikkikapadiaandrewshie-sentry
authored andcommitted
feat(schema-hints): Add analytics for hint clicks and drawer open/close (#87536)
Added analytics to be able to tell which hints have been clicked, where they have been clicked from, and when a drawer has been open/closed. A drawer can be seen as open or closed when only `schema_hints_drawer_open` is defined. Side note: the `onOpen` function was never actually being called in the `GlobalDrawer` hook so I added that into the `openDrawer` callback.
1 parent 1acb965 commit 1775021

File tree

4 files changed

+46
-7
lines changed

4 files changed

+46
-7
lines changed

static/app/components/globalDrawer/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ export function GlobalDrawer({children}: any) {
9999
>();
100100
// If no config is set, the global drawer is closed.
101101
const isDrawerOpen = !!currentDrawerConfig;
102-
const openDrawer = useCallback<DrawerContextType['openDrawer']>(
103-
(renderer, options) => overwriteDrawerConfig({renderer, options}),
104-
[]
105-
);
102+
const openDrawer = useCallback<DrawerContextType['openDrawer']>((renderer, options) => {
103+
overwriteDrawerConfig({renderer, options});
104+
options.onOpen?.();
105+
}, []);
106106
const closeDrawer = useCallback<DrawerContextType['closeDrawer']>(
107107
() => overwriteDrawerConfig(undefined),
108108
[]

static/app/utils/analytics/tracingEventMap.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ export type TracingEventParameters = {
2929
visualizes_count: number;
3030
empty_buckets_percentage?: number[];
3131
};
32+
'trace.explorer.schema_hints_click': {
33+
source: 'list' | 'drawer';
34+
hint_key?: string;
35+
};
36+
'trace.explorer.schema_hints_drawer': {
37+
drawer_open: boolean;
38+
};
3239
'trace.load.empty_state': {
3340
source: TraceWaterFallSource;
3441
};
@@ -163,6 +170,10 @@ export const tracingEventMap: Record<TracingEventKey, string | null> = {
163170
'trace.load.empty_state': 'Trace Load Empty State',
164171
'trace.load.error_state': 'Trace Load Error State',
165172
'trace.explorer.metadata': 'Improved Trace Explorer Pageload Metadata',
173+
'trace.explorer.schema_hints_click':
174+
'Improved Trace Explorer: Schema Hints Click Events',
175+
'trace.explorer.schema_hints_drawer':
176+
'Improved Trace Explorer: Schema Hints Drawer Events',
166177
'trace.trace_layout.change': 'Changed Trace Layout',
167178
'trace.trace_layout.drawer_minimize': 'Minimized Trace Drawer',
168179
'trace.trace_drawer_explore_search': 'Searched Trace Explorer',

static/app/views/explore/components/schemaHintsDrawer.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import {IconSearch} from 'sentry/icons';
99
import {t} from 'sentry/locale';
1010
import {space} from 'sentry/styles/space';
1111
import type {Tag} from 'sentry/types/group';
12+
import {trackAnalytics} from 'sentry/utils/analytics';
1213
import {prettifyTagKey} from 'sentry/utils/discover/fields';
1314
import {FieldKind, FieldValueType, getFieldDefinition} from 'sentry/utils/fields';
1415
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
16+
import useOrganization from 'sentry/utils/useOrganization';
1517
import {
1618
useExploreQuery,
1719
useSetExploreQuery,
@@ -24,7 +26,7 @@ type SchemaHintsDrawerProps = {
2426
function SchemaHintsDrawer({hints}: SchemaHintsDrawerProps) {
2527
const exploreQuery = useExploreQuery();
2628
const setExploreQuery = useSetExploreQuery();
27-
29+
const organization = useOrganization();
2830
const [searchQuery, setSearchQuery] = useState('');
2931

3032
const selectedFilterKeys = useMemo(() => {
@@ -84,8 +86,13 @@ function SchemaHintsDrawer({hints}: SchemaHintsDrawerProps) {
8486
);
8587
}
8688
setExploreQuery(filterQuery.formatString());
89+
trackAnalytics('trace.explorer.schema_hints_click', {
90+
hint_key: hint.key,
91+
source: 'drawer',
92+
organization,
93+
});
8794
},
88-
[exploreQuery, setExploreQuery]
95+
[exploreQuery, organization, setExploreQuery]
8996
);
9097

9198
const noAttributesMessage = (

static/app/views/explore/components/schemaHintsList.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {getFunctionTags} from 'sentry/components/performance/spanSearchQueryBuil
1212
import {t} from 'sentry/locale';
1313
import {space} from 'sentry/styles/space';
1414
import type {Tag, TagCollection} from 'sentry/types/group';
15+
import {trackAnalytics} from 'sentry/utils/analytics';
1516
import {prettifyTagKey} from 'sentry/utils/discover/fields';
1617
import {
1718
type AggregationKey,
@@ -21,6 +22,7 @@ import {
2122
} from 'sentry/utils/fields';
2223
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
2324
import {useLocation} from 'sentry/utils/useLocation';
25+
import useOrganization from 'sentry/utils/useOrganization';
2426
import SchemaHintsDrawer from 'sentry/views/explore/components/schemaHintsDrawer';
2527
import {SCHEMA_HINTS_LIST_ORDER_KEYS} from 'sentry/views/explore/components/schemaHintsUtils/schemaHintsListOrder';
2628
import {
@@ -65,7 +67,7 @@ function SchemaHintsList({
6567
const exploreQuery = useExploreQuery();
6668
const setExploreQuery = useSetExploreQuery();
6769
const location = useLocation();
68-
70+
const organization = useOrganization();
6971
const {openDrawer, isDrawerOpen, closeDrawer} = useDrawer();
7072

7173
const functionTags = useMemo(() => {
@@ -193,6 +195,19 @@ function SchemaHintsList({
193195
)
194196
);
195197
},
198+
onOpen: () => {
199+
trackAnalytics('trace.explorer.schema_hints_drawer', {
200+
drawer_open: true,
201+
organization,
202+
});
203+
},
204+
205+
onClose: () => {
206+
trackAnalytics('trace.explorer.schema_hints_drawer', {
207+
drawer_open: false,
208+
organization,
209+
});
210+
},
196211
}
197212
);
198213
}
@@ -215,11 +230,17 @@ function SchemaHintsList({
215230
isBoolean ? 'True' : hint.kind === FieldKind.MEASUREMENT ? '>0' : ''
216231
);
217232
setExploreQuery(newSearchQuery.formatString());
233+
trackAnalytics('trace.explorer.schema_hints_click', {
234+
hint_key: hint.key,
235+
source: 'list',
236+
organization,
237+
});
218238
},
219239
[
220240
exploreQuery,
221241
setExploreQuery,
222242
isDrawerOpen,
243+
organization,
223244
openDrawer,
224245
filterTagsSorted,
225246
location.pathname,

0 commit comments

Comments
 (0)