|
@@ -0,0 +1,74 @@
|
|
|
+import {useEffect, useState} from 'react';
|
|
|
+
|
|
|
+import {Client} from 'sentry/api';
|
|
|
+import Button from 'sentry/components/button';
|
|
|
+import {t} from 'sentry/locale';
|
|
|
+import {RequestState} from 'sentry/types/core';
|
|
|
+import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
|
|
|
+import {generateProfileFlamegraphRoute} from 'sentry/utils/profiling/routes';
|
|
|
+import useApi from 'sentry/utils/useApi';
|
|
|
+import useOrganization from 'sentry/utils/useOrganization';
|
|
|
+
|
|
|
+interface Props {
|
|
|
+ orgId: string;
|
|
|
+ projectId: string;
|
|
|
+ transactionId: string;
|
|
|
+}
|
|
|
+
|
|
|
+function TransactionToProfileButton({transactionId, orgId, projectId}: Props) {
|
|
|
+ const api = useApi();
|
|
|
+ const organization = useOrganization();
|
|
|
+
|
|
|
+ const [profileIdState, setProfileIdState] = useState<RequestState<string>>({
|
|
|
+ type: 'initial',
|
|
|
+ });
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ fetchProfileId(api, transactionId, orgId, projectId).then((profileId: ProfileId) => {
|
|
|
+ setProfileIdState({type: 'resolved', data: profileId.profile_id});
|
|
|
+ });
|
|
|
+ }, [api, transactionId, orgId, projectId]);
|
|
|
+
|
|
|
+ if (profileIdState.type !== 'resolved') {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ function handleGoToProfile() {
|
|
|
+ trackAdvancedAnalyticsEvent('profiling_views.go_to_flamegraph', {
|
|
|
+ organization,
|
|
|
+ source: 'transaction_details',
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ const target = generateProfileFlamegraphRoute({
|
|
|
+ orgSlug: orgId,
|
|
|
+ projectSlug: projectId,
|
|
|
+ profileId: profileIdState.data,
|
|
|
+ });
|
|
|
+
|
|
|
+ return (
|
|
|
+ <Button onClick={handleGoToProfile} to={target}>
|
|
|
+ {t('Go to Profile')}
|
|
|
+ </Button>
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+type ProfileId = {
|
|
|
+ profile_id: string;
|
|
|
+};
|
|
|
+
|
|
|
+function fetchProfileId(
|
|
|
+ api: Client,
|
|
|
+ transactionId: string,
|
|
|
+ orgId: string,
|
|
|
+ projectId: string
|
|
|
+): Promise<ProfileId> {
|
|
|
+ return api.requestPromise(
|
|
|
+ `/projects/${orgId}/${projectId}/profiling/transactions/${transactionId}/`,
|
|
|
+ {
|
|
|
+ method: 'GET',
|
|
|
+ }
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+export {TransactionToProfileButton};
|