Skip to content

Micrometer Tracing doesn't work with @GrpcClient injection in constructors  #1138

@artsidorenko

Description

@artsidorenko

The context

I was trying to setup observability for application, that use both GrpcServer and GrpcClient.

The bug

It seems that configuration order of micrometer tracing breaks when I add @GrpcClient like ctor parameter for my service, for example:

@Service
class MyService(
    @GrpcClient("my-client")
    private val myClient: OtherServiceGrpcKt.OtherServiceCoroutineStub
) {...}
  1. The ObservationRegistry, needed to configure tracing interceptors is noOp, so traces don't work.

  2. Everything works fine if I add @GrpcClient as lateinit property to my service and do not use ctor injection.

  3. Also works if I add Configuration with @GrpcClientBean and inject client beans without @GrpcClient. (btw, it seems that @dependsOn on config with client beans is necessary, otherwise spring fails to find these beans)

  4. And also (that is strange) works if I exclude GrpcClientMicrometerAutoConfiguration:

spring:
  autoconfigure:
    exclude: net.devh.boot.grpc.client.autoconfigure.GrpcClientMicrometerTraceAutoConfiguration

and copy-paste source code of this class to my own code)

Stacktrace and logs
There are tons of WARNs like:
trationDelegate$BeanPostProcessorChecker : Bean 'net.devh.boot.grpc.client.autoconfigure.GrpcClientAutoConfiguration' of type [net.devh.boot.grpc.client.autoconfigure.GrpcClientAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying). Is this bean getting eagerly injected into a currently created BeanPostProcessor [grpcClientBeanPostProcessor]? Check the corresponding BeanPostProcessor declaration and its dependencies.

These WARNs are absent in 2) and 3).

Steps to Reproduce

Steps to reproduce the behavior:

  1. Create class via the @GrpcClient injected in ctor.
  2. Expose some endpoint like hello and try to log traceIds there
  3. (*) Try to add logging via ObservationHandler and see that your handler is not registered (and ObservationRegistry is noop as well).

The application's environment

Which versions do you use?

  • Spring (boot): 3.3.0
  • grpc-java: 1.64.0
  • grpc-kotlin-stub: 1.4.1
  • grpc-spring-boot-starter: 3.1.0.RELEASE

Additional context

I see that @GrpcClient constructor injection is experimental (as said in javadoc). Hope this issue helps you somehow

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething does not work as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions