Conversation
| String name, Map<String, String> tags) { | ||
| if (tags.size() > 1 && !(tags instanceof LinkedHashMap<String, String>)) | ||
| throw new RuntimeException("Tags must be of type LinkedHashMap. tags: " + tags + " type: " + tags.getClass().getName()); | ||
| StringBuilder nameBuilder = new StringBuilder(100); |
There was a problem hiding this comment.
Thanks for the experiment — it’s useful for surfacing assumptions around tag map ordering.
Two suggestions if this moves toward something mergeable:
Call-site compatibility: explicitMetricName accepts a Map<String, String>, but a strict instanceof LinkedHashMap check would fail for existing multi-tag call sites that use other Map implementations. For example, some partition-scoped meters build tags with Map.of("topic", ..., "partition", ...), and other paths use HashMap-backed tags. Those callers would either need to be migrated first, or the method would need to normalize the tag order internally instead of enforcing a concrete map type.
Exception type: if we do want to reject invalid inputs here, IllegalArgumentException would be clearer than a bare RuntimeException.
Since we aren't on Java 21 yet, I'm falling back to LinkedHashMap. Let's
see how much this smells :)