Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diagnostics_channel: capture console messages #56292

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Qard
Copy link
Member

@Qard Qard commented Dec 17, 2024

I've added diagnostics_channel support to capture and modify inputs to the main console methods. This enables some useful things like APMs injecting tracing data into log messages to correlate log messages to the requests from which they originated. You can also replace the args list entirely, so you could apply your own custom formatting to produce JSON logs instead or things like that.

cc @nodejs/diagnostics @nodejs/console

@Qard Qard added console Issues and PRs related to the console subsystem. diagnostics_channel Issues and PRs related to diagnostics channel labels Dec 17, 2024
@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Dec 17, 2024
@Qard Qard force-pushed the console-diagnostics-channels branch from 6ba11e5 to 07fbcd4 Compare December 17, 2024 16:11
@Qard Qard marked this pull request as ready for review December 17, 2024 16:12
@Qard Qard added the request-ci Add this label to start a Jenkins CI on a PR. label Dec 17, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Dec 17, 2024
@nodejs-github-bot
Copy link
Collaborator

@Qard Qard force-pushed the console-diagnostics-channels branch from 07fbcd4 to 8094626 Compare December 17, 2024 16:22
@Qard Qard force-pushed the console-diagnostics-channels branch from 8094626 to b3830bf Compare December 17, 2024 16:56
@eugeneo
Copy link
Contributor

eugeneo commented Dec 17, 2024

I lack context on this, so I might be missing some point.

Can this use the Inspector protocol instead of adding hooks directly into console object. In-process inspector API can be configured to watch for the messages? This way there will be less coupling.

@Qard
Copy link
Member Author

Qard commented Dec 17, 2024

The Inspector API is substantially more expensive. This is meant for being able to rewrite potentially all log messages in production, so it needs to be fast.

@eugeneo
Copy link
Contributor

eugeneo commented Dec 17, 2024

Thanks for the reply.

@Flarna
Copy link
Member

Flarna commented Dec 17, 2024

Maybe worth to extend test to verify adding/removing/replacing elements,

Main problem I see with mutating diagnostics channels is the undefined sequence if there are more subscribers.


* `args` {any\[]}

Emitted when `console.log()` is called. Receives and array of the arguments
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe describe that this is the arguments array and therefore mutation is possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
console Issues and PRs related to the console subsystem. diagnostics_channel Issues and PRs related to diagnostics channel needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants