private static Optional<String> toScope(Map<String, String> tags) {
        if (tags == null) {
            return Optional.empty();
        }

        SortedMap<String, String> nonEmptyTags = collectNonEmptyTags(tags, TreeMap::new);
        if (nonEmptyTags.isEmpty()) {
            return Optional.empty();
        } else {
            StringBuilder tagsString = new StringBuilder();

            for (Iterator<Map.Entry<String, String>> iterator = nonEmptyTags.entrySet().iterator(); iterator.hasNext();) {
                // convert dot to _ since reporters like Graphite typically use dot to represent hierarchy
                Map.Entry<String, String> tagEntry = iterator.next();
                String convertedValue = tagEntry.getValue().replaceAll("\\.", "_");
                tagsString.append(tagEntry.getKey());
                tagsString.append(".");
                tagsString.append(convertedValue);

                if (iterator.hasNext()) {
                    tagsString.append(".");
                }
            }
            return Optional.of(tagsString.toString());
        }
    }
convenience method to replace {@link com.yammer.metrics.Metrics#defaultRegistry()}
server-common/src/main/java/org/apache/kafka/server/metrics/KafkaYammerMetrics.java