4

When creating a GRPC client in NodeJS, if I'm using the grpc package, I can start my program with the GRPC_VERBOSITY set to debug environmental variable.

$ GRPC_VERBOSITY=debug node index.js

and I'll get a ton of information about the network communication that's happening.

However, if I switch out implementations and use the @grpc/grpc-js package, GRPC_VERBOSITY=debug has no effect.

I've poked at the underlying typescript that implements @grpc/grpc-js, and I see what look like logging calls.

So my question: How can I enable logging when using the @grpc/grpc-js NPM package with NodeJS

Ayush Gupta
  • 8,716
  • 8
  • 59
  • 92
Alana Storm
  • 164,128
  • 91
  • 395
  • 599

1 Answers1

12

As can be seen here:

if (process.env.GRPC_VERBOSITY) {
  switch (process.env.GRPC_VERBOSITY) {
    case 'DEBUG':
      _logVerbosity = LogVerbosity.DEBUG;
      break;
    case 'INFO':
      _logVerbosity = LogVerbosity.INFO;
      break;
    case 'ERROR':
      _logVerbosity = LogVerbosity.ERROR;
      break;
    default:
    // Ignore any other values
  }
}

Set GRPC_VERBOSITY=DEBUG in uppercase

Also, according to this, you have to set GRPC_TRACE to specify what kind of logs you want to see. To see all logs, you can set it to all.

So, In your case, the command becomes

GRPC_VERBOSITY=DEBUG GRPC_TRACE=all node index.js
Ayush Gupta
  • 8,716
  • 8
  • 59
  • 92
  • Thank you for responding Ayush, I appreciate it. However, running my program with `GRPC_VERBOSITY=DEBUG node index.js` with @grpc/grpc-js does not result in any output being sent to the console, whereas using `GRPC_VERBOSITY=debug` with `grpc` does result in output being sent to the console. Therefore this answer, while it contains useful information, doesn't answer my question. – Alana Storm Mar 30 '20 at 17:00
  • 2
    Can you try `GRPC_VERBOSITY=DEBUG GRPC_TRACE=all node index.js` according to [this](https://github.com/grpc/grpc-node/blob/master/packages/grpc-js/src/logging.ts#L68)? – Ayush Gupta Mar 30 '20 at 17:45
  • Thank you @ayush, `GRPC_TRACE=all` was the missing piece. With that AND GRPC_VERBOSITY U was able to get a bunch of logs. If you want to add that to answer I'm happy to mark as best. – Alana Storm Mar 30 '20 at 18:49
  • What are the possible values for `GRPC_TRACE` and can it be set programmatically? – CMCDragonkai Feb 10 '22 at 12:33