{"record":{"id":"25f058833bef4bfc","repo":"thanos-io/thanos","slug":"cannot-convert-exponential-to-native-histogram-sc","errorCode":null,"errorMessage":"cannot convert exponential to native histogram. Scale must be >= -4, was %d","messagePattern":"cannot convert exponential to native histogram\\. Scale must be >= -4, was (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/receive/otlptranslator/histograms.go","lineNumber":76,"sourceCode":"\n\t\texemplars, err := getPromExemplars[pmetric.ExponentialHistogramDataPoint](ctx, &c.everyN, pt)\n\t\tif err != nil {\n\t\t\treturn annots, err\n\t\t}\n\t\tts.Exemplars = append(ts.Exemplars, exemplars...)\n\t}\n\n\treturn annots, nil\n}\n\n// exponentialToNativeHistogram translates an OTel Exponential Histogram data point\n// to a Prometheus Native Histogram.\nfunc exponentialToNativeHistogram(p pmetric.ExponentialHistogramDataPoint) (prompb.Histogram, annotations.Annotations, error) {\n\tvar annots annotations.Annotations\n\tscale := p.Scale()\n\tif scale < -4 {\n\t\treturn prompb.Histogram{}, annots,\n\t\t\tfmt.Errorf(\"cannot convert exponential to native histogram.\"+\n\t\t\t\t\" Scale must be >= -4, was %d\", scale)\n\t}\n\n\tvar scaleDown int32\n\tif scale > 8 {\n\t\tscaleDown = scale - 8\n\t\tscale = 8\n\t}\n\n\tpSpans, pDeltas := convertBucketsLayout(p.Positive(), scaleDown)\n\tnSpans, nDeltas := convertBucketsLayout(p.Negative(), scaleDown)\n\n\th := prompb.Histogram{\n\t\t// The counter reset detection must be compatible with Prometheus to\n\t\t// safely set ResetHint to NO. This is not ensured currently.\n\t\t// Sending a sample that triggers counter reset but with ResetHint==NO\n\t\t// would lead to Prometheus panic as it does not double check the hint.\n\t\t// Thus we're explicitly saying UNKNOWN here, which is always safe.","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/receive/otlptranslator/histograms.go#L58-L94","documentation":"exponentialToNativeHistogram maps OTLP exponential histograms to Prometheus native histograms, which only support scale >= -4. If the data point's scale is below -4 the conversion cannot proceed and this error is returned (the whole metric fails; a smaller scale would need bucket regeneration).","triggerScenarios":"Receiving OTLP ExponentialHistogram data points with Scale() < -4 — very coarse bucket layouts — sent to the OTLP translation endpoint and converted with native histogram support enabled.","commonSituations":"Producers configured with extremely low-resolution exponential histograms; SDKs letting users set negative scale aggressively; metric data crafted/synthetic with scale like -7.","solutions":["Increase the histogram scale on the producer (e.g. rescale in the SDK/collector so scale >= -4)","Configure the OTel collector's transform/aggregate processor to convert scale before forwarding","Disable native-histogram conversion for these metrics so they are exported differently","Prefer scaleDown path only when scale > 8; for scale < -4 you must fix the source data"],"exampleFix":"// before: producer sets very coarse scale\nagg := aggregator.NewExponential(aggConfig{Scale: -6})\n// after: ensure minimum supported scale\nagg := aggregator.NewExponential(aggConfig{Scale: -4})","handlingStrategy":"validation","validationCode":"if dp.Scale() < -4 {\n    return fmt.Errorf(\"histogram scale %d below native-histogram minimum -4\", dp.Scale())\n}","typeGuard":"func nativeHistCompatible(dp pmetric.ExponentialHistogramDataPoint) bool {\n    return dp.Scale() >= -4\n}","tryCatchPattern":"h, annots, err := exponentialToNativeHistogram(dp)\nif err != nil {\n    if strings.Contains(err.Error(), \"Scale must be >= -4\") {\n        log.Warnf(\"dropping histogram: %v\", err)\n        return nil\n    }\n    return err\n}","preventionTips":["Set SDK histogram aggregation scale to the default (>= 0) unless rescaling is understood","Rescale in the collector before forwarding to a native-histogram receiver","Alert on exported scales below -4 in telemetry pipelines"],"tags":["otlp","histogram","native-histogram"],"backgroundTag":"value-out-of-range","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"}