@@ -26,6 +26,7 @@ import (
2626 "io/ioutil"
2727 "net"
2828 "net/http"
29+ "strconv"
2930 "strings"
3031 "sync"
3132
@@ -392,7 +393,7 @@ func nodeFromZipkinEndpoints(zs *zipkinmodel.SpanModel) *commonpb.Node {
392393 node .ServiceInfo = & commonpb.ServiceInfo {
393394 Name : lep .ServiceName ,
394395 }
395- node .Attributes = zipkinEndpointIntoAttributes (lep , node .Attributes , func ( s string ) string { return s } )
396+ node .Attributes = zipkinEndpointIntoAttributes (lep , node .Attributes , isLocalEndpoint )
396397 }
397398
398399 // Retrieve and make use of the remote endpoint
@@ -404,30 +405,44 @@ func nodeFromZipkinEndpoints(zs *zipkinmodel.SpanModel) *commonpb.Node {
404405 // "zipkin.remoteEndpoint.port": "9000"
405406 // "zipkin.remoteEndpoint.serviceName": "backend",
406407 // }
407- node .Attributes = zipkinEndpointIntoAttributes (rep , node .Attributes , func (s string ) string {
408- return "zipkin.remoteEndpoint." + s
409- })
408+ node .Attributes = zipkinEndpointIntoAttributes (rep , node .Attributes , isRemoteEndpoint )
410409 }
411410 return node
412411}
413412
413+ type zipkinDirection bool
414+
415+ const (
416+ isLocalEndpoint zipkinDirection = true
417+ isRemoteEndpoint zipkinDirection = false
418+ )
419+
414420var blankIP net.IP
415421
416- func zipkinEndpointIntoAttributes (ep * zipkinmodel.Endpoint , into map [string ]string , prefixFunc func ( string ) string ) map [string ]string {
422+ func zipkinEndpointIntoAttributes (ep * zipkinmodel.Endpoint , into map [string ]string , endpointType zipkinDirection ) map [string ]string {
417423 if into == nil {
418424 into = make (map [string ]string )
419425 }
426+
427+ var ipv4Key , ipv6Key , portKey , serviceNameKey string
428+ if endpointType == isLocalEndpoint {
429+ ipv4Key , ipv6Key = "ipv4" , "ipv6"
430+ portKey , serviceNameKey = "port" , "serviceName"
431+ } else {
432+ ipv4Key , ipv6Key = "zipkin.remoteEndpoint.ipv4" , "zipkin.remoteEndpoint.ipv6"
433+ portKey , serviceNameKey = "zipkin.remoteEndpoint.port" , "zipkin.remoteEndpoint.serviceName"
434+ }
420435 if ep .IPv4 != nil && ! ep .IPv4 .Equal (blankIP ) {
421- into [prefixFunc ( "ipv4" ) ] = ep .IPv4 .String ()
436+ into [ipv4Key ] = ep .IPv4 .String ()
422437 }
423438 if ep .IPv6 != nil && ! ep .IPv6 .Equal (blankIP ) {
424- into [prefixFunc ( "ipv6" ) ] = ep .IPv6 .String ()
439+ into [ipv6Key ] = ep .IPv6 .String ()
425440 }
426441 if ep .Port > 0 {
427- into [prefixFunc ( "port" ) ] = fmt . Sprintf ( "%d" , ep .Port )
442+ into [portKey ] = strconv . Itoa ( int ( ep .Port ) )
428443 }
429444 if serviceName := ep .ServiceName ; serviceName != "" {
430- into [prefixFunc ( "serviceName" ) ] = serviceName
445+ into [serviceNameKey ] = serviceName
431446 }
432447 return into
433448}
0 commit comments