Skip to content

Commit

Permalink
[internal/stanza] Add support for []string in converter.go (open-tele…
Browse files Browse the repository at this point in the history
…metry#9887)

* added fix to include string array type to converter

* updated changelog

* updated Changelog entry
  • Loading branch information
armstrmi authored and djaglowski committed May 10, 2022
1 parent 4ae7986 commit 4f686f1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
- `tanzuobservabilityexporter`: Make metrics stanza in config be optional (#9098)
- `filelogreceiver`: Update Kubernetes examples to fix native OTel logs collection issue where 0 length logs cause errors (#9754)
- `logstransformprocessor`: Resolve node ordering to fix intermittent failures (#9761)
- `filelog`, `journald`, `syslog`, `tcplog`, `udplog`: Add support for []string type for converting log record entries (#9887)

## v0.50.0

Expand Down
15 changes: 15 additions & 0 deletions internal/stanza/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ func insertToAttributeVal(value interface{}, dest pcommon.Value) {
dest.SetBoolVal(t)
case string:
dest.SetStringVal(t)
case []string:
toStringArray(t).CopyTo(dest)
case []byte:
dest.SetBytesVal(t)
case int64:
Expand Down Expand Up @@ -420,6 +422,9 @@ func insertToAttributeMap(obsMap map[string]interface{}, dest pcommon.Map) {
dest.InsertBool(k, t)
case string:
dest.InsertString(k, t)
case []string:
arr := toStringArray(t)
dest.Insert(k, arr)
case []byte:
dest.InsertBytes(k, t)
case int64:
Expand Down Expand Up @@ -468,6 +473,16 @@ func toAttributeArray(obsArr []interface{}) pcommon.Value {
return arrVal
}

func toStringArray(strArr []string) pcommon.Value {
arrVal := pcommon.NewValueSlice()
arr := arrVal.SliceVal()
arr.EnsureCapacity(len(strArr))
for _, v := range strArr {
insertToAttributeVal(v, arr.AppendEmpty())
}
return arrVal
}

var sevMap = map[entry.Severity]plog.SeverityNumber{
entry.Default: plog.SeverityNumberUNDEFINED,
entry.Trace: plog.SeverityNumberTRACE,
Expand Down

0 comments on commit 4f686f1

Please sign in to comment.