Implement stats_v2 API

The Grafana integration uses it. So we should too. It isn't documented so we only have reverse engineering.

Grafana appears to send queries like this ?category=error&end=2022-02-11T18%3A57%3A43&field=sum%28quantity%29&start=2022-02-11T17%3A57%3A43

  • category: type of event (error, uptime, transaction, etc)
  • start and end dates
  • field can be either sum(quantity) or sum(times_seen)
  • And optional filters for category, outcome, reason, and group by.

This API is likely too complex to entirely support but we could focus on more common use cases as we see them in the wild. For now that is limited to whatever grafana wants. It seems to match the documented format here. It's possible that stats_v2 is an alias of sessions.

Example response

{
  "intervals": ["2022-02-11T1:00:00Z", "2022-02-11T2:00:00Z"],
  "groups": [{"series": {"sum(quantity)": [4, 6]},}],
}

It gets the intervals every hour on the hour, regardless of start time minutes. Then gives a "groups" of the requested series which is either quantity or times_seen.

Anyone who wants to help, please keep in mind this API in Sentry is not open source nor documented. Thus I have to assume it's intended to be proprietary and out of an abundance of caution, if you have read the sentry source code that powers this, please do not contribute to this issue in any way.

Edited by David Burke