elastic APM and NestJS does not differentiate graphql queries

829 views Asked by At

I am adding the elastic-apm-node package to our nestjs backend. I am using the graphql feature of nestjs. Because of this, all requests are merged together as /graphql in elastic.

Is this how it is supposed to be? I imagined that since apollo-server-express is supported by elastic-apm-node, which is also used by nestjs, it should be displaying it better. Am I missing something?

UPDATE

The graphql feature is set up using the docs for nestjs: https://docs.nestjs.com/graphql/quick-start it is basically their recommended setup I am using.

1

There are 1 answers

2
Alana Storm On

It's hard to say without knowing exactly how you're using NestJS and GraphQL together, and without knowing which parts of Apollo Server that NestJS itself uses. Seeing a small sample of what I am using the graphql feature of nestjs means would be useful.

Here's a few datapoints that might help you narrow things down. Also, opening an issue in the Agent repository or a question in their forums might get more of the right eyes on this.

The Elastic APM instrumentation for Apollo Server works by wrapping the runHttpQuery function of the apollo-server-core module, and marking the transaction with trans._graphqlRoute.

When the agent sees this _graphqlRoute property, it runs some code that will set a default name for the transaction

      if (trans._graphqlRoute) {
        var name = queries.length > 0 ? queries.join(', ') : 'Unknown GraphQL query'
        if (trans.req) var path = getPathFromRequest(trans.req, true)
        var defaultName = name
        defaultName = path ? defaultName + ' (' + path + ')' : defaultName
        defaultName = operationName ? operationName + ' ' + defaultName : defaultName
        trans.setDefaultName(defaultName)
        trans.type = 'graphql'
      }

In your application, either the _graphqlRoute property isn't getting set, or the renaming code above is doing something weird, or something about NestJS comes along and renames the transaction after it's been named with the above code.

Knowing more specifically what you're doing would help folks narrow in on your problems.