question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GRPC client interceptor does not get called

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

GRPC client interceptor not called when passed through ClientsModule options but is working when passed through options.channelOptions:

This does not work:

ClientsModule.register([
  {
    name: 'HERO_PACKAGE',
    transport: Transport.GRPC,
    options: {
      package: 'hero',
      protoPath: join(__dirname, 'hero.proto'),
      interceptors: [
        (options, nextCall) => {
          console.log('CALLED INTERCEPTOR');
          return new InterceptingCall(nextCall(options));
        },
      ],
    },
  },
])

This is working:

ClientsModule.register([
  {
    name: 'HERO_PACKAGE',
    transport: Transport.GRPC,
    options: {
      package: 'hero',
      protoPath: join(__dirname, 'hero.proto'),
      channelOptions: {
        interceptors: [
          (options, nextCall) => {
            console.log('CALLED INTERCEPTOR');
            return new InterceptingCall(nextCall(options));
          },
        ],
      },
    },
  },
])

Minimum reproduction code

https://github.com/ckfngod/grpc-client-interceptor-issue

Steps to reproduce

  1. npm i
  2. npm run start
  3. curl localhost:3000

GRPC request is successful but there is no console output from application when interceptor should be logging.

Expected behavior

GRPC client interceptor should be called.

Package

Other package

No response

NestJS version

8.2.6

Packages versions

[System Information] OS Version : macOS Monterey NodeJS Version : v16.13.2 NPM Version : 8.1.2

[Nest CLI] Nest CLI Version : 8.2.0

[Nest Platform Information] platform-express version : 8.2.6 microservices version : 8.2.6 schematics version : 8.0.5 testing version : 8.2.6 common version : 8.2.6 core version : 8.2.6 cli version : 8.2.0

Node.js version

16.13.2

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
kamilmysliwieccommented, Mar 25, 2022

Yeah, it turns out #8231 was an invalid PR that exposed interceptors option in the wrong place. You should pass interceptors as part of the channelOptions object, as in this example:

ClientsModule.register([
  {
    name: 'HERO_PACKAGE',
    transport: Transport.GRPC,
    options: {
      package: 'hero',
      protoPath: join(__dirname, 'hero.proto'),
      channelOptions: {
        interceptors: [
          (options, nextCall) => {
            console.log('CALLED INTERCEPTOR');
            return new InterceptingCall(nextCall(options));
          },
        ],
      },
    },
  },
])

#8231 will be reverted

1reaction
hyunjinjeongcommented, Apr 20, 2022

We can use it with type casting as a workaround.

const options = {
  ...
} as unknown as GrpcOptions

// or more specifically
const options = {
  options: {
    channelOptions: {
      interceptors: [SomeInterceptor],
    } as unknown as GrpcOptions['options']['channelOptions']
  }
}

We need a proper typing though…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Grpc interceptor is not being called - Stack Overflow
The Intercept method returns the decorated ServerServiceDefinition ; as such, you probably want something more like:
Read more >
A Guide to gRPC and Interceptors - The Edgehog Portal
In this blog, we're going to cover what gRPC interceptors are, alongside an open-source example that you can make your own changes to, ......
Read more >
gRPC interceptors on .NET - Microsoft Learn
Interceptors are a gRPC concept that allows apps to interact with incoming or outgoing gRPC calls. They offer a way to enrich the...
Read more >
gRPC Python 1.46.2 documentation
TypeError – If interceptor does not derive from any of UnaryUnaryClientInterceptor, UnaryStreamClientInterceptor, StreamUnaryClientInterceptor, or ...
Read more >
Reference — grpc-interceptor documentation
This is not part of the grpc_interceptor.AsyncServerInterceptor API, but must have a public name. Do not override it, unless you know what you're...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found