Skip to content

Commit

Permalink
update: use intermediary context off of sanic request object for chan…
Browse files Browse the repository at this point in the history
…ges in sanic 19.9+
  • Loading branch information
edaniszewski committed Aug 26, 2020
1 parent b277659 commit 5ee5837
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions synse_server/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

class Monitor:

_req_start_time = '__req_start_time'

#
# Metrics for Synse Server's HTTP API
#
Expand Down Expand Up @@ -134,11 +132,11 @@ def register(self) -> None:

@self.app.middleware('request')
async def before_request(request: Request) -> None:
request[self._req_start_time] = time.time()
request.ctx.req_start_time = time.time()

@self.app.middleware('response')
async def before_response(request: Request, response: HTTPResponse) -> None:
latency = time.time() - request[self._req_start_time]
latency = time.time() - request.ctx.req_start_time

# WebSocket handler ignores response logic, so default
# to a 200 response in such case.
Expand Down

0 comments on commit 5ee5837

Please sign in to comment.