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

pull/1767/head
shedfreewu 2 weeks ago
parent 8f69fbb864
commit 2cf0c2c5ee

@ -56,13 +56,16 @@ public class PolarisSpanAttributesProvider implements SpanAttributesProvider {
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);
if (CollectionUtils.isNotEmpty(upstreamDisposableCustomAttributes)) {
for (Map.Entry<String, String> entry : upstreamDisposableCustomAttributes.entrySet()) {
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()

@ -100,13 +100,28 @@ public class TsfSpanAttributesProvider implements SpanAttributesProvider {
@Override
public Map<String, String> getServerFinallySpanAttributes(EnhancedPluginContext context) {
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).
getMetadataValue(ContextConstant.Trace.EXTRA_TRACE_ATTRIBUTES);
if (MetadataContextUtils.existMetadataValue(extraTraceAttributeObject)) {
Map<String, String> extraTraceAttributes = extraTraceAttributeObject.getObjectValue().get();
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;
}
}

Loading…
Cancel
Save