Skip to content

Commit

Permalink
NETOBSERV-1522 & NETOBSERV-1750 FLP otel fixes (#684)
Browse files Browse the repository at this point in the history
* fix open telemetry attributes

* skip callback if nil
  • Loading branch information
jpinsonneau authored Jul 19, 2024
1 parent 915552b commit 42ce534
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
40 changes: 33 additions & 7 deletions pkg/pipeline/encode/opentelemetry/opentelemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,19 +275,45 @@ func obtainAttributesFromEntry(entry config.GenericMap) *[]attribute.KeyValue {
var att = make([]attribute.KeyValue, len(entry))
index := 0
for k, v := range entry {
switch v.(type) {
switch v := v.(type) {
case []string:
att[index] = attribute.StringSlice(k, v)
case string:
valString := v
att[index] = attribute.String(k, valString.(string))
case int, int32, int64, int16, uint, uint8, uint16, uint32, uint64:
att[index] = attribute.String(k, v)
case []int:
att[index] = attribute.IntSlice(k, v)
case []int32:
valInt64Slice := []int64{}
for _, valInt32 := range v {
valInt64, _ := utils.ConvertToInt64(valInt32)
valInt64Slice = append(valInt64Slice, valInt64)
}
att[index] = attribute.Int64Slice(k, valInt64Slice)
case []int64:
att[index] = attribute.Int64Slice(k, v)
case int:
att[index] = attribute.Int(k, v)
case int32, int64, int16, uint, uint8, uint16, uint32, uint64:
valInt, _ := utils.ConvertToInt64(v)
att[index] = attribute.Int64(k, valInt)
case float32, float64:
case []float32:
valFloat64Slice := []float64{}
for _, valFloat32 := range v {
valFloat64, _ := utils.ConvertToFloat64(valFloat32)
valFloat64Slice = append(valFloat64Slice, valFloat64)
}
att[index] = attribute.Float64Slice(k, valFloat64Slice)
case []float64:
att[index] = attribute.Float64Slice(k, v)
case float32:
valFloat, _ := utils.ConvertToFloat64(v)
att[index] = attribute.Float64(k, valFloat)
case float64:
att[index] = attribute.Float64(k, v)
case []bool:
att[index] = attribute.BoolSlice(k, v)
case bool:
valBool := v
att[index] = attribute.Bool(k, valBool.(bool))
att[index] = attribute.Bool(k, v)
case nil:
// skip this field
continue
Expand Down
4 changes: 3 additions & 1 deletion pkg/pipeline/utils/timed_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ func (tc *TimedCache) CleanupExpiredEntries(expiry time.Duration, callback Cache
return
}
deleted++
callback(pCacheInfo.SourceEntry)
if callback != nil {
callback(pCacheInfo.SourceEntry)
}
delete(tc.cacheMap, pCacheInfo.key)
tc.cacheList.Remove(listEntry)
if tc.cacheLenMetric != nil {
Expand Down

0 comments on commit 42ce534

Please sign in to comment.