Skip to content

feat(starfish): Adds useSpansQuery to handle querying from prod or local#48664

Merged
edwardgou-sentry merged 3 commits into
masterfrom
egou/feat/starfish/prod-spans-queries
May 8, 2023
Merged

feat(starfish): Adds useSpansQuery to handle querying from prod or local#48664
edwardgou-sentry merged 3 commits into
masterfrom
egou/feat/starfish/prod-spans-queries

Conversation

@edwardgou-sentry

Copy link
Copy Markdown
Contributor

Adds a useSpansQuery hook that handles querying from either prod via discover apis, or local scraped data.
Updates some areas of API module to query via useSpansQuery for testing.

Note: There's no ui toggle at the moment to switch between prod and local data. Just update useStarfishOptions to default useDiscover to true.

TODO: Need to add support for events-stats queries

@edwardgou-sentry edwardgou-sentry requested review from a team May 5, 2023 21:01
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label May 5, 2023

@gggritso gggritso left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, nice work! Having two methods to fetch is really confusing, so I hope we don't have to live in this state for too long, but for now this is a really good step forward

Comment on lines +21 to +40
}): ReturnType {
const {options} = useStarfishOptions();
const {useDiscover} = options;
const queryFunction = getQueryFunction({useDiscover});
if (isDiscoverFunction(queryFunction)) {
if (eventView) {
return queryFunction(eventView, initialData);
}
throw new Error(
'eventView argument must be defined when Starfish useDiscover is true'
);
}

if (queryString) {
return queryFunction(queryString, initialData);
}
throw new Error(
'queryString argument must be defined when Starfish useDiscover is false, ie when using scraped data via fetch API'
);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is really confusing because it's checking useDiscover, creating a function based on useDiscover, then checking the types of the functions to implement the behaviour. It'd be way simple to just do the conditional in one spot

if (useDiscover) {
  const {isLoading, data} = useDiscoverQuery({
     eventView,
     orgSlug: organization.slug,
     location,
   });

   return {isLoading, data: isLoading && initialData ? initialData : data?.data};
} else {

  const {isLoading, data} = useQuery({
     queryKey: [queryString],
     queryFn: () => fetch(`${HOST}/?query=${queryString}`).then(res => res.json()),
     retry: false,
     initialData,
   });
   return {isLoading, data};

}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I can see this being confusing. Fwiw, I did this so I could use a type guard on isDiscoverFunction to get typescript from complaining about arg types. I can definitely correct this though, I'll follow up in another pr!

@edwardgou-sentry

Copy link
Copy Markdown
Contributor Author

Awesome, nice work! Having two methods to fetch is really confusing, so I hope we don't have to live in this state for too long, but for now this is a really good step forward

Thanks! Yeah ideally we move exclusively onto useSpanQuery which will be able to handle both local and prod cases, but thats gunna take some time for sure

@edwardgou-sentry edwardgou-sentry merged commit c3333a3 into master May 8, 2023
@edwardgou-sentry edwardgou-sentry deleted the egou/feat/starfish/prod-spans-queries branch May 8, 2023 21:49
@github-actions github-actions Bot locked and limited conversation to collaborators May 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants