Skip to content

Commit

Permalink
do not convert measurement values to strings
Browse files Browse the repository at this point in the history
  • Loading branch information
codecapitano committed Apr 5, 2024
1 parent f904c53 commit 1b2fcae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions internal/component/faro/receiver/internal/payload/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,12 @@ func (m Measurement) KeyVal() *KeyVal {
MergeKeyVal(kv, m.Trace.KeyVal())
MergeKeyValWithPrefix(kv, KeyValFromMap(m.Context), "context_")

valuesAsString := make(map[string]string, len(m.Values))
values := make(map[string]float64, len(m.Values))
for key, value := range m.Values {
valuesAsString[key] = fmt.Sprintf("%v", value)
values[key] = value
}

MergeKeyValWithPrefix(kv, KeyValFromMap(valuesAsString), "value_")
MergeKeyValWithPrefix(kv, KeyValFromFloatMap(values), "value_")

return kv
}
Expand Down
14 changes: 14 additions & 0 deletions internal/component/faro/receiver/internal/payload/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ func KeyValFromMap(m map[string]string) *KeyVal {
return kv
}

// KeyValFromMap will instantiate KeyVal from a map[string]float64
func KeyValFromFloatMap(m map[string]float64) *KeyVal {
kv := NewKeyVal()
keys := make([]string, 0, len(m))
for k := range m {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
kv.Set(k, m[k])
}
return kv
}

// MergeKeyVal will merge source in target
func MergeKeyVal(target *KeyVal, source *KeyVal) {
for el := source.Oldest(); el != nil; el = el.Next() {
Expand Down

0 comments on commit 1b2fcae

Please sign in to comment.