body.tsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import {Location} from 'history';
  2. import moment from 'moment-timezone';
  3. import EmptyStateWarning from 'sentry/components/emptyStateWarning';
  4. import {getTraceDateTimeRange} from 'sentry/components/events/interfaces/spans/utils';
  5. import LoadingIndicator from 'sentry/components/loadingIndicator';
  6. import {Panel, PanelBody} from 'sentry/components/panels';
  7. import {ALL_ACCESS_PROJECTS} from 'sentry/constants/pageFilters';
  8. import {t} from 'sentry/locale';
  9. import {Organization} from 'sentry/types';
  10. import {Event} from 'sentry/types/event';
  11. import DiscoverQuery from 'sentry/utils/discover/discoverQuery';
  12. import EventView from 'sentry/utils/discover/eventView';
  13. import List from './list';
  14. type Props = {
  15. event: Event;
  16. location: Location;
  17. organization: Organization;
  18. traceID?: string;
  19. };
  20. const Body = ({traceID, organization, event, location}: Props) => {
  21. if (!traceID) {
  22. return (
  23. <Panel>
  24. <PanelBody>
  25. <EmptyStateWarning small withIcon={false}>
  26. {t(
  27. 'This event has no trace context, therefore it was not possible to fetch similar issues by trace ID.'
  28. )}
  29. </EmptyStateWarning>
  30. </PanelBody>
  31. </Panel>
  32. );
  33. }
  34. const orgSlug = organization.slug;
  35. const orgFeatures = organization.features;
  36. const dateCreated = moment(event.dateCreated).valueOf() / 1000;
  37. const {start, end} = getTraceDateTimeRange({start: dateCreated, end: dateCreated});
  38. const eventView = EventView.fromSavedQuery({
  39. id: undefined,
  40. name: `Issues with Trace ID ${traceID}`,
  41. fields: ['issue.id'],
  42. orderby: '-timestamp',
  43. query: `trace:${traceID} !event.type:transaction !id:${event.id} `,
  44. projects: orgFeatures.includes('global-views')
  45. ? [ALL_ACCESS_PROJECTS]
  46. : [Number(event.projectID)],
  47. version: 2,
  48. start,
  49. end,
  50. });
  51. return (
  52. <DiscoverQuery eventView={eventView} location={location} orgSlug={orgSlug} limit={5}>
  53. {data => {
  54. if (data.isLoading) {
  55. return <LoadingIndicator />;
  56. }
  57. const issues = data?.tableData?.data || [];
  58. return (
  59. <List
  60. issues={issues}
  61. pageLinks={data.pageLinks}
  62. traceID={traceID}
  63. orgSlug={orgSlug}
  64. location={location}
  65. period={{start, end}}
  66. />
  67. );
  68. }}
  69. </DiscoverQuery>
  70. );
  71. };
  72. export default Body;