guards.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import {
  2. MissingInstrumentationNode,
  3. ParentAutogroupNode,
  4. SiblingAutogroupNode,
  5. type TraceTree,
  6. type TraceTreeNode,
  7. } from './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. !('autogrouped_by' in node.value)
  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);
  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.value && 'autogrouped_by' in node.value);
  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.astro':
  76. return false;
  77. case undefined:
  78. return true;
  79. default:
  80. return true;
  81. }
  82. }