Search code examples
javainterceptorgrpcgrpc-javaopentracing

Using grpc server interceptors for nested server calls


I have a client that calls a grpc service A that calls another grpc service B. I want to use ServerInterceptor implementations to capture the entire call trace under a root span (level 1) starting at client and service A as its child span (level 2) and service B as the next level child span (at level 3) like this:

Client Span
   |
   |__ Server A Span
              |
              |__ Server B Span

I would like to use client and server interceptors for this purpose since I can trace all method calls without explicitly instrumenting the entire product code. So, I would need to inject the span context with parent span while making every child call so that the interceptor at child level can extract and use it as the parent span while creating its own span.

Since I need to declare and pass all interceptors at the server start as shown here, these interceptors do not interact with each other. In such case, how do I dynamically inject the span context at every level? Is there a way to add a ServerInterceptor into a started service while intercepting another call?

In other words, how do I propagate spans contexts across services that are traced using separate server tracing interceptors?

Here is how I am adding interceptors:

server = ServerBuilder.forPort(port)
.addService(ServerInterceptors.intercept(service, someInterceptor,
    someOtherInterceptor, serverTracingInterceptor))
.build()
.start();

I am trying to create Server and Client tracing interceptors similar to these: ServerTracingInterceptor.java, ClientTracingInterceptor.java.

If this is not possible, can you please suggest alternative approaches?

Thanks!


Solution

  • It's definitely a bug. Please submit an issue against opentracing java-grpc