fix: get source service name from upstream application meta in getServerPreSpanAttributes & set custom tag in current server span in tsf. (#1767)

Signed-off-by: Haotian Zhang <928016560@qq.com>
2024
shedfreewu 2 weeks ago committed by Haotian Zhang
parent 79936c2f62
commit d1e6b7103a

@ -32,3 +32,4 @@
- [fix: fix get gateway config in tsf ipv6.](https://github.com/Tencent/spring-cloud-tencent/pull/1747) - [fix: fix get gateway config in tsf ipv6.](https://github.com/Tencent/spring-cloud-tencent/pull/1747)
- [fix: fix nacos service discovery. ](https://github.com/Tencent/spring-cloud-tencent/pull/1751) - [fix: fix nacos service discovery. ](https://github.com/Tencent/spring-cloud-tencent/pull/1751)
- [fix:fix NPE when rate-limiting with null value.](https://github.com/Tencent/spring-cloud-tencent/pull/1764) - [fix:fix NPE when rate-limiting with null value.](https://github.com/Tencent/spring-cloud-tencent/pull/1764)
- [fix: get source service name from upstream application meta in getServerPreSpanAttributes & set custom tag in current server span in tsf.](https://github.com/Tencent/spring-cloud-tencent/pull/1767)

@ -56,13 +56,16 @@ public class PolarisSpanAttributesProvider implements SpanAttributesProvider {
attributes.put("custom." + entry.getKey(), entry.getValue()); attributes.put("custom." + entry.getKey(), entry.getValue());
} }
} }
Map<String, String> upstreamDisposableApplicationAttributes = metadataContext.getFragmentContext(MetadataContext.FRAGMENT_UPSTREAM_APPLICATION);
if (CollectionUtils.isNotEmpty(upstreamDisposableApplicationAttributes)
&& upstreamDisposableApplicationAttributes.containsKey(MetadataConstant.DefaultMetadata.DEFAULT_METADATA_SOURCE_SERVICE_NAME)) {
attributes.put("net.peer.service",
upstreamDisposableApplicationAttributes.get(MetadataConstant.DefaultMetadata.DEFAULT_METADATA_SOURCE_SERVICE_NAME));
}
Map<String, String> upstreamDisposableCustomAttributes = metadataContext.getFragmentContext(MetadataContext.FRAGMENT_UPSTREAM_DISPOSABLE); Map<String, String> upstreamDisposableCustomAttributes = metadataContext.getFragmentContext(MetadataContext.FRAGMENT_UPSTREAM_DISPOSABLE);
if (CollectionUtils.isNotEmpty(upstreamDisposableCustomAttributes)) { if (CollectionUtils.isNotEmpty(upstreamDisposableCustomAttributes)) {
for (Map.Entry<String, String> entry : upstreamDisposableCustomAttributes.entrySet()) { for (Map.Entry<String, String> entry : upstreamDisposableCustomAttributes.entrySet()) {
attributes.put("custom." + entry.getKey(), entry.getValue()); attributes.put("custom." + entry.getKey(), entry.getValue());
if (MetadataConstant.DefaultMetadata.DEFAULT_METADATA_SOURCE_SERVICE_NAME.equals(entry.getKey())) {
attributes.put("net.peer.service", entry.getValue());
}
} }
} }
attributes.put("http.port", CalleeMetadataContainerGroup.getStaticApplicationMetadataContainer() attributes.put("http.port", CalleeMetadataContainerGroup.getStaticApplicationMetadataContainer()

@ -100,13 +100,28 @@ public class TsfSpanAttributesProvider implements SpanAttributesProvider {
@Override @Override
public Map<String, String> getServerFinallySpanAttributes(EnhancedPluginContext context) { public Map<String, String> getServerFinallySpanAttributes(EnhancedPluginContext context) {
Map<String, String> attributes = new HashMap<>(); Map<String, String> attributes = new HashMap<>();
MetadataObjectValue<Map<String, String>> extraTraceAttributeObject = MetadataContextHolder.get(). MetadataContext metadataContext = MetadataContextHolder.get();
MetadataObjectValue<Map<String, String>> extraTraceAttributeObject = metadataContext.
getMetadataContainer(MetadataType.CUSTOM, false). getMetadataContainer(MetadataType.CUSTOM, false).
getMetadataValue(ContextConstant.Trace.EXTRA_TRACE_ATTRIBUTES); getMetadataValue(ContextConstant.Trace.EXTRA_TRACE_ATTRIBUTES);
if (MetadataContextUtils.existMetadataValue(extraTraceAttributeObject)) { if (MetadataContextUtils.existMetadataValue(extraTraceAttributeObject)) {
Map<String, String> extraTraceAttributes = extraTraceAttributeObject.getObjectValue().get(); Map<String, String> extraTraceAttributes = extraTraceAttributeObject.getObjectValue().get();
attributes.putAll(extraTraceAttributes); attributes.putAll(extraTraceAttributes);
} }
Map<String, String> transitiveCustomAttributes = metadataContext.getFragmentContext(MetadataContext.FRAGMENT_TRANSITIVE);
if (CollectionUtils.isNotEmpty(transitiveCustomAttributes)) {
for (Map.Entry<String, String> entry : transitiveCustomAttributes.entrySet()) {
attributes.put("custom." + entry.getKey(), entry.getValue());
}
}
Map<String, String> disposableCustomAttributes = metadataContext.getFragmentContext(MetadataContext.FRAGMENT_DISPOSABLE);
if (CollectionUtils.isNotEmpty(disposableCustomAttributes)) {
for (Map.Entry<String, String> entry : disposableCustomAttributes.entrySet()) {
attributes.put("custom." + entry.getKey(), entry.getValue());
}
}
return attributes; return attributes;
} }
} }

Loading…
Cancel
Save