Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion instana/instrumentation/aiohttp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ async def stan_middleware(request, handler):
if custom_header in request.headers:
scope.span.set_tag("http.%s" % custom_header, request.headers[custom_header])

response = await handler(request)
response = None
try:
response = await handler(request)
except aiohttp.web.HTTPException as e:
# AIOHTTP uses exceptions for specific responses
# see https://docs.aiohttp.org/en/latest/web_exceptions.html#web-server-exceptions
response = e
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In AIOHTTP their exception objects have the status & headers attributes just like the response objects (same interface) so this shouldn't break the lines below. https://docs.aiohttp.org/en/latest/web_exceptions.html#base-http-exception


if response is not None:
# Mark 500 responses as errored
Expand Down