TraceView: Add scope attributes to span details (#103173)

* Add scope attributes to span details

* Tests
This commit is contained in:
Joey
2025-04-01 13:26:16 +01:00
committed by GitHub
parent feadd37f27
commit 4689b7c0cd
2 changed files with 101 additions and 1 deletions
+22 -1
View File
@@ -143,7 +143,12 @@ func spanToSpanRow(span *tracev11.Span, libraryTags *commonv11.InstrumentationSc
return nil, fmt.Errorf("failed to marshal service tags: %w", err)
}
spanTags, err := json.Marshal(getSpanTags(span))
// Get both span tags and scope tags and combine them
spanTagsList := getSpanTags(span)
scopeTagsList := getScopeTags(libraryTags)
spanTagsList = append(spanTagsList, scopeTagsList...)
spanTags, err := json.Marshal(spanTagsList)
if err != nil {
return nil, fmt.Errorf("failed to marshal span tags: %w", err)
}
@@ -270,6 +275,22 @@ func getSpanTags(span *tracev11.Span) []*KeyValue {
return tags
}
func getScopeTags(scope *commonv11.InstrumentationScope) []*KeyValue {
if scope == nil || len(scope.Attributes) == 0 {
return nil
}
tags := make([]*KeyValue, len(scope.Attributes))
for i, attr := range scope.Attributes {
val, err := getAttributeVal(attr.Value)
if err != nil {
logger.Debug("error transforming scope attributes", "err", err)
}
tags[i] = &KeyValue{Key: attr.Key, Value: val}
}
return tags
}
func getSpanKind(spanKind tracev11.Span_SpanKind) string {
var tagStr string
switch spanKind {