question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Knex database spans not recorded when using async/await

See original GitHub issue

Describe 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:

  1. Use this config ‘…’
  2. Then call ‘…’
  3. Then do ‘…’
  4. 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:open
  • Created 5 years ago
  • Reactions:3
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
PaulMougelcommented, Jan 3, 2020

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?

2reactions
watsoncommented, Feb 28, 2019

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…

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found