Skip to content

Commit 629a790

Browse files
shedfreewuSkyeBeFreeman
authored andcommitted
feat: server span support preferIpv6 in tsf. (#1790)
Signed-off-by: Haotian Zhang <928016560@qq.com>
1 parent 2dd8090 commit 629a790

File tree

6 files changed

+30
-0
lines changed

6 files changed

+30
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,4 @@
5454
- [fix: fix NPE when application context is null #1787](https://github.com/Tencent/spring-cloud-tencent/pull/1787)
5555
- [fix: fix lane router property name.](https://github.com/Tencent/spring-cloud-tencent/pull/1789)
5656
- [feat: support kafka lane.](https://github.com/Tencent/spring-cloud-tencent/pull/1791)
57+
- [feat: server span support preferIpv6 in tsf.](https://github.com/Tencent/spring-cloud-tencent/pull/1790)

spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/util/OtUtils.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public final class OtUtils {
3737
*/
3838
public static final String OTEL_LANE_ID_KEY = "lane-id";
3939

40+
/**
41+
* Key of prefer ipv6.
42+
*/
43+
public static final String OTEL_PREFER_IPV6_KEY = "prefer.ipv6";
44+
4045
private static final Logger LOGGER = LoggerFactory.getLogger(OtUtils.class);
4146

4247
private static String otServiceName = null;

spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/util/TsfTagUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ public static Map<String, String> getTsfMetadataMap(Map<String, String> calleeTr
150150
case TsfMetadataConstants.TSF_NAMESPACE_ID:
151151
metadata.setNamespaceId(entry.getValue());
152152
break;
153+
case TsfMetadataConstants.TSF_PREFER_IPV6:
154+
metadata.setPreferIpv6(Boolean.parseBoolean(entry.getValue()));
155+
break;
153156
}
154157
}
155158
tsfMetadataMap.put(MetadataConstant.HeaderName.TSF_METADATA, JacksonUtils.serialize2Json(metadata));
@@ -221,6 +224,7 @@ public static void updateTsfMetadata(Map<String, String> mergedTransitiveMetadat
221224
if (StringUtils.isNotEmpty(metadata.getLocalIp())) {
222225
mergedApplicationMetadata.put(MetadataConstants.LOCAL_IP, metadata.getLocalIp());
223226
}
227+
mergedApplicationMetadata.put(TsfMetadataConstants.TSF_PREFER_IPV6, String.valueOf(metadata.isPreferIpv6()));
224228
}
225229

226230
if (LOGGER.isDebugEnabled()) {

spring-cloud-tencent-plugin-starters/spring-cloud-starter-tencent-trace-plugin/src/main/java/com/tencent/cloud/plugin/trace/attribute/tsf/TsfSpanAttributesProvider.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ public Map<String, String> getServerPreSpanAttributes(EnhancedPluginContext cont
9494
}
9595
}
9696
}
97+
98+
Map<String, String> upstreamApplicationAttributes = metadataContext.getFragmentContext(MetadataContext.FRAGMENT_UPSTREAM_APPLICATION);
99+
attributes.put(OtUtils.OTEL_PREFER_IPV6_KEY,
100+
upstreamApplicationAttributes.getOrDefault(TsfMetadataConstants.TSF_PREFER_IPV6, "false"));
101+
97102
return attributes;
98103
}
99104

spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/config/extend/tsf/TsfCoreProperties.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ public class TsfCoreProperties {
135135
@Value("${tsf_ratelimit_master_port:7000}")
136136
private Integer ratelimitMasterPort;
137137

138+
@Value("${tsf_prefer_ipv6:false}")
139+
private Boolean preferIpv6;
140+
138141
public String getAppId() {
139142
return appId;
140143
}
@@ -290,6 +293,14 @@ public void setRatelimitMasterPort(Integer ratelimitMasterPort) {
290293
this.ratelimitMasterPort = ratelimitMasterPort;
291294
}
292295

296+
public Boolean getPreferIpv6() {
297+
return preferIpv6;
298+
}
299+
300+
public void setPreferIpv6(Boolean preferIpv6) {
301+
this.preferIpv6 = preferIpv6;
302+
}
303+
293304
@Override
294305
public String toString() {
295306
return "TsfCoreProperties{" +
@@ -311,6 +322,7 @@ public String toString() {
311322
", eventMasterPort=" + eventMasterPort +
312323
", ratelimitMasterIp='" + ratelimitMasterIp + '\'' +
313324
", ratelimitMasterPort=" + ratelimitMasterPort +
325+
", preferIpv6=" + preferIpv6 +
314326
'}';
315327
}
316328
}

spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/config/extend/tsf/TsfInstanceMetadataProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ public Map<String, String> getMetadata() {
8282
if (StringUtils.isNotBlank(ipv6Address)) {
8383
tsfMetadata.put(TsfMetadataConstants.TSF_ADDRESS_IPV6, ipv6Address);
8484
}
85+
if (tsfCoreProperties.getPreferIpv6() != null) {
86+
tsfMetadata.put(TsfMetadataConstants.TSF_PREFER_IPV6, tsfCoreProperties.getPreferIpv6().toString());
87+
}
8588
return tsfMetadata;
8689
}
8790
}

0 commit comments

Comments
 (0)