We are using ProjectReactor and grpc, as well as using reactive drivers for postgres r2dbc-postgresql.
There are 3 microservices.
A grpc request is made from the pvi-adapter application, to the ed-server application, then a transaction is opened, some kind of business logic is executed, then a grpc call to the dicts server is made.
When you start the application for the first time and receive the first grpc request from pvi-adapter, all spans are appended in the correct sequence and to the correct trace.
But all subsequent requests received via grpc from pvi-adpater are also bound to the span that was formed at the first request.
To pass the span in the reactor, we use
Hooks.onEachOperator (TracedSubscriber.asOperator (tracer));
Hooks.onLastOperator (TracedSubscriber.asOperator (tracer));
as you have written about it https://github.com/opentracing-contrib/java-reactor
To pass the span through grpc, we use
TracingServerInterceptor and TracingClientInterceptor from repository
https://github.com/opentracing-contrib/java-grpc
After a long debugging, I came to the conclusion that the problem is that the postgres r2dbc driver keeps the context passed through TracedSubscriber until the connection to the database is interrupted io.r2dbc.postgresql.client.ReactorNettyClient
https://github.com/pgjdbc/r2dbc-postgresql/blob/main/src/main/java/io/r2dbc/postgresql/client/ReactorNettyClient.java
The question is who faced such a problem and how to get around it? Now it turns out that using TracedSubscriber in a fully reactive environment with reactive drivers for postgres is not possible.
We are using ProjectReactor and grpc, as well as using reactive drivers for postgres r2dbc-postgresql.
There are 3 microservices.
A grpc request is made from the pvi-adapter application, to the ed-server application, then a transaction is opened, some kind of business logic is executed, then a grpc call to the dicts server is made.
When you start the application for the first time and receive the first grpc request from pvi-adapter, all spans are appended in the correct sequence and to the correct trace.
But all subsequent requests received via grpc from pvi-adpater are also bound to the span that was formed at the first request.
To pass the span in the reactor, we use
Hooks.onEachOperator (TracedSubscriber.asOperator (tracer));
Hooks.onLastOperator (TracedSubscriber.asOperator (tracer));
as you have written about it https://github.com/opentracing-contrib/java-reactor
To pass the span through grpc, we use
TracingServerInterceptor and TracingClientInterceptor from repository
https://github.com/opentracing-contrib/java-grpc
After a long debugging, I came to the conclusion that the problem is that the postgres r2dbc driver keeps the context passed through TracedSubscriber until the connection to the database is interrupted io.r2dbc.postgresql.client.ReactorNettyClient
https://github.com/pgjdbc/r2dbc-postgresql/blob/main/src/main/java/io/r2dbc/postgresql/client/ReactorNettyClient.java
The question is who faced such a problem and how to get around it? Now it turns out that using TracedSubscriber in a fully reactive environment with reactive drivers for postgres is not possible.