profileView.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import {Fragment, useState} from 'react';
  2. import {SpanProfileDetails} from 'sentry/components/events/interfaces/spans/spanProfileDetails';
  3. import {RawSpanType} from 'sentry/components/events/interfaces/spans/types';
  4. import LoadingIndicator from 'sentry/components/loadingIndicator';
  5. import useOrganization from 'sentry/utils/useOrganization';
  6. import {ProfileGroupProvider} from 'sentry/views/profiling/profileGroupProvider';
  7. import {ProfileContext, ProfilesProvider} from 'sentry/views/profiling/profilesProvider';
  8. import {
  9. useQueryGetEvent,
  10. useQueryGetProfileIds,
  11. } from 'sentry/views/starfish/modules/databaseModule/queries';
  12. type Props = {
  13. spanHash: string;
  14. transactionNames: string[];
  15. };
  16. export function ProfileView(props: Props) {
  17. const {spanHash, transactionNames} = props;
  18. const organization = useOrganization();
  19. const [transactionIdx, setTransactionIdx] = useState<number>(0);
  20. const result = useQueryGetProfileIds(transactionNames);
  21. const transactionIds = result?.data?.data?.map(d => d.id) ?? [];
  22. const eventResult = useQueryGetEvent(transactionIds[transactionIdx]);
  23. const isLoading = result.isLoading || eventResult.isLoading || eventResult.isRefetching;
  24. if (isLoading) {
  25. return <LoadingIndicator />;
  26. }
  27. const handleNoProfileFound = () => {
  28. setTransactionIdx(transactionIdx + 1);
  29. };
  30. if (eventResult.data.id && transactionIdx < transactionIds.length) {
  31. const event = eventResult.data;
  32. const spans = event.entries[0].data as RawSpanType[];
  33. const currentSpan = spans.find(s => s.hash === spanHash);
  34. const profileId = event.contexts?.profile?.profile_id ?? undefined;
  35. if (currentSpan && profileId) {
  36. return (
  37. <ProfilesProvider
  38. orgSlug={organization.slug}
  39. profileId={profileId}
  40. projectSlug="sentry" // TODO - don't harcode this
  41. >
  42. <ProfileContext.Consumer>
  43. {profiles => (
  44. <ProfileGroupProvider
  45. type="flamechart"
  46. input={profiles?.type === 'resolved' ? profiles.data : null}
  47. traceID={profileId || ''}
  48. >
  49. <SpanProfileDetails
  50. onNoProfileFound={handleNoProfileFound}
  51. event={event}
  52. span={currentSpan}
  53. />
  54. </ProfileGroupProvider>
  55. )}
  56. </ProfileContext.Consumer>
  57. </ProfilesProvider>
  58. );
  59. }
  60. handleNoProfileFound();
  61. }
  62. return <Fragment>'No profile found'</Fragment>;
  63. }
  64. export default ProfileView;