how about adding remote-endpoint in the client span for rpc (eg, openfeign) ?
I am using sleuth-zipkin to setup a tracing solution with openfeign client. the version I am using as parent is :
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.
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:
- Sleuth wraps instrumented http clients; in case of Feign, there are multiple wrappers, one of them is
TracingFeignClient - You can see that it is using a
HttpClientHandler; in case of Brave, the implementation isBraveHttpClientHandler - If you look into this, you will see that it is just delegating the work to
brave.http.HttpClientHandler - In Brave's handler you can see that it is setting the
remoteServiceNamethat comes from aHttpTracinginstance - So we "only" need to provide the name of the service to this class in Brave
- If you search in the Sleuth autoconfig for this, you should find that when it is created,
HttpTracingCustomizers are applied - If you look into
HttpTracingCustomizer, you will see that it gets aHttpTracing.Builderthat can set the server name but the setter is package private so you can't set it here (I don't know why) :( - Though
HttpTracinghas a setter for this (clientOf) - So you can create your own
HttpTracingbean and set the remote server name this is how Sleuth creates it
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.
fyi: https://github.com/openzipkin/brave/issues/1296
We are not planning on adding any new features for Sleuth