in oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/otlp/OpenTelemetryTraceHandler.java [236:274]
private Endpoint convertEndpointFromTags(Map<String, String> resourceTags, String localServiceName, boolean isRemote, Set<String> redundantKeys) {
final Endpoint.Builder builder = Endpoint.newBuilder();
String serviceName = localServiceName;
String tmpVal;
if (isRemote && StringUtil.isNotEmpty(tmpVal = getAndPutRedundantKey(resourceTags, "peer.service", redundantKeys))) {
serviceName = tmpVal;
} else if (isRemote &&
StringUtil.isNotEmpty(tmpVal = getAndPutRedundantKey(resourceTags, "net.peer.name", redundantKeys)) &&
// if it's not IP, then define it as service name
!builder.parseIp(tmpVal)) {
serviceName = tmpVal;
}
String ipKey, portKey;
if (isRemote) {
ipKey = "net.peer.ip";
portKey = "net.peer.port";
} else {
ipKey = "net.host.ip";
portKey = "net.host.port";
}
boolean ipParseSuccess = false;
if (StringUtil.isNotEmpty(tmpVal = getAndPutRedundantKey(resourceTags, ipKey, redundantKeys))) {
if (!(ipParseSuccess = builder.parseIp(tmpVal))) {
// if ip parse failed, use the value as service name
serviceName = StringUtil.isEmpty(serviceName) ? tmpVal : serviceName;
}
}
if (StringUtil.isNotEmpty(tmpVal = getAndPutRedundantKey(resourceTags, portKey, redundantKeys))) {
builder.port(Integer.parseInt(tmpVal));
}
if (StringUtil.isEmpty(serviceName) && !ipParseSuccess) {
return null;
}
builder.serviceName(serviceName);
return builder.build();
}