Skip to content

Instantly share code, notes, and snippets.

@urouro-net
Created April 20, 2018 03:58
Show Gist options
  • Save urouro-net/cc46036142e09f65c94b045433342a3a to your computer and use it in GitHub Desktop.
Save urouro-net/cc46036142e09f65c94b045433342a3a to your computer and use it in GitHub Desktop.
Sentry Crash Free Rate Calcuration
# An example for calculation of the crash free rate with Sentry.
# This example calculates the crash free rate yesterday.
require 'json'
require 'net/http'
require 'uri'
# Set your API Token
# https://sentry.io/api/
SENTRY_API_TOKEN = 'xxx'
# Sentry Organization Slug
SENTRY_ORG = 'your-organization'
# Sentry Project Slug
SENTRY_PRJ = 'your-project'
# Set your DAU (via an other system e.g. Google Analytics)
DAU = 100.0
uri = URI.parse("https://sentry.io/api/0/projects/#{SENTRY_ORG}/#{SENTRY_PRJ}/issues/?statsPeriod=14d")
request = Net::HTTP::Get.new(uri)
request.content_type = 'application/json'
request["Authorization"] = "Bearer #{SENTRY_API_TOKEN}"
req_options = {
use_ssl: uri.scheme == 'https',
}
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
http.request(request)
end
json = JSON.parse(response.body)
time = Time.now - 60 * 60 * 24 * 1
start_of_yesterday = Time.local( time.year, time.month, time.day, 0, 0, 0)
end_of_yesterday = Time.local( time.year, time.month, time.day, 23, 59, 59)
total_crashes = 0
json.each do |issue|
issue['stats']['14d'].each do |stat|
if stat[1] > 0 &&
Time.at(stat[0]) >= start_of_yesterday &&
Time.at(stat[0]) <= end_of_yesterday
total_crashes += stat[1]
end
end
end
crash_free_rate = (1 - (total_crashes / DAU)) * 100.0
p total_crashes # Yesterday's Total Crash
p crash_free_rate # Yesterday's Crash Free Rate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment