eventContext.tsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import {Fragment, useEffect} from 'react';
  2. import styled from '@emotion/styled';
  3. import {Location} from 'history';
  4. import {
  5. getStacktrace,
  6. StackTracePreviewContent,
  7. } from 'sentry/components/groupPreviewTooltip/stackTracePreview';
  8. import {t} from 'sentry/locale';
  9. import {space} from 'sentry/styles/space';
  10. import {Event, Project} from 'sentry/types';
  11. import {trackAnalytics} from 'sentry/utils/analytics';
  12. import EventView from 'sentry/utils/discover/eventView';
  13. import {getDuration} from 'sentry/utils/formatters';
  14. import {useApiQuery} from 'sentry/utils/queryClient';
  15. import {
  16. getStatusBodyText,
  17. HttpStatus,
  18. } from 'sentry/views/performance/transactionDetails/eventMetas';
  19. import ActionDropDown, {ContextValueType} from './actionDropdown';
  20. import {NoContext} from './quickContextWrapper';
  21. import {
  22. ContextBody,
  23. ContextContainer,
  24. ContextHeader,
  25. ContextRow,
  26. ContextTitle,
  27. NoContextWrapper,
  28. Wrapper,
  29. } from './styles';
  30. import {BaseContextProps, ContextType, tenSecondInMs} from './utils';
  31. interface EventContextProps extends BaseContextProps {
  32. eventView?: EventView;
  33. location?: Location;
  34. projects?: Project[];
  35. }
  36. function EventContext(props: EventContextProps) {
  37. const {organization, dataRow, eventView, location} = props;
  38. const {isLoading, isError, data} = useApiQuery<Event>(
  39. [
  40. `/organizations/${organization.slug}/events/${dataRow['project.name']}:${dataRow.id}/`,
  41. ],
  42. {
  43. staleTime: tenSecondInMs,
  44. }
  45. );
  46. useEffect(() => {
  47. if (data) {
  48. trackAnalytics('discover_v2.quick_context_hover_contexts', {
  49. organization,
  50. contextType: ContextType.EVENT,
  51. eventType: data.type,
  52. });
  53. }
  54. }, [data, organization]);
  55. if (isLoading || isError) {
  56. return <NoContext isLoading={isLoading} />;
  57. }
  58. if (data.type === 'transaction') {
  59. const transactionDuration = getDuration(
  60. data.endTimestamp - data.startTimestamp,
  61. 2,
  62. true
  63. );
  64. const status = getStatusBodyText(data);
  65. return (
  66. <Wrapper data-test-id="quick-context-hover-body">
  67. <EventContextContainer>
  68. <ContextHeader>
  69. <ContextTitle>{t('Transaction Duration')}</ContextTitle>
  70. {location && eventView && (
  71. <ActionDropDown
  72. dataRow={dataRow}
  73. contextValueType={ContextValueType.DURATION}
  74. location={location}
  75. eventView={eventView}
  76. organization={organization}
  77. queryKey="transaction.duration"
  78. value={transactionDuration}
  79. />
  80. )}
  81. </ContextHeader>
  82. <EventContextBody>{transactionDuration}</EventContextBody>
  83. </EventContextContainer>
  84. {location && (
  85. <EventContextContainer>
  86. <Fragment>
  87. <ContextHeader>
  88. <ContextTitle>{t('Status')}</ContextTitle>
  89. {location && eventView && (
  90. <ActionDropDown
  91. dataRow={dataRow}
  92. contextValueType={ContextValueType.STRING}
  93. location={location}
  94. eventView={eventView}
  95. organization={organization}
  96. queryKey="transaction.status"
  97. value={status}
  98. />
  99. )}
  100. </ContextHeader>
  101. <EventContextBody>
  102. <ContextRow>
  103. {status}
  104. <HttpStatusWrapper>
  105. (<HttpStatus event={data} />)
  106. </HttpStatusWrapper>
  107. </ContextRow>
  108. </EventContextBody>
  109. </Fragment>
  110. </EventContextContainer>
  111. )}
  112. </Wrapper>
  113. );
  114. }
  115. const stackTrace = getStacktrace(data);
  116. return stackTrace ? (
  117. <Fragment>
  118. {!dataRow.title && (
  119. <ErrorTitleContainer>
  120. <ContextHeader>
  121. <ContextTitle>{t('Title')}</ContextTitle>
  122. {location && eventView && (
  123. <ActionDropDown
  124. dataRow={dataRow}
  125. contextValueType={ContextValueType.STRING}
  126. location={location}
  127. eventView={eventView}
  128. organization={organization}
  129. queryKey="title"
  130. value={data.title}
  131. />
  132. )}
  133. </ContextHeader>
  134. <ErrorTitleBody>{data.title}</ErrorTitleBody>
  135. </ErrorTitleContainer>
  136. )}
  137. <StackTraceWrapper>
  138. <StackTracePreviewContent event={data} stacktrace={stackTrace} />
  139. </StackTraceWrapper>
  140. </Fragment>
  141. ) : (
  142. <NoContextWrapper>
  143. {t('There is no stack trace available for this event.')}
  144. </NoContextWrapper>
  145. );
  146. }
  147. const ErrorTitleContainer = styled(ContextContainer)`
  148. padding: ${space(1.5)};
  149. `;
  150. const ErrorTitleBody = styled(ContextBody)`
  151. margin: 0;
  152. max-width: 450px;
  153. ${p => p.theme.overflowEllipsis}
  154. `;
  155. const EventContextBody = styled(ContextBody)`
  156. font-size: ${p => p.theme.fontSizeExtraLarge};
  157. margin: 0;
  158. align-items: flex-start;
  159. flex-direction: column;
  160. `;
  161. const EventContextContainer = styled(ContextContainer)`
  162. & + & {
  163. margin-top: ${space(2)};
  164. }
  165. `;
  166. const StackTraceWrapper = styled('div')`
  167. overflow: hidden;
  168. max-height: 300px;
  169. width: 500px;
  170. overflow-y: auto;
  171. .traceback {
  172. margin-bottom: 0;
  173. border: 0;
  174. }
  175. border-radius: ${p => p.theme.borderRadius};
  176. `;
  177. const HttpStatusWrapper = styled('span')`
  178. margin-left: ${space(0.5)};
  179. `;
  180. export default EventContext;