From b7d982e5ea3c4050a6c41e3b934ede3bc41fcce8 Mon Sep 17 00:00:00 2001 From: Demian Parkhomenko <95881717+DemianParkhomenko@users.noreply.github.com> Date: Thu, 19 Feb 2026 00:52:23 +0100 Subject: [PATCH 1/2] feat: add diagnostics_channel support for app initialization --- lib/application.js | 1 + lib/diagnostics.js | 7 +++++++ lib/express.js | 6 ++++++ test/diagnostics-channel.js | 26 ++++++++++++++++++++++++++ 4 files changed, 40 insertions(+) create mode 100644 lib/diagnostics.js create mode 100644 test/diagnostics-channel.js diff --git a/lib/application.js b/lib/application.js index 47be2a20c1a..927d093be57 100644 --- a/lib/application.js +++ b/lib/application.js @@ -24,6 +24,7 @@ var compileTrust = require('./utils').compileTrust; var resolve = require('node:path').resolve; var once = require('once') var Router = require('router'); +const channels = require('./diagnostics'); /** * Module variables. diff --git a/lib/diagnostics.js b/lib/diagnostics.js new file mode 100644 index 00000000000..f11044a2dad --- /dev/null +++ b/lib/diagnostics.js @@ -0,0 +1,7 @@ +'use strict'; + +const dc = require('node:diagnostics_channel'); + +const initialization = dc.channel('express.initialization'); + +module.exports = { initialization }; diff --git a/lib/express.js b/lib/express.js index 2d502eb54e4..33309fa8435 100644 --- a/lib/express.js +++ b/lib/express.js @@ -19,6 +19,7 @@ var proto = require('./application'); var Router = require('router'); var req = require('./request'); var res = require('./response'); +const channels = require('./diagnostics'); /** * Expose `createApplication()`. @@ -52,6 +53,11 @@ function createApplication() { }) app.init(); + + if (channels.initialization.hasSubscribers) { + channels.initialization.publish({ express: app }); + } + return app; } diff --git a/test/diagnostics-channel.js b/test/diagnostics-channel.js new file mode 100644 index 00000000000..92e212c1c73 --- /dev/null +++ b/test/diagnostics-channel.js @@ -0,0 +1,26 @@ +'use strict' + +const dc = require('node:diagnostics_channel') +const express = require('../') +const assert = require('node:assert') + +describe('diagnostics channels', function () { + describe('express.initialization', function () { + it('should publish when app is created', function () { + let msg + + dc.subscribe('express.initialization', function handler (data) { + msg = data + dc.unsubscribe('express.initialization', handler) + }) + + const app = express() + assert.ok(msg, 'express.initialization was not published') + assert.strictEqual(msg.express, app) + }) + + it('should not throw when there are no subscribers', function () { + assert.ok(express()) + }) + }) +}) From 73207d493d23c160714d13685638e596119423d4 Mon Sep 17 00:00:00 2001 From: Demian Parkhomenko <95881717+DemianParkhomenko@users.noreply.github.com> Date: Fri, 20 Feb 2026 11:16:08 +0100 Subject: [PATCH 2/2] Fix contract of diagnostics channel publish --- lib/application.js | 1 - lib/express.js | 2 +- test/diagnostics-channel.js | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/application.js b/lib/application.js index 927d093be57..47be2a20c1a 100644 --- a/lib/application.js +++ b/lib/application.js @@ -24,7 +24,6 @@ var compileTrust = require('./utils').compileTrust; var resolve = require('node:path').resolve; var once = require('once') var Router = require('router'); -const channels = require('./diagnostics'); /** * Module variables. diff --git a/lib/express.js b/lib/express.js index 33309fa8435..c4b1173ec13 100644 --- a/lib/express.js +++ b/lib/express.js @@ -55,7 +55,7 @@ function createApplication() { app.init(); if (channels.initialization.hasSubscribers) { - channels.initialization.publish({ express: app }); + channels.initialization.publish({ app }); } return app; diff --git a/test/diagnostics-channel.js b/test/diagnostics-channel.js index 92e212c1c73..c4ed76ea829 100644 --- a/test/diagnostics-channel.js +++ b/test/diagnostics-channel.js @@ -16,7 +16,7 @@ describe('diagnostics channels', function () { const app = express() assert.ok(msg, 'express.initialization was not published') - assert.strictEqual(msg.express, app) + assert.strictEqual(msg.app, app) }) it('should not throw when there are no subscribers', function () {