12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- import {Client} from 'sentry/api';
- import {t} from 'sentry/locale';
- import {ServerSideSamplingStore} from 'sentry/stores/serverSideSamplingStore';
- import {Organization, Project} from 'sentry/types';
- import {SamplingDistribution, SamplingSdkVersion} from 'sentry/types/sampling';
- import handleXhrErrorResponse from 'sentry/utils/handleXhrErrorResponse';
- export function fetchSamplingSdkVersions({
- api,
- orgSlug,
- }: {
- api: Client;
- orgSlug: Organization['slug'];
- }): Promise<SamplingSdkVersion[]> {
- const {samplingDistribution} = ServerSideSamplingStore.getState();
- const projectIds = samplingDistribution.project_breakdown?.map(
- projectBreakdown => projectBreakdown.project_id
- );
- const promise = api.requestPromise(
- `/organizations/${orgSlug}/dynamic-sampling/sdk-versions/`,
- {
- query: {
- project: projectIds,
- statsPeriod: '24h',
- },
- }
- );
- ServerSideSamplingStore.setFetching(true);
- promise
- .then(ServerSideSamplingStore.loadSamplingSdkVersionsSuccess)
- .catch(response => {
- const errorMessage = t('Unable to fetch sampling sdk versions');
- handleXhrErrorResponse(errorMessage)(response);
- })
- .finally(() => {
- ServerSideSamplingStore.setFetching(false);
- });
- return promise;
- }
- export function fetchSamplingDistribution({
- api,
- orgSlug,
- projSlug,
- }: {
- api: Client;
- orgSlug: Organization['slug'];
- projSlug: Project['slug'];
- }): Promise<SamplingDistribution> {
- ServerSideSamplingStore.reset();
- ServerSideSamplingStore.setFetching(true);
- const promise = api.requestPromise(
- `/projects/${orgSlug}/${projSlug}/dynamic-sampling/distribution/`,
- {
- query: {
- statsPeriod: '24h',
- },
- }
- );
- promise
- .then(ServerSideSamplingStore.loadSamplingDistributionSuccess)
- .catch(response => {
- const errorMessage = t('Unable to fetch sampling distribution');
- handleXhrErrorResponse(errorMessage)(response);
- })
- .finally(() => {
- ServerSideSamplingStore.setFetching(false);
- });
- return promise;
- }
|