guards.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. }
  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. }