Skip to content

Commit a472cf7

Browse files
carsoniplahsivjar
authored andcommitted
[exporter/elasticsearch] Merge *.geo.location.{lat,lon} to *.geo.location in OTel mode (open-telemetry#36594)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description In OTel mapping mode, merge *.geo.location.{lat,lon} to *.geo.location such that they are stored as [geo_point](https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-point.html) in Elasticsearch. <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes open-telemetry#36565 <!--Describe what testing was performed and which tests were added.--> #### Testing <!--Describe the documentation added.--> #### Documentation <!--Please delete paragraphs that you did not use before submitting.--> --------- Co-authored-by: Vishal Raj <[email protected]>
1 parent 45e98be commit a472cf7

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

exporter/elasticsearchexporter/model_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,3 +1329,36 @@ func TestEncodeLogBodyMapMode(t *testing.T) {
13291329
require.Error(t, err)
13301330
require.ErrorIs(t, err, ErrInvalidTypeForBodyMapMode)
13311331
}
1332+
1333+
func TestMergeGeolocation(t *testing.T) {
1334+
attributes := map[string]any{
1335+
"geo.location.lon": 1.1,
1336+
"geo.location.lat": 2.2,
1337+
"foo.bar.geo.location.lon": 3.3,
1338+
"foo.bar.geo.location.lat": 4.4,
1339+
"a.geo.location.lon": 5.5,
1340+
"b.geo.location.lat": 6.6,
1341+
"unrelatedgeo.location.lon": 7.7,
1342+
"unrelatedgeo.location.lat": 8.8,
1343+
"d": 9.9,
1344+
"e.geo.location.lon": "foo",
1345+
"e.geo.location.lat": "bar",
1346+
}
1347+
wantAttributes := map[string]any{
1348+
"geo.location": []any{1.1, 2.2},
1349+
"foo.bar.geo.location": []any{3.3, 4.4},
1350+
"a.geo.location.lon": 5.5,
1351+
"b.geo.location.lat": 6.6,
1352+
"unrelatedgeo.location.lon": 7.7,
1353+
"unrelatedgeo.location.lat": 8.8,
1354+
"d": 9.9,
1355+
"e.geo.location.lon": "foo",
1356+
"e.geo.location.lat": "bar",
1357+
}
1358+
input := pcommon.NewMap()
1359+
err := input.FromRaw(attributes)
1360+
require.NoError(t, err)
1361+
mergeGeolocation(input)
1362+
after := input.AsRaw()
1363+
assert.Equal(t, wantAttributes, after)
1364+
}

0 commit comments

Comments
 (0)