1 | |
2 | |
3 | * Retrieve an organizations events count by project |
4 | * Query summarized event counts by project for your Organization. Also see https://docs.sentry.io/api/organizations/retrieve-event-counts-for-an-organization-v2/ for reference. |
5 | */ |
6 | export async function main( |
7 | auth: RT.Sentry, |
8 | field: 'sum(quantity)' | 'sum(times_seen)' | undefined, |
9 | statsPeriod?: string | undefined, |
10 | interval?: string | undefined, |
11 | start?: string | undefined, |
12 | end?: string | undefined, |
13 | project?: string | undefined, |
14 | category?: 'error' | 'transaction' | 'attachment' | 'replays' | 'profiles' | undefined, |
15 | outcome?: |
16 | | 'accepted' |
17 | | 'filtered' |
18 | | 'rate_limited' |
19 | | 'invalid' |
20 | | 'abuse' |
21 | | 'client_discard' |
22 | | 'cardinality_limited' |
23 | | undefined, |
24 | reason?: string | undefined, |
25 | download?: string | undefined |
26 | ) { |
27 | const url = new URL( |
28 | `https://${auth.region}.sentry.io/api/0/organizations/${auth.organizationSlug}/stats-summary/` |
29 | ) |
30 | for (const [k, v] of [ |
31 | ['field', field], |
32 | ['statsPeriod', statsPeriod], |
33 | ['interval', interval], |
34 | ['start', start], |
35 | ['end', end], |
36 | ['project', project], |
37 | ['category', category], |
38 | ['outcome', outcome], |
39 | ['reason', reason], |
40 | ['download', download] |
41 | ]) { |
42 | if (v !== undefined && v !== '') { |
43 | url.searchParams.append(k, v) |
44 | } |
45 | } |
46 | const response = await fetch(url, { |
47 | method: 'GET', |
48 | headers: { |
49 | Authorization: 'Bearer ' + auth.token |
50 | }, |
51 | body: undefined |
52 | }) |
53 | if (!response.ok) { |
54 | const text = await response.text() |
55 | throw new Error(`${response.status} ${text}`) |
56 | } |
57 | return await response.json() |
58 | } |
59 |
|