From 51bef51d8ec0605cac9196b5fc0f60568ba8e565 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 1 Dec 2023 13:12:02 -0800 Subject: [PATCH] Simplify implementation --- .../elasticsearchexporter/internal/objmodel/objmodel.go | 8 -------- exporter/elasticsearchexporter/model.go | 6 ++++-- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/exporter/elasticsearchexporter/internal/objmodel/objmodel.go b/exporter/elasticsearchexporter/internal/objmodel/objmodel.go index 045bd31fe188..a26260144fa1 100644 --- a/exporter/elasticsearchexporter/internal/objmodel/objmodel.go +++ b/exporter/elasticsearchexporter/internal/objmodel/objmodel.go @@ -244,14 +244,6 @@ func (doc *Document) Serialize(w io.Writer, dedot bool) error { return doc.iterJSON(v, dedot) } -// MergeFrom merges the fields of anotherDoc into doc, overwriting any existing fields. -func (doc *Document) MergeFrom(anotherDoc Document) { - for _, field := range anotherDoc.fields { - doc.Add(field.key, field.value) - } - doc.Dedup() -} - func (doc *Document) iterJSON(v *json.Visitor, dedot bool) error { if dedot { return doc.iterJSONDedot(v) diff --git a/exporter/elasticsearchexporter/model.go b/exporter/elasticsearchexporter/model.go index ca57e5c2ddf1..fc0f0052e0af 100644 --- a/exporter/elasticsearchexporter/model.go +++ b/exporter/elasticsearchexporter/model.go @@ -94,8 +94,10 @@ func (m *encodeModel) encodeSpan(resource pcommon.Resource, span ptrace.Span, sc func (m *encodeModel) encodeAttributes(document *objmodel.Document, attributes pcommon.Map) { if m.omitAttributesPrefix { - rawDoc := objmodel.DocumentFromAttributes(attributes) - document.MergeFrom(rawDoc) + attributes.Range(func(k string, v pcommon.Value) bool { + document.AddAttribute(k, v) + return true + }) } else { document.AddAttributes("Attributes", attributes) }