feat: Add tracing channel support#16275
Open
logaretm wants to merge 2 commits into
Open
Conversation
Add first-class Node.js TracingChannel (diagnostics_channel) support so APM tools can instrument Mongoose without monkey-patching. Four channels covering all operation types: - mongoose:query (Query.exec - find, update, delete, count, distinct) - mongoose:aggregate (Aggregate.exec) - mongoose:save (Model.prototype.save) - mongoose:model (insertMany, bulkWrite) Zero-cost when no subscribers are registered. Ref: Automattic#16105
Collapse 4 channels into one. All operations (find, save, aggregate, insertMany, bulkWrite) emit on mongoose:query with a common payload: operation, collection, database, serverAddress, serverPort, args. The args field carries operation-specific data (filter, pipeline, docs, ops) without imposing a typed shape — APM tools that need it can dig in.
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR explores adding tracing channels to enable agnostic observability for users and APMs alike without having to resort to monkey patching or module patchers.
Unlike the original proposal in #16105, I realized that one channel is cleaner and allows for creating all the needed span descriptions that currently exist in the OTEL instrumentation. This keeps the changes small and managable.
Implementation
So a single
mongoose:querychannel that emits the following payload:operationstringfind,updateOne,aggregate)collectionstringdatabasestringserverAddressstringserverPortnumberargsRecord<string, any>I also exported the types for use by consumers.
Example Consumer
this is what it looks like after consuming the events in an APM, which is inline with current instrumentations today.
closes #16105