From 02006152ec4ba79fe073b51858d6ed7c5aa63522 Mon Sep 17 00:00:00 2001 From: Scott Cooper Date: Thu, 30 Jan 2025 12:59:00 -0800 Subject: [PATCH] fix(issues): Adjust bootstrap.ui transaction The previous version only measured the time until the organization was available. --- static/app/views/organizationContext.tsx | 49 ++++++++++++++---------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/static/app/views/organizationContext.tsx b/static/app/views/organizationContext.tsx index 87a65d1e96b21c..9515aba5708e3c 100644 --- a/static/app/views/organizationContext.tsx +++ b/static/app/views/organizationContext.tsx @@ -56,6 +56,24 @@ export function useEnsureOrganization() { }, [organizationPromise]); } +/** + * Record if the organization was bootstrapped in the last 10 minutes + */ +function setRecentBootstrapTag(orgSlug: string) { + const previousBootstrapKey = `previous-bootstrap-${orgSlug}`; + try { + const previousBootstrapTime = localStorage.getItem(previousBootstrapKey); + Sentry.setTag( + 'is_recent_boot', + previousBootstrapTime + ? Date.now() - Number(previousBootstrapTime) < 10 * 60 * 1000 + : false + ); + localStorage.setItem(previousBootstrapKey, `${Date.now()}`); + } catch { + // Ignore errors + } +} /** * Context provider responsible for loading the organization into the * OrganizationStore if it is not already present. @@ -73,7 +91,6 @@ export function OrganizationContextProvider({children}: Props) { const [organizationPromise, setOrganizationPromise] = useState | null>( null ); - const spanRef = useRef(null); const lastOrganizationSlug: string | null = configStore.lastOrganization ?? organizations[0]?.slug ?? null; @@ -87,13 +104,7 @@ export function OrganizationContextProvider({children}: Props) { useEffect(() => { // Nothing to do if we already have the organization loaded - const previousBootstrapKey = `previous-bootstrap-${orgSlug}`; if (organization && organization.slug === orgSlug) { - if (spanRef.current) { - spanRef.current.end(); - spanRef.current = null; - localStorage.setItem(previousBootstrapKey, `${Date.now()}`); - } return; } @@ -102,20 +113,18 @@ export function OrganizationContextProvider({children}: Props) { return; } - const previousBootstrapTime = localStorage.getItem(previousBootstrapKey); - spanRef.current = Sentry.startInactiveSpan({ - name: 'ui.bootstrap', - op: 'ui.render', - forceTransaction: true, - attributes: { - // Bootstrapped in the last 10 minutes - is_recent_boot: previousBootstrapTime - ? Date.now() - Number(previousBootstrapTime) < 10 * 60 * 1000 - : false, - }, - }); + setRecentBootstrapTag(orgSlug); - setOrganizationPromise(fetchOrganizationDetails(api, orgSlug, false, true)); + const promise = Sentry.startSpan( + { + name: 'ui.bootstrap', + op: 'ui.render', + forceTransaction: true, + }, + // Bootstraps organization, projects, and teams + () => fetchOrganizationDetails(api, orgSlug, false, true) + ); + setOrganizationPromise(promise); }, [api, orgSlug, organization]); // XXX(epurkhiser): User may be null in some scenarios at this point in app