Skip to content

Commit 8363101

Browse files
committed
- use unittest assert statements
- capture a list of headers Signed-off-by: Varsha GS <[email protected]>
1 parent 88a867b commit 8363101

File tree

3 files changed

+104
-96
lines changed

3 files changed

+104
-96
lines changed

instana/instrumentation/django/middleware.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@ def __init__(self, get_response=None):
3030
self.get_response = get_response
3131

3232
def _extract_custom_headers(self, span, headers, format):
33-
try:
34-
if agent.options.extra_http_headers is not None:
35-
for custom_header in agent.options.extra_http_headers:
36-
# Headers are available in this format: HTTP_X_CAPTURE_THIS
37-
django_header = ('HTTP_' + custom_header.upper()).replace('-', '_') if format else custom_header
33+
if agent.options.extra_http_headers is None:
34+
return
35+
36+
try:
37+
for custom_header in agent.options.extra_http_headers:
38+
# Headers are available in this format: HTTP_X_CAPTURE_THIS
39+
django_header = ('HTTP_' + custom_header.upper()).replace('-', '_') if format else custom_header
3840

39-
if django_header in headers:
40-
span.set_tag("http.header.%s" % custom_header, headers[django_header])
41+
if django_header in headers:
42+
span.set_tag("http.header.%s" % custom_header, headers[django_header])
4143

4244
except Exception:
4345
logger.debug("extract_custom_headers: ", exc_info=True)

tests/apps/app_django.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,11 @@ def complex(request):
126126

127127

128128
def response_with_headers(request):
129-
response = HttpResponse(content_type='')
130-
response['X-Capture-This-Too'] = 'this too'
131-
return response
129+
headers = {
130+
'X-Capture-This-Too': 'this too',
131+
'X-Capture-That-Too': 'that too'
132+
}
133+
return HttpResponse('Stan wuz here with headers!', headers=headers)
132134

133135

134136
urlpatterns = [

0 commit comments

Comments
 (0)