hydrateErrors.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import invariant from 'invariant';
  2. import isValidDate from 'sentry/utils/date/isValidDate';
  3. import type {ErrorFrame, RawReplayError} from 'sentry/utils/replays/types';
  4. import {isErrorFrame} from 'sentry/utils/replays/types';
  5. import type {ReplayRecord} from 'sentry/views/replays/types';
  6. export default function hydrateErrors(
  7. replayRecord: ReplayRecord,
  8. errors: RawReplayError[]
  9. ): ErrorFrame[] {
  10. const startTimestampMs = replayRecord.started_at.getTime();
  11. return errors
  12. .map(error => {
  13. try {
  14. const time = new Date(error.timestamp);
  15. invariant(isValidDate(time), 'errorFrame.timestamp is invalid');
  16. return {
  17. category: 'issue' as const,
  18. data: {
  19. eventId: error.id,
  20. groupId: error['issue.id'],
  21. groupShortId: error.issue,
  22. label:
  23. (Array.isArray(error['error.type'])
  24. ? error['error.type'][0]
  25. : error['error.type']) ?? '',
  26. labels: error['error.type'].filter(Boolean),
  27. projectSlug: error['project.name'],
  28. },
  29. message: error.title,
  30. offsetMs: Math.abs(time.getTime() - startTimestampMs),
  31. timestamp: time,
  32. timestampMs: time.getTime(),
  33. type: 'error', // For compatibility reasons. See BreadcrumbType
  34. };
  35. } catch {
  36. return undefined;
  37. }
  38. })
  39. .filter(isErrorFrame);
  40. }