grpc and opentracing

71 views
Skip to first unread message

Petros

unread,
Jan 26, 2021, 2:27:25 AM1/26/21
to vert.x
Hello,

i know right now there no direct support for grpc and opentracing.
I am asking, is there some recommended way how to do it right now in vertx 4?
Right now i have it implemented that i in interceptor get opentracing span from header and then put it in vertx context and on method ASAP take it from vertx context and after that a send it everywhere as value or function parameter. But it is not ideal as vertx context is share between eventloop thread.

Thomas SEGISMONT

unread,
Jan 26, 2021, 4:44:03 AM1/26/21
to vert.x
Hi,

Since Vert.x 4, there is a DuplicatedContext class. An instance of DuplicatedContext is created by calling ContextInternal.duplicate() in places where starting a span is supported (e.g. HttpServer or MessageConsumer).

You could implement your services so that:

- the context is duplicated at the beginning of the method
- then you invoke runOnContext on the duplicated context
- inside runOnContext you start a span and then invoke your verticle code

Are you interested in contributing support for Vert.x 4.1? We can assist you and this would help creating your app plus a huge bonus for the community.

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/92d4bc0d-d22f-49f9-8247-9f3a4c8d33d3n%40googlegroups.com.

Petros

unread,
Jan 26, 2021, 5:03:35 AM1/26/21
to vert.x
Hi,

but how can i recognize which span i want use, because i suppose that even duplicated context is shared on thread which can run multiple request so they are sharing same thread context. And its look like there is no advantage againts what i am using right now and that is base vartx context to send variable from grpc interceptor to grpc method and on the beginning of method i get span from it and then delegate everywhere where i need it. 

Dne úterý 26. ledna 2021 v 10:44:03 UTC+1 uživatel tsegi...@gmail.com napsal:

Thomas SEGISMONT

unread,
Jan 27, 2021, 4:46:51 AM1/27/21
to vert.x
Le mar. 26 janv. 2021 à 11:03, Petros <petr...@gmail.com> a écrit :
Hi,

but how can i recognize which span i want use, because i suppose that even duplicated context is shared on thread

DuplicatedContext is not shared. If you look at the implementation of HttpServer, a DuplicatedContext is created for each incoming request.
This allows to store data which is specific to the request (localData) while using the same event loop for running the code.
 

Petros

unread,
Jan 27, 2021, 5:32:10 AM1/27/21
to vert.x
That sound like a solution for me, i will try to use it. Hopefully it will work for grpc
Tanks for help

Dne středa 27. ledna 2021 v 10:46:51 UTC+1 uživatel tsegi...@gmail.com napsal:

Petros

unread,
Jan 28, 2021, 6:14:28 AM1/28/21
to vert.x
I look at DuplicateContext, but i did not find it in implementation of HttpServer, i found only ContextInternal, but it is marker for only internal use.
I try use DuplicateContext, but i don't know how to use it witch GRPC, i understand that i need duplicate context and then run code on that duplicated context, but don't know how to manage that on grpc interceptor where i get opentracing span from metadata and then pass them to DuplicatedContext and run method on that context.
Basically i need save solution to pass span from grpc header to grpc method, right know i have it like this.
In interceptor i do
```
val context: VertxContext = serverContext.vertx.getOrCreateContext()
context.put("span", span)
context.put("spanContext", span.context())
context.put("xgrid", xgrid)
```
and than on grpc method
```
val context: VertxContext = Vertx.currentContext()
val span: Span = context.get<Span>("span")
```
but i don't know if this is thread switch save solution, for testing i didn't see span mixing, but i am not sure about it as what i am aware vertx context is shared between requests on eventloop

Dne středa 27. ledna 2021 v 11:32:10 UTC+1 uživatel Petros napsal:

Thomas SEGISMONT

unread,
Jan 28, 2021, 8:23:11 AM1/28/21
to vert.x
Le jeu. 28 janv. 2021 à 12:14, Petros <petr...@gmail.com> a écrit :
I look at DuplicateContext, but i did not find it in implementation of HttpServer, i found only ContextInternal, but it is marker for only internal use.

I meant that you can see in HttpServer implementation how:

- a duplicated context is created any time a request is received
- the duplicated context is used to run the request handler

That's the behavior that needs to be ported to vertx-grpc.
 
I try use DuplicateContext, but i don't know how to use it witch GRPC, i understand that i need duplicate context and then run code on that duplicated context, but don't know how to manage that on grpc interceptor where i get opentracing span from metadata and then pass them to DuplicatedContext and run method on that context.

I'm not really knowledgeable with vertx-grpc but my understanding is an interceptor is not the best place to do this because it has a synchronous design.
I will ask the maintainer to take a look.
 

Petros

unread,
Jan 28, 2021, 8:26:39 AM1/28/21
to vert.x
You need use interceptor if you want get metadata from header. To my knowledge there is no other way, but i find that vertx have `ContextServerInterceptor` and it is look like it is what i am looking for.

Dne čtvrtek 28. ledna 2021 v 14:23:11 UTC+1 uživatel tsegi...@gmail.com napsal:
Reply all
Reply to author
Forward
0 new messages