powertools-lambda-typescript icon indicating copy to clipboard operation
powertools-lambda-typescript copied to clipboard

fix(tracer): include request pathname in trace data

Open dreamorosi opened this issue 1 year ago • 1 comments

Summary

Changes

Please provide a summary of what's being changed

This PR modifies the internal implementation of the Tracer patching for the fetch request module so that it includes the pathname of a request in the segment data.

As reported in the linked issue, the current implementation only records the host name, so a request to https://aws.amazon.com/free would generate a segment similar to this:

{
  "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
}

while it should have generated one like this:

{
  "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
}

Notice how the http.request.url includes both the path and protocol.

The PR also modifies and adds some unit tests to account for the updated logic.

Please add the issue number below, if no issue is present the PR might get blocked and not be reviewed

Issue number: closes #2954


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

dreamorosi avatar Aug 20 '24 11:08 dreamorosi

Integration tests passing: https://github.com/aws-powertools/powertools-lambda-typescript/actions/runs/10794586570

dreamorosi avatar Sep 10 '24 14:09 dreamorosi