Skip to content

Commit

Permalink
deprecate AttributeMapToMap in favour of AsRaw (#3939)
Browse files Browse the repository at this point in the history
Deprecating `AttributeMapToMap`. Moving the functionality to AttributeMap instead.

**Link to tracking Issue:** Part of #3926
  • Loading branch information
alrex authored Sep 8, 2021
1 parent e8bd3be commit ed36a6b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion config/configparser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func decoderConfig(result interface{}) *mapstructure.DecoderConfig {
// config:
// thing:
//
// we want an unmarshalled Config to be equivalent to
// we want an unmarshaled Config to be equivalent to
// Config{Thing: &SomeStruct{}} instead of Config{Thing: nil}
func expandNilStructPointers() mapstructure.DecodeHookFunc {
return func(from reflect.Value, to reflect.Value) (interface{}, error) {
Expand Down
2 changes: 1 addition & 1 deletion config/configunmarshaler/defaultunmarshaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func NewDefault() ConfigUnmarshaler {
}

// Unmarshal the Config from a Parser.
// After the config is unmarshalled, `Validate()` must be called to validate.
// After the config is unmarshaled, `Validate()` must be called to validate.
func (*defaultUnmarshaler) Unmarshal(v *configparser.ConfigMap, factories component.Factories) (*config.Config, error) {
var cfg config.Config

Expand Down
16 changes: 11 additions & 5 deletions model/pdata/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ func (a AttributeValue) AsString() string {
return strconv.FormatInt(a.IntVal(), 10)

case AttributeValueTypeMap:
jsonStr, _ := json.Marshal(AttributeMapToMap(a.MapVal()))
jsonStr, _ := json.Marshal(a.MapVal().AsRaw())
return string(jsonStr)

case AttributeValueTypeArray:
Expand Down Expand Up @@ -795,10 +795,10 @@ func (am AttributeMap) CopyTo(dest AttributeMap) {
*dest.orig = origs
}

// AttributeMapToMap converts an OTLP AttributeMap to a standard go map
func AttributeMapToMap(attrMap AttributeMap) map[string]interface{} {
// AsRaw converts an OTLP AttributeMap to a standard go map
func (am AttributeMap) AsRaw() map[string]interface{} {
rawMap := make(map[string]interface{})
attrMap.Range(func(k string, v AttributeValue) bool {
am.Range(func(k string, v AttributeValue) bool {
switch v.Type() {
case AttributeValueTypeString:
rawMap[k] = v.StringVal()
Expand All @@ -811,7 +811,7 @@ func AttributeMapToMap(attrMap AttributeMap) map[string]interface{} {
case AttributeValueTypeNull:
rawMap[k] = nil
case AttributeValueTypeMap:
rawMap[k] = AttributeMapToMap(v.MapVal())
rawMap[k] = v.MapVal().AsRaw()
case AttributeValueTypeArray:
rawMap[k] = attributeArrayToSlice(v.ArrayVal())
}
Expand All @@ -820,6 +820,12 @@ func AttributeMapToMap(attrMap AttributeMap) map[string]interface{} {
return rawMap
}

// AttributeMapToMap converts an OTLP AttributeMap to a standard go map
// Deprecated: use AttributeMap's AsRaw method instead.
func AttributeMapToMap(attrMap AttributeMap) map[string]interface{} {
return attrMap.AsRaw()
}

// attributeArrayToSlice creates a slice out of a AnyValueArray.
func attributeArrayToSlice(attrArray AnyValueArray) []interface{} {
rawSlice := make([]interface{}, 0, attrArray.Len())
Expand Down

0 comments on commit ed36a6b

Please sign in to comment.