TraceDetailsRouting.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. traceId,
  32. datetimeSelection,
  33. getEventTimestamp(event),
  34. event.eventID
  35. );
  36. const query = {...traceDetailsLocation.query};
  37. if (location.hash.includes('span')) {
  38. const spanHashValue = location.hash
  39. .split('#')
  40. .filter(value => value.includes('span'))[0];
  41. const spanId = spanHashValue.split('-')[1];
  42. if (spanId) {
  43. query.node = [`span-${spanId}`, `txn-${event.eventID}`];
  44. }
  45. }
  46. browserHistory.replace({
  47. pathname: traceDetailsLocation.pathname,
  48. query,
  49. });
  50. }
  51. }
  52. return children;
  53. }
  54. export default TraceDetailsRouting;