Add metrics for donations and failures

This commit is contained in:
Deimos
2019-08-27 16:15:52 -06:00
parent a03dfa42a1
commit e9a193d698
2 changed files with 10 additions and 0 deletions

View File

@@ -18,6 +18,12 @@ _COUNTERS = {
"comment_labels": Counter(
"tildes_comment_labels_total", "Comment Labels", labelnames=["label"]
),
"donations": Counter(
"tildes_donations_total", "Donation Attempts", labelnames=["type"]
),
"donation_failures": Counter(
"tildes_donation_failures_total", "Donation Failures", labelnames=["type"]
),
"invite_code_failures": Counter(
"tildes_invite_code_failures_total", "Invite Code Failures"
),

View File

@@ -12,6 +12,7 @@ from pyramid.security import NO_PERMISSION_REQUIRED
from pyramid.view import view_config
from webargs.pyramidparser import use_kwargs
from tildes.metrics import incr_counter
from tildes.views.decorators import rate_limit_view
@@ -40,6 +41,8 @@ def post_donate_stripe(
except KeyError:
raise HTTPInternalServerError
incr_counter("donations", type="stripe")
payment_successful = True
try:
stripe.Charge.create(
@@ -51,6 +54,7 @@ def post_donate_stripe(
statement_descriptor="Donation - tildes.net",
)
except stripe.error.StripeError:
incr_counter("donation_failures", type="stripe")
payment_successful = False
return {"payment_successful": payment_successful}