useLogReplayDataLoaded.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import {useEffect} from 'react';
  2. import {trackAnalytics} from 'sentry/utils/analytics';
  3. import type useReplayReader from 'sentry/utils/replays/hooks/useReplayReader';
  4. import useOrganization from 'sentry/utils/useOrganization';
  5. import useProjectFromSlug from 'sentry/utils/useProjectFromSlug';
  6. interface Props
  7. extends Pick<
  8. ReturnType<typeof useReplayReader>,
  9. 'fetchError' | 'fetching' | 'projectSlug' | 'replay'
  10. > {}
  11. function useLogReplayDataLoaded({fetchError, fetching, projectSlug, replay}: Props) {
  12. const organization = useOrganization();
  13. const project = useProjectFromSlug({
  14. organization,
  15. projectSlug: projectSlug ?? undefined,
  16. });
  17. useEffect(() => {
  18. if (fetching || fetchError || !replay || !project) {
  19. return;
  20. }
  21. const feErrorIds = replay.getReplay().error_ids || [];
  22. const allErrors = replay.getRawErrors();
  23. const beErrorCount = allErrors.filter(error => !feErrorIds.includes(error.id)).length;
  24. trackAnalytics('replay.details-data-loaded', {
  25. organization,
  26. be_errors: beErrorCount,
  27. fe_errors: feErrorIds.length,
  28. project_platform: project.platform!,
  29. replay_errors: 0,
  30. total_errors: allErrors.length,
  31. started_at_delta: replay.timestampDeltas.startedAtDelta,
  32. finished_at_delta: replay.timestampDeltas.finishedAtDelta,
  33. replay_id: replay.getReplay().id,
  34. });
  35. }, [organization, project, fetchError, fetching, projectSlug, replay]);
  36. }
  37. export default useLogReplayDataLoaded;