Skip to content

Commit

Permalink
- use unittest assert statements
Browse files Browse the repository at this point in the history
- capture a list of headers

Signed-off-by: Varsha GS <[email protected]>
  • Loading branch information
GSVarsha committed Dec 29, 2023
1 parent 88a867b commit 8363101
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 96 deletions.
16 changes: 9 additions & 7 deletions instana/instrumentation/django/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ def __init__(self, get_response=None):
self.get_response = get_response

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

try:
for custom_header in agent.options.extra_http_headers:
# Headers are available in this format: HTTP_X_CAPTURE_THIS
django_header = ('HTTP_' + custom_header.upper()).replace('-', '_') if format else custom_header

if django_header in headers:
span.set_tag("http.header.%s" % custom_header, headers[django_header])
if django_header in headers:
span.set_tag("http.header.%s" % custom_header, headers[django_header])

except Exception:
logger.debug("extract_custom_headers: ", exc_info=True)
Expand Down
8 changes: 5 additions & 3 deletions tests/apps/app_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,11 @@ def complex(request):


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


urlpatterns = [
Expand Down
Loading

0 comments on commit 8363101

Please sign in to comment.