private static Optional<String> toMBeanName(Map<String, String> tags) {
        List<Map.Entry<String, String>> filteredTags = tags.entrySet().stream()
                .filter(entry -> !entry.getValue().isEmpty())
                .collect(Collectors.toList());
        if (!filteredTags.isEmpty()) {
            String tagsString = filteredTags.stream()
                    .map(entry -> entry.getKey() + "=" + Sanitizer.jmxSanitize(entry.getValue()))
                    .collect(Collectors.joining(","));
            return Optional.of(tagsString);
        } else {
            return Optional.empty();
        }
    }
Creates a new MetricName object for gauges, meters, etc. created for this
metrics group.
@param name Descriptive name of the metric.
@param tags Additional attributes which mBean will have.
@return Sanitized metric name object.
server-common/src/main/java/org/apache/kafka/server/metrics/KafkaMetricsGroup.java