guards.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import {
  2. MissingInstrumentationNode,
  3. NoDataNode,
  4. ParentAutogroupNode,
  5. SiblingAutogroupNode,
  6. type TraceTree,
  7. type TraceTreeNode,
  8. } from './traceModels/traceTree';
  9. export function isMissingInstrumentationNode(
  10. node: TraceTreeNode<TraceTree.NodeValue>
  11. ): node is MissingInstrumentationNode {
  12. return node instanceof MissingInstrumentationNode;
  13. }
  14. export function isSpanNode(
  15. node: TraceTreeNode<TraceTree.NodeValue>
  16. ): node is TraceTreeNode<TraceTree.Span> {
  17. return (
  18. !!(node.value && !('transaction' in node.value) && 'span_id' in node.value) &&
  19. !isAutogroupedNode(node)
  20. );
  21. }
  22. export function isTransactionNode(
  23. node: TraceTreeNode<TraceTree.NodeValue>
  24. ): node is TraceTreeNode<TraceTree.Transaction> {
  25. return !!(node.value && 'transaction' in node.value) && !isAutogroupedNode(node);
  26. }
  27. export function isParentAutogroupedNode(
  28. node: TraceTreeNode<TraceTree.NodeValue>
  29. ): node is ParentAutogroupNode {
  30. return node instanceof ParentAutogroupNode;
  31. }
  32. export function isSiblingAutogroupedNode(
  33. node: TraceTreeNode<TraceTree.NodeValue>
  34. ): node is SiblingAutogroupNode {
  35. return node instanceof SiblingAutogroupNode;
  36. }
  37. export function isAutogroupedNode(
  38. node: TraceTreeNode<TraceTree.NodeValue>
  39. ): node is ParentAutogroupNode | SiblingAutogroupNode {
  40. return node instanceof ParentAutogroupNode || node instanceof SiblingAutogroupNode;
  41. }
  42. export function isTraceErrorNode(
  43. node: TraceTreeNode<TraceTree.NodeValue>
  44. ): node is TraceTreeNode<TraceTree.TraceError> {
  45. return !!(node.value && 'level' in node.value);
  46. }
  47. export function isRootNode(
  48. node: TraceTreeNode<TraceTree.NodeValue>
  49. ): node is TraceTreeNode<null> {
  50. return node.value === null && !(node instanceof NoDataNode);
  51. }
  52. export function isTraceNode(
  53. node: TraceTreeNode<TraceTree.NodeValue>
  54. ): node is TraceTreeNode<TraceTree.Trace> {
  55. return !!(
  56. node.value &&
  57. ('orphan_errors' in node.value || 'transactions' in node.value)
  58. );
  59. }
  60. export function isNoDataNode(
  61. node: TraceTreeNode<TraceTree.NodeValue>
  62. ): node is NoDataNode {
  63. return node instanceof NoDataNode;
  64. }
  65. export function shouldAddMissingInstrumentationSpan(sdk: string | undefined): boolean {
  66. if (!sdk) return true;
  67. if (sdk.length < 'sentry.javascript.'.length) return true;
  68. switch (sdk.toLowerCase()) {
  69. case 'sentry.javascript.browser':
  70. case 'sentry.javascript.react':
  71. case 'sentry.javascript.gatsby':
  72. case 'sentry.javascript.ember':
  73. case 'sentry.javascript.vue':
  74. case 'sentry.javascript.angular':
  75. case 'sentry.javascript.angular-ivy':
  76. case 'sentry.javascript.nextjs':
  77. case 'sentry.javascript.electron':
  78. case 'sentry.javascript.remix':
  79. case 'sentry.javascript.svelte':
  80. case 'sentry.javascript.sveltekit':
  81. case 'sentry.javascript.astro':
  82. return false;
  83. case undefined:
  84. return true;
  85. default:
  86. return true;
  87. }
  88. }