Skip to content

feat(insights): add analytics to insight sample panels #70822

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

Merged
merged 9 commits into from
May 15, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import type {CursorHandler} from 'sentry/components/pagination';
import Pagination from 'sentry/components/pagination';
import {t} from 'sentry/locale';
import {space} from 'sentry/styles/space';
import {trackAnalytics} from 'sentry/utils/analytics';
import {decodeScalar} from 'sentry/utils/queryString';
import {useLocation} from 'sentry/utils/useLocation';
import useOrganization from 'sentry/utils/useOrganization';
import {useParams} from 'sentry/utils/useParams';
import {RESOURCE_THROUGHPUT_UNIT} from 'sentry/views/performance/browser/resources';
import {useResourceModuleFilters} from 'sentry/views/performance/browser/resources/utils/useResourceFilters';
Expand All @@ -22,7 +24,11 @@ import {renderHeadCell} from 'sentry/views/starfish/components/tableCells/render
import ResourceSizeCell from 'sentry/views/starfish/components/tableCells/resourceSizeCell';
import {WiderHovercard} from 'sentry/views/starfish/components/tableCells/spanDescriptionCell';
import {ThroughputCell} from 'sentry/views/starfish/components/tableCells/throughputCell';
import {SpanIndexedField, SpanMetricsField} from 'sentry/views/starfish/types';
import {
ModuleName,
SpanIndexedField,
SpanMetricsField,
} from 'sentry/views/starfish/types';
import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
import {DataTitles, getThroughputTitle} from 'sentry/views/starfish/views/spans/types';

