1 | |
2 | |
3 | * Retrieve event counts for an organization v 2 |
4 | * Query event counts for your Organization. |
5 | Select a field, define a date range, and group or filter by columns. |
6 | */ |
7 | export async function main( |
8 | auth: RT.Sentry, |
9 | groupBy: string | undefined, |
10 | field: 'sum(quantity)' | 'sum(times_seen)' | undefined, |
11 | statsPeriod?: string | undefined, |
12 | interval?: string | undefined, |
13 | start?: string | undefined, |
14 | end?: string | undefined, |
15 | project?: string | undefined, |
16 | category?: |
17 | | 'error' |
18 | | 'transaction' |
19 | | 'attachment' |
20 | | 'replay' |
21 | | 'profile' |
22 | | 'profile_duration' |
23 | | 'profile_duration_ui' |
24 | | 'profile_chunk' |
25 | | 'profile_chunk_ui' |
26 | | 'monitor' |
27 | | undefined, |
28 | outcome?: |
29 | | 'accepted' |
30 | | 'filtered' |
31 | | 'rate_limited' |
32 | | 'invalid' |
33 | | 'abuse' |
34 | | 'client_discard' |
35 | | 'cardinality_limited' |
36 | | undefined, |
37 | reason?: string | undefined |
38 | ) { |
39 | const url = new URL( |
40 | `https://${auth.region}.sentry.io/api/0/organizations/${auth.organizationSlug}/stats_v2/` |
41 | ) |
42 | for (const [k, v] of [ |
43 | ['groupBy', groupBy], |
44 | ['field', field], |
45 | ['statsPeriod', statsPeriod], |
46 | ['interval', interval], |
47 | ['start', start], |
48 | ['end', end], |
49 | ['project', project], |
50 | ['category', category], |
51 | ['outcome', outcome], |
52 | ['reason', reason] |
53 | ]) { |
54 | if (v !== undefined && v !== '') { |
55 | url.searchParams.append(k, v) |
56 | } |
57 | } |
58 | const response = await fetch(url, { |
59 | method: 'GET', |
60 | headers: { |
61 | Authorization: 'Bearer ' + auth.token |
62 | }, |
63 | body: undefined |
64 | }) |
65 | if (!response.ok) { |
66 | const text = await response.text() |
67 | throw new Error(`${response.status} ${text}`) |
68 | } |
69 | return await response.json() |
70 | } |
71 |
|