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

Only first request to application is passed with distributed tracing to New Relic #4312

Closed
zbowyer20 opened this issue Aug 16, 2022 · 1 comment

Comments

@zbowyer20
Copy link

zbowyer20 commented Aug 16, 2022

When using Mesh with the useNewRelic plugin, only the first request is sent to New Relic with all expected distributed tracing, limiting the granularity of the metrics we are able to monitor, including, for instance, how long was spent on different data sources.

For instance, with the following setup:
.meshrc.yaml:

sources:
  - name: Currencies
    handler:
      jsonSchema:
        baseUrl: https://api.coinbase.com/v2
        operations:
          - type: Query
            field: currencies
            path: /currencies
            method: GET
            responseSchema: "https://api.coinbase.com/v2/currencies"

  - name: Dogs
    handler:
      jsonSchema:
        baseUrl: https://dog.ceo/api/breeds/image
        operations:
          - type: Query
            field: dog
            path: /random
            method: GET
            responseSchema: "https://dog.ceo/api/breeds/image/random"


additionalEnvelopPlugins: "./envelop-plugins"
customFetch: "./custom-fetch.js"

envelop-plugins.ts:

import { useNewRelic } from "@envelop/newrelic"

export const pluginFactory = async() => {
  return [
    useNewRelic({
      includeOperationDocument: true,
      includeExecuteVariables: false,
      includeRawResult: false,
      trackResolvers: true,
      includeResolverArgs: false,
      rootFieldsNaming: true
    })
  ]
}

export default pluginFactory

custom-fetch.js:

const fetch = require('node-fetch')

module.exports = (url, args) => {
  return fetch(url, args)
}

(customFetch set as Mesh uses undici, which isn't supported by New Relic by default, and requires a feature flag to be set)

When making individual requests for both dogs and currencies, both should appear with full distributed tracing, listed as dependencies, on New Relic. But only the first reaches New Relic. For instance, if the dogs query comes first (crucial bits at the bottom of the screenshots, where we can see any API calls made):
dogs
currencies
dependencies

If the application is closed and a new instance booted up (pointing to a different New Relic app for this example), and the currencies query comes first:
currencies-first-currency
currencies-first-dog
currencies-first-dependencies

(if these had been sent to the same New Relic application as the first example, the two dependencies would both appear).

It looks like manually instrumenting newrelic calls on our codebase suffers the same issue too.

I've experimented with using newrelic and useNewRelic without the use of Mesh and that works as expected. I've also used graphql-yoga without Mesh and that also works as expected. It looks like something in Mesh is causing an issue.

While debugging (eg. at this point), I did notice that when using Mesh, the first transaction is populated in newrelic, but every transaction after that is null. However, the transaction is available as expected during the useNewRelic plugin. I looked to see if different agents were being created but couldn't see any sign that was the case. It looks like the state is being lost at some point?

The issue doesn't look to be restricted to the handler used, locally I've found that the same issue happens with newOpenApi and in our production environment nothing is being recorded except for the first transaction of every instance.

@ardatan
Copy link
Owner

ardatan commented Sep 15, 2022

It seems some additional feature flags need to be configured in NewRelic.
The following commit adds those to the docs;
12a8093

@zbowyer20 Do you think we can close this?

@ardatan ardatan closed this as completed Sep 15, 2022
@theguild-bot theguild-bot mentioned this issue Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants