Skip to content

Commit

Permalink
Bug 1372639 - Track the time spent redirecting when making requests
Browse files Browse the repository at this point in the history
By default New Relic only tracks the overall time spent making an
external HTTP request, when this could in fact cover multiple
sub-requests, if the first redirected.

This adds a New Relic custom event that tracks the time spent
redirecting, to help assess the priority of bug 1348072.
  • Loading branch information
edmorley committed Jun 16, 2017
1 parent 92ac490 commit 58daa2c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions treeherder/etl/common.py
Expand Up @@ -3,6 +3,7 @@
import logging
import re

import newrelic.agent
import requests
from dateutil import parser
from django.conf import settings
Expand Down Expand Up @@ -41,6 +42,15 @@ def make_request(url, method='GET', headers=None,
headers=headers,
timeout=timeout,
**kwargs)

if response.history:
params = {
'url': url,
'redirects': len(response.history),
'duration': sum(r.elapsed.total_seconds() for r in response.history)
}
newrelic.agent.record_custom_event('RedirectedRequest', params=params)

response.raise_for_status()
return response

Expand Down

0 comments on commit 58daa2c

Please sign in to comment.