spanDescription.tsx 923 B

12345678910111213141516171819202122232425262728293031323334
  1. import styled from '@emotion/styled';
  2. import {CodeSnippet} from 'sentry/components/codeSnippet';
  3. import {MetricsResponse, SpanMetricsField} from 'sentry/views/starfish/types';
  4. import {SQLishFormatter} from 'sentry/views/starfish/utils/sqlish/SQLishFormatter';
  5. type Props = {
  6. span: Pick<
  7. MetricsResponse,
  8. SpanMetricsField.SPAN_OP | SpanMetricsField.SPAN_DESCRIPTION
  9. >;
  10. };
  11. export function SpanDescription({span}: Props) {
  12. if (span[SpanMetricsField.SPAN_OP]?.startsWith('db')) {
  13. return <DatabaseSpanDescription span={span} />;
  14. }
  15. return <WordBreak>{span[SpanMetricsField.SPAN_DESCRIPTION]}</WordBreak>;
  16. }
  17. function DatabaseSpanDescription({span}: Props) {
  18. const formatter = new SQLishFormatter();
  19. return (
  20. <CodeSnippet language="sql">
  21. {formatter.toString(span[SpanMetricsField.SPAN_DESCRIPTION])}
  22. </CodeSnippet>
  23. );
  24. }
  25. const WordBreak = styled('div')`
  26. word-break: break-word;
  27. `;