Skip to content

Commit 4d10fcc

Browse files
authored
Merge pull request #20 from locustio/improve-spans
Improve trace spans
2 parents 19e848f + df8aab8 commit 4d10fcc

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎src/aiolocust/users/http.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ async def __aenter__(self) -> LocustResponse:
107107
await super().__aenter__()
108108
except (ClientConnectorError, ClientResponseError, TimeoutError) as e:
109109
if request_info := getattr(e, "request_info", None):
110-
url = request_info.url
110+
url = str(request_info.url)
111111
else:
112112
url = self.str_or_url
113113
self.span.record_exception(e)
@@ -151,6 +151,7 @@ async def __aexit__(
151151
else:
152152
# wrap plain strings in Exceptions. Callstack may be confusing, but it is better than nothing
153153
self.span.record_exception(Exception(err))
154+
self.span.set_attribute("http.status", str(self._resp.status))
154155
context.detach(self._token)
155156
self.span.end(self.end_time)
156157

‎tests/test_zzaiolocust.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ async def run(user):
108108
logger.info("info level log message")
109109
async with user.client.get("http://localhost:8081/") as resp:
110110
pass
111+
async with user.client.get("http://localhost:8081/500") as resp:
112+
pass
111113
""")
112114
proc = await asyncio.create_subprocess_exec(
113115
"aiolocust",
@@ -135,9 +137,13 @@ async def run(user):
135137
err = stderr.decode(errors="replace")
136138
print(err)
137139
output = stdout.decode(errors="replace")
140+
print(output)
138141
assert "warning level log message" in err
139142
assert "info level log message" not in err
140143
assert "exception" not in err.lower()
144+
# test some span stuff while we are at it
145+
assert '"http.status": "200"' in output
146+
assert '"http.status": "500"' in output
141147
assert await proc.wait() == 0
142148

143149

0 commit comments

Comments
 (0)