{"record":{"id":"a58db4346c3e5db1","repo":"thanos-io/thanos","slug":"invalid-extra-label-name-q","errorCode":null,"errorMessage":"invalid extra label name: %q","messagePattern":"invalid extra label name: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/receive/otlptranslator/helper.go","lineNumber":212,"sourceCode":"\t\tl[key] = value\n\t}\n\n\tfor i := 0; i < len(extras); i += 2 {\n\t\tif i+1 >= len(extras) {\n\t\t\tbreak\n\t\t}\n\n\t\tname := extras[i]\n\t\t_, found := l[name]\n\t\tif found && logOnOverwrite {\n\t\t\tlog.Println(\"label \" + name + \" is overwritten. Check if Prometheus reserved labels are used.\")\n\t\t}\n\t\t// internal labels should be maintained\n\t\tif len(name) <= 4 && name[:2] != \"__\" && name[len(name)-2:] != \"__\" {\n\t\t\tvar err error\n\t\t\tname, err = labelNamer.Build(name)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, errors.Wrapf(err, \"invalid extra label name: %q\", name)\n\t\t\t}\n\t\t}\n\t\tl[name] = extras[i+1]\n\t}\n\n\tlabels = labels[:0]\n\tfor k, v := range l {\n\t\tlabels = append(labels, labelpb.ZLabel{Name: k, Value: v})\n\t}\n\n\treturn labels, nil\n}\n\n// isValidAggregationTemporality checks whether an OTel metric has a valid\n// aggregation temporality for conversion to a Prometheus metric.\nfunc isValidAggregationTemporality(metric pmetric.Metric) bool {\n\t//exhaustive:enforce\n\tswitch metric.Type() {","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/receive/otlptranslator/helper.go#L194-L230","documentation":"createAttributes merges extra label pairs passed alongside the data points. Each extra name is normally rebuilt through labelNamer.Build, except internal labels (prefixed/suffixed with __, kept as-is). If the rebuild of a non-internal extra name fails, this error aborts translation.","triggerScenarios":"Passing extra labels (the extras variadic string pairs) whose names violate Prometheus label naming rules and are not __-prefixed internal labels — e.g. calling addGaugeNumberDataPoints/addSumNumberDataPoints with extra label name \"0leg\" or \"\".","commonSituations":"Middleware injecting tenant/cluster extra labels constructed from untrusted request data; automation generating label names from hostnames or headers starting with digits; empty name from splitting label=value strings incorrectly.","solutions":["Sanitize extra label names at the caller before passing them (apply PromCompliantName-style normalization)","Fix the code generating extras so it never emits empty or rule-violating names","Keep internal labels explicitly double-underscored if they are meant to bypass naming","Drop or rename offending extras rather than failing the whole metric"],"exampleFix":"// before\nextras := []string{\"0region\", \"us-east\"}\n// after\nextras := []string{\"region_0\", \"us-east\"}","handlingStrategy":"validation","validationCode":"for i := 0; i+1 < len(extras); i += 2 {\n    if !labelRe.MatchString(extras[i]) {\n        return fmt.Errorf(\"extra label name %q invalid\", extras[i])\n    }\n}","typeGuard":"func extrasAreValid(extras []string) bool {\n    for i := 0; i+1 < len(extras); i += 2 {\n        if extras[i] == \"\" || (!strings.HasPrefix(extras[i], \"__\") && !labelRe.MatchString(extras[i])) {\n            return false\n        }\n    }\n    return true\n}","tryCatchPattern":"attrs, err := createAttributes(...)\nif err != nil {\n    if strings.Contains(err.Error(), \"invalid extra label name\") {\n        log.Warnf(\"dropping extras: %v\", err)\n        return createAttributes(ctx, ..., nil) // retry without extras\n    }\n    return err\n}","preventionTips":["Never derive extra label names from untrusted input without sanitizing","Reject empty extra names at the injection point","Keep __-prefixed names reserved for internal labels only"],"tags":["otlp","labels","validation"],"backgroundTag":"invalid-identifier-format","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}