IllegalArgumentException: metric name cannot contain whitespace when registering custom metrics
0 reputation · 06 Nov 2021, 06:47 UTC
MetricRegistry Name Validation
When adding a custom metric to Dropwizard’s MetricRegistry, the framework throws IllegalArgumentException: metric name cannot contain whitespace if the supplied name includes spaces. This exception is documented in the MetricRegistry Javadoc and is also the root cause of 400 responses from the /metrics endpoint when malformed names are registered programmatically.
The goal is to expose human‑readable metric names in the /metrics output while still conforming to Prometheus label constraints, which disallow spaces. The current implementation requires manual replacement or sanitization of names before registration.
Unresolved decisions:
- Is there a built‑in mechanism or configuration option to transform or alias metric names containing spaces?
- What is the recommended strategy for mapping display names to valid Prometheus metric identifiers?
- How does the name transformation affect metric uniqueness and the ability to query metrics in Prometheus?