Skip to content

Bug: Fetch traces only capture the hostname of the request URL #2954

Closed
@gruntster

Description

@gruntster

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

  1. Set AWS_XRAY_DEBUG_MODE environment variable to true of an instrumented Lambda function.
  2. Perform requests using fetch and node:https
await fetch("https://aws.amazon.com/free?test=1");
await axios.get("https://aws.amazon.com/free?test=1");
  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

bugSomething isn't workingcompletedThis item is complete and has been merged/shippedtracerThis item relates to the Tracer Utility

Type

No type

Projects

Status

Shipped

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions