From fd5fd24d223be4b6ed4f5420b733a725f0b921d5 Mon Sep 17 00:00:00 2001 From: Arya Date: Fri, 19 Sep 2025 15:40:42 +0530 Subject: [PATCH 1/2] fix: provide fallback for diagChannel.tracingChannel in older Node versions --- lib/tools.js | 14 +++++++++++++- test/diagnostics.test.js | 7 +++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/tools.js b/lib/tools.js index 5cd5825a4..efd6197f3 100644 --- a/lib/tools.js +++ b/lib/tools.js @@ -28,7 +28,19 @@ const { const { isMainThread } = require('worker_threads') const transport = require('./transport') -const asJsonChan = diagChan.tracingChannel('pino_asJson') +let asJsonChan +// Node >= 18.19 supports diagnostics_channel.tracingChannel +if (typeof diagChan.tracingChannel === 'function') { + asJsonChan = diagChan.tracingChannel('pino_asJson') +} else { + // Older Node 18.x (e.g. 18.18), provided a no-op fallback + asJsonChan = { + hasSubscribers: false, + traceSync (fn, store, thisArg, ...args) { + return fn.call(thisArg, ...args) + } + } +} function noop () { } diff --git a/test/diagnostics.test.js b/test/diagnostics.test.js index 143892011..2291fa898 100644 --- a/test/diagnostics.test.js +++ b/test/diagnostics.test.js @@ -13,6 +13,9 @@ const { pid } = process const AS_JSON_START = 'tracing:pino_asJson:start' const AS_JSON_END = 'tracing:pino_asJson:end' +// Skip tests if diagnostics_channel.tracingChannel is not available (Node < 18.19) +const skip = typeof diagChan.tracingChannel !== 'function' + test.beforeEach(ctx => { ctx.pino = { ts: 1757512800000, // 2025-09-10T10:00:00.000-05:00 @@ -33,7 +36,7 @@ test.afterEach(ctx => { Date.now = ctx.pino.now }) -test('asJson emits events', async (t) => { +test('asJson emits events', { skip }, async (t) => { const plan = tspl(t, { plan: 8 }) const { dest } = t.pino const logger = pino({}, dest) @@ -74,7 +77,7 @@ test('asJson emits events', async (t) => { } }) -test('asJson context is not lost', async (t) => { +test('asJson context is not lost', { skip }, async (t) => { const plan = tspl(t, { plan: 2 }) const { dest } = t.pino const logger = pino({}, dest) From e39299369f065d415e1df3f3827532e503af4eea Mon Sep 17 00:00:00 2001 From: Arya Date: Fri, 19 Sep 2025 20:45:43 +0530 Subject: [PATCH 2/2] ci: add node 18.18 to test matrix --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 39eeca43f..522254d04 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,7 +43,7 @@ jobs: fail-fast: false matrix: os: [macOS-latest, windows-latest, ubuntu-latest] - node-version: [18, 20, 22] + node-version: [18, '18.18', 20, 22] exclude: - os: windows-latest node-version: 22