//native
/**
* Retrieve event counts for an organization v 2
* Query event counts for your Organization.
Select a field, define a date range, and group or filter by columns.
*/
export async function main(
auth: RT.Sentry,
groupBy: string | undefined,
field: 'sum(quantity)' | 'sum(times_seen)' | undefined,
statsPeriod?: string | undefined,
interval?: string | undefined,
start?: string | undefined,
end?: string | undefined,
project?: string | undefined,
category?:
| 'error'
| 'transaction'
| 'attachment'
| 'replay'
| 'profile'
| 'profile_duration'
| 'profile_duration_ui'
| 'profile_chunk'
| 'profile_chunk_ui'
| 'monitor'
| undefined,
outcome?:
| 'accepted'
| 'filtered'
| 'rate_limited'
| 'invalid'
| 'abuse'
| 'client_discard'
| 'cardinality_limited'
| undefined,
reason?: string | undefined
) {
const url = new URL(
`https://${auth.region}.sentry.io/api/0/organizations/${auth.organizationSlug}/stats_v2/`
)
for (const [k, v] of [
['groupBy', groupBy],
['field', field],
['statsPeriod', statsPeriod],
['interval', interval],
['start', start],
['end', end],
['project', project],
['category', category],
['outcome', outcome],
['reason', reason]
]) {
if (v !== undefined && v !== '') {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'GET',
headers: {
Authorization: 'Bearer ' + auth.token
},
body: undefined
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 235 days ago