Skip to content

Commit 3467721

Browse files
1pkgcarsonip
andauthored
otlp: handle host.ip attribute data type more defensively (#500)
* otlp: handle host.ip attribute data type more defensively --------- Co-authored-by: Carson Ip <carsonip@users.noreply.github.com>
1 parent 0986548 commit 3467721

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

input/otlp/metadata.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ func translateResourceMetadata(resource pcommon.Resource, out *modelpb.APMEvent)
194194
if out.Host == nil {
195195
out.Host = &modelpb.Host{}
196196
}
197+
if v.Type() != pcommon.ValueTypeSlice {
198+
break // switch
199+
}
197200
slice := v.Slice()
198201
result := make([]*modelpb.IP, 0, slice.Len())
199202
for i := 0; i < slice.Len(); i++ {

input/otlp/metadata_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,25 @@ func TestResourceConventions(t *testing.T) {
241241
},
242242
},
243243
},
244+
"host_ip_invalid_type": {
245+
attrs: map[string]interface{}{
246+
"host.name": "host_name",
247+
"host.id": "host_id",
248+
"host.type": "host_type",
249+
"host.arch": "host_arch",
250+
"host.ip": "10.244.0.1",
251+
},
252+
expected: &modelpb.APMEvent{
253+
Agent: &defaultAgent,
254+
Service: &defaultService,
255+
Host: &modelpb.Host{
256+
Hostname: "host_name",
257+
Id: "host_id",
258+
Type: "host_type",
259+
Architecture: "host_arch",
260+
},
261+
},
262+
},
244263
"device": {
245264
attrs: map[string]interface{}{
246265
"device.id": "device_id",

0 commit comments

Comments
 (0)