{"record":{"id":"6906769e2bb9fcea","repo":"apache/shenyu","slug":"we-not-support-metric-registration-for-type-metric-gettype","errorCode":null,"errorMessage":"we not support metric registration for type: ${metric.getType()}","messagePattern":"we not support metric registration for type: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"shenyu-plugin/shenyu-plugin-metrics/src/main/java/org/apache/shenyu/plugin/metrics/reporter/MetricsReporter.java","lineNumber":72,"sourceCode":"    /**\n     * Register metrics.\n     *\n     * @param metrics metric collection\n     */\n    public static void registerMetrics(final Collection<Metric> metrics) {\n        for (Metric metric : metrics) {\n            switch (metric.getType()) {\n                case COUNTER:\n                    registerCounter(metric.getName(), getLabelNames(metric.getLabels()), metric.getDocument());\n                    break;\n                case GAUGE:\n                    registerGauge(metric.getName(), getLabelNames(metric.getLabels()), metric.getDocument());\n                    break;\n                case HISTOGRAM:\n                    registerHistogram(metric.getName(), getLabelNames(metric.getLabels()), metric.getDocument());\n                    break;\n                default:\n                    throw new RuntimeException(\"we not support metric registration for type: \" + metric.getType());\n            }\n        }\n    }\n\n    /**\n     * Register counter.\n     *\n     * @param name name\n     * @param labelNames label names\n     * @param document document for counter\n     */\n    public static void registerCounter(final String name, final String[] labelNames, final String document) {\n        Optional.ofNullable(metricsRegister).ifPresent(register -> register.registerCounter(name, labelNames, document));\n    }\n\n    /**\n     * Register counter.\n     *","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-plugin/shenyu-plugin-metrics/src/main/java/org/apache/shenyu/plugin/metrics/reporter/MetricsReporter.java#L54-L90","documentation":"MetricsReporter.registerMetrics iterates over metric definitions and registers each by its MetricType (counter, gauge, histogram, etc.). The switch statement has no case for the metric's type, so the default branch throws a RuntimeException. This means a metric definition was supplied with a type the reporter does not know how to register.","triggerScenarios":"Calling registerMetrics (directly or via the metrics plugin collecting a Metric) with a metric whose getType() returns a MetricType value not covered by the switch cases (e.g. SUMMARY or any newly added enum value not yet handled).","commonSituations":"Users enabling the metrics plugin with a prometheus/otel config that emits metric types the ShenYu reporter version doesn't support; upgrading ShenYu or a metrics library where new MetricType enum values appear but the reporter wasn't updated; custom metric collectors registering exotic metric types.","solutions":["Check the metric's type in your metrics configuration and change it to a supported type (counter, gauge, histogram).","Upgrade or align the shenyu-plugin-metrics module with the metrics library version so all MetricType values have switch cases.","If you control the code, add a case for the missing MetricType in MetricsReporter.registerMetrics instead of falling into default.","Skip/log unsupported metrics instead of throwing by replacing the default throw with a warning if partial registration is acceptable."],"exampleFix":"// before\ndefault:\n    throw new RuntimeException(\"we not support metric registration for type: \" + metric.getType());\n// after\ndefault:\n    LOG.warn(\"unsupported metric type {}, skipping registration for {}\", metric.getType(), metric.getName());\n    break;","handlingStrategy":"validation","validationCode":"if (!EnumSet.of(MetricType.COUNTER, MetricType.GAUGE, MetricType.HISTOGRAM).contains(metric.getType())) {\n    throw new IllegalArgumentException(\"unsupported metric type: \" + metric.getType());\n}","typeGuard":null,"tryCatchPattern":"try {\n    reporter.registerMetrics(metric);\n} catch (RuntimeException e) {\n    LOG.warn(\"metric {} skipped: {}\", metric.getName(), e.getMessage());\n}","preventionTips":["Restrict metric definitions to counter/gauge/histogram types.","When upgrading metrics library versions, diff the MetricType enum against the reporter's switch.","Prefer logging-and-skip over throwing for non-critical metrics."],"tags":["metrics","unsupported-type","runtime"],"backgroundTag":"unsupported-enum-value","analyzedSha":"567142e07261b3e615ae8850b30f4421f455cc5d","analyzedAt":"2026-09-12T10:08:21.293Z","contentChangedAt":"2026-09-12T10:08:21.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}