Skip to content

Commit

Permalink
diagnostics-channel: use not deprecated subscribe fn
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak committed Sep 13, 2024
1 parent 0b287b9 commit b5e7c93
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 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,7 +36,8 @@ function trackClientEvents (debugLog = undiciDebugLog) {

isTrackingClientEvents = true

diagnosticsChannel.channel('undici:client:beforeConnect').subscribe(evt => {
diagnosticsChannel.subscribe('undici:client:beforeConnect',

Check failure on line 39 in lib/core/diagnostics.js

View workflow job for this annotation

GitHub Actions / Lint

Trailing spaces not allowed
evt => {
const {

Check failure on line 41 in lib/core/diagnostics.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 6 spaces but found 4
connectParams: { version, protocol, port, host }

Check failure on line 42 in lib/core/diagnostics.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 8 spaces but found 6
} = evt

Check failure on line 43 in lib/core/diagnostics.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 6 spaces but found 4
Expand All @@ -48,7 +50,8 @@ function trackClientEvents (debugLog = undiciDebugLog) {
)
})

diagnosticsChannel.channel('undici:client:connected').subscribe(evt => {
diagnosticsChannel.subscribe('undici:client:connected',
evt => {
const {
connectParams: { version, protocol, port, host }
} = evt
Expand All @@ -61,7 +64,8 @@ function trackClientEvents (debugLog = undiciDebugLog) {
)
})

diagnosticsChannel.channel('undici:client:connectError').subscribe(evt => {
diagnosticsChannel.subscribe('undici:client:connectError',
evt => {
const {
connectParams: { version, protocol, port, host },
error
Expand All @@ -76,7 +80,8 @@ function trackClientEvents (debugLog = undiciDebugLog) {
)
})

diagnosticsChannel.channel('undici:client:sendHeaders').subscribe(evt => {
diagnosticsChannel.subscribe('undici:client:sendHeaders',
evt => {
const {
request: { method, path, origin }
} = evt
Expand All @@ -93,7 +98,8 @@ function trackRequestEvents (debugLog = undiciDebugLog) {

isTrackingRequestEvents = true

diagnosticsChannel.channel('undici:request:headers').subscribe(evt => {
diagnosticsChannel.subscribe('undici:request:headers',
evt => {
const {
request: { method, path, origin },
response: { statusCode }
Expand All @@ -107,14 +113,16 @@ function trackRequestEvents (debugLog = undiciDebugLog) {
)
})

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

diagnosticsChannel.channel('undici:request:error').subscribe(evt => {
diagnosticsChannel.subscribe('undici:request:error',
evt => {
const {
request: { method, path, origin },
error
Expand All @@ -138,14 +146,16 @@ function trackWebSocketEvents (debugLog = websocketDebuglog) {

isTrackingWebSocketEvents = true

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

diagnosticsChannel.channel('undici:websocket:close').subscribe(evt => {
diagnosticsChannel.subscribe('undici:websocket:close',
evt => {
const { websocket, code, reason } = evt
debugLog(
'closed connection to %s - %s %s',
Expand All @@ -155,15 +165,18 @@ function trackWebSocketEvents (debugLog = websocketDebuglog) {
)
})

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

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

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

0 comments on commit b5e7c93

Please sign in to comment.