rootSpanStatus.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import {Component} from 'react';
  2. import styled from '@emotion/styled';
  3. import {SectionHeading} from 'sentry/components/charts/styles';
  4. import {TraceContextType} from 'sentry/components/events/interfaces/spans/types';
  5. import {t} from 'sentry/locale';
  6. import space from 'sentry/styles/space';
  7. import {Event, EventTransaction} from 'sentry/types/event';
  8. type Props = {
  9. event: Event;
  10. };
  11. class RootSpanStatus extends Component<Props> {
  12. getTransactionEvent(): EventTransaction | undefined {
  13. const {event} = this.props;
  14. if (event.type === 'transaction') {
  15. return event as EventTransaction;
  16. }
  17. return undefined;
  18. }
  19. getRootSpanStatus(): string {
  20. const event = this.getTransactionEvent();
  21. const DEFAULT = '\u2014';
  22. if (!event) {
  23. return DEFAULT;
  24. }
  25. const traceContext: TraceContextType | undefined = event?.contexts?.trace;
  26. return traceContext?.status ?? DEFAULT;
  27. }
  28. getHttpStatusCode(): string {
  29. const {event} = this.props;
  30. const {tags} = event;
  31. if (!Array.isArray(tags)) {
  32. return '';
  33. }
  34. const tag = tags.find(tagObject => tagObject.key === 'http.status_code');
  35. if (!tag) {
  36. return '';
  37. }
  38. return tag.value;
  39. }
  40. render() {
  41. const event = this.getTransactionEvent();
  42. if (!event) {
  43. return null;
  44. }
  45. const label = `${this.getHttpStatusCode()} ${this.getRootSpanStatus()}`.trim();
  46. return (
  47. <Container>
  48. <Header>
  49. <SectionHeading>{t('Status')}</SectionHeading>
  50. </Header>
  51. <div>{label}</div>
  52. </Container>
  53. );
  54. }
  55. }
  56. const Container = styled('div')`
  57. color: ${p => p.theme.subText};
  58. font-size: ${p => p.theme.fontSizeMedium};
  59. margin-bottom: ${space(4)};
  60. `;
  61. const Header = styled('div')`
  62. display: flex;
  63. align-items: center;
  64. `;
  65. export default RootSpanStatus;