TraceDetailsRouting.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import type {LocationDescriptorObject} from 'history';
  2. import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse';
  3. import {getEventTimestamp} from 'sentry/components/quickTrace/utils';
  4. import type {Event} from 'sentry/types/event';
  5. import {browserHistory} from 'sentry/utils/browserHistory';
  6. import {useLocation} from 'sentry/utils/useLocation';
  7. import useOrganization from 'sentry/utils/useOrganization';
  8. import {getTraceDetailsUrl} from './utils';
  9. type Props = {
  10. children: JSX.Element;
  11. event: Event;
  12. };
  13. function TraceDetailsRouting(props: Props) {
  14. const {event, children} = props;
  15. const organization = useOrganization();
  16. const location = useLocation();
  17. const datetimeSelection = normalizeDateTimeParams(location.query);
  18. const traceId = event.contexts?.trace?.trace_id ?? '';
  19. if (location.query?.legacy) {
  20. return children;
  21. }
  22. if (organization.features.includes('trace-view-v1')) {
  23. if (event?.groupID && event?.eventID) {
  24. const issuesLocation = `/organizations/${organization.slug}/issues/${event.groupID}/events/${event.eventID}`;
  25. browserHistory.replace({
  26. pathname: issuesLocation,
  27. });
  28. } else {
  29. const traceDetailsLocation: LocationDescriptorObject = getTraceDetailsUrl({
  30. organization,
  31. traceSlug: traceId,
  32. dateSelection: datetimeSelection,
  33. timestamp: getEventTimestamp(event),
  34. eventId: event.eventID,
  35. location,
  36. });
  37. const query = {...traceDetailsLocation.query};
  38. if (location.hash.includes('span')) {
  39. const spanHashValue = location.hash
  40. .split('#')
  41. .filter(value => value.includes('span'))[0];
  42. const spanId = spanHashValue.split('-')[1];
  43. if (spanId) {
  44. query.node = [`span-${spanId}`, `txn-${event.eventID}`];
  45. }
  46. }
  47. browserHistory.replace({
  48. pathname: traceDetailsLocation.pathname,
  49. query,
  50. });
  51. }
  52. }
  53. return children;
  54. }
  55. export default TraceDetailsRouting;