apm-agent-nodejs icon indicating copy to clipboard operation
apm-agent-nodejs copied to clipboard

Custom Transactions not instrumenting mongoDB calls

Open ppatel890 opened this issue 5 years ago • 3 comments

Describe the bug I am using the custom transaction api to start a transaction when a 'request' comes in on socket.io. I am able to see the transaction in the dashboard, but the calls to mongodb are not instrumented properly. When calling the same code path with a REST request, things seem to work find.

To Reproduce

Steps to reproduce the behavior:

  1. Use this config '...'
  2. Then call '....'
  3. Then do '....'
  4. See error

Expected behavior The request timeline should show spans of MongoDB calls

Environment (please complete the following information)

  • OS: Mac OS X
  • Node.js version: v10.16.3
  • APM Server version: 7.6.1
  • Agent version: 3.5.0

How are you starting the agent? (please tick one of the boxes)

  • [x] Calling agent.start() directly (e.g. require('elastic-apm-node').start(...))
  • [ ] Requiring elastic-apm-node/start from within the source code
  • [ ] Starting node with -r elastic-apm-node/start

Additional context

Code Sample

  const trans = apm.startTransaction(name, 'socket');
  // Do some stuff that calls mongodb
  trans.end()

Socket Request: Screen Shot 2020-03-25 at 2 52 26 PM

vs. REST Request: Screen Shot 2020-03-25 at 2 53 50 PM

ppatel890 avatar Mar 25 '20 21:03 ppatel890

As an update, here are the trace logs, seems like the mongodb-core instrumentation can't find the current transaction. If I use a custom transaction for a background task to run this same code path, thing seem to work as expected, so seems to be an issue with how I am starting/ending custom transactions with the websocket requests

intercepted call to ws.prototype.send { id: null }
start trace { trans: '621b3beb00202cf0',
  parent: undefined,
  trace: '8a4477ba1f040b5e144cc41a9fdd5790',
  name: 'unnamed',
  type: null,
  subtype: null,
  action: null }
setting transaction name { trans: '621b3beb00202cf0',
  parent: undefined,
  trace: '8a4477ba1f040b5e144cc41a9fdd5790',
  name: 'GET workers/21872b54-594c-42a6-ae38-fef09fa86ec4' }
intercepted call to mongodb-core.Cursor.prototype.next { id: null }
intercepted call to mongodb-core.Cursor.prototype.next { id: null }
intercepted call to mongodb-core.Cursor.prototype.next { id: null }
setting transaction result { trans: '621b3beb00202cf0',
  parent: undefined,
  trace: '8a4477ba1f040b5e144cc41a9fdd5790',
  result: 'success' }
WARNING: no currentTransaction found { current: null,
  spans: 0,
  trans: '621b3beb00202cf0',
  parent: undefined,
  trace: '8a4477ba1f040b5e144cc41a9fdd5790' }
sending transaction { trans: '621b3beb00202cf0',
  trace: '8a4477ba1f040b5e144cc41a9fdd5790' }
ended transaction { trans: '621b3beb00202cf0',
  parent: undefined,
  trace: '8a4477ba1f040b5e144cc41a9fdd5790',
  type: 'socket',
  result: 'success',
  name: 'GET workers/21872b54-594c-42a6-ae38-fef09fa86ec4' }
no active transaction found - cannot build new span
intercepted call to ws.prototype.send { id: null }

ppatel890 avatar Mar 26 '20 22:03 ppatel890

Having the same issue, but setting asyncHooks to false seems to solve the issue?

simllll avatar Oct 29 '20 17:10 simllll

anybody solved this ?

sibelius avatar Jan 15 '24 14:01 sibelius