spanDescription.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import styled from '@emotion/styled';
  2. import Feature from 'sentry/components/acl/feature';
  3. import {CodeSnippet} from 'sentry/components/codeSnippet';
  4. import {Project} from 'sentry/types';
  5. import {StackTraceMiniFrame} from 'sentry/views/starfish/components/stackTraceMiniFrame';
  6. import {MetricsResponse, SpanMetricsField} from 'sentry/views/starfish/types';
  7. import {SQLishFormatter} from 'sentry/views/starfish/utils/sqlish/SQLishFormatter';
  8. type Props = {
  9. span: Pick<
  10. MetricsResponse,
  11. SpanMetricsField.SPAN_OP | SpanMetricsField.SPAN_DESCRIPTION
  12. > & {
  13. data?: {
  14. 'code.filepath'?: string;
  15. 'code.function'?: string;
  16. 'code.lineno'?: number;
  17. };
  18. };
  19. project?: Project;
  20. };
  21. export function SpanDescription({span, project}: Props) {
  22. if (span[SpanMetricsField.SPAN_OP]?.startsWith('db')) {
  23. return <DatabaseSpanDescription span={span} project={project} />;
  24. }
  25. return <WordBreak>{span[SpanMetricsField.SPAN_DESCRIPTION]}</WordBreak>;
  26. }
  27. function DatabaseSpanDescription({span, project}: Props) {
  28. const formatter = new SQLishFormatter();
  29. return (
  30. <Frame>
  31. <CodeSnippet language="sql" isRounded={false}>
  32. {formatter.toString(span[SpanMetricsField.SPAN_DESCRIPTION])}
  33. </CodeSnippet>
  34. <Feature features={['organizations:performance-database-view-query-source']}>
  35. {span?.data?.['code.filepath'] && (
  36. <StackTraceMiniFrame
  37. project={project}
  38. frame={{
  39. absPath: span?.data?.['code.filepath'],
  40. lineNo: span?.data?.['code.lineno'],
  41. function: span?.data?.['code.function'],
  42. }}
  43. />
  44. )}
  45. </Feature>
  46. </Frame>
  47. );
  48. }
  49. const Frame = styled('div')`
  50. border: solid 1px ${p => p.theme.border};
  51. border-radius: ${p => p.theme.borderRadius};
  52. overflow: hidden;
  53. `;
  54. const WordBreak = styled('div')`
  55. word-break: break-word;
  56. `;