import {Fragment, useEffect} from 'react';
import styled from '@emotion/styled';
import {setTag} from '@sentry/react';
import {Location} from 'history';
import Feature from 'sentry/components/acl/feature';
import IdBadge from 'sentry/components/idBadge';
import * as Layout from 'sentry/components/layouts/thirds';
import space from 'sentry/styles/space';
import {Organization, Project} from 'sentry/types';
import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
import DiscoverQuery from 'sentry/utils/discover/discoverQuery';
import EventView from 'sentry/utils/discover/eventView';
import SpanExamplesQuery, {
ChildrenProps as SpanExamplesProps,
} from 'sentry/utils/performance/suspectSpans/spanExamplesQuery';
import SuspectSpansQuery, {
ChildrenProps as SuspectSpansProps,
} from 'sentry/utils/performance/suspectSpans/suspectSpansQuery';
import {SpanSlug} from 'sentry/utils/performance/suspectSpans/types';
import {decodeScalar} from 'sentry/utils/queryString';
import Breadcrumb from 'sentry/views/performance/breadcrumb';
import {getSelectedProjectPlatforms} from 'sentry/views/performance/utils';
import Tab from '../../tabs';
import {SpanSortOthers} from '../types';
import {getTotalsView} from '../utils';
import SpanChart from './chart';
import SpanDetailsControls from './spanDetailsControls';
import SpanDetailsHeader from './spanDetailsHeader';
import SpanTable from './spanDetailsTable';
import {ZoomKeys} from './utils';
type Props = {
eventView: EventView;
location: Location;
organization: Organization;
project: Project | undefined;
spanSlug: SpanSlug;
transactionName: string;
};
export default function SpanDetailsContentWrapper(props: Props) {
const {location, organization, eventView, project, transactionName, spanSlug} = props;
const minExclusiveTime = decodeScalar(location.query[ZoomKeys.MIN]);
const maxExclusiveTime = decodeScalar(location.query[ZoomKeys.MAX]);
useEffect(() => {
if (project) {
trackAdvancedAnalyticsEvent('performance_views.span_summary.view', {
organization,
project_platforms: getSelectedProjectPlatforms(location, [project]),
});
}
}, [organization, project, location]);
return (
{project && (
)}
{transactionName}
{({tableData}) => {
const totalCount: number | null =
(tableData?.data?.[0]?.['count()'] as number) ?? null;
if (totalCount) {
setTag('spans.totalCount', totalCount);
const countGroup = [
1, 5, 10, 20, 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000,
].find(n => totalCount <= n);
setTag('spans.totalCount.grouped', `<=${countGroup}`);
}
return (
{suspectSpansResults => (
{spanExamplesResults => (
)}
)}
);
}}
);
}
const TransactionName = styled('div')`
display: grid;
grid-template-columns: max-content 1fr;
grid-column-gap: ${space(1)};
align-items: center;
`;
type ContentProps = {
eventView: EventView;
location: Location;
organization: Organization;
project: Project | undefined;
spanExamplesResults: SpanExamplesProps;
spanSlug: SpanSlug;
suspectSpansResults: SuspectSpansProps;
totalCount: number;
transactionName: string;
};
function SpanDetailsContent(props: ContentProps) {
const {
location,
organization,
project,
eventView,
spanSlug,
transactionName,
totalCount,
suspectSpansResults,
spanExamplesResults,
} = props;
// There should always be exactly 1 result
const suspectSpan = suspectSpansResults.suspectSpans?.[0];
const examples = spanExamplesResults.examples?.[0]?.examples;
const transactionCountContainingSpan = suspectSpan?.frequency;
return (
);
}
function getSpansEventView(eventView: EventView): EventView {
// TODO: There is a bug where if the sort is not avg occurrence,
// then the avg occurrence will never be added to the fields
eventView = eventView.withSorts([{field: SpanSortOthers.AVG_OCCURRENCE, kind: 'desc'}]);
eventView.fields = [
{field: 'count()'},
{field: 'count_unique(id)'},
{field: 'equation|count() / count_unique(id)'},
{field: 'sumArray(spans_exclusive_time)'},
{field: 'percentileArray(spans_exclusive_time, 0.50)'},
{field: 'percentileArray(spans_exclusive_time, 0.75)'},
{field: 'percentileArray(spans_exclusive_time, 0.95)'},
{field: 'percentileArray(spans_exclusive_time, 0.99)'},
];
return eventView;
}