guards.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {
  2. ParentAutogroupNode,
  3. SiblingAutogroupNode,
  4. type TraceTree,
  5. type TraceTreeNode,
  6. } from './traceTree';
  7. export function isMissingInstrumentationNode(
  8. node: TraceTreeNode<TraceTree.NodeValue>
  9. ): node is TraceTreeNode<TraceTree.MissingInstrumentationSpan> {
  10. return !!(
  11. node.value &&
  12. 'type' in node.value &&
  13. node.value.type === 'missing_instrumentation'
  14. );
  15. }
  16. export function isSpanNode(
  17. node: TraceTreeNode<TraceTree.NodeValue>
  18. ): node is TraceTreeNode<TraceTree.Span> {
  19. return (
  20. !!(node.value && !('transaction' in node.value) && 'span_id' in node.value) &&
  21. !('autogrouped_by' in node.value)
  22. );
  23. }
  24. export function isTransactionNode(
  25. node: TraceTreeNode<TraceTree.NodeValue>
  26. ): node is TraceTreeNode<TraceTree.Transaction> {
  27. return !!(node.value && 'transaction' in node.value);
  28. }
  29. export function isParentAutogroupedNode(
  30. node: TraceTreeNode<TraceTree.NodeValue>
  31. ): node is ParentAutogroupNode {
  32. return node instanceof ParentAutogroupNode;
  33. }
  34. export function isSiblingAutogroupedNode(
  35. node: TraceTreeNode<TraceTree.NodeValue>
  36. ): node is SiblingAutogroupNode {
  37. return node instanceof SiblingAutogroupNode;
  38. }
  39. export function isAutogroupedNode(
  40. node: TraceTreeNode<TraceTree.NodeValue>
  41. ): node is ParentAutogroupNode | SiblingAutogroupNode {
  42. return !!(node.value && 'autogrouped_by' in node.value);
  43. }
  44. export function isTraceErrorNode(
  45. node: TraceTreeNode<TraceTree.NodeValue>
  46. ): node is TraceTreeNode<TraceTree.TraceError> {
  47. return !!(node.value && 'level' in node.value);
  48. }
  49. export function isRootNode(
  50. node: TraceTreeNode<TraceTree.NodeValue>
  51. ): node is TraceTreeNode<null> {
  52. return !!(node.value && node.value === null);
  53. }
  54. export function isTraceNode(
  55. node: TraceTreeNode<TraceTree.NodeValue>
  56. ): node is TraceTreeNode<TraceTree.Trace> {
  57. return !!(node.value && 'orphan_errors' in node.value);
  58. }