traceIcons.tsx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import {Fragment, useMemo} from 'react';
  2. import clamp from 'lodash/clamp';
  3. import {TraceIcons} from '../traceIcons';
  4. import type {TraceTree} from '../traceModels/traceTree';
  5. import type {TraceTreeNode} from '../traceModels/traceTreeNode';
  6. import type {VirtualizedViewManager} from '../traceRenderers/virtualizedViewManager';
  7. interface ErrorIconsProps {
  8. errors: TraceTreeNode<TraceTree.Transaction>['errors'];
  9. manager: VirtualizedViewManager;
  10. node_space: [number, number] | null;
  11. }
  12. export function TraceErrorIcons(props: ErrorIconsProps) {
  13. const errors = useMemo(() => {
  14. return [...props.errors];
  15. }, [props.errors]);
  16. if (!props.errors.size) {
  17. return null;
  18. }
  19. return (
  20. <Fragment>
  21. {errors.map((error, i) => {
  22. const timestamp = error.timestamp ? error.timestamp * 1e3 : props.node_space![0];
  23. // Clamp the error timestamp to the span's timestamp
  24. const left = props.manager.computeRelativeLeftPositionFromOrigin(
  25. clamp(
  26. timestamp,
  27. props.node_space![0],
  28. props.node_space![0] + props.node_space![1]
  29. ),
  30. props.node_space!
  31. );
  32. return (
  33. <div
  34. key={i}
  35. className={`TraceIcon ${error.level}`}
  36. style={{left: left * 100 + '%'}}
  37. >
  38. <TraceIcons.Icon event={error} />
  39. </div>
  40. );
  41. })}
  42. </Fragment>
  43. );
  44. }
  45. interface TracePerformanceIssueIconsProps {
  46. manager: VirtualizedViewManager;
  47. node_space: [number, number] | null;
  48. performance_issues: TraceTreeNode<TraceTree.Transaction>['performance_issues'];
  49. }
  50. export function TracePerformanceIssueIcons(props: TracePerformanceIssueIconsProps) {
  51. const performance_issues = useMemo(() => {
  52. return [...props.performance_issues];
  53. }, [props.performance_issues]);
  54. if (!props.performance_issues.size) {
  55. return null;
  56. }
  57. return (
  58. <Fragment>
  59. {performance_issues.map((issue, i) => {
  60. const timestamp = issue.timestamp
  61. ? issue.timestamp * 1e3
  62. : issue.start
  63. ? issue.start * 1e3
  64. : props.node_space![0];
  65. // Clamp the issue timestamp to the span's timestamp
  66. const left = props.manager.computeRelativeLeftPositionFromOrigin(
  67. clamp(
  68. timestamp,
  69. props.node_space![0],
  70. props.node_space![0] + props.node_space![1]
  71. ),
  72. props.node_space!
  73. );
  74. return (
  75. <div
  76. key={i}
  77. className={`TraceIcon performance_issue`}
  78. style={{left: left * 100 + '%'}}
  79. >
  80. <TraceIcons.Icon event={issue} />
  81. </div>
  82. );
  83. })}
  84. </Fragment>
  85. );
  86. }