Skip to content

Commit

Permalink
diagnostics-channel: use not deprecated subscribe fn (#3600)
Browse files Browse the repository at this point in the history
* diagnostics-channel: use not deprecated subscribe fn

* fix linting
  • Loading branch information
Uzlopak authored Sep 13, 2024
1 parent 0b287b9 commit c773728
Showing 1 changed file with 122 additions and 109 deletions.
231 changes: 122 additions & 109 deletions lib/core/diagnostics.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict'

const diagnosticsChannel = require('node:diagnostics_channel')
const util = require('node:util')

Expand Down Expand Up @@ -35,53 +36,57 @@ function trackClientEvents (debugLog = undiciDebugLog) {

isTrackingClientEvents = true

diagnosticsChannel.channel('undici:client:beforeConnect').subscribe(evt => {
const {
connectParams: { version, protocol, port, host }
} = evt
debugLog(
'connecting to %s%s using %s%s',
host,
port ? `:${port}` : '',
protocol,
version
)
})

diagnosticsChannel.channel('undici:client:connected').subscribe(evt => {
const {
connectParams: { version, protocol, port, host }
} = evt
debugLog(
'connected to %s%s using %s%s',
host,
port ? `:${port}` : '',
protocol,
version
)
})

diagnosticsChannel.channel('undici:client:connectError').subscribe(evt => {
const {
connectParams: { version, protocol, port, host },
error
} = evt
debugLog(
'connection to %s%s using %s%s errored - %s',
host,
port ? `:${port}` : '',
protocol,
version,
error.message
)
})

diagnosticsChannel.channel('undici:client:sendHeaders').subscribe(evt => {
const {
request: { method, path, origin }
} = evt
debugLog('sending request to %s %s/%s', method, origin, path)
})
diagnosticsChannel.subscribe('undici:client:beforeConnect',
evt => {
const {
connectParams: { version, protocol, port, host }
} = evt
debugLog(
'connecting to %s%s using %s%s',
host,
port ? `:${port}` : '',
protocol,
version
)
})

diagnosticsChannel.subscribe('undici:client:connected',
evt => {
const {
connectParams: { version, protocol, port, host }
} = evt
debugLog(
'connected to %s%s using %s%s',
host,
port ? `:${port}` : '',
protocol,
version
)
})

diagnosticsChannel.subscribe('undici:client:connectError',
evt => {
const {
connectParams: { version, protocol, port, host },
error
} = evt
debugLog(
'connection to %s%s using %s%s errored - %s',
host,
port ? `:${port}` : '',
protocol,
version,
error.message
)
})

diagnosticsChannel.subscribe('undici:client:sendHeaders',
evt => {
const {
request: { method, path, origin }
} = evt
debugLog('sending request to %s %s/%s', method, origin, path)
})
}

let isTrackingRequestEvents = false
Expand All @@ -93,40 +98,43 @@ function trackRequestEvents (debugLog = undiciDebugLog) {

isTrackingRequestEvents = true

diagnosticsChannel.channel('undici:request:headers').subscribe(evt => {
const {
request: { method, path, origin },
response: { statusCode }
} = evt
debugLog(
'received response to %s %s/%s - HTTP %d',
method,
origin,
path,
statusCode
)
})

diagnosticsChannel.channel('undici:request:trailers').subscribe(evt => {
const {
request: { method, path, origin }
} = evt
debugLog('trailers received from %s %s/%s', method, origin, path)
})

diagnosticsChannel.channel('undici:request:error').subscribe(evt => {
const {
request: { method, path, origin },
error
} = evt
debugLog(
'request to %s %s/%s errored - %s',
method,
origin,
path,
error.message
)
})
diagnosticsChannel.subscribe('undici:request:headers',
evt => {
const {
request: { method, path, origin },
response: { statusCode }
} = evt
debugLog(
'received response to %s %s/%s - HTTP %d',
method,
origin,
path,
statusCode
)
})

diagnosticsChannel.subscribe('undici:request:trailers',
evt => {
const {
request: { method, path, origin }
} = evt
debugLog('trailers received from %s %s/%s', method, origin, path)
})

diagnosticsChannel.subscribe('undici:request:error',
evt => {
const {
request: { method, path, origin },
error
} = evt
debugLog(
'request to %s %s/%s errored - %s',
method,
origin,
path,
error.message
)
})
}

let isTrackingWebSocketEvents = false
Expand All @@ -138,34 +146,39 @@ function trackWebSocketEvents (debugLog = websocketDebuglog) {

isTrackingWebSocketEvents = true

diagnosticsChannel.channel('undici:websocket:open').subscribe(evt => {
const {
address: { address, port }
} = evt
debugLog('connection opened %s%s', address, port ? `:${port}` : '')
})

diagnosticsChannel.channel('undici:websocket:close').subscribe(evt => {
const { websocket, code, reason } = evt
debugLog(
'closed connection to %s - %s %s',
websocket.url,
code,
reason
)
})

diagnosticsChannel.channel('undici:websocket:socket_error').subscribe(err => {
debugLog('connection errored - %s', err.message)
})

diagnosticsChannel.channel('undici:websocket:ping').subscribe(evt => {
debugLog('ping received')
})

diagnosticsChannel.channel('undici:websocket:pong').subscribe(evt => {
debugLog('pong received')
})
diagnosticsChannel.subscribe('undici:websocket:open',
evt => {
const {
address: { address, port }
} = evt
debugLog('connection opened %s%s', address, port ? `:${port}` : '')
})

diagnosticsChannel.subscribe('undici:websocket:close',
evt => {
const { websocket, code, reason } = evt
debugLog(
'closed connection to %s - %s %s',
websocket.url,
code,
reason
)
})

diagnosticsChannel.subscribe('undici:websocket:socket_error',
err => {
debugLog('connection errored - %s', err.message)
})

diagnosticsChannel.subscribe('undici:websocket:ping',
evt => {
debugLog('ping received')
})

diagnosticsChannel.subscribe('undici:websocket:pong',
evt => {
debugLog('pong received')
})
}

if (undiciDebugLog.enabled || fetchDebuglog.enabled) {
Expand Down

0 comments on commit c773728

Please # to comment.