{"record":{"id":"5e9187883d6b3917","repo":"apache/skywalking","slug":"decorate-not-supported-for-histogram-metrics","errorCode":null,"errorMessage":"decorate() not supported for histogram metrics","messagePattern":"decorate\\(\\) not supported for histogram metrics","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/v2/compiler/MALMetadataExtractor.java","lineNumber":175,"sourceCode":"        boolean hasDecorate = false;\n        for (final List<MALExpressionModel.MethodCall> chain : allChains) {\n            for (final MALExpressionModel.MethodCall mc : chain) {\n                if (\"decorate\".equals(mc.getName())) {\n                    hasDecorate = true;\n                    break;\n                }\n            }\n            if (hasDecorate) {\n                break;\n            }\n        }\n        if (hasDecorate) {\n            if (scopeType != null && scopeType != ScopeType.SERVICE) {\n                throw new IllegalStateException(\n                    \"decorate() should be invoked after service()\");\n            }\n            if (isHistogram) {\n                throw new IllegalStateException(\n                    \"decorate() not supported for histogram metrics\");\n            }\n        }\n\n        return new ExpressionMetadata(\n            new ArrayList<>(sampleNames),\n            scopeType,\n            scopeLabels,\n            aggregationLabels,\n            downsampling,\n            isHistogram,\n            percentiles\n        );\n    }\n\n    /**\n     * Generates the {@code metadata()} method source.\n     *","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/apache/skywalking/blob/102af09b4a56064e22050dded10e2c52e490d040/oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/v2/compiler/MALMetadataExtractor.java#L157-L193","documentation":"Thrown by MALMetadataExtractor when a MAL expression chain both uses decorate({...}) and produces a histogram metric (isHistogram == true, i.e. the chain contains histogram()/histogramIncrease()-style calls). Histogram metrics have a fixed multi-bucket storage shape and cannot carry the per-service attributes that decorate() injects, so the combination is rejected at compile time when the rule is loaded.","triggerScenarios":"A rule expression like '...histogram().service([...]).decorate({ me -> ... })' — any chain where the metadata extractor marked isHistogram and a decorate MethodCall appears. Also triggered when a file-level expPrefix containing decorate() is applied to a histogram rule.","commonSituations":"Adding a generic decorate step to a shared expPrefix in an otel-rules file that also contains histogram rules; porting latency-percentile rules and reusing the service-attribute decoration pattern from counter/gauge rules.","solutions":["Remove the .decorate({...}) call from the histogram rule's expression","If decorate() lives in the file-level expPrefix, move it into per-rule expressions for non-histogram rules only","If you need service attributes for a histogram-derived metric, compute them via tag({...}) on labels before the histogram aggregation instead"],"exampleFix":"# before\nexpr: request_duration.histogram().service(['svc']).decorate({ me -> me.attr0 = 'x' })\n\n# after\nexpr: request_duration.histogram().service(['svc'])","handlingStrategy":"validation","validationCode":"if (expr.contains(\"decorate(\") && (expr.contains(\".histogram(\"))) {\n    throw new IllegalArgumentException(\"decorate() cannot be combined with histogram(): \" + expr);\n}","typeGuard":null,"tryCatchPattern":"catch IllegalStateException at rule load; report the metric name and skip or fail per startup policy","preventionTips":["Treat histogram rules as a separate template without decorate","Audit shared expPrefix blocks for decorate whenever histogram rules share the file"],"tags":["mal","histogram","rule-validation","configuration"],"backgroundTag":null,"analyzedSha":"102af09b4a56064e22050dded10e2c52e490d040","analyzedAt":"2026-08-14T10:47:52.647Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}