You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
gRPC TracingServerInterceptor does NOT finish span when RPC stream is cancelled
Consider my case:
there are 2 services: one of them is grpc client, another - grpc server.
Distributed tracing is not implemented in client service.
On server side distributed tracing is implemented using spring-cloud-starter-sleuth, spring-cloud-sleuth-zipkin and brave-instrumentation-grpc. TracingServerInterceptor is used in grpc server config.
In server service there is an implementation of grpc server side streaming. So, when client calls grpc request, server starts grps stream and a new root span is created by TracingServerInterceptor.
If, during processing of stream messages, client decides to cancel stream before server has sent all required messages, stream will be closed as cancelled on server and created span WILL NOT BE FINISHED. Since span is not finished, it will never be reported to distributed tracing collector (Zipkin in my case). Same behaviour is reproduced when client has closed/lost grpc connection (stream is closed as cancelled, span is not finished). Also this bug is always reproducible, when server returns an infinite stream to the client, client listens to it during some period of time and cancels it when it is needed .
When server has sent all messages, it closes stream as completed and previously created span is finished by TracingServerInterceptor.
gRPC TracingServerInterceptor does NOT finish span when RPC stream is cancelled
Consider my case:
TracingServerInterceptor
is used in grpc server config.In server service there is an implementation of grpc server side streaming. So, when client calls grpc request, server starts grps stream and a new root span is created by
TracingServerInterceptor
.If, during processing of stream messages, client decides to cancel stream before server has sent all required messages, stream will be closed as cancelled on server and created span WILL NOT BE FINISHED. Since span is not finished, it will never be reported to distributed tracing collector (Zipkin in my case). Same behaviour is reproduced when client has closed/lost grpc connection (stream is closed as cancelled, span is not finished). Also this bug is always reproducible, when server returns an infinite stream to the client, client listens to it during some period of time and cancels it when it is needed .
When server has sent all messages, it closes stream as completed and previously created span is finished by
TracingServerInterceptor
.Possible solution might be to finish span in TracingServerInterceptor.TracingServerCallListener#onCancel(). At least, I have created a custom tracing interceptor with this fix and it works in my case.
Libs versions:
io.grpc
- 1.43.2org.springframework.cloud:spring-cloud-starter-sleuth
- 3.1.3org.springframework.cloud:spring-cloud-sleuth-zipkin
- 3.1.3io.zipkin.brave:brave-instrumentation-grpc
- 5.13.10Preconditions:
Steps to Reproduce
Steps to reproduce the behavior:
Expected Behaviour
TracingServerInterceptor should finish span, which was opened when gRPC stream was started, when stream is cancelled.
The text was updated successfully, but these errors were encountered: