traceAnalytics.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import * as Sentry from '@sentry/react';
  2. import type {Organization} from 'sentry/types/organization';
  3. import type {Project} from 'sentry/types/project';
  4. import {trackAnalytics} from 'sentry/utils/analytics';
  5. import type {TraceTree} from 'sentry/views/performance/newTraceDetails/traceModels/traceTree';
  6. import type {TraceType} from 'sentry/views/performance/newTraceDetails/traceType';
  7. const trackTraceMetadata = (
  8. tree: TraceTree,
  9. projects: Project[],
  10. organization: Organization
  11. ) => {
  12. Sentry.metrics.increment(`trace.trace_shape.${tree.shape}`);
  13. // space[1] represents the node duration (in milliseconds)
  14. const trace_duration_seconds = (tree.root.space?.[1] ?? 0) / 1000;
  15. const projectSlugs = [
  16. ...new Set(
  17. tree.list.map(node => node.metadata.project_slug).filter(slug => slug !== undefined)
  18. ),
  19. ];
  20. const projectPlatforms = projects
  21. .filter(p => projectSlugs.includes(p.slug))
  22. .map(project => project?.platform ?? '');
  23. trackAnalytics('trace.metadata', {
  24. shape: tree.shape,
  25. // round trace_duration_seconds to nearest two decimal places
  26. trace_duration_seconds: Math.round(trace_duration_seconds * 100) / 100,
  27. num_root_children: tree.root.children.length,
  28. num_nodes: tree.list.length,
  29. project_platforms: projectPlatforms,
  30. organization,
  31. });
  32. };
  33. const trackFailedToFetchTraceState = () =>
  34. Sentry.metrics.increment('trace.failed_to_fetch_trace');
  35. const trackEmptyTraceState = () => Sentry.metrics.increment('trace.empty_trace');
  36. const trackLayoutChange = (layout: string, organization: Organization) =>
  37. trackAnalytics('trace.trace_layout.change', {
  38. layout,
  39. organization,
  40. });
  41. const trackDrawerMinimize = (organization: Organization) =>
  42. trackAnalytics('trace.trace_layout.drawer_minimize', {
  43. organization,
  44. });
  45. const trackShowInView = (organization: Organization) =>
  46. trackAnalytics('trace.trace_layout.show_in_view', {
  47. organization,
  48. });
  49. const trackViewEventJSON = (organization: Organization) =>
  50. trackAnalytics('trace.trace_layout.view_event_json', {
  51. organization,
  52. });
  53. const trackViewContinuousProfile = (organization: Organization) =>
  54. trackAnalytics('trace.trace_layout.view_continuous_profile', {
  55. organization,
  56. });
  57. const trackTabPin = (organization: Organization) =>
  58. trackAnalytics('trace.trace_layout.tab_pin', {
  59. organization,
  60. });
  61. const trackTabView = (tab: string, organization: Organization) =>
  62. trackAnalytics('trace.trace_layout.tab_view', {
  63. organization,
  64. tab,
  65. });
  66. const trackSearchFocus = (organization: Organization) =>
  67. trackAnalytics('trace.trace_layout.search_focus', {
  68. organization,
  69. });
  70. const trackResetZoom = (organization: Organization) =>
  71. trackAnalytics('trace.trace_layout.reset_zoom', {
  72. organization,
  73. });
  74. const trackPerformanceSetupChecklistTriggered = (organization: Organization) =>
  75. trackAnalytics('trace.quality.performance_setup.checklist_triggered', {
  76. organization,
  77. });
  78. const trackPerformanceSetupBannerLoaded = (organization: Organization) =>
  79. trackAnalytics('trace.quality.performance_setup.banner_loaded', {
  80. organization,
  81. });
  82. const trackQuotaExceededIncreaseBudgetClicked = (
  83. organization: Organization,
  84. traceType: string
  85. ) =>
  86. trackAnalytics('trace.quality.quota_exceeded.increase_budget_clicked', {
  87. organization,
  88. traceType,
  89. });
  90. const trackQuotaExceededLearnMoreClicked = (
  91. organization: Organization,
  92. traceType: string
  93. ) =>
  94. trackAnalytics('trace.quality.quota_exceeded.learn_more_clicked', {
  95. organization,
  96. traceType,
  97. });
  98. const trackQuotaExceededBannerLoaded = (organization: Organization, traceType: string) =>
  99. trackAnalytics('trace.quality.quota_exceeded.banner_loaded', {
  100. organization,
  101. traceType,
  102. });
  103. const trackPerformanceSetupLearnMoreClicked = (organization: Organization) =>
  104. trackAnalytics('trace.quality.performance_setup.learn_more_clicked', {
  105. organization,
  106. });
  107. const trackViewShortcuts = (organization: Organization) =>
  108. trackAnalytics('trace.trace_layout.view_shortcuts', {
  109. organization,
  110. });
  111. const trackTraceWarningType = (type: TraceType, organization: Organization) =>
  112. trackAnalytics('trace.trace_warning_type', {
  113. organization,
  114. type,
  115. });
  116. const trackTraceConfigurationsDocsClicked = (organization: Organization, title: string) =>
  117. trackAnalytics('trace.configurations_docs_link_clicked', {
  118. organization,
  119. title,
  120. });
  121. const traceAnalytics = {
  122. // Trace shape
  123. trackTraceMetadata,
  124. trackEmptyTraceState,
  125. trackFailedToFetchTraceState,
  126. // Drawer actions
  127. trackShowInView,
  128. trackViewEventJSON,
  129. trackViewContinuousProfile,
  130. // Layout actions
  131. trackLayoutChange,
  132. trackDrawerMinimize,
  133. trackSearchFocus,
  134. trackTabPin,
  135. trackTabView,
  136. // Toolbar actions
  137. trackResetZoom,
  138. trackViewShortcuts,
  139. trackTraceWarningType,
  140. // Trace Quality Improvement
  141. trackPerformanceSetupChecklistTriggered,
  142. trackPerformanceSetupLearnMoreClicked,
  143. trackPerformanceSetupBannerLoaded,
  144. trackQuotaExceededIncreaseBudgetClicked,
  145. trackQuotaExceededLearnMoreClicked,
  146. trackQuotaExceededBannerLoaded,
  147. trackTraceConfigurationsDocsClicked,
  148. };
  149. export {traceAnalytics};