Skip to content

Commit 898f277

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

File tree

3 files changed

+507
-415
lines changed

3 files changed

+507
-415
lines changed

instana/instrumentation/asgi.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ def __init__(self, app):
2020
self.app = app
2121

2222
def _extract_custom_headers(self, span, headers):
23+
if agent.options.extra_http_headers is None:
24+
return
2325
try:
24-
if agent.options.extra_http_headers is not None:
25-
for custom_header in agent.options.extra_http_headers:
26-
# Headers are in the following format: b'x-header-1'
27-
for header_pair in headers:
28-
if header_pair[0].decode('utf-8').lower() == custom_header.lower():
29-
span.set_tag("http.header.%s" % custom_header, header_pair[1].decode('utf-8'))
26+
for custom_header in agent.options.extra_http_headers:
27+
# Headers are in the following format: b'x-header-1'
28+
for header_pair in headers:
29+
if header_pair[0].decode('utf-8').lower() == custom_header.lower():
30+
span.set_tag("http.header.%s" % custom_header, header_pair[1].decode('utf-8'))
3031
except Exception:
3132
logger.debug("extract_custom_headers: ", exc_info=True)
3233

tests/apps/fastapi_app/app.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ async def user(user_id):
2626

2727
@fastapi_server.get("/response_headers")
2828
async def response_headers():
29-
headers = {'X-Capture-This-Too': 'this too'}
30-
return Response(content=None, headers=headers)
29+
headers = {
30+
'X-Capture-This-Too': 'this too',
31+
'X-Capture-That-Too': 'that too'
32+
}
33+
return Response("Stan wuz here with headers!", headers=headers)
3134

3235
@fastapi_server.get("/400")
3336
async def four_zero_zero():

0 commit comments

Comments
 (0)