Skip to content

Commit

Permalink
[chore] remove unnecessary duplicate code with AsRaw (open-telemetry#…
Browse files Browse the repository at this point in the history
…17892)

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Jan 23, 2023
1 parent 5f25d5c commit f6f6d89
Showing 1 changed file with 2 additions and 30 deletions.
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

0 comments on commit f6f6d89

Please sign in to comment.