Skip to content

Commit

Permalink
Record userid on each request made to h (#5417)
Browse files Browse the repository at this point in the history
* Record userid on each request made to h

In order to accurately count the rate of requests per user, add
a custom parameter to each transaction in new relic called userid.

* fixup: undo removal of blank line

* fixup: group import w/ thirdparty imports
  • Loading branch information
Hannah Stepanek committed Nov 8, 2018
1 parent 2d21f55 commit 69871ce
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions h/auth/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import unicode_literals
import datetime

import newrelic.agent
from zope.interface import implementer

from h._compat import text_type
Expand All @@ -27,6 +28,9 @@ def __init__(self, token_model):
self.expires = token_model.expires
self.userid = token_model.userid

# Associates the userid with a given transaction/web request.
newrelic.agent.add_custom_parameter("userid", self.userid)

def is_valid(self):
"""Return ``True`` if this token is not expired, ``False`` if it is."""
if self.expires is None:
Expand Down

0 comments on commit 69871ce

Please sign in to comment.