diff --git a/tildes/tildes/metrics.py b/tildes/tildes/metrics.py index 9f93040..87184ae 100644 --- a/tildes/tildes/metrics.py +++ b/tildes/tildes/metrics.py @@ -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" ), diff --git a/tildes/tildes/views/donate.py b/tildes/tildes/views/donate.py index 848de25..9de0039 100644 --- a/tildes/tildes/views/donate.py +++ b/tildes/tildes/views/donate.py @@ -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}