diff --git a/go.mod b/go.mod index 908a3ca80b..b0fb828ed4 100644 --- a/go.mod +++ b/go.mod @@ -206,7 +206,7 @@ require ( github.com/pkg/errors v0.9.1 // indirect github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect - github.com/prometheus/otlptranslator v0.0.0-20250527173959-2573485683d5 + github.com/prometheus/otlptranslator v0.0.0-20250620074007-94f535e0c588 github.com/prometheus/procfs v0.15.1 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/stretchr/objx v0.5.2 // indirect diff --git a/go.sum b/go.sum index 134ebb90ec..d73a7566ee 100644 --- a/go.sum +++ b/go.sum @@ -460,8 +460,8 @@ github.com/prometheus/common/assets v0.2.0 h1:0P5OrzoHrYBOSM1OigWL3mY8ZvV2N4zIE/ github.com/prometheus/common/assets v0.2.0/go.mod h1:D17UVUE12bHbim7HzwUvtqm6gwBEaDQ0F+hIGbFbccI= github.com/prometheus/exporter-toolkit v0.14.0 h1:NMlswfibpcZZ+H0sZBiTjrA3/aBFHkNZqE+iCj5EmRg= github.com/prometheus/exporter-toolkit v0.14.0/go.mod h1:Gu5LnVvt7Nr/oqTBUC23WILZepW0nffNo10XdhQcwWA= -github.com/prometheus/otlptranslator v0.0.0-20250527173959-2573485683d5 h1:LCbPeVKZSu9RS4CsaDCOmDCcribskJ8c6H5u1VvyxY0= -github.com/prometheus/otlptranslator v0.0.0-20250527173959-2573485683d5/go.mod h1:v1PzmPjSnNkmZSDvKJ9OmsWcmWMEF5+JdllEcXrRfzM= +github.com/prometheus/otlptranslator v0.0.0-20250620074007-94f535e0c588 h1:QlySqDdSESgWDePeAYskbbcKKdowI26m9aU9zloHyYE= +github.com/prometheus/otlptranslator v0.0.0-20250620074007-94f535e0c588/go.mod h1:P8AwMgdD7XEr6QRUJ2QWLpiAZTgTE2UYgjlu3svompI= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= diff --git a/storage/remote/otlptranslator/prometheusremotewrite/helper.go b/storage/remote/otlptranslator/prometheusremotewrite/helper.go index 630c010429..111b6212fb 100644 --- a/storage/remote/otlptranslator/prometheusremotewrite/helper.go +++ b/storage/remote/otlptranslator/prometheusremotewrite/helper.go @@ -155,11 +155,9 @@ func createAttributes(resource pcommon.Resource, attributes pcommon.Map, scope s // map ensures no duplicate label names. l := make(map[string]string, maxLabelCount) + labelNamer := otlptranslator.LabelNamer{UTF8Allowed: settings.AllowUTF8} for _, label := range labels { - finalKey := label.Name - if !settings.AllowUTF8 { - finalKey = otlptranslator.NormalizeLabel(finalKey) - } + finalKey := labelNamer.Build(label.Name) if existingValue, alreadyExists := l[finalKey]; alreadyExists { l[finalKey] = existingValue + ";" + label.Value } else { @@ -168,10 +166,7 @@ func createAttributes(resource pcommon.Resource, attributes pcommon.Map, scope s } for _, lbl := range promotedAttrs { - normalized := lbl.Name - if !settings.AllowUTF8 { - normalized = otlptranslator.NormalizeLabel(normalized) - } + normalized := labelNamer.Build(lbl.Name) if _, exists := l[normalized]; !exists { l[normalized] = lbl.Value } @@ -182,9 +177,7 @@ func createAttributes(resource pcommon.Resource, attributes pcommon.Map, scope s l["otel_scope_schema_url"] = scope.schemaURL scope.attributes.Range(func(k string, v pcommon.Value) bool { name := "otel_scope_" + k - if !settings.AllowUTF8 { - name = otlptranslator.NormalizeLabel(name) - } + name = labelNamer.Build(name) l[name] = v.AsString() return true }) @@ -222,8 +215,8 @@ func createAttributes(resource pcommon.Resource, attributes pcommon.Map, scope s log.Println("label " + name + " is overwritten. Check if Prometheus reserved labels are used.") } // internal labels should be maintained. - if !settings.AllowUTF8 && (len(name) <= 4 || name[:2] != "__" || name[len(name)-2:] != "__") { - name = otlptranslator.NormalizeLabel(name) + if len(name) <= 4 || name[:2] != "__" || name[len(name)-2:] != "__" { + name = labelNamer.Build(name) } l[name] = extras[i+1] }