spanSummaryButton.tsx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import {LinkButton} from 'sentry/components/button';
  2. import type {SpanType} from 'sentry/components/events/interfaces/spans/types';
  3. import {t, tct} from 'sentry/locale';
  4. import type {EventTransaction, Organization} from 'sentry/types';
  5. import {trackAnalytics} from 'sentry/utils/analytics';
  6. import {useLocation} from 'sentry/utils/useLocation';
  7. import {DATA_TYPE} from 'sentry/views/insights/browser/resources/settings';
  8. import {resolveSpanModule} from 'sentry/views/insights/common/utils/resolveSpanModule';
  9. import {useModuleURL} from 'sentry/views/insights/common/utils/useModuleURL';
  10. import {ModuleName} from 'sentry/views/insights/types';
  11. import {
  12. querySummaryRouteWithQuery,
  13. resourceSummaryRouteWithQuery,
  14. } from 'sentry/views/performance/transactionSummary/transactionSpans/spanDetails/utils';
  15. interface Props {
  16. event: Readonly<EventTransaction>;
  17. organization: Organization;
  18. span: SpanType;
  19. }
  20. function SpanSummaryButton(props: Props) {
  21. const location = useLocation();
  22. const resourceBaseUrl = useModuleURL(ModuleName.RESOURCE);
  23. const {event, organization, span} = props;
  24. const sentryTags = span.sentry_tags;
  25. if (!sentryTags || !sentryTags.group) {
  26. return null;
  27. }
  28. const resolvedModule = resolveSpanModule(sentryTags.op, sentryTags.category);
  29. if (
  30. organization.features.includes('insights-initial-modules') &&
  31. resolvedModule === ModuleName.DB
  32. ) {
  33. return (
  34. <LinkButton
  35. size="xs"
  36. to={querySummaryRouteWithQuery({
  37. orgSlug: organization.slug,
  38. query: location.query,
  39. group: sentryTags.group,
  40. projectID: event.projectID,
  41. })}
  42. onClick={() => {
  43. trackAnalytics('trace.trace_layout.view_in_insight_module', {
  44. organization,
  45. module: ModuleName.DB,
  46. });
  47. }}
  48. >
  49. {t('View Query Summary')}
  50. </LinkButton>
  51. );
  52. }
  53. if (
  54. organization.features.includes('insights-initial-modules') &&
  55. resolvedModule === ModuleName.RESOURCE &&
  56. resourceSummaryAvailable(sentryTags.op)
  57. ) {
  58. return (
  59. <LinkButton
  60. size="xs"
  61. to={resourceSummaryRouteWithQuery({
  62. baseUrl: resourceBaseUrl,
  63. query: location.query,
  64. group: sentryTags.group,
  65. projectID: event.projectID,
  66. })}
  67. onClick={() => {
  68. trackAnalytics('trace.trace_layout.view_in_insight_module', {
  69. organization,
  70. module: ModuleName.RESOURCE,
  71. });
  72. }}
  73. >
  74. {tct('View [dataType] Summary', {dataType: DATA_TYPE})}
  75. </LinkButton>
  76. );
  77. }
  78. return null;
  79. }
  80. const resourceSummaryAvailable = (op: string = '') =>
  81. ['resource.script', 'resource.css'].includes(op);
  82. export default SpanSummaryButton;