Skip to content

Bug: [Tracer] instrumentFetch breaks when using proxy #4114

Open
@tenjaa

Description

@tenjaa

Expected Behavior

Do not throw an error.

Current Behavior

Throws an error.

Code snippet

import {RetryAgent, ProxyAgent} from 'undici';

const agent = new RetryAgent(
  new ProxyAgent({
    token: `Basic <SOME SECRET PASSWORD>`,
    uri: `http://our-proxy-url:8080`,
  }),
);

agent.request(<call to the API>);

Steps to Reproduce

  1. Have an environment where you can only access the internet through a proxy
  2. Instantiate tracer with "captureHTTPsRequests: false,"
  3. Instantiate agent (see code snippet)
  4. Call tracer.provider.instrumentFetch() <= just to narrow down, that it is this path we are going instead of captureHTTPsGlobal()
  5. Call some api with the proxy agent

Possible Solution

Looking at

it seems that the diagnostics channel returns the proxy url as origin and the url we try to call as path which seems to be wrong.
And this can obviously not be parsed as url and an error gets thrown.

When using getRequestUrl in

const requestURL = getRequestURL(request);
it gets converted back into a string anyway.

So a possible solution I could imagine would be to not parse the URL but to just return a string or an object based on the diagnostics channel data.

Powertools for AWS Lambda (TypeScript) version

2.22.0

AWS Lambda function runtime

22.x

Packaging format used

npm

Execution logs

{
  "errorType": "TypeError",
  "errorMessage": "Invalid URL",
  "code": "ERR_INVALID_URL",
  "input": "http://<PROXY_URL>:8080api.github.com:443",
  "stack": [
    "TypeError: Invalid URL",
    "    at new URL (node:internal/url:818:25)",
    "    at getRequestURL (/node_modules/@aws-lambda-powertools/tracer/lib/esm/provider/utilities.js:46:16)",
    "    at onRequestStart (/node_modules/@aws-lambda-powertools/tracer/lib/esm/provider/ProviderService.js:77:32)",
    "    at Channel.publish (node:diagnostics_channel:150:9)",
    "    at new Request (/node_modules/undici/lib/core/request.js:192:23)",
    "    at Client.[dispatch] (/node_modules/undici/lib/dispatcher/client.js:300:21)",
    "    at Client.dispatch (/node_modules/undici/lib/dispatcher/dispatcher-base.js:148:28)",
    "    at Pool.[dispatch] (/node_modules/undici/lib/dispatcher/pool-base.js:140:28)",
    "    at Pool.dispatch (/node_modules/undici/lib/dispatcher/dispatcher-base.js:148:28)",
    "    at Pool.connect (/node_modules/undici/lib/api/api-connect.js:100:10)"
  ]
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingresearchingThis item is currently under consideration and we'll update once we have more infotracerThis item relates to the Tracer Utility

Type

No type

Projects

Status

Working on it

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions