Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion lib/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
}
Expand Down
7 changes: 5 additions & 2 deletions test/diagnostics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading