Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-5639

Bind current execution context to command callbacks

    • Type: Icon: New Feature New Feature
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: CMAP

      How are you using Mongo? What version of the server and driver are you using?

      MongoDb is used as a storage for an application which is instrumented to get APM data.

      Server version: 5 (via docker image)

      Driver version: 5.9.0

      What is the feature/improvement you would like?

      The driver queues the commands to be sent to the server until a connection is available into the connection_pool. That queue is flushed in the same context which, for most of the commands, is not the same context where the command was created.

      As a consequence APM spans produced by agents like Elastic or Opentelemetry get the wrong parent ID. There is a repo which explains the issue and proposes a fix

      https://github.com/david-luna/node-mongodb-native-async-resource

       

      The issue has been already reported for Elastic APM agent 

      https://github.com/elastic/apm-agent-nodejs/issues/3161

       

      What use case would this feature/improvement enable?

      By binding the execution context to the callbacks queued in the connection pool APM tools will get the that context right and will be able to properly trace MongoDB commands. This will enable observability on NodeJS apps using MongoDB driver.

            Assignee:
            Unassigned Unassigned
            Reporter:
            luna.bistuer@gmail.com David Luna
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: