From ae82a0a9413eb0a27205428b3348ffe0743e5351 Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Tue, 16 Jul 2024 14:32:24 +0200 Subject: [PATCH] Sanitize configured OTel resource attributes Signed-off-by: Arve Knudsen --- config/config.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 0880d518d..fd2e6e06c 100644 --- a/config/config.go +++ b/config/config.go @@ -19,6 +19,7 @@ import ( "net/url" "os" "path/filepath" + "slices" "sort" "strconv" "strings" @@ -1318,5 +1319,22 @@ type OTLPConfig struct { func (c *OTLPConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { *c = DefaultOTLPConfig type plain OTLPConfig - return unmarshal((*plain)(c)) + if err := unmarshal((*plain)(c)); err != nil { + return err + } + + seen := map[string]struct{}{} + i := 0 + for i < len(c.PromoteResourceAttributes) { + s := strings.TrimSpace(c.PromoteResourceAttributes[i]) + if _, exists := seen[s]; exists { + c.PromoteResourceAttributes = slices.Delete(c.PromoteResourceAttributes, i, i+1) + continue + } + + seen[s] = struct{}{} + c.PromoteResourceAttributes[i] = s + i++ + } + return nil }