From f60d701e8f9fa6c15afaf7b27fe67c2a9d7844c6 Mon Sep 17 00:00:00 2001 From: Mauri de Souza Meneguzzo Date: Fri, 10 Jan 2025 14:06:04 -0300 Subject: [PATCH] Use RemoveIf --- exporter/elasticsearchexporter/exporter.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/exporter/elasticsearchexporter/exporter.go b/exporter/elasticsearchexporter/exporter.go index 172f088cf650..08f9d43fe70d 100644 --- a/exporter/elasticsearchexporter/exporter.go +++ b/exporter/elasticsearchexporter/exporter.go @@ -460,13 +460,16 @@ func (e *elasticsearchExporter) pushSpanEvent( return bulkIndexerSession.Add(ctx, fIndex, "", bytes.NewReader(docBytes), nil) } -func (e *elasticsearchExporter) extractDocumentIDAttribute(m pcommon.Map) string { - if e.config.LogsDynamicID.Enabled { - docID, ok := getFromAttributes(documentIDAttributeName, "", m) - m.Remove(documentIDAttributeName) - if docID != "" && ok { - return docID - } +func (e *elasticsearchExporter) extractDocumentIDAttribute(m pcommon.Map) (docID string) { + if !e.config.LogsDynamicID.Enabled { + return } - return "" + m.RemoveIf(func(k string, value pcommon.Value) bool { + if k == documentIDAttributeName { + docID = value.AsString() + return true + } + return false + }) + return }