Closed
Description
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_MODE
environment variable totrue
of an instrumented Lambda function. - Perform requests using
fetch
andnode: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
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Shipped