undici
undici copied to clipboard
Enable debug information for `fetch()` via `NODE_DEBUG=http`
What is the problem this feature will solve?
The HTTP debug information for node-fetch can be turned on by setting the the environment variable NODE_DEBUG=http
:
// node-fetch.test.js
const fetch = require('node-fetch');
fetch('https://github.com')
.then(({statusText}) => console.log(statusText));
$ NODE_DEBUG=http node node-fetch.test.js
HTTP 22032: call onSocket 0 0
HTTP 22032: createConnection github.com:443::::::::::::::::::::: [Object: null prototype] {
protocol: 'https:',
slashes: true,
[redacted]
HTTP 22032: AGENT incoming response!
OK
HTTP 22032: AGENT socket.destroySoon()
HTTP 22032: CLIENT socket onClose
HTTP 22032: removeSocket github.com:443::::::::::::::::::::: writable: false
HTTP 22032: HTTP socket close
Unfortunately, there is no HTTP debug information is shown when the native fetch()
implementation is used:
// fetch.test.js
fetch('https://github.com')
.then(({statusText}) => console.log(statusText));
$ NODE_DEBUG=http node fetch.test.js
OK
Seeing the HTTP request object can be considered as useful for debugging.
What is the feature you are proposing to solve the problem?
- Either display the HTTP debug statement for the native
fetch()
whenNODE_DEBUG=http
is active or - introduce a new flag to display HTTP debug output.
What alternatives have you considered?
The native fetch()
is presenting more information when NODE_DEBUG=net,stream
is used. This information is, however, not suitable for HTTP debugging.
Would diagnostics_channel be sufficient?
You can inspect in any stage according to the document. https://github.com/nodejs/undici/blob/main/docs/api/DiagnosticsChannel.md
Related https://github.com/nodejs/undici/issues/1001
When attempting to figure out what's broken in a node-based CLI tool or similar scenarios where the code isn't owned by the person seeing the error, being able to add NODE_DEBUG=http was extremely useful for seeing what's going on.
It would be great if newer versions of Node could preserve this debug interface.
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.
For more information on how the project manages feature requests, please consult the feature request management document.
@nodejs/undici wdyt?
I think this would be a good feature to add to undici
. As said by @climba03003, I would recommended building it on top of the diagnostics channel support that we have in Undici.
As with most feature requests, this lacks a volunteer to send a PR.
I'm going to move it to undici.
Any advice here on how to tell what request params are involved in the error:
[APP] TypeError: fetch failed
[APP] at Object.fetch (node:internal/deps/undici/undici:11372:11)
[APP] at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
[APP] cause: _ConnectTimeoutError: Connect Timeout Error
[APP] at onConnectTimeout (node:internal/deps/undici/undici:6616:28)
[APP] at node:internal/deps/undici/undici:6574:50
[APP] at Immediate._onImmediate (node:internal/deps/undici/undici:6605:13)
[APP] at process.processImmediate (node:internal/timers:478:21)
[APP] at process.callbackTrampoline (node:internal/async_hooks:130:17) {
[APP] code: 'UND_ERR_CONNECT_TIMEOUT'
[APP] }
[APP] }