Expand All @@ -44,6 +50,7 @@ type Row = {
type Column = GridColumnHeader<keyof Row>;

function ResourceSummaryTable() {
const organization = useOrganization();
const location = useLocation();
const {groupId} = useParams();
const sort = useResourceSummarySort();
Expand Down Expand Up @@ -99,6 +106,12 @@ function ResourceSummaryTable() {

const link = (
<Link
onClick={() =>
trackAnalytics('performance_views.sample_spans.opened', {
organization,
source: ModuleName.RESOURCE,
})
}
to={{
pathname: location.pathname,
query: {
Expand Down
14 changes: 13 additions & 1 deletion static/app/views/performance/cache/samplePanel/samplePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {Button} from 'sentry/components/button';
import Link from 'sentry/components/links/link';
import {t} from 'sentry/locale';
import {space} from 'sentry/styles/space';
import {trackAnalytics} from 'sentry/utils/analytics';
import {DurationUnit, RateUnit, SizeUnit} from 'sentry/utils/discover/fields';
import {PageAlertProvider} from 'sentry/utils/performance/contexts/pageAlert';
import {decodeScalar} from 'sentry/utils/queryString';
Expand All @@ -34,6 +35,7 @@ import {useTransactions} from 'sentry/views/starfish/queries/useTransactions';
import {
MetricsFields,
type MetricsQueryFilters,
ModuleName,
SpanFunction,
SpanIndexedField,
type SpanIndexedQueryFilters,
Expand Down Expand Up @@ -346,7 +348,17 @@ export function CacheSamplePanel() {

<Fragment>
<ModuleLayout.Full>
<Button onClick={handleRefetch}>{t('Try Different Samples')}</Button>
<Button
onClick={() => {
trackAnalytics(
'performance_views.sample_spans.try_different_samples_clicked',
{organization, source: ModuleName.CACHE}
);
handleRefetch();
}}
>
{t('Try Different Samples')}
</Button>
</ModuleLayout.Full>
</Fragment>
</ModuleLayout.Layout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {CacheHitMissCell} from 'sentry/views/performance/cache/tables/cacheHitMi
import {renderHeadCell} from 'sentry/views/starfish/components/tableCells/renderHeadCell';
import {SpanIdCell} from 'sentry/views/starfish/components/tableCells/spanIdCell';
import type {IndexedResponse} from 'sentry/views/starfish/types';
import {SpanIndexedField} from 'sentry/views/starfish/types';
import {ModuleName, SpanIndexedField} from 'sentry/views/starfish/types';

type DataRowKeys =
| SpanIndexedField.PROJECT
Expand Down Expand Up @@ -126,6 +126,7 @@ function renderBodyCell(
if (column.key === SpanIndexedField.ID) {
return (
<SpanIdCell
moduleName={ModuleName.CACHE}
projectSlug={row.project}
traceId={row.trace}
timestamp={row.timestamp}
Expand Down
16 changes: 15 additions & 1 deletion static/app/views/performance/cache/tables/transactionCell.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import * as qs from 'query-string';

import Link from 'sentry/components/links/link';
import {trackAnalytics} from 'sentry/utils/analytics';
import {useLocation} from 'sentry/utils/useLocation';
import useOrganization from 'sentry/utils/useOrganization';
import {useCacheUrl} from 'sentry/views/performance/cache/utils';
import {OverflowEllipsisTextContainer} from 'sentry/views/starfish/components/textAlign';
import {ModuleName} from 'sentry/views/starfish/types';

interface Props {
project?: string;
Expand All @@ -12,6 +15,7 @@ interface Props {
}

export function TransactionCell({project, transaction}: Props) {
const organization = useOrganization();
const location = useLocation();
const cacheUrl = useCacheUrl();

Expand All @@ -27,7 +31,17 @@ export function TransactionCell({project, transaction}: Props) {

return (
<OverflowEllipsisTextContainer>
<Link to={`${cacheUrl}/?${qs.stringify(query)}`}>{transaction}</Link>
<Link
onClick={() =>
trackAnalytics('performance_views.sample_spans.opened', {
organization,
source: ModuleName.CACHE,
})
}
to={`${cacheUrl}/?${qs.stringify(query)}`}
>
{transaction}
</Link>
</OverflowEllipsisTextContainer>
);
}
Expand Down
34 changes: 32 additions & 2 deletions static/app/views/performance/http/httpSamplesPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Link from 'sentry/components/links/link';
import {SegmentedControl} from 'sentry/components/segmentedControl';
import {t} from 'sentry/locale';
import {space} from 'sentry/styles/space';
import {trackAnalytics} from 'sentry/utils/analytics';
import {DurationUnit, RateUnit} from 'sentry/utils/discover/fields';
import {PageAlertProvider} from 'sentry/utils/performance/contexts/pageAlert';
import {decodeScalar} from 'sentry/utils/queryString';
Expand Down Expand Up @@ -44,6 +45,7 @@ import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useDiscoverSer
import {useIndexedSpans} from 'sentry/views/starfish/queries/useIndexedSpans';
import {useSpanMetricsTopNSeries} from 'sentry/views/starfish/queries/useSpanMetricsTopNSeries';
import {
ModuleName,
SpanFunction,
SpanIndexedField,
SpanMetricsField,
Expand Down Expand Up @@ -86,6 +88,12 @@ export function HTTPSamplesPanel() {
: undefined;

const handlePanelChange = newPanelName => {
trackAnalytics('performance_views.sample_spans.filter_updated', {
filter: 'panel',
new_state: newPanelName,
organization,
source: ModuleName.HTTP,
});
router.replace({
pathname: location.pathname,
query: {
Expand All @@ -96,6 +104,12 @@ export function HTTPSamplesPanel() {
};

const handleResponseCodeClassChange = newResponseCodeClass => {
trackAnalytics('performance_views.sample_spans.filter_updated', {
filter: 'status_code',
new_state: newResponseCodeClass.value,
organization,
source: ModuleName.HTTP,
});
router.replace({
pathname: location.pathname,
query: {
Expand Down Expand Up @@ -435,7 +449,15 @@ export function HTTPSamplesPanel() {
</ModuleLayout.Full>

<ModuleLayout.Full>
<Button onClick={() => refetchDurationSpanSamples()}>
<Button
onClick={() => {
trackAnalytics(
'performance_views.sample_spans.try_different_samples_clicked',
{organization, source: ModuleName.HTTP}
);
refetchDurationSpanSamples();
}}
>
{t('Try Different Samples')}
</Button>
</ModuleLayout.Full>
Expand Down Expand Up @@ -468,7 +490,15 @@ export function HTTPSamplesPanel() {
</ModuleLayout.Full>

<ModuleLayout.Full>
<Button onClick={() => refetchResponseCodeSpanSamples()}>
<Button
onClick={() => {
trackAnalytics(
'performance_views.sample_spans.try_different_samples_clicked',
{organization, source: ModuleName.HTTP}
);
refetchResponseCodeSpanSamples();
}}
>
{t('Try Different Samples')}
</Button>
</ModuleLayout.Full>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import useOrganization from 'sentry/utils/useOrganization';
import {renderHeadCell} from 'sentry/views/starfish/components/tableCells/renderHeadCell';
import {SpanIdCell} from 'sentry/views/starfish/components/tableCells/spanIdCell';
import type {IndexedResponse} from 'sentry/views/starfish/types';
import {SpanIndexedField} from 'sentry/views/starfish/types';
import {ModuleName, SpanIndexedField} from 'sentry/views/starfish/types';

type DataRowKeys =
| SpanIndexedField.PROJECT
Expand Down Expand Up @@ -110,6 +110,7 @@ function renderBodyCell(
if (column.key === SpanIndexedField.ID) {
return (
<SpanIdCell
moduleName={ModuleName.HTTP}
projectSlug={row.project}
traceId={row.trace}
timestamp={row.timestamp}
Expand Down
14 changes: 13 additions & 1 deletion static/app/views/performance/http/tables/transactionCell.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import * as qs from 'query-string';

import Link from 'sentry/components/links/link';
import {trackAnalytics} from 'sentry/utils/analytics';
import {useLocation} from 'sentry/utils/useLocation';
import useOrganization from 'sentry/utils/useOrganization';
import {normalizeUrl} from 'sentry/utils/withDomainRequired';
import {OverflowEllipsisTextContainer} from 'sentry/views/starfish/components/textAlign';
import {ModuleName} from 'sentry/views/starfish/types';

interface Props {
domain?: string;
Expand Down Expand Up @@ -46,7 +48,17 @@ export function TransactionCell({

return (
<OverflowEllipsisTextContainer>
<Link to={`${pathname}?${qs.stringify(query)}`}>{label}</Link>
<Link
onClick={() =>
trackAnalytics('performance_views.sample_spans.opened', {
organization,
source: ModuleName.HTTP,
})
}
to={`${pathname}?${qs.stringify(query)}`}
>
{label}
</Link>
</OverflowEllipsisTextContainer>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export function ScreenSummary() {
...(deviceClass ? {[SpanMetricsField.DEVICE_CLASS]: deviceClass} : {}),
}}
groupId={spanGroup}
moduleName={ModuleName.STARTUP}
moduleName={ModuleName.APP_START}
transactionName={transactionName}
spanDescription={spanDescription}
spanOp={spanOp}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {CursorHandler} from 'sentry/components/pagination';
import Pagination from 'sentry/components/pagination';
import {t} from 'sentry/locale';
import type {NewQuery} from 'sentry/types/organization';
import {trackAnalytics} from 'sentry/utils/analytics';
import {browserHistory} from 'sentry/utils/browserHistory';
import type {TableDataRow} from 'sentry/utils/discover/discoverQuery';
import type {MetaType} from 'sentry/utils/discover/eventView';
Expand Down Expand Up @@ -37,7 +38,7 @@ import {
} from 'sentry/views/starfish/components/releaseSelector';
import {PercentChangeCell} from 'sentry/views/starfish/components/tableCells/percentChangeCell';
import {OverflowEllipsisTextContainer} from 'sentry/views/starfish/components/textAlign';
import {SpanMetricsField} from 'sentry/views/starfish/types';
import {ModuleName, SpanMetricsField} from 'sentry/views/starfish/types';
import {STARFISH_CHART_INTERVAL_FIDELITY} from 'sentry/views/starfish/utils/constants';
import {appendReleaseFilters} from 'sentry/views/starfish/utils/releaseComparison';
import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
Expand Down Expand Up @@ -159,7 +160,15 @@ export function SpanOperationTable({
};

return (
<Link to={`${pathname}?${qs.stringify(query)}`}>
<Link
onClick={() =>
trackAnalytics('performance_views.sample_spans.opened', {
organization,
source: ModuleName.APP_START,
})
}
to={`${pathname}?${qs.stringify(query)}`}
Comment on lines +164 to +170
Copy link
Member

Choose a reason for hiding this comment

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

An alternative I'm curious about is if we'd be able to instrument this in the panel itself since you're already passing along the module name. e.g. in a useEffect hook that just runs once when it's rendered unless for some reason that won't work with how we've set up the panel

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think we can for all of the modules

>
<OverflowEllipsisTextContainer>{label}</OverflowEllipsisTextContainer>
</Link>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ function ScreenLoadSpans() {
{spanGroup && (
<SpanSamplesPanel
groupId={spanGroup}
moduleName={ModuleName.SCREEN}
moduleName={ModuleName.SCREEN_LOAD}
transactionName={transactionName}
spanDescription={spanDescription}
onClose={() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {Tooltip} from 'sentry/components/tooltip';
import {t, tct} from 'sentry/locale';
import type {NewQuery} from 'sentry/types/organization';
import type {Project} from 'sentry/types/project';
import {trackAnalytics} from 'sentry/utils/analytics';
import {browserHistory} from 'sentry/utils/browserHistory';
import type {TableDataRow} from 'sentry/utils/discover/discoverQuery';
import type {MetaType} from 'sentry/utils/discover/eventView';
Expand Down Expand Up @@ -46,7 +47,7 @@ import {
} from 'sentry/views/starfish/components/releaseSelector';
import {OverflowEllipsisTextContainer} from 'sentry/views/starfish/components/textAlign';
import {useTTFDConfigured} from 'sentry/views/starfish/queries/useHasTtfdConfigured';
import {SpanMetricsField} from 'sentry/views/starfish/types';
import {ModuleName, SpanMetricsField} from 'sentry/views/starfish/types';
import {STARFISH_CHART_INTERVAL_FIDELITY} from 'sentry/views/starfish/utils/constants';
import {appendReleaseFilters} from 'sentry/views/starfish/utils/releaseComparison';
import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
Expand Down Expand Up @@ -180,7 +181,15 @@ export function ScreenLoadSpansTable({
};

return (
<Link to={`${pathname}?${qs.stringify(query)}`}>
<Link
onClick={() =>
trackAnalytics('performance_views.sample_spans.opened', {
organization,
source: ModuleName.SCREEN_LOAD,
})
}
to={`${pathname}?${qs.stringify(query)}`}
>
<OverflowEllipsisTextContainer>{label}</OverflowEllipsisTextContainer>
</Link>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {CursorHandler} from 'sentry/components/pagination';
import Pagination from 'sentry/components/pagination';
import {t} from 'sentry/locale';
import type {Organization} from 'sentry/types';
import {trackAnalytics} from 'sentry/utils/analytics';
import {browserHistory} from 'sentry/utils/browserHistory';
import type {EventsMetaType} from 'sentry/utils/discover/eventView';
import {FIELD_FORMATTERS, getFieldRenderer} from 'sentry/utils/discover/fieldRenderers';
Expand All @@ -23,7 +24,11 @@ import useOrganization from 'sentry/utils/useOrganization';
import {normalizeUrl} from 'sentry/utils/withDomainRequired';
import {useQueuesByTransactionQuery} from 'sentry/views/performance/queues/queries/useQueuesByTransactionQuery';
import {renderHeadCell} from 'sentry/views/starfish/components/tableCells/renderHeadCell';
import {SpanFunction, type SpanMetricsResponse} from 'sentry/views/starfish/types';
import {
ModuleName,
SpanFunction,
type SpanMetricsResponse,
} from 'sentry/views/starfish/types';
import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';

type Row = Pick<
Expand Down Expand Up @@ -232,6 +237,12 @@ function TransactionCell({transaction, op}: {op: string; transaction: string}) {
return (
<NoOverflow>
<Link
onClick={() =>
trackAnalytics('performance_views.sample_spans.opened', {
organization,
source: ModuleName.QUEUE,
})
}
to={normalizeUrl(
`/organizations/${organization.slug}/performance/queues/destination/?${qs.stringify(queryString)}`
)}
Expand Down
Loading
Loading