Knex database spans not recorded when using async/await
See original GitHub issueDescribe the bug When a define a route wich uses knex to connect do the database, and use async await at the function definition, the apm agent does not send the sql span, not showing the sql info at the request timeline at kibana. The apm agent does not support async/await
To Reproduce Steps to reproduce the behavior:
- Use this config ‘…’
- Then call ‘…’
- Then do ‘…’
- See error
Expected behavior To show the sql span at the request timeline.
Environment (please complete the following information)
- OS: Linux
- Node.js version: v11.10.0
- APM Server version: 6.6.1
- Agent version: 2.5.1
How are you starting the agent? (please tick one of the boxes)
- 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 Add any other context about the problem here.
-
Agent config options
Click to expand
serviceName: 'service',
-
package.json
dependencies:Click to expand
"elastic-apm-node": "^2.5.1", "express": "^4.16.4", "knex": "^0.16.3", "mysql2": "^1.6.5"
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:14 (8 by maintainers)
Top Results From Across the Web
Most of the spans can't find current transaction - Elastic Discuss
Knex database spans not recorded when using async/await ... Describe the bug When a define a route wich uses knex to connect do...
Read more >knex transaction is not working with async await - Stack Overflow
const insertData = async (tableName, data) => { try { return await knex(tableName).insert(data); } catch (err) { logger.error('error ...
Read more >EnteredSpan in tracing::span - Rust - Docs.rs
Records that the field described by field has the value value . This may be used with field::Empty to declare fields whose values...
Read more >dd-trace - Datadog has moved
In most cases, it's not necessary to interact with the scope manager since tracer.trace() activates the span on its scope, and uses the...
Read more >Creating database queries with Knex - DEV Community
Using Knex to retrieve records in a REST API. ... and .catch() methods at the end of the function, or by using the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
FWI, we have the same issue when we use Objection.js (an SQL ORM): queries are not properly associated with the current transaction.
The trace logs show that no transaction is found, even though in our case we are processing a route response from hapi. If we manually create a span it is attached to the correct transaction, and knex requests are properly instrumented and associated with the transaction.
What is the recommended course of action?
Update: It’s somehow related to a combination of async/await and async hooks. A temporary workaround is to set
asyncHooks: false
in the agent config.I’ll continue to investigate to find a more permanent solution…