guards.tsx 2.7 KB

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