Skip to content

Commit

Permalink
fix(issues): Adjust bootstrap.ui transaction
Browse files Browse the repository at this point in the history
The previous version only measured the time until the organization was available.
  • Loading branch information
scttcper committed Jan 30, 2025
1 parent ff6b67d commit 0200615
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions static/app/views/organizationContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -73,7 +91,6 @@ export function OrganizationContextProvider({children}: Props) {
const [organizationPromise, setOrganizationPromise] = useState<Promise<unknown> | null>(
null
);
const spanRef = useRef<Sentry.Span | null>(null);

const lastOrganizationSlug: string | null =
configStore.lastOrganization ?? organizations[0]?.slug ?? null;
Expand All @@ -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;
}

Expand All @@ -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
Expand Down

0 comments on commit 0200615

Please sign in to comment.