feat: server span support preferIpv6 in tsf. (#1790)

Signed-off-by: Haotian Zhang <928016560@qq.com>
2024
shedfreewu 3 days ago committed by Haotian Zhang
parent 3b129bf97a
commit 5a893a8caa

@ -20,3 +20,4 @@
- [fix: fix NPE when application context is null #1787](https://github.com/Tencent/spring-cloud-tencent/pull/1787)
- [fix: fix lane router property name.](https://github.com/Tencent/spring-cloud-tencent/pull/1789)
- [feat: support kafka lane.](https://github.com/Tencent/spring-cloud-tencent/pull/1792)
- [feat: server span support preferIpv6 in tsf.](https://github.com/Tencent/spring-cloud-tencent/pull/1790)

@ -37,6 +37,11 @@ public final class OtUtils {
*/
public static final String OTEL_LANE_ID_KEY = "lane-id";
/**
* Key of prefer ipv6.
*/
public static final String OTEL_PREFER_IPV6_KEY = "prefer.ipv6";
private static final Logger LOGGER = LoggerFactory.getLogger(OtUtils.class);
private static String otServiceName = null;

@ -150,6 +150,9 @@ public final class TsfTagUtils {
case TsfMetadataConstants.TSF_NAMESPACE_ID:
metadata.setNamespaceId(entry.getValue());
break;
case TsfMetadataConstants.TSF_PREFER_IPV6:
metadata.setPreferIpv6(Boolean.parseBoolean(entry.getValue()));
break;
}
}
tsfMetadataMap.put(MetadataConstant.HeaderName.TSF_METADATA, JacksonUtils.serialize2Json(metadata));
@ -221,6 +224,7 @@ public final class TsfTagUtils {
if (StringUtils.isNotEmpty(metadata.getLocalIp())) {
mergedApplicationMetadata.put(MetadataConstants.LOCAL_IP, metadata.getLocalIp());
}
mergedApplicationMetadata.put(TsfMetadataConstants.TSF_PREFER_IPV6, String.valueOf(metadata.isPreferIpv6()));
}
if (LOGGER.isDebugEnabled()) {

@ -94,6 +94,11 @@ public class TsfSpanAttributesProvider implements SpanAttributesProvider {
}
}
}
Map<String, String> upstreamApplicationAttributes = metadataContext.getFragmentContext(MetadataContext.FRAGMENT_UPSTREAM_APPLICATION);
attributes.put(OtUtils.OTEL_PREFER_IPV6_KEY,
upstreamApplicationAttributes.getOrDefault(TsfMetadataConstants.TSF_PREFER_IPV6, "false"));
return attributes;
}

@ -135,6 +135,9 @@ public class TsfCoreProperties {
@Value("${tsf_ratelimit_master_port:7000}")
private Integer ratelimitMasterPort;
@Value("${tsf_prefer_ipv6:false}")
private Boolean preferIpv6;
public String getAppId() {
return appId;
}
@ -290,6 +293,14 @@ public class TsfCoreProperties {
this.ratelimitMasterPort = ratelimitMasterPort;
}
public Boolean getPreferIpv6() {
return preferIpv6;
}
public void setPreferIpv6(Boolean preferIpv6) {
this.preferIpv6 = preferIpv6;
}
@Override
public String toString() {
return "TsfCoreProperties{" +
@ -311,6 +322,7 @@ public class TsfCoreProperties {
", eventMasterPort=" + eventMasterPort +
", ratelimitMasterIp='" + ratelimitMasterIp + '\'' +
", ratelimitMasterPort=" + ratelimitMasterPort +
", preferIpv6=" + preferIpv6 +
'}';
}
}

@ -82,6 +82,9 @@ public class TsfInstanceMetadataProvider implements InstanceMetadataProvider {
if (StringUtils.isNotBlank(ipv6Address)) {
tsfMetadata.put(TsfMetadataConstants.TSF_ADDRESS_IPV6, ipv6Address);
}
if (tsfCoreProperties.getPreferIpv6() != null) {
tsfMetadata.put(TsfMetadataConstants.TSF_PREFER_IPV6, tsfCoreProperties.getPreferIpv6().toString());
}
return tsfMetadata;
}
}

Loading…
Cancel
Save