Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gruntster opened this issue Aug 20, 2024 · 4 comments · Fixed by #2955
Closed

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

gruntster opened this issue Aug 20, 2024 · 4 comments · Fixed by #2955
Assignees
Labels
bug Something isn't working completed This item is complete and has been merged/shipped tracer This item relates to the Tracer Utility

Comments

@gruntster
Copy link

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

@gruntster gruntster added bug Something isn't working triage This item has not been triaged by a maintainer, please wait labels Aug 20, 2024
Copy link

boring-cyborg bot commented Aug 20, 2024

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

@dreamorosi dreamorosi added tracer This item relates to the Tracer Utility confirmed The scope is clear, ready for implementation and removed triage This item has not been triaged by a maintainer, please wait labels Aug 20, 2024
@dreamorosi dreamorosi moved this from Triage to Backlog in Powertools for AWS Lambda (TypeScript) Aug 20, 2024
@dreamorosi
Copy link
Contributor

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.

Copy link
Contributor

⚠️ 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.

@github-actions github-actions bot added pending-release This item has been merged and will be released soon and removed confirmed The scope is clear, ready for implementation labels Sep 10, 2024
Copy link
Contributor

This is now released under v2.8.0 version!

@github-actions github-actions bot added completed This item is complete and has been merged/shipped and removed pending-release This item has been merged and will be released soon labels Sep 16, 2024
@dreamorosi dreamorosi moved this from Coming soon to Shipped in Powertools for AWS Lambda (TypeScript) Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working completed This item is complete and has been merged/shipped tracer This item relates to the Tracer Utility
Projects
Development

Successfully merging a pull request may close this issue.

2 participants