Skip to content

Commit

Permalink
pass X-Debug header downstream
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Davy committed Jan 20, 2020
1 parent a8bb6fb commit 0ee3dab
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions talisker/requests.py
Expand Up @@ -72,6 +72,7 @@
STORAGE = Local()
STORAGE.sessions = {}
HOSTS = module_dict()
DEBUG_HEADER = future.utils.text_to_native_str('X-Debug')


def clear():
Expand Down Expand Up @@ -169,6 +170,8 @@ def send(request, **kwargs):
deadline = datetime.utcfromtimestamp(Context.current.deadline)
formatted = deadline.isoformat() + 'Z'
request.headers[config.deadline_header] = formatted
if Context.debug:
request.headers[DEBUG_HEADER] = '1'
try:
return func(request, **kwargs)
except Exception as e:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_requests.py
Expand Up @@ -223,6 +223,7 @@ def test_metric_hook_registered_endpoint(
def test_configured_session(context, get_breadcrumbs):
deadline = time.time() + 10
expected_deadline = datetime.utcfromtimestamp(deadline).isoformat() + 'Z'
Context.set_debug()
Context.current.deadline = deadline
session = requests.Session()
talisker.requests.configure(session)
Expand All @@ -242,6 +243,7 @@ def test_configured_session(context, get_breadcrumbs):
headers = responses.calls[0].request.headers
assert headers['X-Request-Id'] == 'XXX'
assert headers['X-Request-Deadline'] == expected_deadline
assert headers['X-Debug'] == '1'
assert context.statsd[0] == 'requests.count.localhost.view:1|c'
assert context.statsd[1].startswith(
'requests.latency.localhost.view.200:')
Expand Down

0 comments on commit 0ee3dab

Please sign in to comment.