resourcesAndPossibleSolutions.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import {css} from '@emotion/react';
  2. import styled from '@emotion/styled';
  3. import {AiSuggestedSolution} from 'sentry/components/events/aiSuggestedSolution';
  4. import {Autofix} from 'sentry/components/events/autofix';
  5. import {EventDataSection} from 'sentry/components/events/eventDataSection';
  6. import {Resources} from 'sentry/components/events/interfaces/performance/resources';
  7. import {t} from 'sentry/locale';
  8. import ConfigStore from 'sentry/stores/configStore';
  9. import {space} from 'sentry/styles/space';
  10. import {EntryType, type Event, type Group, type Project} from 'sentry/types';
  11. import {
  12. getConfigForIssueType,
  13. shouldShowCustomErrorResourceConfig,
  14. } from 'sentry/utils/issueTypeConfig';
  15. import {getRegionDataFromOrganization} from 'sentry/utils/regions';
  16. import useOrganization from 'sentry/utils/useOrganization';
  17. type Props = {
  18. event: Event;
  19. group: Group;
  20. project: Project;
  21. };
  22. // Autofix requires the event to have stack trace frames in order to work correctly.
  23. function hasStacktraceWithFrames(event: Event) {
  24. for (const entry of event.entries) {
  25. if (entry.type === EntryType.EXCEPTION) {
  26. if (entry.data.values?.some(value => value.stacktrace?.frames?.length)) {
  27. return true;
  28. }
  29. }
  30. if (entry.type === EntryType.THREADS) {
  31. if (entry.data.values?.some(thread => thread.stacktrace?.frames?.length)) {
  32. return true;
  33. }
  34. }
  35. }
  36. return false;
  37. }
  38. // This section provides users with resources and possible solutions on how to resolve an issue
  39. export function ResourcesAndPossibleSolutions({event, project, group}: Props) {
  40. const organization = useOrganization();
  41. const config = getConfigForIssueType(group, project);
  42. const isSelfHostedErrorsOnly = ConfigStore.get('isSelfHostedErrorsOnly');
  43. // NOTE: Autofix is for INTERNAL testing only for now.
  44. const displayAiAutofix =
  45. project.features.includes('ai-autofix') &&
  46. organization.features.includes('issue-details-autofix-ui') &&
  47. !shouldShowCustomErrorResourceConfig(group, project) &&
  48. config.autofix &&
  49. hasStacktraceWithFrames(event);
  50. const displayAiSuggestedSolution =
  51. // Skip showing AI suggested solution if the issue has a custom resource
  52. organization.aiSuggestedSolution &&
  53. getRegionDataFromOrganization(organization)?.name !== 'de' &&
  54. !shouldShowCustomErrorResourceConfig(group, project) &&
  55. !displayAiAutofix;
  56. if (
  57. isSelfHostedErrorsOnly ||
  58. (!config.resources && !(displayAiSuggestedSolution || displayAiAutofix))
  59. ) {
  60. return null;
  61. }
  62. return (
  63. <Wrapper
  64. type="resources-and-possible-solutions"
  65. title={t('Resources and Possible Solutions')}
  66. configResources={!!config.resources}
  67. >
  68. <Content>
  69. {config.resources && (
  70. <Resources
  71. eventPlatform={event.platform}
  72. groupId={group.id}
  73. configResources={config.resources}
  74. />
  75. )}
  76. {displayAiSuggestedSolution && (
  77. <AiSuggestedSolution event={event} projectSlug={project.slug} />
  78. )}
  79. {displayAiAutofix && <Autofix event={event} group={group} />}
  80. </Content>
  81. </Wrapper>
  82. );
  83. }
  84. const Content = styled('div')`
  85. display: flex;
  86. flex-direction: column;
  87. gap: ${space(2)};
  88. `;
  89. const Wrapper = styled(EventDataSection)<{configResources: boolean}>`
  90. @media (min-width: ${p => p.theme.breakpoints.xlarge}) {
  91. ${p =>
  92. !p.configResources &&
  93. css`
  94. && {
  95. padding-top: ${space(3)};
  96. }
  97. `}
  98. }
  99. `;