Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] remove unnecessary duplicate code with AsRaw #17892

Merged
merged 1 commit into from
Jan 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 2 additions & 30 deletions exporter/awsxrayexporter/internal/translator/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func makeXRayAttributes(attributes map[string]pcommon.Value, resource pcommon.Re
key = fixAnnotationKey(key)
annotations[key] = annoVal
} else {
metaVal := metadataValue(value)
metaVal := value.AsRaw()
if metaVal != nil {
defaultMetadata[key] = metaVal
}
Expand All @@ -381,7 +381,7 @@ func makeXRayAttributes(attributes map[string]pcommon.Value, resource pcommon.Re
annotations[key] = annoVal
}
} else {
metaVal := metadataValue(value)
metaVal := value.AsRaw()
if metaVal != nil {
defaultMetadata[key] = metaVal
}
Expand Down Expand Up @@ -410,34 +410,6 @@ func annotationValue(value pcommon.Value) interface{} {
return nil
}

func metadataValue(value pcommon.Value) interface{} {
switch value.Type() {
case pcommon.ValueTypeStr:
return value.Str()
case pcommon.ValueTypeInt:
return value.Int()
case pcommon.ValueTypeDouble:
return value.Double()
case pcommon.ValueTypeBool:
return value.Bool()
case pcommon.ValueTypeMap:
converted := map[string]interface{}{}
value.Map().Range(func(key string, value pcommon.Value) bool {
converted[key] = metadataValue(value)
return true
})
return converted
case pcommon.ValueTypeSlice:
arrVal := value.Slice()
converted := make([]interface{}, arrVal.Len())
for i := 0; i < arrVal.Len(); i++ {
converted[i] = metadataValue(arrVal.At(i))
}
return converted
}
return nil
}

// fixSegmentName removes any invalid characters from the span name. AWS X-Ray defines
// the list of valid characters here:
// https://docs.aws.amazon.com/xray/latest/devguide/xray-api-segmentdocuments.html
Expand Down