console: usage reporting failing with following stacktrace (core v0.8.3)

POST https://app.graphql-hive.com/usage failed (7ms). The “listener” argument must be of type function. Received an instance of Object"} TypeError [ERR_INVALID_ARG_TYPE]: The “listener” argument must be of type function. Received an instance of Object"} at checkListener (node:events:275:3)“} at ClientRequest.once (node:events:652:3)”} at new ClientRequest (node:_http_client:248:10)“} at request (node:https:381:10)”} at /usr/app/node_modules/@opentelemetry/instrumentation-http/build/src/http.js:513:41"} at safeExecuteInTheMiddle (/usr/app/node_modules/@opentelemetry/instrumentation/build/src/utils.js:28:18)“} at /usr/app/node_modules/@opentelemetry/instrumentation-http/build/src/http.js:505:78”} at AsyncLocalStorage.run (node:internal/async_local_storage/async_hooks:91:14)“} at SentryContextManager.with (/usr/app/node_modules/@opentelemetry/context-async-hooks/build/src/AsyncLocalStorageContextManager.js:33:40)”} at SentryContextManager.with (file:///usr/app/node_modules/@sentry/node/node_modules/@sentry/opentelemetry/build/esm/index.js:1475:24)"}

our implementation:

const hive = createHive({
    enabled: isStaging || isProd,
    debug: isTest || isDevelopment,
    token: config.get<string>('hive.token'),
    usage: {
      exclude: ['sentry_healthcheck'],
      clientInfo(context: MercuriusContext): any {
        const name = context.reply.request.headers['apollographql-client-name']
        const version = context.reply.request.headers['apollographql-client-version']

        if (name && version && typeof name === 'string' && typeof version === 'string') {
          return { name, version }
        }

        return null
      }
    },
    agent: {
      logger: {
        info: (str: string) => {
          logger.info({ str }, 'hive info log')
        },
        error: (str: string, obj: any) => {
          logger.fatal({ obj, str }, 'hive error log')
        }
      }
    }
  })

secondary issue is that the error is passed to the logger so each line is logged separatelny but that i can live with 😃

overall usage is still present in the app, but i see few of these errors in the past few days

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 18 (9 by maintainers)

Most upvoted comments

Hi @dotansimha / @n1ru4l,

With the change in #6559 we were able to just pass the native fetch client which worked perfectly. Just tried using the what-wg fetch again, and that also now seems to work without issue.

Thanks!

In the meantime, we created https://github.com/graphql-hive/console/pull/6559 @mvantellingen, so you don’t have to maintain your own implementation.

@kamilkisiela well, bad news/good news scenario, figured out the culprit in v 0.8.3 there was a change in how fetch (or what fetch implementation) is used, which breaks when other instrumentations of the http layer (opentelemetry, sentry etc are introduced)

fix is kinda straightforward, when creating hive instance, pass { agent: { fetch: fetch } } and everything is ok

(i am passing ofcourse standard node fetch, not some of the many os implementations)

Hey @mvantellingen, is this issue still relevant and can you provide a minimal reproduction if so?

@mvantellingen Do you think you could put together a minimal reproduction of this issue?

Solved this issue for our projects by rewriting the supergraph manager to use native node-fetch, see https://gist.github.com/mvantellingen/9bfeb69df502911b5b508e5982916b18