apache/shenyu · error · RuntimeException

we not support metric registration for type

Error message

we not support metric registration for type: ${metric.getType()}

What it means

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.

Solutions

  1. Check the metric's type in your metrics configuration and change it to a supported type (counter, gauge, histogram).
  2. Upgrade or align the shenyu-plugin-metrics module with the metrics library version so all MetricType values have switch cases.
  3. If you control the code, add a case for the missing MetricType in MetricsReporter.registerMetrics instead of falling into default.
  4. Skip/log unsupported metrics instead of throwing by replacing the default throw with a warning if partial registration is acceptable.

Example fix

// before
default:
    throw new RuntimeException("we not support metric registration for type: " + metric.getType());
// after
default:
    LOG.warn("unsupported metric type {}, skipping registration for {}", metric.getType(), metric.getName());
    break;
Defensive patterns

Strategy: validation

Validate before calling

if (!EnumSet.of(MetricType.COUNTER, MetricType.GAUGE, MetricType.HISTOGRAM).contains(metric.getType())) {
    throw new IllegalArgumentException("unsupported metric type: " + metric.getType());
}

Try / catch

try {
    reporter.registerMetrics(metric);
} catch (RuntimeException e) {
    LOG.warn("metric {} skipped: {}", metric.getName(), e.getMessage());
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of apache/shenyu@567142e072 (2026-09-12). Data as JSON: /api/errors/6906769e2bb9fcea. Report an issue: GitHub.

Appendix: source

Thrown at shenyu-plugin/shenyu-plugin-metrics/src/main/java/org/apache/shenyu/plugin/metrics/reporter/MetricsReporter.java:72

    /**
     * Register metrics.
     *
     * @param metrics metric collection
     */
    public static void registerMetrics(final Collection<Metric> metrics) {
        for (Metric metric : metrics) {
            switch (metric.getType()) {
                case COUNTER:
                    registerCounter(metric.getName(), getLabelNames(metric.getLabels()), metric.getDocument());
                    break;
                case GAUGE:
                    registerGauge(metric.getName(), getLabelNames(metric.getLabels()), metric.getDocument());
                    break;
                case HISTOGRAM:
                    registerHistogram(metric.getName(), getLabelNames(metric.getLabels()), metric.getDocument());
                    break;
                default:
                    throw new RuntimeException("we not support metric registration for type: " + metric.getType());
            }
        }
    }

    /**
     * Register counter.
     *
     * @param name name
     * @param labelNames label names
     * @param document document for counter
     */
    public static void registerCounter(final String name, final String[] labelNames, final String document) {
        Optional.ofNullable(metricsRegister).ifPresent(register -> register.registerCounter(name, labelNames, document));
    }

    /**
     * Register counter.
     *

View on GitHub (pinned to 567142e072)