-
Notifications
You must be signed in to change notification settings - Fork 155
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
[fetch] does not support fetch options like proxy #650
Comments
Hi, you should be able to pass options into the fetch call. For example, the following code sample will change the method type used in fetch from GET to POST. This will be reflected in the trace as well.
The options are added into the fetch call through the aws-xray-sdk-node/sdk_contrib/fetch/lib/fetch_p.js Lines 63 to 117 in 73e1fca
|
Hey, what you say is true but With fetch you can set the dispatcher and the request will go through the Proxy. import { ProxyAgent } from 'undici';
fetch("http://localhost", {
dispatcher: new ProxyAgent("http://localhost:4444"),
})); If we create a request with similar options like this: import { ProxyAgent } from 'undici';
const request = new Request("http://localhost", {
dispatcher: new ProxyAgent("http://localhost:4444"),
});
fetch(request) The Request does not contain the dispatcher option and the request will not pass through the proxy. So inside the |
I see. In this case, the fetch function should not automatically pass the arguments into a Request object as it currently does here: Instead, if the Fetch options are supplied like in your first example, the original object that is passed into the instrumented fetch client should be used when the baseFetchFunction is called. We would welcome a PR from your end if you have a fix in mind! |
Alright sounds good. I'll take a stab at it :) |
Hey @jj22ee, |
Closing issue as PR is merged. This fix will be in the next release. |
Hi @Kruspe, we have reverted the change in #687 in I've re-opened this issue. I think we can take another look at the initial approach in your original PR (627b6df) with some additional changes:
|
I'll take a look tomorrow and see what the issue is. Thanks for the heads up! |
Hey @jj22ee, the PR is there to implement this again. Have a look at let me know what you think. During my testing I noticed that we ignore headers that are set by users if they do this: fetch(new Request("https://somewhere.com"), {headers: {"foo": "bar"}}); These headers will never reach the server as we ignore them. This is different from the original fetch implementation that still respects those headers and will add them to the request. Maybe it would make more sense to add the |
When using the
aws-xray-sdk-fetch
instrumentation it is not possible to supply further options to the fetch call like the agent to supply the undici ProxyAgent.The
capturedFetch
call only calls the global available fetch call with one argumentaws-xray-sdk-node/sdk_contrib/fetch/lib/fetch_p.js
Line 117 in 73e1fca
I would propose to add a third option to the function that patches the global fetch. This would allow the user to use all fetch options and additionally supply their own segment information if required.
aws-xray-sdk-node/sdk_contrib/fetch/lib/fetch_p.js
Line 59 in 73e1fca
For this change it would be necessary to think about how not to introduce a breaking change for users that expect the second argument to be used for segment information. But I guess we can write some internal logic to check the supplied args.
Once I receive some feedback I can get started on a PR and implement the changes.
The text was updated successfully, but these errors were encountered: