traceTreeAnalytics.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import type {TracingEventParameters} from 'sentry/utils/analytics/tracingEventMap';
  2. import type {TraceTree} from './traceModels/traceTree';
  3. import type {TraceTreeNode} from './traceModels/traceTreeNode';
  4. import {
  5. isAutogroupedNode,
  6. isMissingInstrumentationNode,
  7. isParentAutogroupedNode,
  8. isRootNode,
  9. isSpanNode,
  10. isTraceErrorNode,
  11. isTraceNode,
  12. isTransactionNode,
  13. } from './traceGuards';
  14. // Name of node for analytics purposes
  15. export function traceNodeAnalyticsName(node: TraceTreeNode<TraceTree.NodeValue>): string {
  16. if (isAutogroupedNode(node)) {
  17. return isParentAutogroupedNode(node) ? 'parent autogroup' : 'sibling autogroup';
  18. }
  19. if (isSpanNode(node)) {
  20. return 'span';
  21. }
  22. if (isTransactionNode(node)) {
  23. return 'transaction';
  24. }
  25. if (isMissingInstrumentationNode(node)) {
  26. return 'missing instrumentation';
  27. }
  28. if (isRootNode(node)) {
  29. return 'root';
  30. }
  31. if (isTraceNode(node)) {
  32. return 'trace';
  33. }
  34. if (isTraceErrorNode(node)) {
  35. return 'error';
  36. }
  37. return 'unknown';
  38. }
  39. // Adds some extra properties to the node for analytics purposes
  40. export function traceNodeAdjacentAnalyticsProperties(
  41. node: TraceTreeNode<TraceTree.NodeValue>
  42. ): Pick<
  43. TracingEventParameters['trace.trace_layout.span_row_click'],
  44. 'next_op' | 'parent_op' | 'previous_op'
  45. > {
  46. if (isMissingInstrumentationNode(node)) {
  47. return {
  48. previous_op: node.previous.value.op,
  49. next_op: node.next.value.op,
  50. };
  51. }
  52. return {};
  53. }