Custom Transactions not instrumenting mongoDB calls
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:
- Use this config '...'
- Then call '....'
- Then do '....'
- 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/startfrom 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:

vs. REST Request:

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 }
Having the same issue, but setting asyncHooks to false seems to solve the issue?
anybody solved this ?