feat: add diagnostic channels for request lifecycle#7171
feat: add diagnostic channels for request lifecycle#7171OussemaNehdi wants to merge 1 commit intoexpressjs:masterfrom
Conversation
Add Node.js diagnostics_channel support for observing Express request processing. This enables APM tools, monitoring systems, and instrumentation libraries to hook into Express without monkey-patching. Channels added: - express.request.start — published before routing begins - express.request.finish — published when the response is fully sent - express.request.error — published on connection-level errors All channels use hasSubscribers guards so there is zero overhead when no diagnostic tool is listening. Closes expressjs#6353
|
I think we should consider using tracing channels instead, for one they exist in Node 18 and they offer context propagation across the events emitted so APMs and subscribers don't have to do it manually. Also I think we should move it to |
|
Hi, Severity: action required | Category: correctness How to fix: Gate finish publish on !err Agent prompt to fix - you can give this to your LLM of choice:
We noticed a couple of other issues in this PR as well - happy to share if helpful. Spotted by Qodo code review - free for open-source projects. |
Summary
Adds
diagnostics_channelsupport for Express request lifecycle, as requestedin #6353. This enables APM and monitoring tools to observe request processing
without monkey-patching.
Channels
express.request.start{ req, res }express.request.finish{ req, res }express.request.error{ req, res, error }Design decisions
publish()call is guarded byhasSubscribers,so there is no performance cost when no diagnostic tool is listening
on-finishedfor completion tracking: Uses the existingon-finisheddependency (already used by
res.sendFile) to detect when the response isfully sent, covering all code paths including streaming and error responses
express.initializationchannel forapp startup. This PR covers the request lifecycle, which is the primary use
case for APM tools like OpenTelemetry and Datadog
Example usage