Skip to content

Commit ab8cde7

Browse files
pfreixeshaotianw465
authored andcommitted
Fix http.URL field segment for Aiohttp extension (#37)
* Fix http.URL field segment for Aiohttp extension * CHANGELOG
1 parent 29997ec commit ab8cde7

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ unreleased
66
==========
77
* feature: Use the official middleware pattern for Aiohttp ext. `PR29 <https://github.com/aws/aws-xray-sdk-python/pull/29>`_.
88
* bugfix: SQLAlcemy plugin would cause warning messages with some db connection strings that contained invalid characters for a segment/subsegment name.
9+
* bugfix: Aiohttp middleware serialized URL values incorrectly `PR37 <https://github.com/aws/aws-xray-sdk-python/pull/37>`_
10+
911
0.96
1012
====
1113
* feature: Add support for SQLAlchemy and Flask-SQLAlcemy. `PR14 <https://github.com/aws/aws-xray-sdk-python/pull/14>`_.

aws_xray_sdk/ext/aiohttp/middleware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async def middleware(request, handler):
3636
)
3737

3838
# Store request metadata in the current segment
39-
segment.put_http_meta(http.URL, request.url)
39+
segment.put_http_meta(http.URL, str(request.url))
4040
segment.put_http_meta(http.METHOD, request.method)
4141

4242
if 'User-Agent' in request.headers:

tests/ext/aiohttp/test_aiohttp.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,7 @@ async def test_ok(test_client, loop, recorder):
119119
response = segment.http['response']
120120

121121
assert request['method'] == 'GET'
122-
assert str(request['url']).startswith('http://127.0.0.1')
123-
assert request['url'].host == '127.0.0.1'
124-
assert request['url'].path == '/'
122+
assert request['url'] == 'http://127.0.0.1:{port}/'.format(port=client.port)
125123
assert response['status'] == 200
126124

127125

@@ -145,8 +143,7 @@ async def test_error(test_client, loop, recorder):
145143
request = segment.http['request']
146144
response = segment.http['response']
147145
assert request['method'] == 'GET'
148-
assert request['url'].host == '127.0.0.1'
149-
assert request['url'].path == '/error'
146+
assert request['url'] == 'http://127.0.0.1:{port}/error'.format(port=client.port)
150147
assert request['client_ip'] == '127.0.0.1'
151148
assert response['status'] == 404
152149

@@ -172,8 +169,7 @@ async def test_exception(test_client, loop, recorder):
172169
response = segment.http['response']
173170
exception = segment.cause['exceptions'][0]
174171
assert request['method'] == 'GET'
175-
assert request['url'].host == '127.0.0.1'
176-
assert request['url'].path == '/exception'
172+
assert request['url'] == 'http://127.0.0.1:{port}/exception'.format(port=client.port)
177173
assert request['client_ip'] == '127.0.0.1'
178174
assert response['status'] == 500
179175
assert exception.type == 'KeyError'

0 commit comments

Comments
 (0)