spanDescription.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import styled from '@emotion/styled';
  2. import {FormattedCode} from 'sentry/views/starfish/components/formattedCode';
  3. import {SpanMetricsFields} from 'sentry/views/starfish/types';
  4. import {highlightSql} from 'sentry/views/starfish/utils/highlightSql';
  5. const {SPAN_DESCRIPTION, SPAN_ACTION, SPAN_DOMAIN} = SpanMetricsFields;
  6. type SpanMeta = {
  7. 'span.action': string;
  8. 'span.description': string;
  9. 'span.domain': string;
  10. 'span.op': string;
  11. };
  12. export function SpanDescription({spanMeta}: {spanMeta: SpanMeta}) {
  13. if (spanMeta['span.op'].startsWith('db')) {
  14. return <DatabaseSpanDescription spanMeta={spanMeta} />;
  15. }
  16. return <DescriptionWrapper>{spanMeta[SPAN_DESCRIPTION]}</DescriptionWrapper>;
  17. }
  18. function DatabaseSpanDescription({spanMeta}: {spanMeta: SpanMeta}) {
  19. return (
  20. <CodeWrapper>
  21. <FormattedCode>
  22. {highlightSql(spanMeta[SPAN_DESCRIPTION] || '', {
  23. action: spanMeta[SPAN_ACTION] || '',
  24. domain: spanMeta[SPAN_DOMAIN] || '',
  25. })}
  26. </FormattedCode>
  27. </CodeWrapper>
  28. );
  29. }
  30. const CodeWrapper = styled('div')`
  31. font-size: ${p => p.theme.fontSizeMedium};
  32. `;
  33. const DescriptionWrapper = styled('div')`
  34. word-break: break-word;
  35. `;