spring-cloud-sleuth icon indicating copy to clipboard operation
spring-cloud-sleuth copied to clipboard

how about adding remote-endpoint in the client span for rpc (eg, openfeign) ?

Open yangyshdan opened this issue 5 years ago • 3 comments

I am using sleuth-zipkin to setup a tracing solution with openfeign client. the version I am using as parent is : org.springframework.boot spring-boot-starter-parent 2.4.4

My envionrment is very complext, that it is highli possible that some of the applicaions do not get instrumented with sleuth-zipkin. So in order to still draw an the topology as comprehensive as possible, is it possible to add the remote-endpoint in the "client" span for open-feign? such as below

 {   "traceId":"761fa7ad18d9172b",
    "parentId":"761fa7ad18d9172b",
    "id":"514fb6c1bcb6357f",
    "kind":"CLIENT",
    "name":"get",
    "timestamp":1616993053736129,
    "duration":1948,
    "localEndpoint":{
        "serviceName":"application-1"
    },
    **"remoteEndpoint":{
        "serviceName":"application-2"  # ip is also okay. Currently, the remote endpoint is not provided for client span.
    },**

    "tags":{
        "http.method":"GET",
        "http.path":"/echo"
    }}

By this way, even if the server span is not provided, with the client span, one can still get the topology calculated.

yangyshdan avatar Mar 29 '21 04:03 yangyshdan

TL;DR

You should be able to use a HttpTracingCustomizer to add remoteServiceName but you can't because of a package-private setter, instead you can create a HttpTracing bean. If tags are also ok, you can add them via a HttpRequestParser.

Longer version

I think localEndpoint is not provided by Sleuth but by Brave. Also, it seems remoteEndpoint is deprecated in favor of remoteServiceName but I don't think Brave can provide that. In some cases, Sleuth does support remoteServiceName (search for it in the codebase) but not in the case of http clients like Feign, I'm not sure why, maybe @marcingrzejszczak does.

Let me walk you through on what happens under the hood so that you will see how to change the behavior:

If I omit all of the logic, basically you should replace return builder.build(); to return builder.build().clientOf("myServer");

This is just a workaround and I don't think this will work for multiple Feign clients, I'm going to open a new issue for Brave to see why isn't this possible (package-private setter):

@Bean
HttpTracingCustomizer httpTracingCustomizer() {
    return builder -> builder.serverName("myServer");
}

It might work if your @Configuration class is in the brave.http package but if anyone asks, I wasn't the one who said this. 😃

I'm also going to talk to @marcingrzejszczak to see what we can do: injecting the server name should be easy, what I'm worried about is having multiple Feign clients.

jonatan-ivanov avatar Mar 30 '21 21:03 jonatan-ivanov

fyi: https://github.com/openzipkin/brave/issues/1296

jonatan-ivanov avatar Mar 30 '21 21:03 jonatan-ivanov

We are not planning on adding any new features for Sleuth

marcingrzejszczak avatar Mar 07 '22 22:03 marcingrzejszczak