Bug: Fetch traces only capture the hostname of the request URL
Expected Behavior
The request URL captured by the trace of a Fetch request should be the URL of the request.
Current Behavior
The request URL captured by the trace of a Fetch request is only the requested hostname.
Code snippet
await fetch("https://aws.amazon.com/free?test=1");
Steps to Reproduce
- Set
AWS_XRAY_DEBUG_MODEenvironment variable totrueof an instrumented Lambda function. - Perform requests using
fetchandnode:https
await fetch("https://aws.amazon.com/free?test=1");
await axios.get("https://aws.amazon.com/free?test=1");
- Compare output of subsegments.
fetch emits incorrect request URL:
{
"id": "45b22f447784c44f",
"name": "aws.amazon.com",
"start_time": 1724108234.18,
"namespace": "remote",
"http": {
"request": {
"url": "aws.amazon.com",
"method": "GET"
},
"response": {
"status": 301,
"content_length": 0
}
},
"end_time": 1724108234.849
}
node:https emits correct request URL:
{
"id": "e861c05fa31a14ab",
"name": "aws.amazon.com",
"start_time": 1724108234.856,
"namespace": "remote",
"http": {
"request": {
"url": "https://aws.amazon.com/free",
"method": "GET"
},
"response": {
"status": 301,
"content_length": 0
}
},
"end_time": 1724108235.218
}
Possible Solution
Modify the onRequestStart function of the Tracer's ProviderService to generate a URL rather than use the hostname.
For example, modify to the following:
const origin = getOriginURL(request.origin + request.path);
...
(subsegment as HttpSubsegment).http = {
request: {
url: `${origin.protocol}//${origin.hostname}${origin.pathname}`,
method,
},
};
...
Powertools for AWS Lambda (TypeScript) version
2.7.0
AWS Lambda function runtime
20.x
Packaging format used
npm
Execution logs
No response
Thanks for opening your first issue here! We'll come back to you as soon as we can. In the meantime, check out the #typescript channel on our Powertools for AWS Lambda Discord: Invite link
Hi @gruntster, thank you for taking the time to report the issue.
I looked into it and I am able to reproduce the behavior you described. When making requests with fetch, the trace data is indeed missing the path/pathname.
I'll be working on a fix before this week's release.
⚠️ COMMENT VISIBILITY WARNING ⚠️
This issue is now closed. Please be mindful that future comments are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.
This is now released under v2.8.0 version!