Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support knex/thenables #598

Open
JaneJeon opened this issue Jan 22, 2021 · 12 comments
Open

Support knex/thenables #598

JaneJeon opened this issue Jan 22, 2021 · 12 comments

Comments

@JaneJeon
Copy link

Hi, I googled this but was unable to find any reference to this.

Currently, knex.js (which is a heavily used/depended-on library in the nodejs space) basically “slurps up” .then() chains, which means it removes reference to the original stack trace on every async call. This is a well-known issue, and both datadog and elastic-apm have specifically built workarounds for this:

https://github.com/DataDog/dd-trace-js/blob/master/packages/datadog-plugin-knex/src/index.js

https://github.com/elastic/apm-agent-nodejs/blob/master/lib/instrumentation/modules/knex.js

However, it does not seem like newrelic’s agent takes care of scenarios like this where the stack trace is lost through async calls (I believe it’s not only knex, but a couple of other libraries that have this behaviour as well - for example, I’ve heard that apollo-server also has a similar behaviour with async stack traces).

Currently, this would be a hard blocker for any production application utilizing knex.js directly or even indirectly to adopt newrelic’s APM. I don’t know if a fix for this is already implemented, but if not, I would request that newrelic’s APM implement it as well.

Thanks!

Related issues:
elastic/apm-agent-nodejs#873
DataDog/dd-trace-js#563

@carlo-808
Copy link
Contributor

Hi @JaneJeon ! Thank you for the request and the really thorough description of a possible workaround. I will bring this up with our Product Manager and we'll get this prioritized. If you're feeling ambitious, PRs are welcome to add this functionality. Thanks again!

@JaneJeon
Copy link
Author

Hi, any update on this? It is a hard blocker for not just me, but anyone using knex (or any library that uses its own promise implementation, which is a surprising number of them).

@michaelgoin
Copy link
Member

Hi @JaneJeon,

We do not yet have this scheduled on our roadmap. I know at least a few customers have asked for knex support so this will be balanced with those requests as the PM makes roadmap decisions. I'll go ahead and make them re-aware of this issue, too.

Thank you,

Michael

@taylorlapeyre
Copy link

Another +1! Having 0 visibility into queries in new relic just because of Knex is really a kick in the shin

@garbados
Copy link
Contributor

A user reported a workaround:

if we add an asCallback call to the query seems to make the built in pg instrumentation work through knex.

const results = await knexQuery.asCallback(() => {})

When we do this with our knex queries newrelic starts to record the database queries fine.

@dwjohnston
Copy link

For posterity, the asCallback solution didn't work for me.

Original code:

   await this.knexConnection(this.table).insert([newWorkflow]);
   return this.getById(workflowId);

Attempt one:

    const promise = new Promise((res, rej) => {

      this.knexConnection(this.table).insert([newWorkflow]).asCallback((err, rows) => {
        if (err) {
          rej(err);
        }

        else {

          this.getById(workflowId).then((result) => {
            res(result);
          }).catch((err) => {
            rej(err);
          })
    
        }
      });


    });
    
    return promise; 
    

Attempt two:

    await this.knexConnection(this.table).insert([newWorkflow]).asCallback(() => {}); 
    return this.getById(workflowId);

@robertoandrade
Copy link

Is it even worth voting on this FR anymore? https://discuss.newrelic.com/t/feature-idea-knex-support-in-nodejs-client/67212/7

@robertoandrade
Copy link

I'm considering as an alternative, ditching the newrelic node agent altogether and leveraging opentelemetry.io and its flexible and extensive list of instrumentation plugins (knex included: https://www.npmjs.com/package/@opentelemetry/instrumentation-knex) and configure it with a newrelic exporter to send that to newrelic for analysis. Perhaps others would want to check that out too.

@JaneJeon
Copy link
Author

@robertoandrade For what it's worth, I've simply switched over to ddog. I couldn't wait a year+ for this basic feature.

@pbeckerproaxiom
Copy link

We started using https://vincit.github.io/objection.js/ which uses Knex underneath, so we are running into this problem now as well. I'd be happy to lend a hand as needed, but I don't have much experience in the Node.js world.

@renatobenks
Copy link

I'm having this same problem in datadog as well, just to other people know that too.

@bizob2828 bizob2828 reopened this Jul 16, 2024
@workato-integration
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Triage Needed: Unprioritized Features
Development

No branches or pull requests

10 participants