-
-
Notifications
You must be signed in to change notification settings - Fork 674
feat(#2191): Add support for NODE_DEBUG
#2585
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
143bb0a
feat: add debug support through diagnostics channel
metcoder95 67be3a8
refactor: replace old diagnostics with new abstraction
metcoder95 5750b6e
refactor: handle diagnostics simpler
metcoder95 d3b90f0
Merge branch 'main' into feat/debug
metcoder95 f0c25e8
test: move tests to 'right' path
metcoder95 97ddbc3
fix: smaller tweaks
metcoder95 4a16174
refactor: use debuglog instead
metcoder95 3c60f7a
docs: add documentation
metcoder95 e13d7a1
fix: code review
metcoder95 8515e0b
test: add testing coverage
metcoder95 b4c8883
refactor: remove leftover
metcoder95 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,214 @@ | ||
| let channels | ||
| try { | ||
| const diagnosticsChannel = require('diagnostics_channel') | ||
| let isClientSet = false | ||
| channels = { | ||
| // Client | ||
| beforeConnect: diagnosticsChannel.channel('undici:client:beforeConnect'), | ||
| connected: diagnosticsChannel.channel('undici:client:connected'), | ||
| connectError: diagnosticsChannel.channel('undici:client:connectError'), | ||
| sendHeaders: diagnosticsChannel.channel('undici:client:sendHeaders'), | ||
| // Request | ||
| create: diagnosticsChannel.channel('undici:request:create'), | ||
| bodySent: diagnosticsChannel.channel('undici:request:bodySent'), | ||
| headers: diagnosticsChannel.channel('undici:request:headers'), | ||
| trailers: diagnosticsChannel.channel('undici:request:trailers'), | ||
| error: diagnosticsChannel.channel('undici:request:error'), | ||
| // WebSocket | ||
| open: diagnosticsChannel.channel('undici:websocket:open'), | ||
| close: diagnosticsChannel.channel('undici:websocket:close'), | ||
| socketError: diagnosticsChannel.channel('undici:websocket:socket_error'), | ||
| ping: diagnosticsChannel.channel('undici:websocket:ping'), | ||
| pong: diagnosticsChannel.channel('undici:websocket:pong') | ||
| } | ||
|
|
||
| if (process.env.NODE_DEBUG.match(/(fetch|undici)/) != null) { | ||
| // Track all Client events | ||
| diagnosticsChannel.channel('undici:client:beforeConnect').subscribe(evt => { | ||
| const { | ||
| connectParams: { version, protocol, port, host } | ||
| } = evt | ||
| console.log( | ||
| `HTTP:undici ${process.pid}: connecting to ${host}${ | ||
| port ? `:${port}` : '' | ||
| } using ${protocol}${version}` | ||
| ) | ||
| }) | ||
|
|
||
| diagnosticsChannel.channel('undici:client:connected').subscribe(evt => { | ||
| const { | ||
| connectParams: { version, protocol, port, host } | ||
| } = evt | ||
| console.log( | ||
| `HTTP:undici ${process.pid}: connected to ${host}${ | ||
| port ? `:${port}` : '' | ||
| } using ${protocol}${version}` | ||
| ) | ||
| }) | ||
|
|
||
| diagnosticsChannel.channel('undici:client:connectError').subscribe(evt => { | ||
| const { | ||
| connectParams: { version, protocol, port, host }, | ||
| error | ||
| } = evt | ||
| console.log( | ||
| `HTTP:undici ${process.pid}: connection to ${host}${ | ||
| port ? `:${port}` : '' | ||
| } using ${protocol}${version} errored - ${error.message}` | ||
| ) | ||
| }) | ||
|
|
||
| diagnosticsChannel.channel('undici:client:sendHeaders').subscribe(evt => { | ||
| const { | ||
| request: { method, path, origin } | ||
| } = evt | ||
| console.log( | ||
| `HTTP:undici ${process.pid}: sending request to ${method} ${origin}/${path}` | ||
| ) | ||
| }) | ||
|
|
||
| // Track Request events | ||
| diagnosticsChannel.channel('undici:request:headers').subscribe(evt => { | ||
| const { | ||
| request: { method, path, origin }, | ||
| response: { statusCode } | ||
| } = evt | ||
| console.log( | ||
| `HTTP:undici ${process.pid}: received response ${method} ${origin}/${path} - HTTP ${statusCode}` | ||
| ) | ||
| }) | ||
|
|
||
| diagnosticsChannel.channel('undici:request:trailers').subscribe(evt => { | ||
| const { | ||
| request: { method, path, origin } | ||
| } = evt | ||
| console.log( | ||
| `HTTP:undici ${process.pid}: trailers received from ${method} ${origin}/${path}` | ||
| ) | ||
| }) | ||
|
|
||
| diagnosticsChannel.channel('undici:request:error').subscribe(evt => { | ||
| const { | ||
| request: { method, path, origin }, | ||
| error | ||
| } = evt | ||
| console.log( | ||
| `HTTP:undici ${process.pid}: request errored ${method} ${origin}/${path} - ${error.message}` | ||
| ) | ||
| }) | ||
|
|
||
| isClientSet = true | ||
| } | ||
|
|
||
| if (process.env.NODE_DEBUG.match(/websocket/) != null) { | ||
| if (!isClientSet) { | ||
| diagnosticsChannel | ||
| .channel('undici:client:beforeConnect') | ||
| .subscribe(evt => { | ||
| const { | ||
| connectParams: { version, protocol, port, host } | ||
| } = evt | ||
| console.log( | ||
| `HTTP:undici ${process.pid}: connecting to ${host}${ | ||
| port ? `:${port}` : '' | ||
| } using ${protocol}${version}` | ||
| ) | ||
| }) | ||
|
|
||
| diagnosticsChannel.channel('undici:client:connected').subscribe(evt => { | ||
| const { | ||
| connectParams: { version, protocol, port, host } | ||
| } = evt | ||
| console.log( | ||
| `HTTP:undici ${process.pid}: connected to ${host}${ | ||
| port ? `:${port}` : '' | ||
| } using ${protocol}${version}` | ||
| ) | ||
| }) | ||
|
|
||
| diagnosticsChannel | ||
| .channel('undici:client:connectError') | ||
| .subscribe(evt => { | ||
| const { | ||
| connectParams: { version, protocol, port, host }, | ||
| error | ||
| } = evt | ||
| console.log( | ||
| `HTTP:undici ${process.pid}: connection to ${host}${ | ||
| port ? `:${port}` : '' | ||
| } using ${protocol}${version} errored - ${error.message}` | ||
| ) | ||
| }) | ||
|
|
||
| diagnosticsChannel.channel('undici:client:sendHeaders').subscribe(evt => { | ||
| const { | ||
| request: { method, path, origin } | ||
| } = evt | ||
| console.log( | ||
| `HTTP:undici ${process.pid}: sending request to ${method} ${origin}/${path}` | ||
| ) | ||
| }) | ||
| } | ||
|
|
||
| // Track all Client events | ||
| diagnosticsChannel.channel('undici:websocket:open').subscribe(evt => { | ||
| const { | ||
| address: { address, port }, | ||
| protocol, | ||
| extensions | ||
| } = evt | ||
| console.log( | ||
| `WebSocket:undici ${process.pid}: connection opened ${address}${ | ||
| port ? `:${port}` : '' | ||
| } using ${protocol}-${extensions}` | ||
| ) | ||
| }) | ||
|
|
||
| diagnosticsChannel.channel('undici:websocket:close').subscribe(evt => { | ||
| const { websocket, code, reason } = evt | ||
| console.log( | ||
| `WebSocket:undici ${process.pid}: closed connection to ${websocket.url} - ${code} ${reason}` | ||
| ) | ||
| }) | ||
|
|
||
| diagnosticsChannel | ||
| .channel('undici:websocket:socket_error') | ||
| .subscribe(err => { | ||
| console.log( | ||
| `WebSocket:undici ${process.pid}: connection errored - ${err.message}` | ||
| ) | ||
| }) | ||
|
|
||
| diagnosticsChannel.channel('undici:websocket:ping').subscribe(evt => { | ||
| console.log(`WebSocket:undici ${process.pid}: ping received`) | ||
| }) | ||
|
|
||
| diagnosticsChannel.channel('undici:websocket:pong').subscribe(evt => { | ||
| console.log(`WebSocket:undici ${process.pid}: pong received`) | ||
| }) | ||
| } | ||
| } catch (error) { | ||
| channels = { | ||
| // Client | ||
| sendHeaders: { hasSubcribers: false }, | ||
| beforeConnect: { hasSubcribers: false }, | ||
| connectError: { hasSubcribers: false }, | ||
| connected: { hasSubcribers: false }, | ||
| // Request | ||
| create: { hasSubcribers: false }, | ||
| bodySent: { hasSubcribers: false }, | ||
| headers: { hasSubcribers: false }, | ||
| trailers: { hasSubcribers: false }, | ||
| error: { hasSubcribers: false }, | ||
| // WebSocket | ||
| open: { hasSubcribers: false }, | ||
| close: { hasSubcribers: false }, | ||
| socketError: { hasSubcribers: false }, | ||
| ping: { hasSubcribers: false }, | ||
| pong: { hasSubcribers: false } | ||
| } | ||
| } | ||
|
|
||
| module.exports = { | ||
| channels | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.