{"record":{"id":"757d98da14c67c00","repo":"apache/skywalking","slug":"can-t-find-metrics","errorCode":null,"errorMessage":"Can't find metrics, {}","messagePattern":"Can't find metrics, (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/v2/metadata/MetricsHolder.java","lineNumber":60,"sourceCode":"                MetricsFunction metricsFunction = aClass.getAnnotation(MetricsFunction.class);\n                REGISTER.put(\n                    metricsFunction.functionName(),\n                    (Class<? extends Metrics>) aClass\n                );\n            }\n        }\n    }\n\n    @SneakyThrows\n    public static Class<? extends Metrics> find(String functionName) {\n        if (!INITIALIZED) {\n            init();\n            INITIALIZED = true;\n        }\n\n        Class<? extends Metrics> metricsClass = REGISTER.get(functionName);\n        if (metricsClass == null) {\n            throw new IllegalArgumentException(\"Can't find metrics, \" + functionName);\n        }\n        return metricsClass;\n    }\n}\n","sourceCodeStart":42,"sourceCodeEnd":65,"githubUrl":"https://github.com/apache/skywalking/blob/102af09b4a56064e22050dded10e2c52e490d040/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/v2/metadata/MetricsHolder.java#L42-L65","documentation":"Thrown by MetricsHolder.find(functionName) during OAL script analysis when the aggregation function used in an OAL rule is not registered. MetricsHolder lazily scans and registers all classes implementing the Metrics aggregator interface (discovered via SPI/service files) into a REGISTER map keyed by function name. A null lookup means no registered aggregator answers to that function name.","triggerScenarios":"An OAL script uses an aggregation function that does not exist, e.g. 'percentile90(...)' or 'median(...)' when only registered names like 'longAvg', 'avg', 'sum', 'percentile' are available; or a custom Metrics implementation was written but its service-file entry in META-INF/services is missing; or the function name case does not match the registered key.","commonSituations":"Writing new OAL rules with a guessed function name; upgrading SkyWalking where function names changed; adding a custom aggregator without SPI registration; typo in the OAL rule (e.g. 'longAVG' vs 'longAvg').","solutions":["Check the supported function list in the OAL docs (docs/en/concepts-and-designs/oal.md) and correct the function name in the .oal file","If you intended a custom function, implement the Metrics class and register it via META-INF/services so MetricsHolder.init() picks it up, then rebuild","Verify the exact spelling/case of the registered key by inspecting the registered Metrics implementations' name() methods"],"exampleFix":"// before (OAL)\nservice_resp_time = from ServiceSpan.sum(duration) --> no; wrong usage\nendpoint_avg = from Endpoint.latency.longAvg() --> endpointAvg\n// after: use a registered function name\nendpoint_avg = from Endpoint.latency.avg() --> endpointAvg","handlingStrategy":"validation","validationCode":"// Lint OAL function names against the registry before deploy:\nSet<String> valid = Arrays.stream(metricsImplementations).map(m -> m.name()).collect(toSet());\nif (!valid.contains(oalFunctionName)) fail(\"Unknown OAL function: \" + oalFunctionName);","typeGuard":null,"tryCatchPattern":"Catch IllegalArgumentException around OALScriptParserV2 / MetricsHolder usage in tooling (CLI lint, dsl-debugging install) and surface the message; in OAP startup, let it fail fast — an OAL rule with an unknown function cannot work.","preventionTips":["Validate new OAL rules in a staging OAP or via the dsl-debugging API before applying them through dynamic configuration","For custom aggregators, add an SPI registration test that fails the build if the function name is not resolvable via MetricsHolder.find()"],"tags":["oal","aggregation","code-generation","spi"],"backgroundTag":null,"analyzedSha":"102af09b4a56064e22050dded10e2c52e490d040","analyzedAt":"2026-08-14T10:47:52.647Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}