Skip to content

Commit

Permalink
[exporter/elasticsearch] Merge geo.location.{lat,lon} to geo.location
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonip committed Nov 28, 2024
1 parent 54691eb commit 32c7305
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions exporter/elasticsearchexporter/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -998,3 +998,29 @@ func sliceHash(h hash.Hash, s pcommon.Slice) {
valueHash(h, s.At(i))
}
}

// convertGeolocationToGeopoint mutates attributes map to merge `geo.location.lat` and `geo.location.lon` to `geo.location`.
func convertGeolocationToGeopoint(attributes pcommon.Map) {
const (
lonKey = "geo.location.lon"
latKey = "geo.location.lat"
mergedKey = "geo.location"
)
var lon, lat pcommon.Value
if v, ok := attributes.Get(lonKey); ok {
lon = v
}
if v, ok := attributes.Get(latKey); ok {
lat = v
}
if lon.Type() == pcommon.ValueTypeDouble && lat.Type() == pcommon.ValueTypeDouble {
attributes.PutStr(mergedKey, fmt.Sprintf("POINT(%f %f)", lon.Double(), lat.Double()))
attributes.RemoveIf(func(key string, val pcommon.Value) bool {
switch key {
case lonKey, latKey:
return true
}
return false
})
}
}

0 comments on commit 32c7305

Please sign in to comment.