123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- import {useCallback, useMemo} from 'react';
- import type {WithRouterProps} from 'react-router';
- import type {Location} from 'history';
- import {updateProjects} from 'sentry/actionCreators/pageFilters';
- import {Alert} from 'sentry/components/alert';
- import ExternalLink from 'sentry/components/links/externalLink';
- import Link from 'sentry/components/links/link';
- import {SidebarPanelKey} from 'sentry/components/sidebar/types';
- import {t, tct} from 'sentry/locale';
- import SidebarPanelStore from 'sentry/stores/sidebarPanelStore';
- import type {Organization} from 'sentry/types/organization';
- import type {Project} from 'sentry/types/project';
- import type EventView from 'sentry/utils/discover/eventView';
- import type {MetricDataSwitcherOutcome} from 'sentry/utils/performance/contexts/metricsCardinality';
- import type {DiscoverQueryPageSource} from '../utils';
- import {
- createUnnamedTransactionsDiscoverTarget,
- getIsMultiProject,
- getSelectedProjectPlatformsArray,
- } from '../utils';
- interface MetricEnhancedDataAlertProps extends MetricDataSwitcherOutcome {
- eventView: EventView;
- location: Location;
- organization: Organization;
- projects: Project[];
- router: WithRouterProps['router'];
- source?: DiscoverQueryPageSource;
- }
- /**
- * From
- * https://github.com/getsentry/sentry-docs/blob/master/src/platforms/common/enriching-events/transaction-name.mdx
- */
- const SUPPORTED_TRANSACTION_NAME_DOCS = [
- 'javascript',
- 'node',
- 'python',
- 'ruby',
- 'native',
- 'react-native',
- 'dotnet',
- 'unity',
- 'flutter',
- 'dart',
- 'java',
- 'android',
- ];
- const UNSUPPORTED_TRANSACTION_NAME_DOCS = [
- 'javascript.cordova',
- 'javascript.nextjs',
- 'native.minidumps',
- ];
- export function MetricsDataSwitcherAlert(
- props: MetricEnhancedDataAlertProps
- ): React.ReactElement | null {
- const isOnFallbackThresolds = props.organization.features.includes(
- 'performance-mep-bannerless-ui'
- );
- const handleReviewUpdatesClick = useCallback(() => {
- SidebarPanelStore.activatePanel(SidebarPanelKey.BROADCASTS);
- }, []);
- const docsLink = useMemo(() => {
- const platforms = getSelectedProjectPlatformsArray(props.location, props.projects);
- if (platforms.length < 1) {
- return null;
- }
- const platform = platforms[0];
- if (UNSUPPORTED_TRANSACTION_NAME_DOCS.includes(platform)) {
- return null;
- }
- const supportedPlatform = SUPPORTED_TRANSACTION_NAME_DOCS.find(platformBase =>
- platform.includes(platformBase)
- );
- if (!supportedPlatform) {
- return null;
- }
- return `https://docs.sentry.io/platforms/${supportedPlatform}/enriching-events/transaction-name/`;
- }, [props.location, props.projects]);
- const handleSwitchToCompatibleProjects = useCallback(() => {
- updateProjects(props.compatibleProjects || [], props.router);
- }, [props.compatibleProjects, props.router]);
- if (!props.shouldNotifyUnnamedTransactions && !props.shouldWarnIncompatibleSDK) {
- // Control showing generic sdk-alert here since stacking alerts is noisy.
- return null;
- }
- const discoverTarget = createUnnamedTransactionsDiscoverTarget(props);
- if (isOnFallbackThresolds) {
- return null;
- }
- if (props.shouldWarnIncompatibleSDK) {
- const updateSDK = (
- <Link to="" onClick={handleReviewUpdatesClick}>
- {t('update your SDK version')}
- </Link>
- );
- if (getIsMultiProject(props.eventView.project)) {
- if ((props.compatibleProjects ?? []).length === 0) {
- return (
- <Alert
- type="warning"
- showIcon
- data-test-id="landing-mep-alert-multi-project-all-incompatible"
- >
- {tct(
- `A few projects are incompatible with dynamic sampling. To enable this feature [updateSDK].`,
- {
- updateSDK,
- }
- )}
- </Alert>
- );
- }
- return (
- <Alert
- type="warning"
- showIcon
- data-test-id="landing-mep-alert-multi-project-incompatible"
- >
- {tct(
- `A few projects are incompatible with dynamic sampling. You can either [updateSDK] or [onlyViewCompatible]`,
- {
- updateSDK,
- onlyViewCompatible: (
- <Link to="" onClick={handleSwitchToCompatibleProjects}>
- {t('only view compatible projects.')}
- </Link>
- ),
- }
- )}
- </Alert>
- );
- }
- return (
- <Alert
- type="warning"
- showIcon
- data-test-id="landing-mep-alert-single-project-incompatible"
- >
- {tct(
- `Your project has an outdated SDK which is incompatible with dynamic sampling. To enable this feature [updateSDK].`,
- {
- updateSDK,
- }
- )}
- </Alert>
- );
- }
- if (props.shouldNotifyUnnamedTransactions) {
- const discover = <Link to={discoverTarget}>{t('open them in Discover.')}</Link>;
- if (!docsLink) {
- return (
- <Alert type="warning" showIcon data-test-id="landing-mep-alert-unnamed-discover">
- {tct(
- `You have some unparameterized transactions which are incompatible with dynamic sampling. You can [discover]`,
- {
- discover,
- }
- )}
- </Alert>
- );
- }
- return (
- <Alert
- type="warning"
- showIcon
- data-test-id="landing-mep-alert-unnamed-discover-or-set"
- >
- {tct(
- `You have some unparameterized transactions which are incompatible with dynamic sampling. You can either [setNames] or [discover]`,
- {
- setNames: (
- <ExternalLink href={docsLink}>{t('set names manually')}</ExternalLink>
- ),
- discover,
- }
- )}
- </Alert>
- );
- }
- return null;
- }
|